diff options
author | 2012-01-05 10:24:51 -0500 | |
---|---|---|
committer | 2012-01-05 10:24:51 -0500 | |
commit | 7cf43c7dd653ef28c2212975f81b14be6473e06f (patch) | |
tree | 251c33430f492d8780ab22cd69a9abe0af02f0c3 | |
parent | bd351f0bef198d981b67830ddb5e4cd42c3aca37 (diff) |
Code cleanup.
-rw-r--r-- | core/file_io.lua | 2 | ||||
-rw-r--r-- | core/gui.lua | 20 | ||||
-rw-r--r-- | init.lua | 6 | ||||
-rw-r--r-- | modules/cpp/init.lua | 2 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 46 | ||||
-rw-r--r-- | modules/textadept/find.lua | 11 | ||||
-rw-r--r-- | themes/dark/lexer.lua | 6 | ||||
-rw-r--r-- | themes/light/lexer.lua | 6 |
8 files changed, 43 insertions, 56 deletions
diff --git a/core/file_io.lua b/core/file_io.lua index 8546d652..35be637d 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -210,7 +210,7 @@ end local function save(buffer) if not buffer then buffer = _G.buffer end buffer:check_global() - if not buffer.filename then return buffer:save_as() end + 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) if buffer.encoding then diff --git a/core/gui.lua b/core/gui.lua index ab7d0909..51af5b71 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -216,6 +216,7 @@ function gui.select_theme() local theme = gui.filteredlist(_L['Select Theme'], _L['Name'], themes) if not theme then return end gui.set_theme(theme) + -- Write the theme to the user's theme file. local f = io.open(_USERHOME..'/theme', 'wb') if not f then return end f:write(theme) @@ -394,17 +395,14 @@ events_connect(events.QUIT, function() list[#list + 1] = buffer.filename or buffer._type or _L['Untitled'] end end - if #list > 0 and gui.dialog('msgbox', - '--title', _L['Quit without saving?'], - '--text', - _L['The following buffers are unsaved:'], - '--informative-text', table.concat(list, '\n'), - '--button1', 'gtk-cancel', - '--button2', _L['Quit _without saving'], - '--no-newline') ~= '2' then - return false - end - return true + return #list < 1 or gui.dialog('msgbox', + '--title', _L['Quit without saving?'], + '--text', + _L['The following buffers are unsaved:'], + '--informative-text', table.concat(list, '\n'), + '--button1', 'gtk-cancel', + '--button2', _L['Quit _without saving'], + '--no-newline') == '2' end) events_connect(events.ERROR, @@ -2,10 +2,8 @@ package.path = table.concat({ _USERHOME..'/?.lua', - _USERHOME..'/modules/?.lua', - _USERHOME..'/modules/?/init.lua', - _HOME..'/modules/?.lua', - _HOME..'/modules/?/init.lua', + _USERHOME..'/modules/?.lua', _USERHOME..'/modules/?/init.lua', + _HOME..'/modules/?.lua', _HOME..'/modules/?/init.lua', package.path }, ';'); diff --git a/modules/cpp/init.lua b/modules/cpp/init.lua index f0f1d117..e8c6201c 100644 --- a/modules/cpp/init.lua +++ b/modules/cpp/init.lua @@ -117,7 +117,7 @@ if type(snippets) == 'table' then lit = 'lua_istable(%1(lua), %2(-1))', lith = 'lua_isthread(%1(lua), %2(-1))', liu = 'lua_isuserdata(%1(lua), %2(-1))', - llen = 'lua_objlen(%1(lua), %2(-1))', + llen = 'lua_rawlen(%1(lua), %2(-1))', lpop = 'lua_pop(%1(lua), %2(1));', lpb = 'lua_pushboolean(%1(lua), %2(boolean));', lpcc = 'lua_pushcclosure(%1(lua), %2(closure_func), %3(num_values));', diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 2ac5a763..6907e6d7 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -302,25 +302,26 @@ events_connect(events.FILE_BEFORE_SAVE, M.prepare_for_save) -- @name transpose_chars function M.transpose_chars() local buffer = buffer - local pos = buffer.current_pos - if pos == buffer.length then return end - local c1, c2 = buffer.char_at[pos - 1], buffer.char_at[pos] - buffer:begin_undo_action() - buffer:delete_back() - buffer:insert_text((c2 == 10 or c2 == 13) and pos - 2 or pos, string.char(c1)) - buffer:end_undo_action() - buffer:goto_pos(pos) + local pos, c = buffer.current_pos, buffer.char_at[buffer.current_pos] + local eol = c == 10 or c == 13 or pos == buffer.length + if eol then pos = pos - 1 end + buffer.target_start, buffer.target_end = pos - 1, pos + 1 + buffer:replace_target(buffer:text_range(pos - 1, pos + 1):reverse()) + buffer:goto_pos(not eol and pos or pos + 1) end --- --- Joins the current line with the line below. +-- Joins the currently selected lines. +-- If no lines are selected, joins the current line with the line below. -- @name join_lines function M.join_lines() local buffer = buffer + buffer:target_from_selection() buffer:line_end() - local line = buffer:line_from_position(buffer.current_pos) - buffer.target_start = buffer.current_pos - buffer.target_end = buffer:position_from_line(line + 1) + local line = buffer:line_from_position(buffer.target_start) + if line == buffer:line_from_position(buffer.target_end) then + buffer.target_end = buffer:position_from_line(line + 1) + end buffer:lines_join() end @@ -333,14 +334,11 @@ end -- @name enclose function M.enclose(left, right) local buffer = buffer - buffer:begin_undo_action() - local txt = buffer:get_sel_text() - if txt == '' then - buffer:word_left_extend() - txt = buffer:get_sel_text() - end - buffer:replace_sel(left..txt..right) - buffer:end_undo_action() + buffer:target_from_selection() + local s, e = buffer.target_start, buffer.target_end + if s == e then buffer.target_start = buffer:word_start_position(s, true) end + buffer:replace_target(left..buffer:text_range(buffer.target_start, e)..right) + buffer:goto_pos(buffer.target_end) end --- @@ -374,8 +372,8 @@ end -- @name select_word function M.select_word(action) local buffer = buffer - buffer:set_sel(buffer:word_start_position(buffer.current_pos), - buffer:word_end_position(buffer.current_pos)) + buffer:set_sel(buffer:word_start_position(buffer.current_pos, true), + buffer:word_end_position(buffer.current_pos, true)) end --- @@ -469,10 +467,10 @@ function M.highlight_word() local buffer = buffer local s, e = buffer.selection_start, buffer.selection_end if s == e then - s, e = buffer:word_start_position(s), buffer:word_end_position(s) + s, e = buffer:word_start_position(s, true), buffer:word_end_position(s) end + if s == e then return end local word = buffer:text_range(s, e) - if word == '' then return end buffer.search_flags = _SCINTILLA.constants.SCFIND_WHOLEWORD + _SCINTILLA.constants.SCFIND_MATCHCASE buffer.target_start, buffer.target_end = 0, buffer.length diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index f07bdade..c847bba8 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -165,12 +165,10 @@ local function find_(text, next, flags, nowrap, wrapped) local buffer_text = buffer:get_text(buffer.length) local results = { buffer_text:find(text, buffer.anchor + increment + 1) } if #results > 0 then - result = results[1] find.captures = { table.unpack(results, 3) } - buffer:set_sel(results[2], result - 1) - else - result = -1 + buffer:set_sel(results[2], results[1] - 1) end + result = results[1] or -1 else -- find in files find.find_in_files() return @@ -221,11 +219,10 @@ events_connect(events.COMMAND_ENTRY_KEYPRESS, function(code) if keys.KEYSYMS[code] == 'esc' then find.incremental = nil elseif code < 256 or keys.KEYSYMS[code] == '\b' then - local text = gui.command_entry.entry_text if keys.KEYSYMS[code] == '\b' then - find_incremental(text:sub(1, -2)) + find_incremental(gui.command_entry.entry_text:sub(1, -2)) else - find_incremental(text..string.char(code)) + find_incremental(gui.command_entry.entry_text..string.char(code)) end end end diff --git a/themes/dark/lexer.lua b/themes/dark/lexer.lua index da02a6ab..c752ffc3 100644 --- a/themes/dark/lexer.lua +++ b/themes/dark/lexer.lua @@ -87,10 +87,8 @@ elseif OSX then font_size = 12 end l.style_default = style { - font = font_face, - size = font_size, - fore = l.colors.light_grey, - back = l.colors.black + font = font_face, size = font_size, + fore = l.colors.light_grey, back = l.colors.black } l.style_line_number = style { fore = l.colors.dark_grey, back = l.colors.black } l.style_bracelight = style { fore = l.colors.light_blue } diff --git a/themes/light/lexer.lua b/themes/light/lexer.lua index 4a8eb897..aa7fe003 100644 --- a/themes/light/lexer.lua +++ b/themes/light/lexer.lua @@ -86,10 +86,8 @@ elseif OSX then font_size = 12 end l.style_default = style { - font = font_face, - size = font_size, - fore = l.colors.light_black, - back = l.colors.white + font = font_face, size = font_size, + fore = l.colors.light_black, back = l.colors.white } l.style_line_number = style { fore = l.colors.grey, back = l.colors.white } l.style_bracelight = style { fore = l.colors.light_blue } |