From 2a9d3e73daa332ffe652c9b33c160b784e51ed0e Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Tue, 18 Feb 2020 15:58:16 -0500 Subject: 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. --- modules/ansi_c/init.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'modules/ansi_c') 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 -- cgit v1.2.3