aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2012-08-16 15:08:58 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2012-08-16 15:08:58 -0400
commitd8cecf9af47382904a2adfc9477259cd2f26126b (patch)
tree67b8513774522e0804428f143232e15bde4f9262 /modules/textadept
parent170f1fd141bf3b1be12aad4f7a5ae874f3d53789 (diff)
downloadtextadept-d8cecf9af47382904a2adfc9477259cd2f26126b.tar.gz
textadept-d8cecf9af47382904a2adfc9477259cd2f26126b.zip
Consolidated bookmark add/remove into `toggle`; modules/textadept/bookmarks.lua
Diffstat (limited to 'modules/textadept')
-rw-r--r--modules/textadept/bookmarks.lua31
1 files changed, 9 insertions, 22 deletions
diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua
index 7c06ac64..f508626d 100644
--- a/modules/textadept/bookmarks.lua
+++ b/modules/textadept/bookmarks.lua
@@ -14,32 +14,19 @@ M.MARK_BOOKMARK_COLOR = not NCURSES and 0xB3661A or 0xFF0000
local MARK_BOOKMARK = _SCINTILLA.next_marker_number()
---
--- Adds a bookmark to the current line.
--- @name add
-function M.add()
- local buffer = buffer
- local line = buffer:line_from_position(buffer.current_pos)
- buffer:marker_add(line, MARK_BOOKMARK)
-end
-
----
--- Clears the bookmark at the current line.
--- @name remove
-function M.remove()
- local buffer = buffer
- local line = buffer:line_from_position(buffer.current_pos)
- buffer:marker_delete(line, MARK_BOOKMARK)
-end
-
----
-- Toggles a bookmark on the current line.
+-- @param on If `true`, adds a bookmark to the current line. If `false`, removes
+-- the bookmark on the current line. Otherwise, toggles a bookmark.
-- @name toggle
-function M.toggle()
+function M.toggle(on)
local buffer = buffer
local line = buffer:line_from_position(buffer.current_pos)
- local markers = buffer:marker_get(line) -- bit mask
- local bit = 2^MARK_BOOKMARK
- if markers % (bit + bit) < bit then M.add() else M.remove() end
+ local f = on and buffer.marker_add or buffer.marker_delete
+ if on == nil then -- toggle
+ local bit, marker_mask = 2^MARK_BOOKMARK, buffer:marker_get(line)
+ if marker_mask % (bit + bit) < bit then f = buffer.marker_add end
+ end
+ f(buffer, line, MARK_BOOKMARK)
end
---