diff options
author | 2012-01-01 12:32:38 -0500 | |
---|---|---|
committer | 2012-01-01 12:32:38 -0500 | |
commit | 3d6f697add4606a1a84f9d77993d8f05daf4f8fe (patch) | |
tree | f98059344b097e3843908277206ebc69f2b226f7 | |
parent | bd55d676f133a5b38ca53c33bf599d66dfe1fc87 (diff) | |
download | textadept-3d6f697add4606a1a84f9d77993d8f05daf4f8fe.tar.gz textadept-3d6f697add4606a1a84f9d77993d8f05daf4f8fe.zip |
Code cleanup.
-rw-r--r--[-rwxr-xr-x] | core/._m.luadoc | 0 | ||||
-rw-r--r-- | core/file_io.lua | 18 | ||||
-rw-r--r-- | core/gui.lua | 46 | ||||
-rw-r--r-- | modules/textadept/adeptsense.lua | 4 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 42 | ||||
-rw-r--r-- | modules/textadept/find.lua | 16 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 201 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 124 | ||||
-rw-r--r-- | modules/textadept/mime_types.lua | 14 | ||||
-rw-r--r-- | modules/textadept/run.lua | 8 | ||||
-rw-r--r-- | modules/textadept/session.lua | 3 |
11 files changed, 237 insertions, 239 deletions
diff --git a/core/._m.luadoc b/core/._m.luadoc index 0a6839d3..0a6839d3 100755..100644 --- a/core/._m.luadoc +++ b/core/._m.luadoc diff --git a/core/file_io.lua b/core/file_io.lua index 82ddd73d..8546d652 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -41,7 +41,7 @@ module('io')]] -- * `filename`: The filename encoded in UTF-8. -- Events. -local events = events +local events, events_connect = events, events.connect events.FILE_OPENED = 'file_opened' events.FILE_BEFORE_SAVE = 'file_before_save' events.FILE_AFTER_SAVE = 'file_after_save' @@ -139,15 +139,15 @@ function io.open_file(utf8_filenames) else encoding = nil end - local c = _SCINTILLA.constants buffer.encoding, buffer.encoding_bom = encoding, encoding_bom - buffer.code_page = encoding and c.SC_CP_UTF8 or 0 + buffer.code_page = encoding and _SCINTILLA.constants.SC_CP_UTF8 or 0 -- Tries to set the buffer's EOL mode appropriately based on the file. local s, e = text:find('\r\n?') if s and e then - buffer.eol_mode = (s == e and c.SC_EOL_CR or c.SC_EOL_CRLF) + buffer.eol_mode = (s == e and _SCINTILLA.constants.SC_EOL_CR or + _SCINTILLA.constants.SC_EOL_CRLF) else - buffer.eol_mode = c.SC_EOL_LF + buffer.eol_mode = _SCINTILLA.constants.SC_EOL_LF end buffer:add_text(text, #text) buffer:goto_pos(0) @@ -317,11 +317,11 @@ local function update_modified_file() end end end -events.connect(events.BUFFER_AFTER_SWITCH, update_modified_file) -events.connect(events.VIEW_AFTER_SWITCH, update_modified_file) +events_connect(events.BUFFER_AFTER_SWITCH, update_modified_file) +events_connect(events.VIEW_AFTER_SWITCH, update_modified_file) -- Set additional buffer functions. -events.connect(events.BUFFER_NEW, function() +events_connect(events.BUFFER_NEW, function() local buffer = buffer buffer.reload = reload buffer.save, buffer.save_as = save, save_as @@ -330,7 +330,7 @@ events.connect(events.BUFFER_NEW, function() end) -- Close initial "Untitled" buffer. -events.connect(events.FILE_OPENED, function(utf8_filename) +events_connect(events.FILE_OPENED, function(utf8_filename) local b = _BUFFERS[1] if #_BUFFERS == 2 and not (b.filename or b._type or b.dirty) then view:goto_buffer(1) diff --git a/core/gui.lua b/core/gui.lua index 349c0dbb..ab7d0909 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -222,10 +222,10 @@ function gui.select_theme() f:close() end -local connect = events.connect +local events, events_connect = events, events.connect -- Sets default properties for a Scintilla window. -connect(events.VIEW_NEW, function() +events_connect(events.VIEW_NEW, function() local buffer = buffer local c = _SCINTILLA.constants @@ -244,7 +244,7 @@ connect(events.VIEW_NEW, function() local ok, err = pcall(dofile, THEME..'/view.lua') if not ok then io.stderr:write(err) end end) -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] @@ -269,7 +269,7 @@ local function set_properties() end -- Sets default properties for a Scintilla document. -connect(events.BUFFER_NEW, function() +events_connect(events.BUFFER_NEW, function() -- Normally when an error occurs, a new buffer is created with the error -- message, but if an error occurs here, this event would be called again and -- again, erroring each time resulting in an infinite loop; print error to @@ -287,19 +287,19 @@ local function set_title(buffer) end -- Changes Textadept title to show the buffer as being "clean". -connect(events.SAVE_POINT_REACHED, function() +events_connect(events.SAVE_POINT_REACHED, function() buffer.dirty = false set_title(buffer) end) -- Changes Textadept title to show thee buffer as "dirty". -connect(events.SAVE_POINT_LEFT, function() +events_connect(events.SAVE_POINT_LEFT, function() buffer.dirty = true set_title(buffer) end) -- Open uri(s). -connect(events.URI_DROPPED, function(utf8_uris) +events_connect(events.URI_DROPPED, function(utf8_uris) for utf8_uri in utf8_uris:gmatch('[^\r\n]+') do if utf8_uri:find('^file://') then utf8_uri = utf8_uri:match('^file://([^\r\n]+)') @@ -312,7 +312,7 @@ connect(events.URI_DROPPED, function(utf8_uris) end end end) -connect(events.APPLEEVENT_ODOC, function(uri) +events_connect(events.APPLEEVENT_ODOC, function(uri) return events.emit(events.URI_DROPPED, 'file://'..uri) end) @@ -320,7 +320,7 @@ local string_format = string.format local EOLs = { _L['CRLF'], _L['CR'], _L['LF'] } local GETLEXERLANGUAGE = _SCINTILLA.functions.get_lexer_language[1] -- Sets docstatusbar text. -connect(events.UPDATE_UI, function() +events_connect(events.UPDATE_UI, function() local buffer = buffer local pos = buffer.current_pos local line, max = buffer:line_from_position(pos) + 1, buffer.line_count @@ -336,32 +336,30 @@ connect(events.UPDATE_UI, function() end) -- Toggles folding. -connect(events.MARGIN_CLICK, function(margin, pos, modifiers) +events_connect(events.MARGIN_CLICK, function(margin, pos, modifiers) if margin == 2 then buffer:toggle_fold(buffer:line_from_position(pos)) end end) -- Updates the statusbar and titlebar for a new Scintilla document. -connect(events.BUFFER_NEW, function() events.emit(events.UPDATE_UI) end) -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(buffer) end) -- Save buffer properties. -connect(events.BUFFER_BEFORE_SWITCH, function() +events_connect(events.BUFFER_BEFORE_SWITCH, function() local buffer = buffer -- Save view state. buffer._anchor, buffer._current_pos = buffer.anchor, buffer.current_pos buffer._first_visible_line = buffer.first_visible_line -- Save fold state. buffer._folds = {} - local folds = buffer._folds - local i = buffer:contracted_fold_next(0) + local folds, i = buffer._folds, buffer:contracted_fold_next(0) while i >= 0 do - folds[#folds + 1] = i - i = buffer:contracted_fold_next(i + 1) + folds[#folds + 1], i = i, buffer:contracted_fold_next(i + 1) end end) -- Restore buffer properties. -connect(events.BUFFER_AFTER_SWITCH, function() +events_connect(events.BUFFER_AFTER_SWITCH, function() local buffer = buffer if not buffer._folds then return end -- Restore fold state. @@ -374,21 +372,22 @@ connect(events.BUFFER_AFTER_SWITCH, function() end) -- Updates titlebar and statusbar. -connect(events.BUFFER_AFTER_SWITCH, function() +events_connect(events.BUFFER_AFTER_SWITCH, function() set_title(buffer) events.emit(events.UPDATE_UI) end) -- Updates titlebar and statusbar. -connect(events.VIEW_AFTER_SWITCH, function() +events_connect(events.VIEW_AFTER_SWITCH, function() set_title(buffer) events.emit(events.UPDATE_UI) end) -connect(events.RESET_AFTER, function() gui.statusbar_text = 'Lua reset' end) +events_connect(events.RESET_AFTER, + function() gui.statusbar_text = 'Lua reset' end) -- Prompts for confirmation if any buffers are dirty. -connect(events.QUIT, function() +events_connect(events.QUIT, function() local list = {} for _, buffer in ipairs(_BUFFERS) do if buffer.dirty then @@ -408,7 +407,8 @@ connect(events.QUIT, function() return true end) -connect(events.ERROR, function(...) gui._print(_L['[Error Buffer]'], ...) end) +events_connect(events.ERROR, + function(...) gui._print(_L['[Error Buffer]'], ...) end) --[[ The functions below are Lua C functions. diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua index 39381762..281937fe 100644 --- a/modules/textadept/adeptsense.lua +++ b/modules/textadept/adeptsense.lua @@ -903,9 +903,7 @@ syntax = { class_definition = 'class%s+([%w_]+)', word_chars = '%w_', symbol_chars = '[%w_%.]', - type_declarations = { - '(%u[%w_%.]+)%s+%_', -- Foo bar - }, + type_declarations = { '(%u[%w_%.]+)%s+%_' }, -- Foo bar type_declarations_exclude = {}, type_assignments = {} }, diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 6128e320..7111870b 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -71,11 +71,11 @@ M.braces = { [40] = 1, [41] = 1, [91] = 1, [93] = 1, [123] = 1, [125] = 1 } -- @name current_call_tip local current_call_tip = {} -local events = events +local events, events_connect = events, events.connect local K = keys.KEYSYMS -- Matches characters specified in char_matches. -events.connect(events.CHAR_ADDED, function(c) +events_connect(events.CHAR_ADDED, function(c) if not M.AUTOPAIR then return end local buffer = buffer local match = (M.char_matches[buffer:get_lexer()] or M.char_matches)[c] @@ -83,7 +83,7 @@ events.connect(events.CHAR_ADDED, function(c) end) -- Removes matched chars on backspace. -events.connect(events.KEYPRESS, function(code) +events_connect(events.KEYPRESS, function(code) if not M.AUTOPAIR or K[code] ~= '\b' or buffer.selections ~= 1 then return end local buffer = buffer local pos = buffer.current_pos @@ -93,7 +93,7 @@ events.connect(events.KEYPRESS, function(code) end) -- Highlights matching braces. -events.connect(events.UPDATE_UI, function() +events_connect(events.UPDATE_UI, function() if not M.HIGHLIGHT_BRACES then return end local buffer = buffer local pos = buffer.current_pos @@ -110,7 +110,7 @@ events.connect(events.UPDATE_UI, function() end) -- Auto-indent on return. -events.connect(events.CHAR_ADDED, function(char) +events_connect(events.CHAR_ADDED, function(char) if not M.AUTOINDENT or char ~= 10 then return end local buffer = buffer local anchor, caret = buffer.anchor, buffer.current_pos @@ -122,20 +122,19 @@ events.connect(events.CHAR_ADDED, function(char) local s = buffer.line_indent_position[line] buffer.line_indentation[line] = indentation local e = buffer.line_indent_position[line] - local diff = e - s if e > s then -- move selection on - if anchor >= s then anchor = anchor + diff end - if caret >= s then caret = caret + diff end + if anchor >= s then anchor = anchor + e - s end + if caret >= s then caret = caret + e - s end elseif e < s then -- move selection back - if anchor >= e then anchor = anchor >= s and anchor + diff or e end - if caret >= e then caret = caret >= s and caret + diff or e end + if anchor >= e then anchor = anchor >= s and anchor + e - s or e end + if caret >= e then caret = caret >= s and caret + e - s or e end end buffer:set_sel(anchor, caret) end end) -- Autocomplete multiple selections. -events.connect(events.AUTO_C_SELECTION, function(text, position) +events_connect(events.AUTO_C_SELECTION, function(text, position) local buffer = buffer local caret = buffer.selection_n_caret[buffer.main_selection] buffer:begin_undo_action() @@ -293,7 +292,7 @@ function M.prepare_for_save() buffer:convert_eo_ls(buffer.eol_mode) buffer:end_undo_action() end -events.connect(events.FILE_BEFORE_SAVE, M.prepare_for_save) +events_connect(events.FILE_BEFORE_SAVE, M.prepare_for_save) --- -- Selects the current word under the caret and if action indicates, deletes it. @@ -363,9 +362,8 @@ end function M.select_enclosed(left, right) local buffer = buffer buffer:search_anchor() - local s = buffer:search_prev(0, left) - local e = buffer:search_next(0, right) - if s and e then buffer:set_sel(s + 1, e) end + local s, e = buffer:search_prev(0, left), buffer:search_next(0, right) + if s >= 0 and e >= 0 then buffer:set_sel(s + 1, e) end end --- @@ -413,12 +411,10 @@ function M.select_indented_block() local e = buffer:line_from_position(buffer.selection_end) local indent = buffer.line_indentation[s] - buffer.indent if indent < 0 then return end - if buffer:get_sel_text() ~= '' then - if buffer.line_indentation[s - 1] == indent and - buffer.line_indentation[e + 1] == indent then - s, e = s - 1, e + 1 - indent = indent + buffer.indent -- do not run while loops - end + if buffer:get_sel_text() ~= '' and + buffer.line_indentation[s - 1] == indent and + buffer.line_indentation[e + 1] == indent then + s, e, indent = s - 1, e + 1, indent + buffer.indent end while buffer.line_indentation[s - 1] > indent do s = s - 1 end while buffer.line_indentation[e + 1] > indent do e = e + 1 end @@ -462,7 +458,7 @@ local function clear_highlighted_words() buffer.indicator_current = INDIC_HIGHLIGHT buffer:indicator_clear_range(0, buffer.length) end -events.connect(events.KEYPRESS, function(code) +events_connect(events.KEYPRESS, function(code) if K[code] == 'esc' then clear_highlighted_words() end end) @@ -501,6 +497,6 @@ local function set_highlight_properties() buffer.indic_alpha[INDIC_HIGHLIGHT] = M.INDIC_HIGHLIGHT_ALPHA end if buffer then set_highlight_properties() end -events.connect(events.VIEW_NEW, set_highlight_properties) +events_connect(events.VIEW_NEW, set_highlight_properties) return M diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 8086d5a8..269c2f9b 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -118,7 +118,7 @@ function find.find_in_files(utf8_dir) end end -local events = events +local events, events_connect = events, events.connect local c = _SCINTILLA.constants -- Finds and selects text in the current buffer. @@ -193,7 +193,7 @@ local function find_(text, next, flags, nowrap, wrapped) return result end -events.connect(events.FIND, find_) +events_connect(events.FIND, find_) -- Finds and selects text incrementally in the current buffer from a start -- point. @@ -216,7 +216,7 @@ function find.find_incremental() gui.command_entry.focus() end -events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code) +events_connect(events.COMMAND_ENTRY_KEYPRESS, function(code) if find.incremental then if keys.KEYSYMS[code] == 'esc' then find.incremental = nil @@ -232,7 +232,7 @@ events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code) end, 1) -- place before command_entry.lua's handler (if necessary) -- 'Find next' for incremental search. -events.connect(events.COMMAND_ENTRY_COMMAND, function(text) +events_connect(events.COMMAND_ENTRY_COMMAND, function(text) if find.incremental then find.incremental_start = buffer.current_pos + 1 find_incremental(text) @@ -290,7 +290,7 @@ local function replace(rtext) buffer:goto_pos(buffer.current_pos) end end -events.connect(events.REPLACE, replace) +events_connect(events.REPLACE, replace) -- Replaces all found text. -- If any text is selected, all found text in that selection is replaced. @@ -336,7 +336,7 @@ local function replace_all(ftext, rtext, flags) gui.statusbar_text = ("%d %s"):format(count, _L['replacement(s) made']) buffer:end_undo_action() end -events.connect(events.REPLACE_ALL, replace_all) +events_connect(events.REPLACE_ALL, replace_all) -- When the user double-clicks a found file, go to the line in the file the text -- was found at. @@ -356,7 +356,7 @@ local function goto_file(pos, line_num) end end end -events.connect(events.DOUBLE_CLICK, goto_file) +events_connect(events.DOUBLE_CLICK, goto_file) --- -- Goes to the next or previous file found relative to the file @@ -391,7 +391,7 @@ function find.goto_file_in_list(next) end if buffer then buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end -events.connect(events.VIEW_NEW, function() +events_connect(events.VIEW_NEW, function() buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end) diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 50ea4dd7..1c2f8aaf 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -9,14 +9,10 @@ local M = {} -- This module, should be 'require'ed last, but before _m.textadept.menu. module('_m.textadept.keys')]] -local keys, gui, _buffer, _view = keys, gui, buffer, view -local m_textadept, m_editing = _m.textadept, _m.textadept.editing -local c, OSX = _SCINTILLA.constants, OSX - -- Utility functions. M.utils = { enclose_as_xml_tags = function() - m_editing.enclose('<', '>') + _m.textadept.editing.enclose('<', '>') local buffer = buffer local pos = buffer.current_pos while buffer.char_at[pos - 1] ~= 60 do pos = pos - 1 end -- '<' @@ -29,7 +25,7 @@ M.utils = { select_command = function() _m.textadept.menu.select_command() end, snapopen_filedir = function() if buffer.filename then - m_textadept.snapopen.open(buffer.filename:match('^(.+)[/\\]')) + _m.textadept.snapopen.open(buffer.filename:match('^(.+)[/\\]')) end end, show_style = function() @@ -99,6 +95,13 @@ events.connect(events.BUFFER_NEW, constantize_menu_buffer_functions) -- Scintilla's first buffer does not have this. if not RESETTING then constantize_menu_buffer_functions() end +local keys = keys +local io, gui, gui_find, buffer, view = io, gui, gui.find, buffer, view +local m_textadept, m_editing = _m.textadept, _m.textadept.editing +local m_bookmarks, m_snippets = m_textadept.bookmarks, m_textadept.snippets +local OSX, c = OSX, _SCINTILLA.constants +local utils = M.utils + --[[ Windows and Linux menu key commands. @@ -135,25 +138,25 @@ if not RESETTING then constantize_menu_buffer_functions() end keys[not OSX and 'cn' or 'mn'] = new_buffer keys[not OSX and 'co' or 'mo'] = io.open_file keys[not OSX and 'cao' or 'cmo'] = io.open_recent_file -keys[not OSX and 'cO' or 'mO'] = _buffer.reload -keys[not OSX and 'cs' or 'ms'] = _buffer.save -keys[not OSX and 'cS' or 'mS'] = _buffer.save_as -keys[not OSX and 'cw' or 'mw'] = _buffer.close +keys[not OSX and 'cO' or 'mO'] = buffer.reload +keys[not OSX and 'cs' or 'ms'] = buffer.save +keys[not OSX and 'cS' or 'mS'] = buffer.save_as +keys[not OSX and 'cw' or 'mw'] = buffer.close keys[not OSX and 'cW' or 'mW'] = io.close_all -- TODO: m_textadept.sessions.prompt_load -- TODO: m_textadept.sessions.prompt_save keys[not OSX and 'aq' or 'mq'] = quit -- Edit. -keys[not OSX and 'cz' or 'mz'] = _buffer.undo -if not OSX then keys.cy = _buffer.redo end -keys[not OSX and 'cZ' or 'mZ'] = _buffer.redo -keys[not OSX and 'cx' or 'mx'] = _buffer.cut -keys[not OSX and 'cc' or 'mc'] = _buffer.copy -keys[not OSX and 'cv' or 'mv'] = _buffer.paste -keys[not OSX and 'cd' or 'md'] = _buffer.line_duplicate -keys.del = _buffer.clear -keys[not OSX and 'ca' or 'ma'] = _buffer.select_all +keys[not OSX and 'cz' or 'mz'] = buffer.undo +if not OSX then keys.cy = buffer.redo end +keys[not OSX and 'cZ' or 'mZ'] = buffer.redo +keys[not OSX and 'cx' or 'mx'] = buffer.cut +keys[not OSX and 'cc' or 'mc'] = buffer.copy +keys[not OSX and 'cv' or 'mv'] = buffer.paste +keys[not OSX and 'cd' or 'md'] = buffer.line_duplicate +keys.del = buffer.clear +keys[not OSX and 'ca' or 'ma'] = buffer.select_all keys.cm = m_editing.match_brace keys[not OSX and 'c\n' or 'cesc'] = { m_editing.autocomplete_word, '%w_' } keys[not OSX and 'adel' or 'cdel'] = { m_editing.current_word, 'delete' } @@ -175,9 +178,9 @@ keys[not OSX and 'cN' or 'mN'] = m_editing.select_line keys[not OSX and 'cP' or 'mP'] = m_editing.select_paragraph keys[not OSX and 'cI' or 'mI'] = m_editing.select_indented_block -- Selection. -keys[not OSX and 'cau' or 'cu'] = _buffer.upper_case -keys[not OSX and 'caU' or 'cU'] = _buffer.lower_case -keys[not OSX and 'a<' or 'c<'] = M.utils.enclose_as_xml_tags +keys[not OSX and 'cau' or 'cu'] = buffer.upper_case +keys[not OSX and 'caU' or 'cU'] = buffer.lower_case +keys[not OSX and 'a<' or 'c<'] = utils.enclose_as_xml_tags keys[not OSX and 'a>' or 'c>'] = { m_editing.enclose, '<', ' />' } keys[not OSX and "a'" or "c'"] = { m_editing.enclose, "'", "'" } keys[not OSX and 'a"' or 'c"'] = { m_editing.enclose, '"', '"' } @@ -186,31 +189,31 @@ keys[not OSX and 'a[' or 'c['] = { m_editing.enclose, '[', ']' } keys[not OSX and 'a{' or 'c{'] = { m_editing.enclose, '{', '}' } keys[not OSX and 'c+' or 'm+'] = { m_editing.grow_selection, 1 } keys[not OSX and 'c_' or 'm_'] = { m_editing.grow_selection, -1 } -keys.csup = _buffer.move_selected_lines_up -keys.csdown = _buffer.move_selected_lines_down +keys.csup = buffer.move_selected_lines_up +keys.csdown = buffer.move_selected_lines_down -- Search. -keys[not OSX and 'cf' or 'mf'] = gui.find.focus -keys[not OSX and 'cg' or 'mg'] = gui.find.find_next +keys[not OSX and 'cf' or 'mf'] = gui_find.focus +keys[not OSX and 'cg' or 'mg'] = gui_find.find_next if not OSX then keys.f3 = keys.cg end -keys[not OSX and 'cG' or 'mG'] = gui.find.find_prev +keys[not OSX and 'cG' or 'mG'] = gui_find.find_prev if not OSX then keys.sf3 = keys.cG end -keys[not OSX and 'car' or 'cr'] = gui.find.replace -keys[not OSX and 'caR' or 'cR'] = gui.find.replace_all +keys[not OSX and 'car' or 'cr'] = gui_find.replace +keys[not OSX and 'caR' or 'cR'] = gui_find.replace_all -- Find Next is an when find pane is focused. -- Find Prev is ap when find pane is focused. -- Replace is ar when find pane is focused. -- Replace All is aa when find pane is focused. -keys[not OSX and 'caf' or 'cmf'] = gui.find.find_incremental -keys[not OSX and 'cF' or 'mF'] = M.utils.find_in_files +keys[not OSX and 'caf' or 'cmf'] = gui_find.find_incremental +keys[not OSX and 'cF' or 'mF'] = utils.find_in_files -- Find in Files is ai when find pane is focused. -keys[not OSX and 'cag' or 'cmg'] = { gui.find.goto_file_in_list, true } -keys[not OSX and 'caG' or 'cmG'] = { gui.find.goto_file_in_list, false } +keys[not OSX and 'cag' or 'cmg'] = { gui_find.goto_file_in_list, true } +keys[not OSX and 'caG' or 'cmG'] = { gui_find.goto_file_in_list, false } keys[not OSX and 'cj' or 'mj'] = m_editing.goto_line -- Tools. keys[not OSX and 'ce' or 'me'] = gui.command_entry.focus -keys[not OSX and 'cE' or 'mE'] = M.utils.select_command +keys[not OSX and 'cE' or 'mE'] = utils.select_command keys[not OSX and 'cr' or 'mr'] = m_textadept.run.run keys[not OSX and 'cR' or 'mR'] = m_textadept.run.compile keys[not OSX and 'c|' or 'm|'] = m_textadept.filter_through.filter_through @@ -218,101 +221,101 @@ keys[not OSX and 'c|' or 'm|'] = m_textadept.filter_through.filter_through keys[not OSX and 'c ' or 'aesc'] = m_textadept.adeptsense.complete_symbol keys.ch = m_textadept.adeptsense.show_documentation -- Snippets. -keys[not OSX and 'ck' or 'a\t'] = m_textadept.snippets._select -keys['\t'] = m_textadept.snippets._insert -keys['s\t'] = m_textadept.snippets._previous -keys[not OSX and 'cK' or 'as\t'] = m_textadept.snippets._cancel_current +keys[not OSX and 'ck' or 'a\t'] = m_snippets._select +keys['\t'] = m_snippets._insert +keys['s\t'] = m_snippets._previous +keys[not OSX and 'cK' or 'as\t'] = m_snippets._cancel_current -- Bookmark. -keys[not OSX and 'cf2' or 'mf2'] = m_textadept.bookmarks.toggle -keys[not OSX and 'csf2' or 'msf2'] = m_textadept.bookmarks.clear -keys.f2 = m_textadept.bookmarks.goto_next -keys.sf2 = m_textadept.bookmarks.goto_prev -keys.af2 = m_textadept.bookmarks.goto_bookmark +keys[not OSX and 'cf2' or 'mf2'] = m_bookmarks.toggle +keys[not OSX and 'csf2' or 'msf2'] = m_bookmarks.clear +keys.f2 = m_bookmarks.goto_next +keys.sf2 = m_bookmarks.goto_prev +keys.af2 = m_bookmarks.goto_bookmark -- Snapopen. keys[not OSX and 'cu' or 'mu'] = { m_textadept.snapopen.open, _USERHOME } -- TODO: { m_textadept.snapopen.open, _HOME } -keys[not OSX and 'caO' or 'cmO'] = M.utils.snapopen_filedir -keys[not OSX and 'ci' or 'mi'] = M.utils.show_style +keys[not OSX and 'caO' or 'cmO'] = utils.snapopen_filedir +keys[not OSX and 'ci' or 'mi'] = utils.show_style -- Buffer. -keys['c\t'] = { _view.goto_buffer, _view, 1, true } -keys['cs\t'] = { _view.goto_buffer, _view, -1, true } +keys['c\t'] = { view.goto_buffer, view, 1, true } +keys['cs\t'] = { view.goto_buffer, view, -1, true } keys[not OSX and 'cb' or 'mb'] = gui.switch_buffer -- Indentation. --- TODO: { M.utils.set_indentation, 2 } --- TODO: { M.utils.set_indentation, 3 } --- TODO: { M.utils.set_indentation, 4 } --- TODO: { M.utils.set_indentation, 8 } -keys[not OSX and 'caT' or 'cT'] = { M.utils.toggle_property, 'use_tabs' } +-- TODO: { utils.set_indentation, 2 } +-- TODO: { utils.set_indentation, 3 } +-- TODO: { utils.set_indentation, 4 } +-- TODO: { utils.set_indentation, 8 } +keys[not OSX and 'caT' or 'cT'] = { utils.toggle_property, 'use_tabs' } keys[not OSX and 'cai' or 'ci'] = m_editing.convert_indentation -- EOL Mode. --- TODO: { M.utils.set_eol_mode, c.SC_EOL_CRLF } --- TODO: { M.utils.set_eol_mode, c.SC_EOL_CR } --- TODO: { M.utils.set_eol_mode, c.SC_EOL_LF } +-- TODO: { utils.set_eol_mode, c.SC_EOL_CRLF } +-- TODO: { utils.set_eol_mode, c.SC_EOL_CR } +-- TODO: { utils.set_eol_mode, c.SC_EOL_LF } -- Encoding. --- TODO: { M.utils.set_encoding, 'UTF-8' } --- TODO: { M.utils.set_encoding, 'ASCII' } --- TODO: { M.utils.set_encoding, 'ISO-8859-1' } --- TODO: { M.utils.set_encoding, 'MacRoman' } --- TODO: { M.utils.set_encoding, 'UTF-16LE' } +-- TODO: { utils.set_encoding, 'UTF-8' } +-- TODO: { utils.set_encoding, 'ASCII' } +-- TODO: { utils.set_encoding, 'ISO-8859-1' } +-- TODO: { utils.set_encoding, 'MacRoman' } +-- TODO: { utils.set_encoding, 'UTF-16LE' } keys[not OSX and 'cL' or 'mL'] = m_textadept.mime_types.select_lexer -keys.f5 = { _buffer.colourise, _buffer, 0, -1 } +keys.f5 = { buffer.colourise, buffer, 0, -1 } -- View. keys[not OSX and 'can' or 'ca\t'] = { gui.goto_view, 1, true } keys[not OSX and 'cap' or 'cas\t'] = { gui.goto_view, -1, true } -keys[not OSX and 'cas' or 'cs'] = { _view.split, _view } +keys[not OSX and 'cas' or 'cs'] = { view.split, view } if not OSX then keys.cah = keys.cas end -keys[not OSX and 'cav' or 'cv'] = { _view.split, _view, true } -keys[not OSX and 'caw' or 'cw'] = { _view.unsplit, _view } -keys[not OSX and 'caW' or 'cW'] = M.utils.unsplit_all -keys[not OSX and 'ca+' or 'c+'] = { M.utils.grow, 10 } -keys[not OSX and 'ca=' or 'c='] = { M.utils.grow, 10 } -keys[not OSX and 'ca-' or 'c-'] = { M.utils.shrink, 10 } --- TODO: M.utils.toggle_current_fold -keys[not OSX and 'ca\n' or 'c\n'] = { M.utils.toggle_property, 'view_eol' } +keys[not OSX and 'cav' or 'cv'] = { view.split, view, true } +keys[not OSX and 'caw' or 'cw'] = { view.unsplit, view } +keys[not OSX and 'caW' or 'cW'] = utils.unsplit_all +keys[not OSX and 'ca+' or 'c+'] = { utils.grow, 10 } +keys[not OSX and 'ca=' or 'c='] = { utils.grow, 10 } +keys[not OSX and 'ca-' or 'c-'] = { utils.shrink, 10 } +-- TODO: utils.toggle_current_fold +keys[not OSX and 'ca\n' or 'c\n'] = { utils.toggle_property, 'view_eol' } if not OSX then keys['ca\n\r'] = keys['ca\n'] end -keys[not OSX and 'ca\\' or 'c\\'] = { M.utils.toggle_property, 'wrap_mode' } +keys[not OSX and 'ca\\' or 'c\\'] = { utils.toggle_property, 'wrap_mode' } keys[not OSX and 'caI' or 'cI'] = - { M.utils.toggle_property, 'indentation_guides' } -keys[not OSX and 'caS' or 'cS'] = { M.utils.toggle_property, 'view_ws' } + { utils.toggle_property, 'indentation_guides' } +keys[not OSX and 'caS' or 'cS'] = { utils.toggle_property, 'view_ws' } keys[not OSX and 'caV' or 'cV'] = - { M.utils.toggle_property, 'virtual_space_options', c.SCVS_USERACCESSIBLE } -keys[not OSX and 'c=' or 'm='] = _buffer.zoom_in -keys[not OSX and 'c-' or 'm-'] = _buffer.zoom_out -keys[not OSX and 'c0' or 'm0'] = M.utils.reset_zoom + { utils.toggle_property, 'virtual_space_options', c.SCVS_USERACCESSIBLE } +keys[not OSX and 'c=' or 'm='] = buffer.zoom_in +keys[not OSX and 'c-' or 'm-'] = buffer.zoom_out +keys[not OSX and 'c0' or 'm0'] = utils.reset_zoom keys[not OSX and 'cT' or 'mT'] = gui.select_theme -- Help. -keys.f1 = { M.utils.open_webpage, _HOME..'/doc/manual/1_Introduction.html' } -keys.sf1 = { M.utils.open_webpage, _HOME..'/doc/index.html' } +keys.f1 = { utils.open_webpage, _HOME..'/doc/manual/1_Introduction.html' } +keys.sf1 = { utils.open_webpage, _HOME..'/doc/index.html' } -- TODO: { gui.dialog, 'ok-msgbox', '--title', 'Textadept' -- '--informative-text', _RELEASE, '--no-cancel' } -- Movement commands. if OSX then keys.ck = function() - buffer:line_end_extend() - buffer:cut() + _G.buffer:line_end_extend() + _G.buffer:cut() end - keys.cf = _buffer.char_right - keys.cF = _buffer.char_right_extend - keys.cmf = _buffer.word_right - keys.cmF = _buffer.word_right_extend - keys.cb = _buffer.char_left - keys.cB = _buffer.char_left_extend - keys.cmb = _buffer.word_left - keys.cmB = _buffer.word_left_extend - keys.cn = _buffer.line_down - keys.cN = _buffer.line_down_extend - keys.cp = _buffer.line_up - keys.cP = _buffer.line_up_extend - keys.ca = _buffer.vc_home - keys.cA = _buffer.vc_home_extend - keys.ce = _buffer.line_end - keys.cE = _buffer.line_end_extend - keys.cd = _buffer.clear - keys.cl = _buffer.vertical_centre_caret + keys.cf = buffer.char_right + keys.cF = buffer.char_right_extend + keys.cmf = buffer.word_right + keys.cmF = buffer.word_right_extend + keys.cb = buffer.char_left + keys.cB = buffer.char_left_extend + keys.cmb = buffer.word_left + keys.cmB = buffer.word_left_extend + keys.cn = buffer.line_down + keys.cN = buffer.line_down_extend + keys.cp = buffer.line_up + keys.cP = buffer.line_up_extend + keys.ca = buffer.vc_home + keys.cA = buffer.vc_home_extend + keys.ce = buffer.line_end + keys.cE = buffer.line_end_extend + keys.cd = buffer.clear + keys.cl = buffer.vertical_centre_caret end return M diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 8cb7bc1c..a07c29e2 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -10,11 +10,6 @@ local M = {} -- looks up defined key commands to show them in menus. module('_m.textadept.menu')]] -local _L, gui, _buffer, _view = _L, gui, buffer, view -local m_textadept, m_editing = _m.textadept, _m.textadept.editing -local c, SEPARATOR = _SCINTILLA.constants, { 'separator' } -local utils = m_textadept.keys.utils - -- Get a string uniquely identifying a key command. -- This is used to match menu items with key commands to show the key shortcut. -- @param f A value in the `keys` table. @@ -28,6 +23,12 @@ local function get_id(f) return id end +local _L, io, gui, gui_find, buffer, view = _L, io, gui, gui.find, buffer, view +local m_textadept, m_editing = _m.textadept, _m.textadept.editing +local m_bookmarks, m_snippets = m_textadept.bookmarks, m_textadept.snippets +local utils = m_textadept.keys.utils +local SEPARATOR, c = { 'separator' }, _SCINTILLA.constants + --- -- Contains the main menubar. -- @class table @@ -37,11 +38,11 @@ M.menubar = { { _L['gtk-new'], new_buffer }, { _L['gtk-open'], io.open_file }, { _L['Open Recent...'], io.open_recent_file }, - { _L['Reload'], _buffer.reload }, - { _L['gtk-save'], _buffer.save }, - { _L['gtk-save-as'], _buffer.save_as }, + { _L['Reload'], buffer.reload }, + { _L['gtk-save'], buffer.save }, + { _L['gtk-save-as'], buffer.save_as }, SEPARATOR, - { _L['gtk-close'], _buffer.close }, + { _L['gtk-close'], buffer.close }, { _L['Close All'], io.close_all }, SEPARATOR, { _L['Load Session...'], m_textadept.session.prompt_load }, @@ -50,15 +51,15 @@ M.menubar = { { _L['gtk-quit'], quit }, }, { title = _L['Edit'], - { _L['gtk-undo'], _buffer.undo }, - { _L['gtk-redo'], _buffer.redo }, + { _L['gtk-undo'], buffer.undo }, + { _L['gtk-redo'], buffer.redo }, SEPARATOR, - { _L['gtk-cut'], _buffer.cut }, - { _L['gtk-copy'], _buffer.copy }, - { _L['gtk-paste'], _buffer.paste }, - { _L['Duplicate Line'], _buffer.line_duplicate }, - { _L['gtk-delete'], _buffer.clear }, - { _L['gtk-select-all'], _buffer.select_all }, + { _L['gtk-cut'], buffer.cut }, + { _L['gtk-copy'], buffer.copy }, + { _L['gtk-paste'], buffer.paste }, + { _L['Duplicate Line'], buffer.line_duplicate }, + { _L['gtk-delete'], buffer.clear }, + { _L['gtk-select-all'], buffer.select_all }, SEPARATOR, { _L['Match Brace'], m_editing.match_brace }, { _L['Complete Word'], { m_editing.autocomplete_word, '%w_' } }, @@ -85,8 +86,8 @@ M.menubar = { { _L['Select Indented Block'], m_editing.select_indented_block }, }, { title = _L['Selection'], - { _L['Upper Case Selection'], _buffer.upper_case }, - { _L['Lower Case Selection'], _buffer.lower_case }, + { _L['Upper Case Selection'], buffer.upper_case }, + { _L['Lower Case Selection'], buffer.lower_case }, SEPARATOR, { _L['Enclose as XML Tags'], utils.enclose_as_xml_tags }, { _L['Enclose as Single XML Tag'], { m_editing.enclose, '<', ' />' } }, @@ -99,21 +100,21 @@ M.menubar = { { _L['Grow Selection'], { m_editing.grow_selection, 1 } }, { _L['Shrink Selection'], { m_editing.grow_selection, -1 } }, SEPARATOR, - { _L['Move Selected Lines Up'], _buffer.move_selected_lines_up }, - { _L['Move Selected Lines Down'], _buffer.move_selected_lines_down }, + { _L['Move Selected Lines Up'], buffer.move_selected_lines_up }, + { _L['Move Selected Lines Down'], buffer.move_selected_lines_down }, }, }, { title = _L['Search'], - { _L['gtk-find'], gui.find.focus }, - { _L['Find Next'], gui.find.find_next }, - { _L['Find Previous'], gui.find.find_prev }, - { _L['Replace'], gui.find.replace }, - { _L['Replace All'], gui.find.replace_all }, - { _L['Find Incremental'], gui.find.find_incremental }, + { _L['gtk-find'], gui_find.focus }, + { _L['Find Next'], gui_find.find_next }, + { _L['Find Previous'], gui_find.find_prev }, + { _L['Replace'], gui_find.replace }, + { _L['Replace All'], gui_find.replace_all }, + { _L['Find Incremental'], gui_find.find_incremental }, SEPARATOR, { _L['Find in Files'], utils.find_in_files }, - { _L['Goto Next File Found'], { gui.find.goto_file_in_list, true } }, - { _L['Goto Previous File Found'], { gui.find.goto_file_in_list, false } }, + { _L['Goto Next File Found'], { gui_find.goto_file_in_list, true } }, + { _L['Goto Previous File Found'], { gui_find.goto_file_in_list, false } }, SEPARATOR, { _L['gtk-jump-to'], m_editing.goto_line }, }, @@ -130,11 +131,11 @@ M.menubar = { { _L['Show Documentation'], m_textadept.adeptsense.show_documentation }, }, { 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['Toggle Bookmark'], m_bookmarks.toggle }, + { _L['Clear Bookmarks'], m_bookmarks.clear }, + { _L['Next Bookmark'], m_bookmarks.goto_next }, + { _L['Previous Bookmark'], m_bookmarks.goto_prev }, + { _L['Goto Bookmark...'], m_bookmarks.goto_bookmark }, }, { title = _L['Snapopen'], { _L['Snapopen User Home'], { m_textadept.snapopen.open, _USERHOME } }, @@ -142,17 +143,17 @@ M.menubar = { { _L['Snapopen Current Directory'], utils.snapopen_filedir }, }, { title = _L['Snippets'], - { _L['Insert Snippet...'], m_textadept.snippets._select }, - { _L['Expand Snippet/Next Placeholder'], m_textadept.snippets._insert }, - { _L['Previous Snippet Placeholder'], m_textadept.snippets._previous }, - { _L['Cancel Snippet'], m_textadept.snippets._cancel_current }, + { _L['Insert Snippet...'], m_snippets._select }, + { _L['Expand Snippet/Next Placeholder'], m_snippets._insert }, + { _L['Previous Snippet Placeholder'], m_snippets._previous }, + { _L['Cancel Snippet'], m_snippets._cancel_current }, }, SEPARATOR, { _L['Show Style'], utils.show_style }, }, { title = _L['Buffer'], - { _L['Next Buffer'], { _view.goto_buffer, _view, 1, true } }, - { _L['Previous Buffer'], { _view.goto_buffer, _view, -1, true } }, + { _L['Next Buffer'], { view.goto_buffer, view, 1, true } }, + { _L['Previous Buffer'], { view.goto_buffer, view, -1, true } }, { _L['Switch to Buffer...'], gui.switch_buffer }, SEPARATOR, { title = _L['Indentation'], @@ -179,15 +180,15 @@ M.menubar = { SEPARATOR, { _L['Select Lexer...'], m_textadept.mime_types.select_lexer }, { _L['Refresh Syntax Highlighting'], - { _buffer.colourise, _buffer, 0, -1 } }, + { buffer.colourise, buffer, 0, -1 } }, }, { title = _L['View'], { _L['Next View'], { gui.goto_view, 1, true } }, { _L['Previous View'], { gui.goto_view, -1, true } }, SEPARATOR, - { _L['Split View Horizontal'], { _view.split, _view } }, - { _L['Split View Vertical'], { _view.split, _view, true } }, - { _L['Unsplit View'], { _view.unsplit, _view } }, + { _L['Split View Horizontal'], { view.split, view } }, + { _L['Split View Vertical'], { view.split, view, true } }, + { _L['Unsplit View'], { view.unsplit, view } }, { _L['Unsplit All Views'], utils.unsplit_all }, { _L['Grow View'], { utils.grow, 10 } }, { _L['Shrink View'], { utils.shrink, 10 } }, @@ -203,8 +204,8 @@ M.menubar = { { utils.toggle_property, 'virtual_space_options', c.SCVS_USERACCESSIBLE } }, SEPARATOR, - { _L['Zoom In'], _buffer.zoom_in }, - { _L['Zoom Out'], _buffer.zoom_out }, + { _L['Zoom In'], buffer.zoom_in }, + { _L['Zoom Out'], buffer.zoom_out }, { _L['Reset Zoom'], utils.reset_zoom }, SEPARATOR, { _L['Select Theme...'], gui.select_theme }, @@ -225,20 +226,19 @@ M.menubar = { -- @class table -- @name context_menu M.context_menu = { - { _L['gtk-undo'], _buffer.undo }, - { _L['gtk-redo'], _buffer.redo }, + { _L['gtk-undo'], buffer.undo }, + { _L['gtk-redo'], buffer.redo }, SEPARATOR, - { _L['gtk-cut'], _buffer.cut }, - { _L['gtk-copy'], _buffer.copy }, - { _L['gtk-paste'], _buffer.paste }, - { _L['gtk-delete'], _buffer.clear }, + { _L['gtk-cut'], buffer.cut }, + { _L['gtk-copy'], buffer.copy }, + { _L['gtk-paste'], buffer.paste }, + { _L['gtk-delete'], buffer.clear }, SEPARATOR, - { _L['gtk-select-all'], _buffer.select_all } + { _L['gtk-select-all'], buffer.select_all } } local key_shortcuts = {} -local menu_actions = {} -local contextmenu_actions = {} +local menu_actions, contextmenu_actions = {}, {} -- Creates a menu suitable for `gui.gtkmenu()` from the menu table format. -- Also assigns key commands. @@ -344,7 +344,9 @@ function M.rebuild_command_tables() end M.rebuild_command_tables() -events.connect(events.MENU_CLICKED, function(menu_id) +local events, events_connect = events, events.connect + +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] if type(action) ~= 'function' and type(action) ~= 'table' then @@ -355,12 +357,12 @@ end) -- Set a language-specific context menu or the default one. local function set_language_contextmenu() - local lang = buffer:get_lexer() + local lang = _G.buffer:get_lexer() M.set_contextmenu(_m[lang] and _m[lang].context_menu or M.context_menu) end -events.connect(events.LANGUAGE_MODULE_LOADED, set_language_contextmenu) -events.connect(events.BUFFER_AFTER_SWITCH, set_language_contextmenu) -events.connect(events.VIEW_AFTER_SWITCH, set_language_contextmenu) -events.connect(events.BUFFER_NEW, set_lang_contextmenu) +events_connect(events.LANGUAGE_MODULE_LOADED, set_language_contextmenu) +events_connect(events.BUFFER_AFTER_SWITCH, set_language_contextmenu) +events_connect(events.VIEW_AFTER_SWITCH, set_language_contextmenu) +events_connect(events.BUFFER_NEW, set_lang_contextmenu) return M diff --git a/modules/textadept/mime_types.lua b/modules/textadept/mime_types.lua index 6ab0e0d3..df0ea957 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -30,7 +30,7 @@ module('_m.textadept.mime_types')]] -- * `lang`: The language lexer name. -- Events. -local events = events +local events, events_connect = events, events.connect events.LANGUAGE_MODULE_LOADED = 'language_module_loaded' --- @@ -159,7 +159,7 @@ local function get_lexer(buffer, current) return get_style_name(buffer, style_at[i]):match('^(.+)_whitespace$') or lexer end -events.connect(events.BUFFER_NEW, function() +events_connect(events.BUFFER_NEW, function() buffer.set_lexer, buffer.get_lexer = set_lexer, get_lexer buffer.get_style_name = get_style_name end, 1) @@ -190,8 +190,8 @@ local function handle_new() end buffer:set_lexer(lexer or 'container') end -events.connect(events.FILE_OPENED, handle_new) -events.connect(events.FILE_SAVED_AS, handle_new) +events_connect(events.FILE_OPENED, handle_new) +events_connect(events.FILE_SAVED_AS, handle_new) -- Sets the buffer's lexer based on filename, shebang words, or -- first line pattern. @@ -199,10 +199,10 @@ local function restore_lexer() buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer) buffer:private_lexer_call(SETLEXERLANGUAGE, buffer._lexer or 'container') end -events.connect(events.BUFFER_AFTER_SWITCH, restore_lexer) -events.connect(events.VIEW_NEW, restore_lexer, 1) +events_connect(events.BUFFER_AFTER_SWITCH, restore_lexer) +events_connect(events.VIEW_NEW, restore_lexer, 1) -events.connect(events.RESET_AFTER, +events_connect(events.RESET_AFTER, function() buffer:set_lexer(buffer._lexer or 'container') end) return M diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 08033c70..5ef8a3f8 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -29,7 +29,7 @@ module('_m.textadept.run')]] -- * `output`: The output from the command. -- Events. -local events = events +local events, events_connect = events, events.connect events.COMPILE_OUTPUT = 'compile_output' events.RUN_OUTPUT = 'run_output' @@ -90,7 +90,7 @@ function M.compile() events.emit(events.COMPILE_OUTPUT, buffer:get_lexer(), command(M.compile_command)) end -events.connect(events.COMPILE_OUTPUT, +events_connect(events.COMPILE_OUTPUT, function(lexer, output) gui.print(output) end) --- @@ -110,7 +110,7 @@ M.run_command = {} function M.run() events.emit(events.RUN_OUTPUT, buffer:get_lexer(), command(M.run_command)) end -events.connect(events.RUN_OUTPUT, +events_connect(events.RUN_OUTPUT, function(lexer, output) gui.print(output) end) --- @@ -160,6 +160,6 @@ function goto_error(pos, line_num) end end end -events.connect(events.DOUBLE_CLICK, goto_error) +events_connect(events.DOUBLE_CLICK, goto_error) return M diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index fe77650d..99ac0c46 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -61,8 +61,7 @@ function M.load(filename) buffer:visible_from_doc_line(first_visible_line)) buffer:set_sel(anchor, current_pos) elseif line:find('^%s*split%d:') then - local level, num, type, size = - line:match('^(%s*)split(%d): (%S+) (%d+)') + local level, num, type, size = line:match('^(%s*)split(%d): (%S+) (%d+)') local view = splits[#level] and splits[#level][tonumber(num)] or view splits[#level + 1] = { view:split(type == 'true') } splits[#level + 1][1].size = tonumber(size) -- could be 1 or 2 |