diff options
author | mitchell <70453897+667e-11@users.noreply.github.com> | 2014-05-24 12:09:44 -0400 |
---|---|---|
committer | mitchell <70453897+667e-11@users.noreply.github.com> | 2014-05-24 12:09:44 -0400 |
commit | 68147393527efc2364e821a3979d853aac0e5940 (patch) | |
tree | b480658fc9ed2b9cec09564c6e44457fceff8dc3 /modules/ansi_c/init.lua | |
parent | 0e201469a0913267011ce59ff12eb46c3be56a2f (diff) |
Removed Adeptsense in favor of new framework committed in r1735.
Replaced ANSI C and Lua module Adeptsenses with their equivalent autocompleter
functions.
Diffstat (limited to 'modules/ansi_c/init.lua')
-rw-r--r-- | modules/ansi_c/init.lua | 208 |
1 files changed, 120 insertions, 88 deletions
diff --git a/modules/ansi_c/init.lua b/modules/ansi_c/init.lua index 725dd3be..a6173bb8 100644 --- a/modules/ansi_c/init.lua +++ b/modules/ansi_c/init.lua @@ -11,44 +11,65 @@ local M = {} -- -- + `Ctrl+L, M` (`⌘L, M` on Mac OSX | `M-L, M` in curses) -- Open this module for editing. --- + `.` --- Show an autocompletion list of members for the symbol behind the caret. --- + `->` --- Show an autocompletion list of members for the symbol behind the caret. -- + `Shift+Enter` (`⇧↩` | `S-Enter`) -- Add ';' to the end of the current line and insert a newline. --- @field sense --- The C [Adeptsense](textadept.adeptsense.html). --- It loads user tags from *`_USERHOME`/modules/ansi_c/tags* and user apidocs --- from *`_USERHOME`/modules/ansi_c/api*. module('_M.ansi_c')]] --- Adeptsense. +-- Autocompletion and documentation. -M.sense = textadept.adeptsense.new('ansi_c') -local as = textadept.adeptsense -M.sense.ctags_kinds = { - c = as.CLASS, d = as.FUNCTION, e = as.FIELD, f = as.FUNCTION, g = as.CLASS, - m = as.FIELD, s = as.CLASS, t = as.CLASS -} -M.sense:load_ctags(_HOME..'/modules/ansi_c/tags', true) -M.sense.api_files = { - _HOME..'/modules/ansi_c/api', _HOME..'/modules/ansi_c/lua_api' -} -M.sense.syntax.type_declarations = { - '([%w_%.]+)[%s%*&]+%_[^%w_]', -- Foo bar, Foo *bar, Foo* bar, Foo &bar, etc. -} -M.sense:add_trigger('.') -M.sense:add_trigger('->') +--- +-- List of ctags files to use for autocompletion. +-- @class table +-- @name tags +-- @see textadept.editing.autocomplete +M.tags = {_HOME..'/modules/ansi_c/tags', _USERHOME..'/modules/ansi_c/tags'} --- Load user tags and apidoc. -if lfs.attributes(_USERHOME..'/modules/ansi_c/tags') then - M.sense:load_ctags(_USERHOME..'/modules/ansi_c/tags') -end -if lfs.attributes(_USERHOME..'/modules/ansi_c/api') then - M.sense.api_files[#M.sense.api_files + 1] = _USERHOME..'/modules/ansi_c/api' +local XPM = textadept.editing.XPM_IMAGES +local xpms = setmetatable({ + c = XPM.CLASS, d = XPM.SLOT, e = XPM.VARIABLE, f = XPM.METHOD, + g = XPM.TYPEDEF, m = XPM.VARIABLE, s = XPM.STRUCT, t = XPM.TYPEDEF, + v = XPM.VARIABLE +}, {__index = function(t, k) return 0 end}) + +textadept.editing.autocompleters.ansi_c = function() + local list = {} + -- Retrieve the symbol behind the caret. + local line, pos = buffer:get_cur_line() + local symbol, op, part = line:sub(1, pos):match('([%w_]-)([%.%->]*)([%w_]*)$') + if symbol == '' and part == '' and op ~= '' then return nil end -- lone ., -> + if op ~= '' and op ~= '.' and op ~= '->' then return nil end + -- Attempt to identify the symbol type. + local buffer = buffer + local declaration = '([%w_]+)[%s%*&]+'..symbol:gsub('(%p)', '%%%1')..'[^%w_]' + for i = buffer:line_from_position(buffer.current_pos) - 1, 0, -1 do + local class = buffer:get_line(i):match(declaration) + if class then symbol = class break end + end + -- Search through ctags for completions for that symbol. + local name_patt = '^'..part + for i = 1, #M.tags do + if lfs.attributes(M.tags[i]) then + for line in io.lines(M.tags[i]) do + local name = line:match('^%S+') + if name:find(name_patt) and not name:find('^!') and not list[name] then + local fields = line:match(';"\t(.*)$') + if (fields:match('class:(%S+)') or fields:match('enum:(%S+)') or + fields:match('struct:(%S+)') or fields:match('typedef:(%S+)') or + '') == symbol then + list[#list + 1] = ("%s?%d"):format(name, xpms[fields:sub(1, 1)]) + list[name] = true + end + end + end + end + end + return #part, list end +textadept.editing.api_files.ansi_c = { + _HOME..'/modules/ansi_c/api', _USERHOME..'/modules/ansi_c/api' +} + -- Commands. --- @@ -75,64 +96,75 @@ keys.ansi_c = { if type(snippets) == 'table' then snippets.ansi_c = { -- Lua snippets - lf = 'static int %1(function)(lua_State *%2(lua)) {\n\t%0\n\treturn 0;\n}', - ls = 'lua_State', - lgf = 'lua_getfield(%1(lua), %2(-1), %3(field));', - lgg = 'lua_getglobal(%1(lua), %2(global));', - lgt = 'lua_gettable(%1(lua), %2(-2));', - ltop = 'lua_gettop(%1(lua));', - lib = 'lua_isboolean(%1(lua), %2(-1))', - licf = 'lua_iscfunction(%1(lua), %2(-1))', - lif = 'lua_isfunctionu(%1(lua), %2(-1))', - linil = 'lua_isnil(%1(lua), %2(-1))', - linone = 'lua_isnone(%1(lua), %2(-1))', - linonen = 'lua_isnoneornil(%1(lua), %2(-1))', - lin = 'lua_isnumber(%1(lua), %2(-1))', - lis = 'lua_isstring(%1(lua), %2(-1))', - lit = 'lua_istable(%1(lua), %2(-1))', - lith = 'lua_isthread(%1(lua), %2(-1))', - liu = 'lua_isuserdata(%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));', - lpcf = 'lua_pushcfunction(%1(lua), %2(cfunction));', - lpi = 'lua_pushinteger(%1(lua), %2(integer));', - lplu = 'lua_pushlightuserdata(%1(lua), %2(userdata));', - lpnil = 'lua_pushnil(%1(lua));', - lpn = 'lua_pushnumber(%1(lua), %2(number));', - lps = 'lua_pushstring(%1(lua), %2(string));', - lpth = 'lua_pushthread(%1(lua));', - lpv = 'lua_pushvalue(%1(lua), %2(-1));', - lrg = 'lua_rawget(%1(lua), %2(-2));', - lrgi = 'lua_rawgeti(%1(lua), %2(-2), %3(1));', - lrs = 'lua_rawset(%1(lua), %2(-3));', - lrsi = 'lua_rawseti(%1(lua), %2(-2), %3(1));', - lr = 'lua_register(%1(lua), %2(fname), %3(cfunction));', - lsf = 'lua_setfield(%1(lua), %2(-2), %3(field));', - lsg = 'lua_setglobal(%1(lua), %2(global));', - lst = 'lua_settable(%1(lua), %2(-3));', - ltb = 'lua_toboolean(%1(lua), %2(-1))', - ltcf = 'lua_tocfunction(%1(lua), %2(-1))', - lti = 'lua_tointeger(%1(lua), %2(-1))', - ltn = 'lua_tonumber(%1(lua), %2(-1))', - ltp = 'lua_topointer(%1(lua), %2(-1))', - lts = 'lua_tostring(%1(lua), %2(-1))', - ltth = 'lua_tothread(%1(lua), %2(-1))', - ltu = 'lua_touserdata(%1(lua), %2(-1))', - lt = 'lua_type(%1(lua), %2(-1))', - llcint = 'luaL_checkint(%1(lua), %2(-1))', - llci = 'luaL_checkinteger(%1(lua), %2(-1))', - llcl = 'luaL_checklong(%1(lua), %2(-1))', - llcn = 'luaL_checknumber(%1(lua), %2(-1))', - llcs = 'luaL_checkstring(%1(lua), %2(-1))', - llcu = 'luaL_checkudata(%1(lua), %2(-1), %3(mt_name))', - llerr = 'luaL_error(%1(lua), %2(errorstring)%3(, %4(arg)));', - lloint = 'luaL_optint(%1(lua), %2(-1), %3(default))', - lloi = 'luaL_optinteger(%1(lua), %2(-1), %3(default))', - llol = 'luaL_optlong(%1(lua), %2(-1), %3(default))', - llon = 'luaL_optnumber(%1(lua), %2(-1), %3(default))', - llos = 'luaL_optstring(%1(lua), %2(-1), %3(default))', + 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))', } end |