diff options
author | 2015-10-22 13:39:47 -0400 | |
---|---|---|
committer | 2015-10-22 13:39:47 -0400 | |
commit | 9ab96d83b72e058d66a6eb2b109cea574d87e031 (patch) | |
tree | c392c70a9db56c6a46c240bc75e85bf1d7026b2d /modules/lua/init.lua | |
parent | 5caed0d5331c823ad74d2c443b9e0f8702349520 (diff) |
Refactored 'ansi_c' and 'lua' modules' snippets.
Also removed command for auto-'end' insertion of Lua control structures since
snippets are now favored.
Diffstat (limited to 'modules/lua/init.lua')
-rw-r--r-- | modules/lua/init.lua | 58 |
1 files changed, 10 insertions, 48 deletions
diff --git a/modules/lua/init.lua b/modules/lua/init.lua index 095aec79..5d110ccc 100644 --- a/modules/lua/init.lua +++ b/modules/lua/init.lua @@ -6,12 +6,6 @@ local M = {} --- -- The lua module. -- It provides utilities for editing Lua code. --- --- ## Key Bindings --- --- + `Shift+Enter` (`⇧↩` | `S-Enter`) --- Autocomplete an `if`, `while`, `for`, etc. control structure with the `end` --- keyword. module('_M.lua')]] -- Autocompletion and documentation. @@ -81,47 +75,10 @@ textadept.editing.api_files.lua = { -- Commands. --- --- List of patterns for auto-`end` completion for control structures. --- @class table --- @name control_structure_patterns --- @see try_to_autocomplete_end -local control_structure_patterns = { - '^%s*for', '^%s*function', '^%s*if', '^%s*repeat', '^%s*while', - 'function%s*%b()%s*$', '^%s*local%s*function' -} - ---- --- Tries to autocomplete control structures like `if`, `while`, `for`, etc. with --- the `end` keyword. --- @name try_to_autocomplete_end --- @see control_structure_patterns -function M.try_to_autocomplete_end() - local line_num = buffer:line_from_position(buffer.current_pos) - local line = buffer:get_line(line_num) - for _, patt in ipairs(control_structure_patterns) do - if line:find(patt) then - local indent = buffer.line_indentation[line_num] - buffer:begin_undo_action() - buffer:new_line() - buffer:new_line() - buffer:add_text(patt:find('repeat') and 'until' or 'end') - buffer.line_indentation[line_num + 1] = indent + buffer.tab_width - buffer:line_up() - buffer:line_end() - buffer:end_undo_action() - return true - end - end - return false -end - ---- -- Container for Lua-specific key bindings. -- @class table -- @name _G.keys.lua -keys.lua = { - ['s\n'] = M.try_to_autocomplete_end, -} +keys.lua = {} -- Snippets. @@ -131,10 +88,15 @@ if type(snippets) == 'table' then -- @class table -- @name _G.snippets.lua snippets.lua = { - f = "function %1(name)(%2(args))\n\t%0\nend", - ['for'] = "for %1(i) = %2(1), %3(10)%4(, %5(-1)) do\n\t%0\nend", - fori = "for %1(i), %2(v) in ipairs(%3(t)) do\n\t%0\nend", - forp = "for %1(k), %2(v) in pairs(%3(t)) do\n\t%0\nend" + func = 'function %1(name)(%2(args))\n\t%0\nend', + ['if'] = 'if %1 then\n\t%0\nend', + eif = 'elseif %1 then\n\t', + ['for'] = 'for %1(i) = %2(1), %3(10)%4(, %5(-1)) do\n\t%0\nend', + forp = 'for %1(k), %2(v) in pairs(%3(t)) do\n\t%0\nend', + fori = 'for %1(i), %2(v) in ipairs(%3(t)) do\n\t%0\nend', + ['while'] = 'while %1 do\n\t%0\nend', + ['repeat'] = 'repeat\n\t%0\nuntil %1', + ['do'] = 'do\n\t%0\nend', } end |