aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2012-08-16 16:08:14 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2012-08-16 16:08:14 -0400
commit1c095efdb46954937a9f82b5309945ea2043fe8f (patch)
tree041bff74b2c372bce2cb4cf88999713c83447fed
parentd8cecf9af47382904a2adfc9477259cd2f26126b (diff)
Lua code cleanup; modules/textadept/bookmarks.lua
-rw-r--r--modules/textadept/bookmarks.lua29
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
---