aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2012-03-14 09:26:13 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2012-03-14 09:26:13 -0400
commitb100458019694d9bbaf50d2eec9693c34befc3e7 (patch)
treea0d65b41f4d4dd8b57f4ae10f8c32f23a019b97a
parentee14e28a914c889a9987d7880530c2d7553ead72 (diff)
downloadtextadept-b100458019694d9bbaf50d2eec9693c34befc3e7.tar.gz
textadept-b100458019694d9bbaf50d2eec9693c34befc3e7.zip
autocomplete_word() accepts default words; modules/textadept/editing.lua
From Brian Schott.
-rw-r--r--modules/textadept/editing.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 1a9f5f51..5ca59989 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -179,15 +179,22 @@ end
-- Pops up an autocompletion list for the current word based on other words in
-- the document.
-- @param word_chars String of chars considered to be part of words.
+-- @param default_words Optional list of words considered to be in the document,
+-- even if they are not. Words may contain registered images.
-- @return `true` if there were completions to show; `false` otherwise.
-- @name autocomplete_word
-function M.autocomplete_word(word_chars)
+function M.autocomplete_word(word_chars, default_words)
local buffer = buffer
local caret, length = buffer.current_pos, buffer.length
local completions, c_list = {}, {}
local buffer_text = buffer:get_text(buffer.length)
local root = buffer_text:sub(1, caret):match('['..word_chars..']+$')
if not root or root == '' then return end
+ for _, word in ipairs(default_words or {}) do
+ if word:match('^'..root) then
+ c_list[#c_list + 1], completions[word:match('^(.-)%??%d*$')] = word, true
+ end
+ end
local patt = '^['..word_chars..']+'
buffer.target_start, buffer.target_end = 0, buffer.length
buffer.search_flags = _SCINTILLA.constants.SCFIND_WORDSTART
@@ -216,7 +223,8 @@ function M.autocomplete_word(word_chars)
else
-- Scintilla does not emit AUTO_C_SELECTION in this case. This is
-- necessary for autocompletion with multiple selections.
- events.emit(events.AUTO_C_SELECTION, c_list[1], caret - #root)
+ local text = c_list[1]:match('^(.-)%??%d*$')
+ events.emit(events.AUTO_C_SELECTION, text, caret - #root)
end
return true
end