diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/lua/ta_api | 4 | ||||
-rw-r--r-- | modules/lua/ta_tags | 2 | ||||
-rw-r--r-- | modules/textadept/bookmarks.lua | 24 |
3 files changed, 25 insertions, 5 deletions
diff --git a/modules/lua/ta_api b/modules/lua/ta_api index 6a7faa4e..315fe204 100644 --- a/modules/lua/ta_api +++ b/modules/lua/ta_api @@ -61,7 +61,9 @@ EOL_CRLF buffer.EOL_CRLF (number, Read-only)\n EOL_LF buffer.EOL_LF (number, Read-only)\n ERROR events.ERROR (string)\nEmitted when an error occurs.\nArguments:\n\n* _`text`_: The error message text. ERROR lexer.ERROR (string)\nThe token name for error tokens. +FILE_AFTER_RELOAD events.FILE_AFTER_RELOAD (string)\nEmitted after reloading the current file.\nEmitted by `buffer:reload()`. FILE_AFTER_SAVE events.FILE_AFTER_SAVE (string)\nEmitted right after saving a file to disk.\nEmitted by `buffer:save()` and `buffer:save_as()`.\nArguments:\n\n* _`filename`_: The filename of the file being saved.\n* _`saved_as`_: Whether or not the file was saved under a different\n filename. +FILE_BEFORE_RELOAD events.FILE_BEFORE_RELOAD (string)\nEmitted before reloading the current file.\nEmitted by `buffer:reload()`. FILE_BEFORE_SAVE events.FILE_BEFORE_SAVE (string)\nEmitted right before saving a file to disk.\nEmitted by `buffer:save()`.\nArguments:\n\n* _`filename`_: The filename of the file being saved. FILE_CHANGED events.FILE_CHANGED (string)\nEmitted when Textadept detects that an open file was modified externally.\nWhen connecting to this event, connect with an index of 1 in order to\noverride the default prompt to reload the file.\nArguments:\n\n* _`filename`_: The filename externally modified. FILE_OPENED events.FILE_OPENED (string)\nEmitted after opening a file in a new buffer.\nEmitted by `io.open_file()`.\nArguments:\n\n* _`filename`_: The opened file's filename. @@ -779,7 +781,7 @@ regex_label_text ui.find.regex_label_text (string, Write-only)\nThe text of the register args.register(short, long, narg, f, description)\nRegisters a command line switch with short and long versions *short* and\n*long*, respectively. *narg* is the number of arguments the switch accepts,\n*f* is the function called when the switch is tripped, and *description* is\nthe switch's description when displaying help.\n@param short The string short version of the switch.\n@param long The string long version of the switch.\n@param narg The number of expected parameters for the switch.\n@param f The Lua function to run when the switch is tripped. It is passed\n *narg* string arguments.\n@param description The string description of the switch for command line\n help. register_image view.register_image(view, type, xpm_data)\nRegisters XPM image *xpm_data* to type number *type* for use in\nautocompletion and user lists.\n@param view A view.\n@param type Integer type to register the image with.\n@param xpm_data The XPM data as described in `view.marker_define_pixmap()`. register_rgba_image view.register_rgba_image(view, type, pixels)\nRegisters RGBA image *pixels* to type number *type* for use in autocompletion\nand user lists.\nThe dimensions for *pixels* (`view.rgba_image_width` and\n`view.rgba_image_height`) must have already been defined. *pixels* is a\nsequence of 4 byte pixel values (red, blue, green, and alpha) defining the\nimage line by line starting at the top-left pixel.\n@param view A view.\n@param type Integer type to register the image with.\n@param pixels The RGBA data as described in\n `view.marker_define_rgba_image()`. -reload buffer.reload(buffer)\nReloads the buffer's file contents, discarding any changes.\n@param buffer A buffer. +reload buffer.reload(buffer)\nReloads the buffer's file contents, discarding any changes.\nEmits `FILE_BEFORE_RELOAD` and `FILE_AFTER_RELOAD` events if the buffer is\nthe current one.\n@param buffer A buffer. replace ui.find.replace()\nMimics pressing the "Replace" button. replace_all ui.find.replace_all()\nMimics pressing the "Replace All" button. replace_all_button_text ui.find.replace_all_button_text (string, Write-only)\nThe text of the "Replace All" button.\nThis is primarily used for localization. diff --git a/modules/lua/ta_tags b/modules/lua/ta_tags index ecda2683..feb359d0 100644 --- a/modules/lua/ta_tags +++ b/modules/lua/ta_tags @@ -61,7 +61,9 @@ EOL_CRLF _HOME/core/.buffer.luadoc /^module('buffer')$/;" F class:buffer EOL_LF _HOME/core/.buffer.luadoc /^module('buffer')$/;" F class:buffer ERROR _HOME/core/events.lua /^module('events')]]$/;" F class:events ERROR _HOME/lexers/lexer.lua /^module('lexer')]=]$/;" F class:lexer +FILE_AFTER_RELOAD _HOME/core/file_io.lua /^module('io')]]$/;" F class:events FILE_AFTER_SAVE _HOME/core/file_io.lua /^module('io')]]$/;" F class:events +FILE_BEFORE_RELOAD _HOME/core/file_io.lua /^module('io')]]$/;" F class:events FILE_BEFORE_SAVE _HOME/core/file_io.lua /^module('io')]]$/;" F class:events FILE_CHANGED _HOME/core/file_io.lua /^module('io')]]$/;" F class:events FILE_OPENED _HOME/core/file_io.lua /^module('io')]]$/;" F class:events diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index a065baff..04ade1a4 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -26,6 +26,14 @@ end -- @name clear function M.clear() buffer:marker_delete_all(M.MARK_BOOKMARK) end +-- Returns an iterator for all bookmarks in the current buffer. +local function bookmarks() + return function(_, line) + line = buffer:marker_next(line + 1, 1 << M.MARK_BOOKMARK - 1) + return line >= 1 and line or nil + end, nil, 0 +end + --- -- Prompts the user to select a bookmarked line to move the caret to the -- beginning of unless *next* is given. @@ -36,10 +44,10 @@ function M.clear() buffer:marker_delete_all(M.MARK_BOOKMARK) end -- prompting the user for a bookmarked line to go to. -- @name goto_mark function M.goto_mark(next) - local BOOKMARK_BIT = 1 << M.MARK_BOOKMARK - 1 if next ~= nil then local f = next and buffer.marker_next or buffer.marker_previous local current_line = buffer:line_from_position(buffer.current_pos) + local BOOKMARK_BIT = 1 << M.MARK_BOOKMARK - 1 local line = f(buffer, current_line + (next and 1 or -1), BOOKMARK_BIT) if line == -1 then line = f(buffer, (next and 1 or buffer.line_count), BOOKMARK_BIT) @@ -55,12 +63,10 @@ function M.goto_mark(next) local filename = buffer.filename or buffer._type or _L['Untitled'] if buffer.filename then filename = filename:iconv('UTF-8', _CHARSET) end local basename = buffer.filename and filename:match('[^/\\]+$') or filename - local line = buffer:marker_next(1, BOOKMARK_BIT) - while line >= 1 do + for line in bookmarks() do utf8_list[#utf8_list + 1] = string.format( '%s:%d: %s', basename, line, buffer:get_line(line):match('^[^\r\n]*')) buffers[#buffers + 1] = buffer - line = buffer:marker_next(line + 1, BOOKMARK_BIT) end ::continue:: end @@ -75,4 +81,14 @@ function M.goto_mark(next) textadept.editing.goto_line(tonumber(utf8_list[i]:match('^[^:]+:(%d+):'))) end +local lines = {} +-- Save and restore bookmarks on buffer:reload(). +events.connect(events.FILE_BEFORE_RELOAD, function() + for line in bookmarks() do lines[#lines + 1] = line end +end) +events.connect(events.FILE_AFTER_RELOAD, function() + for _, line in ipairs(lines) do buffer:marker_add(line, M.MARK_BOOKMARK) end + lines = {} -- clear +end) + return M |