Scite 自動完成任何語言 |
|
識別碼包括的內容由 IDENTIFIER_PATTERNS 中的樣式清單決定。這個範例允許識別碼中包含點號(例如建議整個「object.member.property」字串)和破折號(例如「lisp-or-css-identifier」)。
如果您在 SciTE 屬性中啟用自動完成,這個腳本可能無法正常運作。(應該可以直接針對某些檔案類型停用它。)
-- Dynamically generate autocomplete lists from possible identifiers in any file. local IGNORE_CASE = true -- Number of chars to type before the autocomplete list appears: local MIN_PREFIX_LEN = 3 -- Length of shortest word to add to the autocomplete list local MIN_IDENTIFIER_LEN = 6 -- A list of string patterns for finding suggestions for the autocomplete menu. local IDENTIFIER_PATTERNS = {"[%a_][%w_]+", "[%a_][%w_.]*[%w_]", "[%a_][%w_-]*[%w_]"} local names = {} local notempty = next if IGNORE_CASE then normalize = string.lower else normalize = function(word) return word end end function buildNames() names = {} local text = editor:GetText() for i, pattern in ipairs(IDENTIFIER_PATTERNS) do for word in string.gmatch(text, pattern) do if string.len(word) >= MIN_IDENTIFIER_LEN then names[word] = true end end end end function handleChar() if not editor:AutoCActive() then editor.AutoCIgnoreCase = IGNORE_CASE local pos = editor.CurrentPos local startPos = editor:WordStartPosition(pos, true) local len = pos - startPos if len >= MIN_PREFIX_LEN then local prefix = editor:textrange(startPos, pos) local menuItems = {} for name, v in pairs(names) do if normalize(string.sub(name, 1, len)) == normalize(prefix) then table.insert(menuItems, name) end end if notempty(menuItems) then table.sort(menuItems) editor:AutoCShow(len, table.concat(menuItems, " ")) end end end end -- Event handlers OnChar = handleChar OnSave = buildNames OnSwitchFile = buildNames OnOpen = buildNamesMartinStone?
很不幸地,如果關鍵字中包含像「.」這樣的字元,AutoCShow() 函式似乎無法運作...