diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ansi_c/init.lua | 4 | ||||
-rw-r--r-- | modules/lua/init.lua | 2 | ||||
-rw-r--r-- | modules/textadept/bookmarks.lua | 30 | ||||
-rw-r--r-- | modules/textadept/command_entry.lua | 8 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 50 | ||||
-rw-r--r-- | modules/textadept/file_types.lua | 33 | ||||
-rw-r--r-- | modules/textadept/find.lua | 65 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 28 | ||||
-rw-r--r-- | modules/textadept/run.lua | 13 | ||||
-rw-r--r-- | modules/textadept/session.lua | 55 | ||||
-rw-r--r-- | modules/textadept/snippets.lua | 4 |
11 files changed, 151 insertions, 141 deletions
diff --git a/modules/ansi_c/init.lua b/modules/ansi_c/init.lua index 6314fea2..950479d3 100644 --- a/modules/ansi_c/init.lua +++ b/modules/ansi_c/init.lua @@ -65,8 +65,8 @@ textadept.editing.autocompleters.ansi_c = function() local fields = tag_line:match(';"\t(.*)$') if (fields:match('class:(%S+)') or fields:match('enum:(%S+)') or fields:match('struct:(%S+)') or '') == symbol then - list[#list + 1] = ("%s%s%d"):format(name, sep, - xpms[fields:sub(1, 1)]) + list[#list + 1] = string.format('%s%s%d', name, sep, + xpms[fields:sub(1, 1)]) list[name] = true elseif name == symbol and fields:match('typeref:') then -- For typeref, change the lookup symbol to the referenced name and diff --git a/modules/lua/init.lua b/modules/lua/init.lua index bc5ced65..1fb007be 100644 --- a/modules/lua/init.lua +++ b/modules/lua/init.lua @@ -58,7 +58,7 @@ textadept.editing.autocompleters.lua = function() local fields = tag_line:match(';"\t(.*)$') local k, class = fields:sub(1, 1), fields:match('class:(%S+)') or '' if class == symbol and (op ~= ':' or k == 'f') then - list[#list + 1] = ("%s%s%d"):format(name, sep, xpms[k]) + list[#list + 1] = string.format('%s%s%d', name, sep, xpms[k]) list[name] = true end end diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index 4d92fcc3..ded52fa4 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -21,7 +21,7 @@ M.MARK_BOOKMARK = _SCINTILLA.next_marker_number() -- @param line Optional line number to add or remove a bookmark on. -- @name toggle function M.toggle(on, line) - line = line or buffer:line_from_position(buffer.current_pos) + if not line then line = buffer:line_from_position(buffer.current_pos) end local f = on and buffer.marker_add or buffer.marker_delete if on == nil then -- toggle local bit, marker_mask = 2^M.MARK_BOOKMARK, buffer:marker_get(line) @@ -46,32 +46,34 @@ function M.clear() buffer:marker_delete_all(M.MARK_BOOKMARK) end -- @name goto_mark function M.goto_mark(next) if next == nil then - local marks = {} + local utf8_list, buffers = {}, {} -- List the current buffer's marks, and then all other buffers' marks. for _, current_buffer_first in ipairs{true, false} do - for i, buffer in ipairs(_BUFFERS) do - if current_buffer_first and buffer == _G.buffer or - not current_buffer_first and buffer ~= _G.buffer then + for i = 1, #_BUFFERS do + if current_buffer_first and _BUFFERS[i] == buffer or + not current_buffer_first and _BUFFERS[i] ~= buffer then + local buffer = _BUFFERS[i] local filename = (buffer.filename or buffer._type or _L['Untitled']):match('[^/\\]+$') local line = buffer:marker_next(0, 2^M.MARK_BOOKMARK) while line >= 0 do - local text = filename..':'..tostring(line + 1)..': '.. - buffer:get_line(line):match('^[^\r\n]*') - marks[#marks + 1], marks[text] = text, i + local mark = string.format('%s:%d: %s', + filename:iconv('UTF-8', _CHARSET), + line + 1, + buffer:get_line(line):match('^[^\r\n]*')) + utf8_list[#utf8_list + 1], buffers[#utf8_list + 1] = mark, i line = buffer:marker_next(line + 1, 2^M.MARK_BOOKMARK) end end end end - if #marks == 0 then return end + if #utf8_list == 0 then return end local button, mark = ui.dialogs.filteredlist{ - title = _L['Select Bookmark'], columns = _L['Bookmark'], items = marks, - string_output = true + title = _L['Select Bookmark'], columns = _L['Bookmark'], items = utf8_list } - if button ~= _L['_OK'] or not mark then return end - view:goto_buffer(marks[mark]) - textadept.editing.goto_line(mark:match('^[^:]+:(%d+):')) + if button ~= 1 or not mark then return end + view:goto_buffer(buffers[mark]) + textadept.editing.goto_line(utf8_list[mark]:match('^[^:]+:(%d+):')) else local f = next and buffer.marker_next or buffer.marker_previous local current_line = buffer:line_from_position(buffer.current_pos) diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 6c7a4359..325db3cb 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -115,9 +115,9 @@ local env = setmetatable({}, { return f end, __newindex = function(t, k, v) - for _, t2 in ipairs{buffer, view, ui} do - if t2[k] ~= nil then t2[k] = v return end - end + if buffer[k] ~= nil then buffer[k] = v return end + if view[k] ~= nil then view[k] = v return end + if ui[k] ~= nil then ui[k] = v return end rawset(t, k, v) end, }) @@ -143,9 +143,9 @@ local function complete_lua() local line, pos = M:get_cur_line() local symbol, op, part = line:sub(1, pos):match('([%w_.]-)([%.:]?)([%w_]*)$') local ok, result = pcall((load('return ('..symbol..')', nil, 'bt', env))) + if (not ok or type(result) ~= 'table') and symbol ~= '' then return end local cmpls = {} part = '^'..part - if (not ok or type(result) ~= 'table') and symbol ~= '' then return end if not ok then -- shorthand notation local pool = { buffer, view, ui, _G, _SCINTILLA.functions, _SCINTILLA.properties diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 758f792a..93c180b7 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -226,8 +226,7 @@ events.connect(events.FILE_BEFORE_SAVE, function() local buffer = buffer buffer:begin_undo_action() -- Strip trailing whitespace. - local lines = buffer.line_count - for line = 0, lines - 1 do + for line = 0, buffer.line_count - 1 do local s, e = buffer:position_from_line(line), buffer.line_end_position[line] local i, c = e - 1, buffer.char_at[e - 1] while i >= s and (c == 9 or c == 32) do @@ -236,8 +235,9 @@ events.connect(events.FILE_BEFORE_SAVE, function() if i < e - 1 then buffer:delete_range(i + 1, e - i - 1) end end -- Ensure ending newline. - local e = buffer:position_from_line(lines) - if lines == 1 or e > buffer:position_from_line(lines - 1) then + local e = buffer:position_from_line(buffer.line_count) + if buffer.line_count == 1 or + e > buffer:position_from_line(buffer.line_count - 1) then buffer:insert_text(e, '\n') end -- Convert non-consistent EOLs @@ -332,7 +332,7 @@ end -- the caret. Otherwise, the characters to the left and right are. -- @name transpose_chars function M.transpose_chars() - if buffer.length == 0 or buffer.current_pos == 0 then return end + if buffer.current_pos == 0 then return end local pos, char = buffer.current_pos, buffer.char_at[buffer.current_pos] if char == 10 or char == 13 or pos == buffer.length then pos = pos - 1 end buffer:set_target_range(pos - 1, pos + 1) @@ -363,14 +363,8 @@ end -- @param right The right part of the enclosure. -- @name enclose function M.enclose(left, right) - buffer:target_from_selection() - local s, e = buffer.target_start, buffer.target_end - if s == e then - buffer:set_target_range(buffer:word_start_position(s, true), - buffer:word_end_position(e, true)) - end - buffer:replace_target(left..buffer.target_text..right) - buffer:goto_pos(buffer.target_end) + if buffer.selection_empty then M.select_word() end + buffer:replace_sel(left..buffer:get_sel_text()..right) end --- @@ -439,16 +433,16 @@ end function M.convert_indentation() local buffer = buffer buffer:begin_undo_action() - for line = 0, buffer.line_count do + for line = 0, buffer.line_count - 1 do local s = buffer:position_from_line(line) local indent = buffer.line_indentation[line] local e = buffer.line_indent_position[line] local current_indentation, new_indentation = buffer:text_range(s, e), nil if buffer.use_tabs then -- Need integer division and LuaJIT does not have // operator. - new_indentation = ('\t'):rep(math.floor(indent / buffer.tab_width)) + new_indentation = string.rep('\t', math.floor(indent / buffer.tab_width)) else - new_indentation = (' '):rep(indent) + new_indentation = string.rep(' ', indent) end if current_indentation ~= new_indentation then buffer:set_target_range(s, e) @@ -510,26 +504,25 @@ end -- @name filter_through function M.filter_through(command) local s, e = buffer.selection_start, buffer.selection_end - local input - if s ~= e then -- use selected lines as input + if s ~= e then + -- Use the selected lines as input. local i, j = buffer:line_from_position(s), buffer:line_from_position(e) if i < j then s = buffer:position_from_line(i) if buffer.column[e] > 0 then e = buffer:position_from_line(j + 1) end end - input = buffer:text_range(s, e) - else -- use whole buffer as input - input = buffer:get_text() + buffer:set_target_range(s, e) + else + -- Use the whole buffer as input. + buffer:target_whole_document() end local p = spawn(command) - p:write(input) + p:write(buffer.target_text) p:close() + buffer:replace_target(p:read('*a')) if s ~= e then - buffer:set_target_range(s, e) - buffer:replace_target(p:read('*a')) buffer:set_sel(buffer.target_start, buffer.target_end) else - buffer:set_text(p:read('*a')) buffer:goto_pos(s) end end @@ -644,8 +637,11 @@ end events.connect(events.CALL_TIP_CLICK, function(position) if not api_docs then return end api_docs.pos = api_docs.pos + (position == 1 and -1 or 1) - if api_docs.pos > #api_docs then api_docs.pos = 1 end - if api_docs.pos < 1 then api_docs.pos = #api_docs end + if api_docs.pos > #api_docs then + api_docs.pos = 1 + elseif api_docs.pos < 1 then + api_docs.pos = #api_docs + end buffer:call_tip_show(buffer.current_pos, api_docs[api_docs.pos]) end) diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua index 3c101d50..fd61e2e2 100644 --- a/modules/textadept/file_types.lua +++ b/modules/textadept/file_types.lua @@ -83,8 +83,8 @@ events.connect(events.BUFFER_NEW, function() buffer.get_lexer, buffer.set_lexer = get_lexer, set_lexer buffer.style_name = setmetatable({}, { __index = function(_, style_num) -- LuaDoc is in core/.buffer.luadoc - assert(style_num >= 0 and style_num <= 255, '0 <= style_num < 256') - return buffer:private_lexer_call(style_num) + return style_num >= 0 and style_num <= 255 and + buffer:private_lexer_call(style_num) or nil end, __newindex = function() error('read-only property') end }) @@ -96,24 +96,14 @@ events.connect(events.FILE_AFTER_SAVE, function(_, saved_as) if saved_as then buffer:set_lexer() end end) --- Restores the buffer's lexer. +-- Restores the buffer's lexer, primarily for the side-effect of emitting +-- `events.LEXER_LOADED`. local function restore_lexer() buffer:set_lexer(buffer._lexer) end events.connect(events.BUFFER_AFTER_SWITCH, restore_lexer) events.connect(events.VIEW_AFTER_SWITCH, restore_lexer) events.connect(events.VIEW_NEW, restore_lexer) events.connect(events.RESET_AFTER, restore_lexer) ---- --- Prompts the user to select a lexer for the current buffer. --- @see buffer.set_lexer --- @name select_lexer -function M.select_lexer() - local button, i = ui.dialogs.filteredlist{ - title = _L['Select Lexer'], columns = _L['Name'], items = M.lexers - } - if button == 1 and i then buffer:set_lexer(M.lexers[i]) end -end - -- Generate lexer list. local lexers_found = {} for _, dir in ipairs{_HOME..'/lexers', _USERHOME..'/lexers'} do @@ -125,7 +115,20 @@ for _, dir in ipairs{_HOME..'/lexers', _USERHOME..'/lexers'} do end end end -for lexer in pairs(lexers_found) do M.lexers[#M.lexers + 1] = lexer end +for lexer in pairs(lexers_found) do + M.lexers[#M.lexers + 1] = lexer:iconv('UTF-8', _CHARSET) +end table.sort(M.lexers) +--- +-- Prompts the user to select a lexer for the current buffer. +-- @see buffer.set_lexer +-- @name select_lexer +function M.select_lexer() + local button, i = ui.dialogs.filteredlist{ + title = _L['Select Lexer'], columns = _L['Name'], items = M.lexers + } + if button == 1 and i then buffer:set_lexer(M.lexers[i]) end +end + return M diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index a9769cb8..1ba93536 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -127,7 +127,7 @@ for k, v in pairs(escapes) do escapes[v] = k end -- for displaying useful statusbar information. This flag is used and set -- internally, and should not be set otherwise. -- @return position of the found text or `-1` -local function find_(text, next, flags, no_wrap, wrapped) +local function find(text, next, flags, no_wrap, wrapped) if text == '' then return end if not flags then flags = 0 @@ -141,9 +141,9 @@ local function find_(text, next, flags, no_wrap, wrapped) -- If text is selected, assume it is from the current search and increment the -- caret appropriately for the next search. - if buffer:get_sel_text() ~= '' then - buffer:goto_pos(buffer[next and 'current_pos' or 'anchor'] + - (next and 1 or -1)) + if not buffer.selection_empty then + local pos = buffer[next and 'current_pos' or 'anchor'] + buffer:goto_pos(buffer:position_relative(pos, next and 1 or -1)) end local pos = -1 @@ -155,17 +155,20 @@ local function find_(text, next, flags, no_wrap, wrapped) elseif flags < 16 then -- Lua pattern search. -- Note: I do not trust utf8.find completely, so only use it if there are - -- UTF-8 characters in patt. Otherwise default to string.find. - local patt = text:gsub('\\[abfnrtv\\]', escapes) + -- UTF-8 characters in the pattern. Otherwise default to string.find. + local lib_find = not text:find('[\xC2-\xF4]') and string.find or utf8.find local s = next and buffer.current_pos or 0 local e = next and buffer.length or buffer.current_pos - local find = not patt:find('[\xC2-\xF4]') and string.find or utf8.find - local caps = {find(buffer:text_range(s, e), next and patt or '^.*()'..patt)} + local patt = text:gsub('\\[abfnrtv\\]', escapes) + if not next then patt = '^.*()'..patt end + local caps = {lib_find(buffer:text_range(s, e), patt)} M.captures = {table.unpack(caps, next and 3 or 4)} if #caps > 0 and caps[2] >= caps[1] then - if find == string.find then + if lib_find == string.find then + -- Positions are bytes. pos, e = s + caps[next and 1 or 3] - 1, s + caps[2] else + -- Positions are characters, which may be multiple bytes. pos = buffer:position_relative(s, caps[next and 1 or 3] - 1) e = buffer:position_relative(s, caps[2]) end @@ -181,7 +184,7 @@ local function find_(text, next, flags, no_wrap, wrapped) buffer:goto_pos(next and 0 or buffer.length) ui.statusbar_text = _L['Search wrapped'] events.emit(events.FIND_WRAPPED) - pos = find_(text, next, flags, true, true) + pos = find(text, next, flags, true, true) if pos == -1 then ui.statusbar_text = _L['No results found'] buffer:line_scroll(0, first_visible_line - buffer.first_visible_line) @@ -193,7 +196,7 @@ local function find_(text, next, flags, no_wrap, wrapped) return pos end -events.connect(events.FIND, find_) +events.connect(events.FIND, find) -- Finds and selects text incrementally in the current buffer from a starting -- position. @@ -204,10 +207,11 @@ events.connect(events.FIND, find_) -- position. local function find_incremental(text, next, anchor) if anchor then - M.incremental_start = buffer.current_pos + (next and 1 or -1) + M._incremental_start = buffer:position_relative(buffer.current_pos, + next and 1 or -1) end - buffer:goto_pos(M.incremental_start or 0) - find_(text, next, M.match_case and buffer.FIND_MATCHCASE or 0) + buffer:goto_pos(M._incremental_start or 0) + find(text, next, M.match_case and buffer.FIND_MATCHCASE or 0) end --- @@ -227,7 +231,7 @@ end -- @name find_incremental function M.find_incremental(text, next, anchor) if text then find_incremental(text, next, anchor) return end - M.incremental_start = buffer.current_pos + M._incremental_start = buffer.current_pos ui.command_entry:set_text('') ui.command_entry.enter_mode('find_incremental') end @@ -262,16 +266,17 @@ function M.find_in_files(dir) buffer.indicator_current = M.INDIC_FIND local found = false - lfs.dir_foreach(dir, function(file) + lfs.dir_foreach(dir, function(filename) local match_case = M.match_case local line_num = 1 - for line in io.lines(file) do + for line in io.lines(filename) do local s, e = (match_case and line or line:lower()):find(text) if s and e then - file = file:iconv('UTF-8', _CHARSET) - buffer:append_text(('%s:%d:%s\n'):format(file, line_num, line)) + local utf8_filename = filename:iconv('UTF-8', _CHARSET) + buffer:append_text(string.format('%s:%d:%s\n', utf8_filename, line_num, + line)) local pos = buffer:position_from_line(buffer.line_count - 2) + - #file + #tostring(line_num) + 2 + #utf8_filename + #tostring(line_num) + 2 buffer:indicator_fill_range(pos + s - 1, e - s + 1) found = true end @@ -283,7 +288,7 @@ function M.find_in_files(dir) end -- Replaces found text. --- `find_()` is called first, to select any found text. The selected text is +-- `find()` is called first, to select any found text. The selected text is -- then replaced by the specified replacement text. -- This function ignores "Find in Files". -- @param rtext The text to replace found text with. It can contain both Lua @@ -336,7 +341,7 @@ local function replace_all(ftext, rtext) local count = 0 if buffer.selection_empty then buffer:goto_pos(0) - while find_(ftext, true, nil, true) ~= -1 do + while find(ftext, true, nil, true) ~= -1 do replace(rtext) count = count + 1 end @@ -345,17 +350,17 @@ local function replace_all(ftext, rtext) buffer.indicator_current = INDIC_REPLACE buffer:indicator_fill_range(e, 1) buffer:goto_pos(s) - local pos = find_(ftext, true, nil, true) + local pos = find(ftext, true, nil, true) while pos ~= -1 and pos <= buffer:indicator_end(INDIC_REPLACE, s) do replace(rtext) count = count + 1 - pos = find_(ftext, true, nil, true) + pos = find(ftext, true, nil, true) end e = buffer:indicator_end(INDIC_REPLACE, s) buffer:set_sel(s, e > 0 and e or buffer.length) buffer:indicator_clear_range(e, 1) end - ui.statusbar_text = ("%d %s"):format(count, _L['replacement(s) made']) + ui.statusbar_text = string.format('%d %s', count, _L['replacement(s) made']) buffer:end_undo_action() end events.connect(events.REPLACE_ALL, replace_all) @@ -372,7 +377,7 @@ local function is_ff_buf(buf) return buf._type == _L['[Files Found Buffer]'] end -- or the previous one. Only applicable when *line* is `nil` or `false`. -- @name goto_file_found function M.goto_file_found(line, next) - local cur_buf, ff_view, ff_buf = _BUFFERS[buffer], nil, nil + local ff_view, ff_buf = nil, nil for i = 1, #_VIEWS do if is_ff_buf(_VIEWS[i].buffer) then ff_view = i break end end @@ -393,16 +398,16 @@ function M.goto_file_found(line, next) buffer:search_anchor() pos = f(buffer, buffer.FIND_REGEXP, '^.+:[0-9]+:.+$') end - if pos == -1 then if CURSES then view:goto_buffer(cur_buf) end return end + if pos == -1 then return end line = buffer:line_from_position(pos) end buffer:goto_line(line) -- Goto the source of the search result. - local file, line_num = buffer:get_cur_line():match('^(.+):(%d+):.+$') - if not file then if CURSES then view:goto_buffer(cur_buf) end return end + local utf8_filename, line_num = buffer:get_cur_line():match('^(.+):(%d+):.+$') + if not utf8_filename then return end textadept.editing.select_line() - ui.goto_file(file:iconv(_CHARSET, 'UTF-8'), true, preferred_view) + ui.goto_file(utf8_filename:iconv(_CHARSET, 'UTF-8'), true, preferred_view) textadept.editing.goto_line(line_num) end events.connect(events.KEYPRESS, function(code) diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 7647db9d..bf32a879 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -250,13 +250,13 @@ local function get_gdk_key(key_seq) local modifiers = ((mods:find('s') or key:lower() ~= key) and 1 or 0) + (mods:find('c') and 4 or 0) + (mods:find('a') and 8 or 0) + (mods:find('m') and 0x10000000 or 0) - local byte = string.byte(key) - if #key > 1 or byte < 32 then + local code = string.byte(key) + if #key > 1 or code < 32 then for i, s in pairs(keys.KEYSYMS) do - if s == key and i > 0xFE20 then byte = i break end + if s == key and i > 0xFE20 then code = i break end end end - return byte, modifiers + return code, modifiers end -- Get a string uniquely identifying a key binding. @@ -282,11 +282,11 @@ end local function read_menu_table(menu, contextmenu) local gtkmenu = {} gtkmenu.title = menu.title - for _, menuitem in ipairs(menu) do - if menuitem.title then - gtkmenu[#gtkmenu + 1] = read_menu_table(menuitem, contextmenu) + for i = 1, #menu do + if menu[i].title then + gtkmenu[#gtkmenu + 1] = read_menu_table(menu[i], contextmenu) else - local label, f = menuitem[1], menuitem[2] + local label, f = menu[i][1], menu[i][2] local menu_id = not contextmenu and #menu_actions + 1 or #contextmenu_actions + 1000 + 1 local key, mods = get_gdk_key(key_shortcuts[get_id(f)]) @@ -306,11 +306,11 @@ end -- @param items The current list of items. -- @param commands The current list of commands. local function build_command_tables(menu, title, items, commands) - for _, menuitem in ipairs(menu) do - if menuitem.title then - build_command_tables(menuitem, menuitem.title, items, commands) - elseif menuitem[1] ~= '' then - local label, f = menuitem[1], menuitem[2] + for i = 1, #menu do + if menu[i].title then + build_command_tables(menu[i], menu[i].title, items, commands) + elseif menu[i][1] ~= '' then + local label, f = menu[i][1], menu[i][2] if title then label = title..': '..label end items[#items + 1] = label:gsub('_([^_])', '%1') items[#items + 1] = key_shortcuts[get_id(f)] or '' @@ -390,7 +390,7 @@ local function set_contextmenus(buffer_menu, tab_menu) set_contextmenus(nil, menu) end) end -if not CURSES then set_contextmenus() end +set_contextmenus() --- -- Prompts the user to select a menu command to run. diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index ce2d75e2..66a57ba4 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -299,7 +299,7 @@ local function is_msg_buf(buf) return buf._type == _L['[Message Buffer]'] end -- @see cwd -- @name goto_error function M.goto_error(line, next) - local cur_buf, msg_view, msg_buf = _BUFFERS[buffer], nil, nil + local msg_view, msg_buf = nil, nil for i = 1, #_VIEWS do if is_msg_buf(_VIEWS[i].buffer) then msg_view = i break end end @@ -322,17 +322,17 @@ function M.goto_error(line, next) if wline == -1 then wline = eline else eline = wline end end line = (next and math.min or math.max)(wline, eline) - if line == -1 then if CURSES then view:goto_buffer(cur_buf) end return end + if line == -1 then return end end buffer:goto_line(line) -- Goto the warning or error and show an annotation. local error = get_error(buffer:get_line(line):match('^[^\r\n]*')) - if not error then if CURSES then view:goto_buffer(cur_buf) end return end + if not error then return end textadept.editing.select_line() ui.goto_file(M.cwd..'/'..error.filename, true, preferred_view, true) local line_num, message = error.line, error.message - buffer:goto_line(line_num - 1) + textadept.editing.goto_line(line_num) if message then buffer.annotation_text[line_num - 1] = message -- Style number 8 is the error style. @@ -411,8 +411,9 @@ events.connect(events.FILE_AFTER_SAVE, function(filename) buffer:goto_pos(buffer:find_column(captures.line, captures.column or 0)) elseif captures.line < top_line or captures.line > bottom_line then local line = buffer:line_from_position(buffer.current_pos) - buffer.annotation_text[line] = 'Line '..(captures.line + 1)..'\n'.. - captures.message + buffer.annotation_text[line] = string.format('%s %d\n%s', _L['Line:'], + captures.line + 1, + captures.message) buffer.annotation_style[line] = 8 -- error style number end end) diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index f7a5c7f9..142fffe7 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -49,16 +49,16 @@ function M.load(filename) for line in f:lines() do if line:find('^buffer:') then local patt = '^buffer: (%d+) (%d+) (%d+) (.+)$' - local anchor, current_pos, first_visible_line, file = line:match(patt) - if not file:find('^%[.+%]$') then - if lfs_attributes(file) then - io.open_file(file) + local anchor, current_pos, first_visible_line, filename = line:match(patt) + if not filename:find('^%[.+%]$') then + if lfs_attributes(filename) then + io.open_file(filename) else - not_found[#not_found + 1] = file + not_found[#not_found + 1] = filename end else - buffer.new()._type = file - events.emit(events.FILE_OPENED, file) + buffer.new()._type = filename + events.emit(events.FILE_OPENED, filename) -- close initial untitled buf end -- Restore saved buffer selection and view. anchor, current_pos = tonumber(anchor) or 0, tonumber(current_pos) or 0 @@ -72,6 +72,10 @@ function M.load(filename) for line in lines:gmatch('%d+') do buffer:marker_add(tonumber(line), textadept.bookmarks.MARK_BOOKMARK) end + elseif line:find('^size:') then + local maximized, width, height = line:match('^size: (%l+) (%d+) (%d+)$') + ui.maximized = maximized == 'true' + if not ui.maximized then ui.size = {width, height} end elseif line:find('^%s*split%d:') then local level, num, type, size = line:match('^(%s*)split(%d): (%S+) (%d+)') local view = splits[#level] and splits[#level][tonumber(num)] or view @@ -86,10 +90,6 @@ function M.load(filename) view:goto_buffer(buf_idx) elseif line:find('^current_view:') then current_view = tonumber(line:match('^current_view: (%d+)')) or 1 - elseif line:find('^size:') then - local maximized, width, height = line:match('^size: (%l*) ?(%d+) (%d+)$') - ui.maximized = maximized == 'true' - if not ui.maximized then ui.size = {width, height} end elseif line:find('^recent:') then local file = line:match('^recent: (.+)$') local recent, exists = io.recent_files, false @@ -105,7 +105,7 @@ function M.load(filename) ui.dialogs.msgbox{ title = _L['Session Files Not Found'], text = _L['The following session files were not found'], - informative_text = table.concat(not_found, '\n'), + informative_text = table.concat(not_found, '\n'):iconv('UTF-8', _CHARSET), icon = 'gtk-dialog-warning' } end @@ -132,20 +132,22 @@ function M.save(filename) } if not filename then return end local session = {} - local buffer_line = "buffer: %d %d %d %s" -- anchor, cursor, line, filename - local split_line = "%ssplit%d: %s %d" -- level, number, type, size - local view_line = "%sview%d: %d" -- level, number, doc index + local buffer_line = 'buffer: %d %d %d %s' -- anchor, cursor, line, filename + local split_line = '%ssplit%d: %s %d' -- level, number, type, size + local view_line = '%sview%d: %d' -- level, number, doc index -- Write out opened buffers. - for _, buffer in ipairs(_BUFFERS) do - local file = buffer.filename or buffer._type - if file then + for i = 1, #_BUFFERS do + local buffer = _BUFFERS[i] + local filename = buffer.filename or buffer._type + if filename then local current = buffer == view.buffer local anchor = current and 'anchor' or '_anchor' local current_pos = current and 'current_pos' or '_current_pos' local top_line = current and 'first_visible_line' or '_first_visible_line' session[#session + 1] = buffer_line:format(buffer[anchor] or 0, buffer[current_pos] or 0, - buffer[top_line] or 0, file) + buffer[top_line] or 0, + filename) -- Write out bookmarks. local lines = {} local line = buffer:marker_next(0, 2^textadept.bookmarks.MARK_BOOKMARK) @@ -159,14 +161,15 @@ function M.save(filename) -- Write out window size. Do this before writing split views since split view -- size depends on the window size. local maximized, size = tostring(ui.maximized), ui.size - session[#session + 1] = ("size: %s %d %d"):format(maximized, size[1], size[2]) + session[#session + 1] = string.format('size: %s %d %d', maximized, size[1], + size[2]) -- Write out split views. local function write_split(split, level, number) local c1, c2 = split[1], split[2] local vertical, size = tostring(split.vertical), split.size - local spaces = (' '):rep(level) + local spaces = string.rep(' ', level) session[#session + 1] = split_line:format(spaces, number, vertical, size) - spaces = (' '):rep(level + 1) + spaces = string.rep(' ', level + 1) if c1[1] and c1[2] then write_split(c1, level + 1, 1) else @@ -185,11 +188,11 @@ function M.save(filename) session[#session + 1] = view_line:format('', 1, _BUFFERS[splits.buffer]) end -- Write out the current focused view. - session[#session + 1] = ("current_view: %d"):format(_VIEWS[view]) + session[#session + 1] = string.format('current_view: %d', _VIEWS[view]) -- Write out other things. for i = 1, #io.recent_files do if i > M.MAX_RECENT_FILES then break end - session[#session + 1] = ("recent: %s"):format(io.recent_files[i]) + session[#session + 1] = string.format('recent: %s', io.recent_files[i]) end -- Write the session. local f = io.open(filename, 'wb') @@ -208,8 +211,8 @@ args.register('-n', '--nosession', 0, function() M.SAVE_ON_QUIT = false end, 'No session functionality') -- Loads the given session on startup. args.register('-s', '--session', 1, function(name) - if lfs.attributes(name) then M.load(name) return end - M.load(_USERHOME..'/'..name) + if not lfs.attributes(name) then name = _USERHOME..'/'..name end + M.load(name) end, 'Load session') return M diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index e0829b1d..64b9c385 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -159,7 +159,7 @@ local function new_snippet(text, trigger) -- Convert and match indentation. local lines = {} - local indent = {[true] = '\t', [false] = (' '):rep(buffer.tab_width)} + local indent = {[true] = '\t', [false] = string.rep(' ', buffer.tab_width)} local use_tabs = buffer.use_tabs for line in (text..'\n'):gmatch('([^\r\n]*)\r?\n') do lines[#lines + 1] = line:gsub('^(%s*)', function(indentation) @@ -355,7 +355,7 @@ function M._select() local lexer = buffer:get_lexer(true) for trigger, text in pairs(snippets[lexer] or {}) do if type(text) == 'string' then - list[#list + 1] = trigger..'\0'..lexer..'\0'..text + list[#list + 1] = string.format('%s\0%s\0%s', trigger, lexer, text) end end table.sort(list) |