diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/textadept/bookmarks.lua | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index f508626d..75f36872 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -36,28 +36,33 @@ function M.clear() buffer:marker_delete_all(MARK_BOOKMARK) end +-- Uses the given function and parameters to go to the next or previous mark. +-- @param f `buffer.marker_next` when going to the next mark, +-- `buffer.marker_previous` when going to the previous mark. +-- @param increment `1` when going to the next mark, `-1` when going to the +-- previous mark. +-- @param start `0` when going to the next mark, `buffer.line_count` when going +-- to the previous mark. +local function goto_mark(f, increment, wrap_start) + local buffer = buffer + local current_line = buffer:line_from_position(buffer.current_pos) + local line = f(buffer, current_line + increment, 2^MARK_BOOKMARK) + if line == -1 then line = f(buffer, wrap_start, 2^MARK_BOOKMARK) end + if line >= 0 then _M.textadept.editing.goto_line(line + 1) end +end + --- -- Goes to the next bookmark in the current buffer. -- @name goto_next function M.goto_next() - local buffer = buffer - local current_line = buffer:line_from_position(buffer.current_pos) - local line = buffer:marker_next(current_line + 1, 2^MARK_BOOKMARK) - if line == -1 then line = buffer:marker_next(0, 2^MARK_BOOKMARK) end - if line >= 0 then _M.textadept.editing.goto_line(line + 1) end + goto_mark(buffer.marker_next, 1, 0) end --- -- Goes to the previous bookmark in the current buffer. -- @name goto_prev function M.goto_prev() - local buffer = buffer - local current_line = buffer:line_from_position(buffer.current_pos) - local line = buffer:marker_previous(current_line - 1, 2^MARK_BOOKMARK) - if line == -1 then - line = buffer:marker_previous(buffer.line_count, 2^MARK_BOOKMARK) - end - if line >= 0 then _M.textadept.editing.goto_line(line + 1) end + goto_mark(buffer.marker_previous, -1, buffer.line_count) end --- |