-- TIME_STAMP 2018-01-22 21:38:27 v 0.3 --[[ - function name from cursor position - 1st: search function in current buffer - 2nd: search function in the included files - write description to console output, if found ]] do --[[ function name from cursor position ]]-- local FuncNameFromCursor = function() local sReturn = '' local sPattern = '[a-zA-Z0-9_]+' local iCaret0 = editor.CurrentPos if ('23 40'):find(tostring(editor.CharAt[iCaret0])) then editor:WordLeft() end local iCaret1 = editor.CurrentPos local iStart = editor:WordStartPosition(iCaret1) local iEnd = editor:WordEndPosition(iCaret1) editor:SetSelection(iStart, iEnd) local sSelection = editor:GetSelText() sReturn = sSelection:sub(sSelection:find(sPattern)) editor:SetSelection(iCaret0, iCaret0) return sReturn, iCaret0 end ------------------------------------------------------------------------------------------------ --[[ include files from current buffer ]]-- local IncludesFromBuffer = function() local sText = editor:GetText() local tIncl, sTmp = {} for incl in sText:gmatch("[\n]?#[iI][nN][cC][lL][uU][dD][eE]%s-<([%w%s_.]+)>") do table.insert(tIncl, incl) -- #include end for _, incl in sText:gmatch("[\n]?#[iI][nN][cC][lL][uU][dD][eE]%s-([\"'])([%w%s_.:\\]+)%1") do if incl:sub(1,1) == '\\' then incl = incl:sub(2,-1) end table.insert(tIncl, incl) -- #include 'abc.au3' or #include "abc.au3" end return tIncl end ------------------------------------------------------------------------------------------------ --[[ locations of include files in the system ]]-- local GetIncludePathes = function() local sProp = props['openpath.$(au3)'] local tPathes = {} -- split by ';' for w in sProp:gmatch('([^;]+)') do table.insert(tPathes, w) end return tPathes end ------------------------------------------------------------------------------------------------ --[[ read description, if function was found in file ]]-- local GetDescription = function(_sFilepath, _sFunc) local FileReadToTable = function(_sFile) local tLines = {} local fH = io.open(_sFile) if fH == nil then return tLines end for line in fH:lines() do table.insert(tLines, line) end fH:close() return tLines end local iLineMatch, sDescription = 0, '' local tFile = FileReadToTable(_sFilepath) if #tFile == 0 then return nil end -- check line by line for declaration for i=1, #tFile do if tFile[i]:upper():find('^FUNC '.._sFunc:upper()) then iLineMatch = i break end end if iLineMatch == 0 then return nil end -- none declaration found -- if found, check lines before for comment and read this if iLineMatch == 1 or not (tFile[iLineMatch-1]:find('^%s*;')) then return nil end -- function in 1st line --> none description ---- or line before without comment for i=iLineMatch -1, 1, -1 do -- starts the line with comment if tFile[i]:find('^%s*;') then sDescription = tFile[i]..'\n'..sDescription else break end end -- return description otherwise nil if sDescription ~= '' then return sDescription else return nil end end ------------------------------------------------------------------------------------------------ --[[ search in include files for function and declaration ]]-- local SearchDescription = function(_tIncl, _sFunc) local FileExists = function(_sFullPath) local fH = io.open(_sFullPath) if fH then fH:close() return true else return false end end local tInclPathes = GetIncludePathes() local sScriptDir, sInclFound, sFull = props['FileDir'] local iFullOrPart -- 0=none folder("def.au3"), 1=partial path("abc\def.au3"), 2=full path("C:\abc\def.au3") local sDescription -- search includes in all pathes for i=1, #_tIncl do -- includes from script sInclFound = nil iFullOrPart = 0 -- if include has partial or full path, use: 'path' or 'ScriptDir & partial path' if _tIncl[i]:sub(2,2) == ':' then -- full path iFullOrPart = 2 if FileExists(_tIncl[i]) then sInclFound = _tIncl[i] end elseif _tIncl[i]:find('\\') then -- partial path iFullOrPart = 1 if FileExists(sScriptDir..'\\'.._tIncl[i]) then sInclFound = sScriptDir..'\\'.._tIncl[i] end end if sInclFound == nil then for j=1, #tInclPathes do -- locations of include files sFull = tInclPathes[j]..'\\'.._tIncl[i] if FileExists(sFull) then sInclFound = sFull end if sInclFound ~= nil then break end end end -- if include file not found in include location directories: search in ScriptDir if sInclFound == nil then if iFullOrPart ~= 2 then if FileExists(sScriptDir..'\\'.._tIncl[i]) then sInclFound = sScriptDir..'\\'.._tIncl[i] end end end if sInclFound ~= nil then sDescription = GetDescription(sInclFound, _sFunc) end if sDescription ~= nil then return sDescription end end return 'None Description found.' end ------------------------------------------------------------------------------------------------ scite.MenuCommand(IDM_CLEAROUTPUT) if props['FileExt']:upper() ~= 'AU3' then scite.SendEditor(SCI_CALLTIPSHOW, editor.CurrentPos, 'The script is only available for AU3 files!') scite.SendEditor(SCI_CALLTIPSETHLT, 0, 43) else local sFunc, iCaret = FuncNameFromCursor() local sDescript = GetDescription(props['FilePath'], sFunc) or SearchDescription(IncludesFromBuffer(), sFunc) if tonumber(props['show.description.calltip']) == 1 then scite.SendEditor(SCI_CALLTIPSHOW, iCaret, sDescript) else print(sDescript) output:GotoPos(0) end end end