diff options
Diffstat (limited to 'modules/textadept')
-rw-r--r-- | modules/textadept/editing.lua | 47 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 14 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 3 |
3 files changed, 18 insertions, 46 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index b9f00382..839b70e8 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -19,11 +19,14 @@ module('_m.textadept.editing', package.seeall) -- * `AUTOINDENT`: Flag indicating whether or not when the enter key is pressed, -- the inserted line has is indented to match the level of indentation of the -- previous line. +-- * `SAVE_STRIPS_WS`: Flag indicating whether or not to strip trailing +-- whitespace on file save. -- settings AUTOPAIR = true HIGHLIGHT_BRACES = true AUTOINDENT = true +SAVE_STRIPS_WS = true -- end settings --- @@ -96,8 +99,9 @@ events.connect('keypress', events.connect('update_ui', function() -- highlights matching braces local buffer = buffer + if not HIGHLIGHT_BRACES then return end local current_pos = buffer.current_pos - if HIGHLIGHT_BRACES and braces[buffer.char_at[current_pos]] and + if braces[buffer.char_at[current_pos]] and buffer:get_style_name(buffer.style_at[current_pos]) == 'operator' then local pos = buffer:brace_match(current_pos) if pos ~= -1 then @@ -245,6 +249,7 @@ end -- converts non-consistent EOLs. function prepare_for_save() local buffer = buffer + if not SAVE_STRIPS_WS then return end buffer:begin_undo_action() -- Strip trailing whitespace. local lines = buffer.line_count @@ -275,20 +280,6 @@ end events.connect('file_before_save', prepare_for_save) --- --- Cuts or copies text ranges intelligently. (Behaves like Emacs.) --- If no text is selected, all text from the cursor to the end of the line is --- cut or copied as indicated by action. If there is text selected, it is cut or --- copied. --- @param copy If false, the text is cut. Otherwise it is copied. -function smart_cutcopy(copy) - local buffer = buffer - local txt = buffer:get_sel_text() - if #txt == 0 then buffer:line_end_extend() end - txt = buffer:get_sel_text() - if copy then buffer:copy() else buffer:cut() end -end - ---- -- Selects the current word under the caret and if action indicates, deletes it. -- @param action Optional action to perform with selected word. If 'delete', it -- is deleted. @@ -322,30 +313,14 @@ function transpose_chars() end --- --- Reduces multiple characters occurances to just one. --- If char is not given, the character to be squeezed is the one behind the --- caret. --- @param char The character (integer) to be used for squeezing. -function squeeze(char) - local buffer = buffer - if not char then char = buffer.char_at[buffer.current_pos - 1] end - local s, e = buffer.current_pos - 1, buffer.current_pos - 1 - while buffer.char_at[s] == char do s = s - 1 end - while buffer.char_at[e] == char do e = e + 1 end - buffer:set_sel(s + 1, e) - buffer:replace_sel(string.char(char)) -end - ---- -- Joins the current line with the line below, eliminating whitespace. function join_lines() local buffer = buffer - buffer:begin_undo_action() buffer:line_end() - buffer:clear() - buffer:add_text(' ') - squeeze() - buffer:end_undo_action() + local line = buffer:line_from_position(buffer.current_pos) + buffer.target_start = buffer.current_pos + buffer.target_end = buffer:position_from_line(line + 1) + buffer:lines_join() end --- @@ -454,7 +429,7 @@ function select_indented_block() 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 -- don't run while loops + indent = indent + buffer.indent -- do not run while loops end end while buffer.line_indentation[s - 1] > indent do s = s - 1 end diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 87c82a28..9a38c709 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -179,10 +179,7 @@ if not MAC then keys.cq = { m_editing.block_comment } -- TODO: { m_editing.current_word, 'delete' } -- TODO: { m_editing.transpose_chars } - -- TODO: { m_editing.squeeze } -- TODO: { m_editing.convert_indentation } - -- TODO: { m_editing.smart_cutcopy } - -- TODO: { m_editing.smart_cutcopy, 'copy' } keys.ac = { -- enClose in... t = { m_editing.enclose, 'tag' }, T = { m_editing.enclose, 'single_tag' }, @@ -335,11 +332,7 @@ else keys.cq = { m_editing.block_comment } -- TODO: { m_editing.current_word, 'delete' } keys.ct = { m_editing.transpose_chars } - -- TODO: { m_editing.squeeze } -- TODO: { m_editing.convert_indentation } - keys.ck = { m_editing.smart_cutcopy } - -- TODO: { m_editing.smart_cutcopy, 'copy' } - keys.cy = { 'paste', b } keys.cc = { -- enClose in... t = { m_editing.enclose, 'tag' }, T = { m_editing.enclose, 'single_tag' }, @@ -474,6 +467,13 @@ else keys.cah = { 'del_word_left', b } keys.cd = { 'clear', b } keys.cad = { 'del_word_right', b } + keys.ck = { + function() + buffer:line_end_extend() + buffer:cut() + end + } + keys.cy = { 'paste', b } end --- diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 589c3205..f014d8c2 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -39,7 +39,6 @@ local ID = { COMPLETE_WORD = 210, DELETE_WORD = 211, TRANSPOSE_CHARACTERS = 212, - SQUEEZE = 213, JOIN_LINES = 245, CONVERT_INDENTATION = 216, ENCLOSE_IN_HTML_TAGS = 224, @@ -164,7 +163,6 @@ local menubar = { { l.MENU_EDIT_COMPLETE_WORD, ID.COMPLETE_WORD }, { l.MENU_EDIT_DELETE_WORD, ID.DELETE_WORD }, { l.MENU_EDIT_TRANSPOSE_CHARACTERS, ID.TRANSPOSE_CHARACTERS }, - { l.MENU_EDIT_SQUEEZE, ID.SQUEEZE }, { l.MENU_EDIT_JOIN_LINES, ID.JOIN_LINES }, { l.MENU_EDIT_CONVERT_INDENTATION, ID.CONVERT_INDENTATION }, { title = l.MENU_EDIT_SEL_TITLE, @@ -387,7 +385,6 @@ local actions = { [ID.COMPLETE_WORD] = { m_editing.autocomplete_word, '%w_' }, [ID.DELETE_WORD] = { m_editing.current_word, 'delete' }, [ID.TRANSPOSE_CHARACTERS] = { m_editing.transpose_chars }, - [ID.SQUEEZE] = { m_editing.squeeze }, [ID.JOIN_LINES] = { m_editing.join_lines }, [ID.CONVERT_INDENTATION] = { m_editing.convert_indentation }, -- Edit -> Selection -> Enclose in... |