yumaxg
Newbie | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору добавить в функцию обработки собития добавления символа function OnChar(charAdded) такое: --............................................... ls = editor.StyleAt[editor.CurrentPos-2] -- тут нюансик из editor.StyleAt[editor.CurrentPos-2] для оптимізації робить лише для ідентифікаторів -- 11 - для Луа для інших може бути інші ідентифікатори if ls == 11 and charAdded == " " then Abbreviations() --see below end --............................................... end --=================================================================================== -- Expand abbreviations and show tooltip when appropriated. by Jos van der Zande (JdeB) -- changed yumax#301170722 function Abbreviations() -- get current word from = editor:WordStartPosition(editor.CurrentPos-2) to = editor:WordEndPosition(editor.CurrentPos-2) curword = editor:textrange(from, to) if string.sub(curword,1,1) == ' ' and string.sub(curword,2,2) == ' ' then curword = string.sub(curword,3,-1) from = from - 2; end -- print(from..' '..to..'-'..curword..'-'..editor.CurrentPos) -- get possible replacement from abbrev.properties local repword = "" ext = props['FileExt'] abbrev_file = props['abbrev.$(file.patterns.'..ext..')']; -- print(abbrev_file) local f = io.open(abbrev_file) if f ~= nil then local Abbrevtxt = f:read('*a') if Abbrevtxt then f:close() local rep_start = string.find(Abbrevtxt,"\n" .. string.lower(curword) .. "=") -- print('-'..Abbrevtxt..'-'..curword..'-',rep_start,"-\n" .. string.lower(curword)..'-') if rep_start ~= nil and rep_start ~= 0 then rep_start = rep_start + string.len(curword) + 2 rep_end = string.find(Abbrevtxt .. "\n","\n",rep_start)-1 repword = string.sub(Abbrevtxt .. "\n",rep_start,rep_end) -- _ALERT("rep_start:" ..rep_start.. "rep_end:"..rep_end ) end end end -- if found process it -- _ALERT("abbr:" .. curword .. " replaced by: " .. repword .. "|" ) if repword ~= nil and repword ~= "" then -- get indent info local s_indent = "" if editor.LineIndentation[editor:LineFromPosition(editor.CurrentPos)] then currentindent = editor.LineIndentation[editor:LineFromPosition(editor.CurrentPos)] -- _ALERT(currentindent) if editor.UseTabs then n_idents = editor.LineIndentation[editor:LineFromPosition(editor.CurrentPos)] / editor.TabWidth s_indent = string.rep("\t",n_idents) else n_idents = editor.LineIndentation[editor:LineFromPosition(editor.CurrentPos)] s_indent = string.rep(" ",n_idents) end end --end -- remove current word editor:remove(from, to +1) -- replace text \n for LF plus the indent info repword = string.gsub(repword, "\\n", "\n" .. s_indent) -- replace text \t for TAB repword = string.gsub(repword, "\\t", "\t") -- find caret position in the word tcaretpos = string.find(repword,"|") -- when string to insert contains | then calculate the pos and remove it if tcaretpos ~= nil and tcaretpos ~= 0 then caretposword = string.find(repword,"|") -1 caretpos = from + string.find(repword,"|") -1 repword = string.gsub(repword, "|", "") else -- set caret pos to the end of the inserted string caretposword = 0 caretpos = from + string.len(repword) end editor:insert(from,repword) editor:GotoPos(caretpos) -- -- try to create the tooltip() -- get keyword/function name part infront of the ( braceopenpos = string.find(repword,"%(") braceclosepos = string.find(repword,"%)") -- when string to insert contains | then calculate the pos and remove it --_ALERT(braceclosepos) if braceclosepos ~= nil and braceclosepos < caretposword then -- caret pos not inside the first function repword = "" elseif braceopenpos then -- get keyword/function name part infront of the | repword = string.sub(repword,1,braceopenpos-1) elseif caretposword ~= 0 then repword = string.sub(repword,1,caretposword) else repword = "" end --_ALERT("repword:" .. repword ) if repword ~= "" and braceopenpos then f = io.open(props['SciteDefaultHome'].."\\api\\au3.api") if f ~= nil then local apitxt = f:read('*a') if apitxt then f:close() local rep_start = string.find(string.lower(apitxt),"\n" .. string.lower(repword).."[\n ]") if rep_start ~= nil then rep_end = string.find(apitxt,"\n",rep_start+2)-1 repword = string.sub(apitxt,rep_start+1,rep_end) -- put the description on the next line.. repword = string.gsub(repword, "%)", "%)\n",1) editor:CallTipShow(caretpos, repword) end end end end end end |