diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ansi_c/init.lua | 96 | ||||
-rw-r--r-- | modules/lua/init.lua | 58 |
2 files changed, 35 insertions, 119 deletions
diff --git a/modules/ansi_c/init.lua b/modules/ansi_c/init.lua index 50b3880f..2a0b793d 100644 --- a/modules/ansi_c/init.lua +++ b/modules/ansi_c/init.lua @@ -102,82 +102,36 @@ keys.ansi_c = { -- Snippets. +if type(snippets) == 'table' then --- -- Table of C-specific snippets. -- @class table -- @name _G.snippets.ansi_c -if type(snippets) == 'table' then snippets.ansi_c = { - -- Lua snippets - lc = 'lua_call(%1(L), %2(nargs), %3(nresults))', - lcs = 'lua_checkstack(%1(L), %2(1))', - lf = 'static int %1(func)(lua_State *%2(L)) {\n\t%0\n\treturn %3(0);\n}', - lgf = 'lua_getfield(%1(L), %2(-1), %3(field))', - lgg = 'lua_getglobal(%1(L), %2(global))', - lgmt = 'lua_getmetatable(%1(L), %2(-1))', - lgt = 'lua_gettable(%1(L), %2(-2))', - ltop = 'lua_gettop(%1(L))', - lib = 'lua_isboolean(%1(L), %2(-1))', - licf = 'lua_iscfunction(%1(L), %2(-1))', - lif = 'lua_isfunction(%1(L), %2(-1))', - lilu = 'lua_islightuserdata(%1(L), %2(-1))', - linil = 'lua_isnil(%1(L), %2(-1))', - linone = 'lua_isnone(%1(L), %2(-1))', - linonen = 'lua_isnoneornil(%1(L), %2(-1))', - lin = 'lua_isnumber(%1(L), %2(-1))', - lis = 'lua_isstring(%1(L), %2(-1))', - lit = 'lua_istable(%1(L), %2(-1))', - liu = 'lua_isuserdata(%1(L), %2(-1))', - llen = 'lua_len(%1(L), %2(-1))', - lrlen = 'lua_rawlen(%1(L), %2(-1))', - lnt = 'lua_newtable(%1(L))', - lnu = '(%3 *)lua_newuserdata(%1(L), %2(sizeof(%3(struct))))', - ln = 'lua_next(%1(L), %2(-2))', - lpc = 'lua_pcall(%1(L), %2(nargs), %3(nresults), %4(msgh))', - lpop = 'lua_pop(%1(L), %2(1))', - lpb = 'lua_pushboolean(%1(L), %2(bool))', - lpcc = 'lua_pushcclosure(%1(L), %2(cfunc), %3(nvalues))', - lpcf = 'lua_pushcfunction(%1(L), %2(cfunc))', - lpi = 'lua_pushinteger(%1(L), %2(integer))', - lplu = 'lua_pushlightuserdata(%1(L), %2(pointer))', - lpnil = 'lua_pushnil(%1(L))', - lpn = 'lua_pushnumber(%1(L), %2(number))', - lps = 'lua_pushstring(%1(L), %2(string))', - lpls = 'lua_pushlstring(%1(L), %2(string), %3(len))', - lpv = 'lua_pushvalue(%1(L), %2(-1))', - lrg = 'lua_rawget(%1(L), %2(-2))', - lrgi = 'lua_rawgeti(%1(L), %2(-2), %3(1))', - lrs = 'lua_rawset(%1(L), %2(-3))', - lrsi = 'lua_rawseti(%1(L), %2(-2), %3(1))', - lr = 'lua_register(%1(L), %2(name), %3(cfunc))', - lsf = 'lua_setfield(%1(L), %2(-2), %3(field))', - lsg = 'lua_setglobal(%1(L), %2(global))', - lsmt = 'lua_setmetatable(%1(L), %2(-2))', - lst = 'lua_settable(%1(L), %2(-3))', - ltb = 'lua_toboolean(%1(L), %2(-1))', - lti = 'lua_tointeger(%1(L), %2(-1))', - ltn = 'lua_tonumber(%1(L), %2(-1))', - ltls = 'lua_tolstring(%1(L), %2(-1), &%3(int))', - lts = 'lua_tostring(%1(L), %2(-1))', - ltu = '(%3 *)lua_touserdata(%1(L), %2(-1))', - lt = 'lua_type(%1(L), %2(-1))', - llac = 'luaL_argcheck(%1(L), %2(expr), %3(1), %4(extramsg))', - llci = 'luaL_checkinteger(%1(L), %2(1))', - llcl = 'luaL_checklong(%1(L), %2(1))', - llcls = 'luaL_checklstring(%1(L), %2(1), &%3(int))', - llcn = 'luaL_checknumber(%1(L), %2(1))', - llcs = 'luaL_checkstring(%1(L), %2(1))', - llcu = '(%4 *)luaL_checkudata(%1(L), %2(1), %3(mt_name))', - llerr = 'luaL_error(%1(L), %2(message)%3(, %4(arg)))', - llgmt = 'luaL_getmetatable(%1(L), %2(mt_name))', - llnmt = 'luaL_newmetatable(%1(L), %2(mt_name))', - lloi = 'luaL_optinteger(%1(L), %2(1), %3(default))', - llol = 'luaL_optlong(%1(L), %2(1), %3(default))', - llon = 'luaL_optnumber(%1(L), %2(1), %3(default))', - llos = 'luaL_optstring(%1(L), %2(1), %3(default))', - llref = 'luaL_ref(%1(L), %2(LUA_REGISTRYINDEX))', - llsmt = 'luaL_setmetatable(%1(L), %2(mt_name))', - lluref = 'luaL_unref(%1(L), %2(LUA_REGISTRYINDEX), %3(ref))', + func = '%1(int) %2(name)(%3(args)) {\n\t%0\n\treturn %4(0);\n}', + vfunc = 'void %1(name)(%2(args)) {\n\t%0\n}', + ['if'] = 'if (%1) {\n\t%0\n}', + eif = 'else if (%1) {\n\t%0\n}', + ['else'] = 'else {\n\t%0\n}', + ['for'] = 'for (%1; %2; %3) {\n\t%0\n}', + ['fori'] = 'for (%1(int) %2(i) = %3(0); %2 %4(<) %5(count); %2%6(++)) {\n'.. + '\t%0\n}', + ['while'] = 'while (%1) {\n\t%0\n}', + ['do'] = 'do {\n\t%0\n} while (%1);', + sw = 'switch (%1) {\n\tcase %2:\n\t\t%0\n\t\tbreak;\n}', + case = 'case %1:\n\t%0\n\tbreak;', + + st = 'struct %1(name) {\n\t%0\n};', + td = 'typedef %1(int) %2(name_t);', + tds = 'typedef struct %1(name) {\n\t%0\n} %1%2(_t);', + + def = '#define %1(name) %2(value)', + inc = '#include "%1"', + Inc = '#include <%1>', + pif = '#if %1\n%0\n#endif', + + main = 'int main(int argc, const char **argv) {\n\t%0\n\treturn 0;\n}', + printf = 'printf("%1(%s)\\n", %2);', } end 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 |