diff options
-rw-r--r-- | core/events.lua | 18 | ||||
-rw-r--r-- | core/ext/mime_types.lua | 3 | ||||
-rw-r--r-- | core/file_io.lua | 4 | ||||
-rw-r--r-- | init.lua | 15 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 18 |
5 files changed, 27 insertions, 31 deletions
diff --git a/core/events.lua b/core/events.lua index 6ffe327f..25dfb25d 100644 --- a/core/events.lua +++ b/core/events.lua @@ -16,9 +16,14 @@ module('textadept.events', package.seeall) -- is useful to have a handler run under a specific condition(s). If this is the -- case, place a conditional in the function that returns if it isn't met. -- --- For users creating their own events, one does not have to be explicitly --- defined. A handler can simply be added for an event name, and 'handle'd when --- necessary. +-- If a handler returns either true or false explicitly, all subsequent handlers +-- are not called. This is useful for something like a 'keypress' event where if +-- the key is handled, true should be returned so as to not propagate the event. +-- +-- Events need not be declared. A handler can simply be added for an event name, +-- and 'handle'd when necessary. As an example, you can create a handler for a +-- custom 'my_event' and call "textadept.events.handle('my_event')" to envoke +-- it. -- -- For reference, events will be shown in 'event(arguments)' format, but in -- reality, the event is handled as 'handle(event, arguments)'. @@ -324,8 +329,6 @@ add_handler('buffer_new', if not ret then io.stderr:write(errmsg) end end) -local title_text = '%s %s Textadept (%s)' - --- -- [Local function] Sets the title of the Textadept window to the buffer's -- filename. @@ -333,9 +336,10 @@ local title_text = '%s %s Textadept (%s)' local function set_title(buffer) local buffer = buffer local filename = buffer.filename or buffer._type or locale.UNTITLED - local d = buffer.dirty and '*' or '-' + local dirty = buffer.dirty and '*' or '-' textadept.title = - string.format(title_text, filename:match('[^/\\]+$'), d, filename) + string.format('%s %s Textadept (%s)', filename:match('[^/\\]+$'), dirty, + filename) end add_handler('save_point_reached', diff --git a/core/ext/mime_types.lua b/core/ext/mime_types.lua index a1867437..7fb7fcab 100644 --- a/core/ext/mime_types.lua +++ b/core/ext/mime_types.lua @@ -45,11 +45,12 @@ end --- -- [Local function] Replacement for buffer:set_lexer_language(). --- Sets a buffer._lexer field so it can be restored without querying the +-- Sets a buffer._lexer field so it can be restored without querying the -- mime-types tables. Also if the user manually sets the lexer, it should be -- restored. -- @param buffer The buffer to set the lexer language of. -- @param lang The string language to set. +-- @usage buffer:set_lexer('language_name') local function set_lexer(buffer, lang) buffer._lexer = lang buffer:set_lexer_language(lang) diff --git a/core/file_io.lua b/core/file_io.lua index b0131aa1..859e52c6 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -91,7 +91,6 @@ local function open_helper(utf8_filename) end local buffer = textadept.new_buffer() if text then - local c = textadept.constants -- Tries to detect character encoding and convert text from it to UTF-8. local encoding, encoding_bom = detect_encoding(text) if encoding ~= 'binary' then @@ -113,6 +112,7 @@ local function open_helper(utf8_filename) else encoding = nil end + local c = textadept.constants buffer.encoding, buffer.encoding_bom = encoding, encoding_bom buffer.code_page = encoding and c.SC_CP_UTF8 or 0 -- Tries to set the buffer's EOL mode appropriately based on the file. @@ -329,7 +329,7 @@ function load_session(filename, only_pm) local anchor, current_pos, first_visible_line, filename = line:match('^buffer: (%d+) (%d+) (%d+) (.+)$') if not filename:find('^%[.+%]$') then - textadept.io.open(filename or '', 'rb') + textadept.io.open(filename or '') else textadept.new_buffer() buffer._type = filename @@ -42,10 +42,9 @@ if not RESETTING then -- for Windows, create arg table from single command line string (arg[0]) if WIN32 and #arg[0] > 0 then local lpeg = require 'lpeg' - local P, S, C, Ct = lpeg.P, lpeg.S, lpeg.C, lpeg.Ct - space = P(' ') - param = P('"') * C((1 - P('"'))^0) * '"' + C((1 - space)^1) - cmdline = Ct(param * (space * param)^0) + local P, C = lpeg.P, lpeg.C + param = P('"') * C((1 - P('"'))^0) * '"' + C((1 - P(' '))^1) + cmdline = lpeg.Ct(param * (P(' ') * param)^0) args = lpeg.match(cmdline, arg[0]) for _, a in ipairs(args) do arg[#arg + 1] = a end end @@ -58,13 +57,9 @@ if not RESETTING then textadept.io.load_session() else local base_dir = arg[0]:match('^.+/') or '' - local filepath for _, filename in ipairs(arg) do - if not filename:find('^~?/') then - textadept.io.open(base_dir..filename) - else - textadept.io.open(filename) - end + if not filename:find('^~?/') then filename = base_dir..filename end + textadept.io.open(filename) end -- read only the Project Manager session settings if not textadept.io.load_session(nil, true) then diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 249952e4..c832c8fe 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -363,8 +363,7 @@ function smart_paste(action, reindent) if txt then if reindent then local indent = - buffer.line_indentation[ - buffer:line_from_position(buffer.current_pos)] + buffer.line_indentation[buffer:line_from_position(buffer.current_pos)] local padding = string.rep(buffer.use_tabs and '\t' or ' ', buffer.use_tabs and indent / buffer.tab_width or indent) @@ -482,19 +481,16 @@ end --- -- Selects text in a specified enclosure. --- @param str The enclosure type in enclosure. If str is not specified, --- matching character pairs defined in char_matches are searched for from the --- caret outwards. +-- @param str The enclosure type in enclosure. -- @see enclosure -- @see char_matches function select_enclosed(str) + if not str then return end local buffer = buffer - if str then - buffer:search_anchor() - local s = buffer:search_prev(0, enclosure[str].left) - local e = buffer:search_next(0, enclosure[str].right) - if s and e then buffer:set_sel(s + 1, e) end - end + buffer:search_anchor() + local s = buffer:search_prev(0, enclosure[str].left) + local e = buffer:search_next(0, enclosure[str].right) + if s and e then buffer:set_sel(s + 1, e) end end --- |