aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/ansi_c
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-02-18 15:58:16 -0500
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-02-18 15:58:16 -0500
commit2a9d3e73daa332ffe652c9b33c160b784e51ed0e (patch)
treee7d0f0dc75319c674711771bfc41213a5dac8370 /modules/ansi_c
parentd5ba0b9a714cfc265f69d3d03974cfbfa0281176 (diff)
Added snippet trigger word completion.
Also refactored snippet lookup, added options to Lua and C modules to include snippet triggers in autocompletion lists, swapped snippet keybindings, and fixed a bug recognizing lexer-specific snippet files as global.
Diffstat (limited to 'modules/ansi_c')
-rw-r--r--modules/ansi_c/init.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/ansi_c/init.lua b/modules/ansi_c/init.lua
index 5d2f85ce..d4f9bf7d 100644
--- a/modules/ansi_c/init.lua
+++ b/modules/ansi_c/init.lua
@@ -6,6 +6,9 @@ local M = {}
---
-- The ansi_c module.
-- It provides utilities for editing C code.
+-- @field autocomplete_snippets (boolean)
+-- Whether or not to include snippets in autocompletion lists.
+-- The default value is `true`.
module('_M.ansi_c')]]
-- Autocompletion and documentation.
@@ -20,6 +23,8 @@ M.tags = {
_USERHOME..'/modules/ansi_c/tags'
}
+M.autocomplete_snippets = true
+
local XPM = textadept.editing.XPM_IMAGES
local xpms = setmetatable({
c = XPM.CLASS, d = XPM.SLOT, e = XPM.VARIABLE, f = XPM.METHOD,
@@ -36,7 +41,7 @@ textadept.editing.autocompleters.ansi_c = function()
-- Attempt to identify the symbol type.
if symbol ~= '' then
local buffer = buffer
- local decl = '([%w_]+)[%s%*&]+'..symbol:gsub('(%p)', '%%%1')..'[^%w_]'
+ local decl = '([%w_]+)[%s%*&]+'..symbol:gsub('%p', '%%%0')..'[^%w_]'
for i = buffer:line_from_position(buffer.current_pos) - 1, 0, -1 do
local class = buffer:get_line(i):match(decl)
if class then symbol = class break end
@@ -73,6 +78,10 @@ textadept.editing.autocompleters.ansi_c = function()
end
end
end
+ if symbol == '' and M.autocomplete_snippets then
+ local _, snippets = textadept.editing.autocompleters.snippet()
+ for i = 1, #snippets do list[#list + 1] = snippets[i] end
+ end
return #part, list
end