-- TIME_STAMP 2018-01-20 13:35:44 v 0.2 --[[ - Funktionsname von Cursorposition - Funktion im Skript selbst suchen - Funktion in Includes des offenen Skriptes suchen - Funktionsbeschreibung (Kommentarzeilen direkt vor der erstellten Funktion) suchen - Funktionsbeschreibung in Konsole ausgeben ]] do --[[ Funktionsname von der Cursorposition auslesen ]]-- 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 end ------------------------------------------------------------------------------------------------ --[[ Includedateien von der Skriptseite auslesen ]]-- 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 ------------------------------------------------------------------------------------------------ --[[ Speicherorte der Includedateien im System auslesen ]]-- local GetIncludePathes = function() local sProp = props['openpath.$(au3)'] local tPathes = {} -- splitten am ';' for w in sProp:gmatch('([^;]+)') do table.insert(tPathes, w) end return tPathes end ------------------------------------------------------------------------------------------------ --[[ Beschreibung aus Datei auslesen, wenn Funktion enthalten ]]-- 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 -- zeilenweise auf Funktionsdeklaration prüfen 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 -- Funktionsdeklaration nicht gefunden -- wenn Deklaration gefunden, die Zeilen davor auf Kommentarzeilen prüfen und Inhalt auslesen if iLineMatch == 1 or not (tFile[iLineMatch-1]:find('^%s*;')) then return nil end -- Funktion in erster Zeile deklariert --> keine Beschreibung -- oder vorhergehende Zeile enthält keinen Kommentar for i=iLineMatch -1, 1, -1 do -- beginnt die Zeile mit Kommentar if tFile[i]:find('^%s*;') then sDescription = tFile[i]..'\n'..sDescription else break end end -- wenn Beschreibung vorhanden diese zurückgeben, sonst nil if sDescription ~= '' then return sDescription else return nil end end ------------------------------------------------------------------------------------------------ --[[ Includes nach der Funktionsdeklaration durchsuchen, Beschreibung auslesen ]]-- 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=kein Pfad("def.au3"), 1=Teilpfad("abc\def.au3"), 2=Vollpfad("C:\abc\def.au3") local sDescription -- alle Includes in allen Pfaden suchen for i=1, #_tIncl do -- Includes aus Skript sInclFound = nil iFullOrPart = 0 -- ist Include Teil-/Vollpfad, Pfad oder SkriptDir & Teilpfad verwenden if _tIncl[i]:sub(2,2) == ':' then -- Vollpfad iFullOrPart = 2 if FileExists(_tIncl[i]) then sInclFound = _tIncl[i] end elseif _tIncl[i]:find('\\') then -- Teilpfad iFullOrPart = 1 if FileExists(sScriptDir..'\\'.._tIncl[i]) then sInclFound = sScriptDir..'\\'.._tIncl[i] end end if sInclFound == nil then for j=1, #tInclPathes do -- Includepfade sFull = tInclPathes[j]..'\\'.._tIncl[i] if FileExists(sFull) then sInclFound = sFull end if sInclFound ~= nil then break end end end -- wenn Include nicht gefunden wurde, im Skriptordner suchen 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) caret_output = output.CurrentPos local sFunc = FuncNameFromCursor() local sDescript = GetDescription(props['FilePath'], sFunc) or SearchDescription(IncludesFromBuffer(), sFunc) print(sDescript) output:GotoPos(caret_output) end