diff options
author | 2012-01-05 10:24:51 -0500 | |
---|---|---|
committer | 2012-01-05 10:24:51 -0500 | |
commit | 7cf43c7dd653ef28c2212975f81b14be6473e06f (patch) | |
tree | 251c33430f492d8780ab22cd69a9abe0af02f0c3 /modules | |
parent | bd351f0bef198d981b67830ddb5e4cd42c3aca37 (diff) | |
download | textadept-7cf43c7dd653ef28c2212975f81b14be6473e06f.tar.gz textadept-7cf43c7dd653ef28c2212975f81b14be6473e06f.zip |
Code cleanup.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/cpp/init.lua | 2 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 46 | ||||
-rw-r--r-- | modules/textadept/find.lua | 11 |
3 files changed, 27 insertions, 32 deletions
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 |