diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/textadept/bookmarks.lua | 69 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 6 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 6 |
3 files changed, 34 insertions, 47 deletions
diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index d04bb424..f3f2f1e1 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -36,48 +36,35 @@ 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 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 bookmarked line in the current buffer. --- @name goto_next -function M.goto_next() - goto_mark(buffer.marker_next, 1, 0) -end - --- --- Goes to the previous bookmarked line in the current buffer. --- @name goto_prev -function M.goto_prev() - goto_mark(buffer.marker_previous, -1, buffer.line_count) -end - ---- --- Prompts the user to select a bookmarked line to go to. --- @name goto_bookmark -function M.goto_bookmark() - local buffer = buffer - local markers, line = {}, buffer:marker_next(0, 2^MARK_BOOKMARK) - if line == -1 then return end - repeat - local text = buffer:get_line(line):sub(1, -2) -- chop \n - markers[#markers + 1] = tostring(line + 1)..': '..text - line = buffer:marker_next(line + 1, 2^MARK_BOOKMARK) - until line < 0 - local line = gui.filteredlist(_L['Select Bookmark'], _L['Bookmark'], markers) - if line then _M.textadept.editing.goto_line(line:match('^%d+')) end +-- Prompts the user to select a bookmarked line to go to unless *next* is given. +-- If *next* is `true` or `false`, goes to the next or previous bookmark, +-- respectively. +-- @param next Optional flag indicating whether to go to the next or previous +-- bookmarked line relative to the current line. The default value is `nil`, +-- prompting the user for a bookmarked line to go to. +-- @name goto_mark +function M.goto_mark(next) + if next == nil then + local buffer = buffer + local marks, line = {}, buffer:marker_next(0, 2^MARK_BOOKMARK) + if line == -1 then return end + repeat + local text = buffer:get_line(line):sub(1, -2) -- chop \n + marks[#marks + 1] = tostring(line + 1)..': '..text + line = buffer:marker_next(line + 1, 2^MARK_BOOKMARK) + until line < 0 + local line = gui.filteredlist(_L['Select Bookmark'], _L['Bookmark'], marks) + if line then _M.textadept.editing.goto_line(line:match('^%d+')) end + else + local f = next and buffer.marker_next or buffer.marker_previous + local current_line = buffer:line_from_position(buffer.current_pos) + local line = f(buffer, current_line + (next and 1 or -1), 2^MARK_BOOKMARK) + if line == -1 then + line = f(buffer, (next and 0 or buffer.line_count), 2^MARK_BOOKMARK) + end + if line >= 0 then _M.textadept.editing.goto_line(line + 1) end + end end local CURSES_MARK = _SCINTILLA.constants.SC_MARK_CHARACTER + string.byte(' ') diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index d0b161d1..672c7994 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -479,9 +479,9 @@ keys[not OSX and (not CURSES and 'cf2' or 'f1') or 'mf2'] = _M.textadept.bookmarks.toggle keys[not OSX and (not CURSES and 'csf2' or 'f6') or 'msf2'] = _M.textadept.bookmarks.clear -keys.f2 = _M.textadept.bookmarks.goto_next -keys[not CURSES and 'sf2' or 'f3'] = _M.textadept.bookmarks.goto_prev -keys[not CURSES and 'af2' or 'f4'] = _M.textadept.bookmarks.goto_bookmark +keys.f2 = {_M.textadept.bookmarks.goto_mark, true} +keys[not CURSES and 'sf2' or 'f3'] = {_M.textadept.bookmarks.goto_mark, false} +keys[not CURSES and 'af2' or 'f4'] = _M.textadept.bookmarks.goto_mark -- Snapopen. keys[not OSX and 'cu' or 'mu'] = {io.snapopen, _USERHOME} -- TODO: {io.snapopen, _HOME} diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index c7babf8d..4791a7c5 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -112,9 +112,9 @@ local menubar = { { title = _L['_Bookmark'], {_L['_Toggle Bookmark'], _M.textadept.bookmarks.toggle}, {_L['_Clear Bookmarks'], _M.textadept.bookmarks.clear}, - {_L['_Next Bookmark'], _M.textadept.bookmarks.goto_next}, - {_L['_Previous Bookmark'], _M.textadept.bookmarks.goto_prev}, - {_L['_Goto Bookmark...'], _M.textadept.bookmarks.goto_bookmark}, + {_L['_Next Bookmark'], {_M.textadept.bookmarks.goto_mark, true}}, + {_L['_Previous Bookmark'], {_M.textadept.bookmarks.goto_mark, false}}, + {_L['_Goto Bookmark...'], _M.textadept.bookmarks.goto_mark}, }, { title = _L['Snap_open'], {_L['Snapopen _User Home'], {io.snapopen, _USERHOME}}, |