diff options
-rw-r--r-- | core/file_io.lua | 13 | ||||
-rw-r--r-- | core/gui.lua | 24 | ||||
-rw-r--r-- | modules/textadept/adeptsense.lua | 1 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 6 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 27 | ||||
-rw-r--r-- | modules/textadept/run.lua | 10 |
6 files changed, 38 insertions, 43 deletions
diff --git a/core/file_io.lua b/core/file_io.lua index 1b24586c..adcc3d28 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -219,7 +219,7 @@ local function set_encoding(buffer, encoding) error(_L['Cannot change binary file encoding']) end local pos, first_visible_line = buffer.current_pos, buffer.first_visible_line - local text = buffer:get_text(buffer.length) + local text = buffer:get_text() text = text:iconv(buffer.encoding, 'UTF-8') text = text:iconv(encoding, buffer.encoding) text = text:iconv('UTF-8', encoding) @@ -236,7 +236,7 @@ local function save(buffer) buffer:check_global() if not buffer.filename then buffer:save_as() return end events.emit(events.FILE_BEFORE_SAVE, buffer.filename) - local text = buffer:get_text(buffer.length) + local text = buffer:get_text() if buffer.encoding then text = (buffer.encoding_bom or '')..text:iconv(buffer.encoding, 'UTF-8') end @@ -264,11 +264,10 @@ local function save_as(buffer, utf8_filename) (buffer.filename or ''):match('[^/\\]+$') or '', '--no-newline') end - if #utf8_filename > 0 then - buffer.filename = utf8_filename - buffer:save() - events.emit(events.FILE_SAVED_AS, utf8_filename) - end + if utf8_filename == '' then return end + buffer.filename = utf8_filename + buffer:save() + events.emit(events.FILE_SAVED_AS, utf8_filename) end --- diff --git a/core/gui.lua b/core/gui.lua index 445a65de..4c3c322e 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -252,7 +252,7 @@ function gui.select_theme() reset() end -local events, events_connect, events_emit = events, events.connect, events.emit +local events, events_connect = events, events.connect -- Sets default properties for a Scintilla window. events_connect(events.VIEW_NEW, function() @@ -274,7 +274,7 @@ events_connect(events.VIEW_NEW, function() local ok, err = pcall(dofile, THEME..'/view.lua') if not ok then io.stderr:write(err) end end) -events_connect(events.VIEW_NEW, function() events_emit(events.UPDATE_UI) end) +events_connect(events.VIEW_NEW, function() events.emit(events.UPDATE_UI) end) local SETDIRECTFUNCTION = _SCINTILLA.properties.direct_function[1] local SETDIRECTPOINTER = _SCINTILLA.properties.doc_pointer[2] @@ -310,7 +310,7 @@ end) -- Sets the title of the Textadept window to the buffer's filename. -- @param buffer The global buffer. -local function set_title(buffer) +local function set_title() local filename = buffer.filename or buffer._type or _L['Untitled'] local basename = buffer.filename and filename:match('[^/\\]+$') or filename gui.title = string.format('%s %s Textadept (%s)', basename, @@ -320,13 +320,13 @@ end -- Changes Textadept title to show the buffer as being "clean". events_connect(events.SAVE_POINT_REACHED, function() buffer.dirty = false - set_title(buffer) + set_title() end) -- Changes Textadept title to show thee buffer as "dirty". events_connect(events.SAVE_POINT_LEFT, function() buffer.dirty = true - set_title(buffer) + set_title() end) -- Open uri(s). @@ -344,7 +344,7 @@ events_connect(events.URI_DROPPED, function(utf8_uris) end end) events_connect(events.APPLEEVENT_ODOC, function(uri) - return events_emit(events.URI_DROPPED, 'file://'..uri) + return events.emit(events.URI_DROPPED, 'file://'..uri) end) local EOLs = {_L['CRLF'], _L['CR'], _L['LF']} @@ -371,8 +371,8 @@ events_connect(events.MARGIN_CLICK, function(margin, pos, modifiers) end) -- Updates the statusbar and titlebar for a new Scintilla document. -events_connect(events.BUFFER_NEW, function() events_emit(events.UPDATE_UI) end) -events_connect(events.BUFFER_NEW, function() set_title(buffer) end) +events_connect(events.BUFFER_NEW, function() events.emit(events.UPDATE_UI) end) +events_connect(events.BUFFER_NEW, function() set_title() end) -- Save buffer properties. events_connect(events.BUFFER_BEFORE_SWITCH, function() @@ -403,14 +403,14 @@ end) -- Updates titlebar and statusbar. events_connect(events.BUFFER_AFTER_SWITCH, function() - set_title(buffer) - events_emit(events.UPDATE_UI) + set_title() + events.emit(events.UPDATE_UI) end) -- Updates titlebar and statusbar. events_connect(events.VIEW_AFTER_SWITCH, function() - set_title(buffer) - events_emit(events.UPDATE_UI) + set_title() + events.emit(events.UPDATE_UI) end) events_connect(events.RESET_AFTER, diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua index 6d58ff41..55c0effc 100644 --- a/modules/textadept/adeptsense.lua +++ b/modules/textadept/adeptsense.lua @@ -661,6 +661,7 @@ function M.get_apidoc(sense, symbol) end local apidocs = nil + --- -- Shows a call tip with API documentation for the symbol behind the caret. -- If documentation is already being shown, cycles through multiple definitions. diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index baaa09ff..896d4b0d 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -86,12 +86,6 @@ M.braces = {[40] = 1, [41] = 1, [91] = 1, [93] = 1, [123] = 1, [125] = 1} -- @see TYPEOVER_CHARS M.typeover_chars = {[41] = 1, [93] = 1, [125] = 1, [39] = 1, [34] = 1} --- The current call tip. --- Used for displaying call tips. --- @class table --- @name current_call_tip -local current_call_tip = {} - -- Matches characters specified in char_matches. events.connect(events.CHAR_ADDED, function(c) if not M.AUTOPAIR then return end diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 67436b1d..7f945a9e 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -11,19 +11,6 @@ local M = {} -- menus. module('_M.textadept.menu')]] --- Get a string uniquely identifying a key binding. --- This is used to match menu items with key bindings to show the key shortcut. --- @param f A value in the `keys` table. -local function get_id(f) - local id = '' - if type(f) == 'function' then - id = tostring(f) - elseif type(f) == 'table' then - for _, v in ipairs(f) do id = id..tostring(v) end - end - return id -end - local _L, _M, buffer, view = _L, _M, buffer, view local m_editing, utils = _M.textadept.editing, _M.textadept.keys.utils local SEPARATOR, c = {''}, _SCINTILLA.constants @@ -246,6 +233,19 @@ local function get_gdk_key(key_seq) return byte, modifiers end +-- Get a string uniquely identifying a key binding. +-- This is used to match menu items with key bindings to show the key shortcut. +-- @param f A value in the `keys` table. +local function get_id(f) + local id = '' + if type(f) == 'function' then + id = tostring(f) + elseif type(f) == 'table' then + for i = 1, #f do id = id..tostring(f[i]) end + end + return id +end + local key_shortcuts, menu_actions, contextmenu_actions -- Creates a menu suitable for `gui.menu()` from the menu table format. @@ -348,6 +348,7 @@ function M.select_command() if i then keys.run_command(commands[i + 1], type(commands[i + 1])) end end +-- Performs the appropriate action when clicking a menu item. events.connect(events.MENU_CLICKED, function(menu_id) local actions = menu_id < 1000 and menu_actions or contextmenu_actions local action = actions[menu_id < 1000 and menu_id or menu_id - 1000] diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 91c8a522..18577448 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -38,7 +38,6 @@ module('_M.textadept.run')]] M.MARK_ERROR_BACK = not CURSES and 0x8080CC or 0x0000FF -- Events. -local events, events_connect, events_emit = events, events.connect, events.emit events.COMPILE_OUTPUT, events.RUN_OUTPUT = 'compile_output', 'run_output' local preferred_view @@ -71,6 +70,7 @@ local function command(cmd_table, compiling) local current_dir = lfs.currentdir() lfs.chdir(filedir) local event = compiling and events.COMPILE_OUTPUT or events.RUN_OUTPUT + local events_emit = events.emit local lexer = buffer:get_lexer() events_emit(event, lexer, '> '..command:iconv('UTF-8', _CHARSET)) local p = io.popen(command..' 2>&1') @@ -138,7 +138,7 @@ M.compile_command = {} -- @see _G.events -- @name compile function M.compile() command(M.compile_command, true) end -events_connect(events.COMPILE_OUTPUT, print_output) +events.connect(events.COMPILE_OUTPUT, print_output) --- -- Map of file extensions (excluding the leading '.') to their associated @@ -165,7 +165,7 @@ M.run_command = {} -- @see _G.events -- @name run function M.run() command(M.run_command) end -events_connect(events.RUN_OUTPUT, print_output) +events.connect(events.RUN_OUTPUT, print_output) --- -- Map of lexer names to their error string details, tables containing the @@ -240,7 +240,7 @@ function M.goto_error(line, next) buffer.annotation_style[line - 1] = 8 -- error end end -events_connect(events.DOUBLE_CLICK, function(pos, line) M.goto_error(line) end) +events.connect(events.DOUBLE_CLICK, function(pos, line) M.goto_error(line) end) local CURSES_MARK = _SCINTILLA.constants.SC_MARK_CHARACTER + string.byte(' ') -- Sets view properties for error markers. @@ -249,6 +249,6 @@ local function set_error_properties() buffer.marker_back[MARK_ERROR] = M.MARK_ERROR_BACK end if buffer then set_error_properties() end -events_connect(events.VIEW_NEW, set_error_properties) +events.connect(events.VIEW_NEW, set_error_properties) return M |