-- TIME_STAMP 2013-02-12 13:33:08 v 0.11 ---------------------------------------------------------------------------------------------------------------------------------- -- Zwei verschiedene Funktionen: -- -- VarGetTipp -- Für Variablen werden in einer separaten Region des Skripts Tipps hinterlegt: -- #region - Variablen-Tipp -- ; $Variable1 Das ist der Tipp für $Variable1 -- ; $Variable2 Das ist der Tipp für $Variable2 -- ; $Variable3 Das ist der Tipp für $Variable3 -- #endregion -- oder sie werden in einer Kommentarzeile mit Tag irgendwo im Skript erstellt: -- ;@ $Variable1 Das ist der Tipp für diese Variable -- oder DIREKT nach Erstellung einer Variablen kann in der Folgezeile mit '-1' auf diese verwiesen werden: -- $GuiMain = GuiCreate(...) -- ;-1 Das ist der Kommentar zur Variable in der Zeile zuvor -- -- oder Tipp für Funktionen: -- In der Folgezeile nach Funktionskopzeile den Tipp hinterlegen mit -- Func _IrgendeineFunc() -- ;-f Tipp zu dieser Funktion\nZweite Zeile zu diesem Tipp -- Ausgabe: -- Funktionsname( ) -- Tipp zu dieser Funktion -- Zweite Zeile zu diesem Tipp -- -- Es können auch Variablen gleichen Namens mehrfach verwendet werden (in unterschiedlichen Funktionen). -- Die Erstellung der Tipps muß dann innerhalb desselben Gültigkeitsbereiches (also in derselben Funktion oder Global) erfolgen. -- Das Skript sucht nach Tipps für die aktuelle Variable im aktuellen Gültigkeitsbereich. Zuerst innerhalb der Funktion, -- falls gerade der Cursor auf einer Variablen in einer Funktion steht, da bei gleichnamigen existierenden lokalen und globalen Variablen, -- die lokale Variable eine höhere Priorität hat. -- Es wird immer der Variablenname und der Gültigkeitsbereich ausgegeben -- $VarBefore [ Global ] -- Das ist ein Kommentar zu $VarBefore -- oder -- $iSelf [ Local: Func _TimeOver() ] -- Das ist ein Kommentar zu $iSelf -- -- Mehrzeilige Tipps lassen sich erstellen mit "\n" als Zeilenumbruchzeichen im Text -- z.B. -- ;@ $VariableXY comment1\ncomment2\ncomment3 -- Ausgabe: -- $VariableXY -- comment1 -- comment2 -- comment3 -- -- Datei speichern als "..\SciTE\LUA\VarGetTipp.lua" -- oder besser in eigenem Skripte-Ordner "..\VarGetTipp.lua -- -- In der "SciTEUser.properties" wird ein Hotkey zum Aufruf der Funktion hinterlegt -- # 49 Variablen Tipp by BugFix -- command.name.49.*.au3=Variablen Tipp -- command.49.*.au3=dostring assert(loadfile(props["Lua.User.Scripts.Path"].."\\VarGetTipp.lua"))("v") -- command.mode.49.*.au3=subsystem:lua,savebefore:no -- command.shortcut.49.*.au3=Ctrl+Alt+V -- -- !!! Zusätzlich folgende properties-Werte erstellen !!! -- #~ Variablentipp / Suche Variable mit Tipp -- #~ Tipp als CallTip (1) oder Konsolenausgabe (0) -- Variable.Tipp.CallTip.*.au3=1 -- #~ Speicherort der Lua-Skriptdateien !! Ohne abschließenden Backslash !! -- Lua.User.Scripts.Path=C:\Code_AutoIt\LUA -- #~ Ergebnis Variablensuche per Tipp in Userliste (1) oder Konsole (0) -- Userlist.VarGetTip=1 -- -- - Cursor auf die Variable setzen -- - Hotkey aufrufen -- - Ist ein Tipp hinterlegt, wird dieser als CallTipp angezeigt oder in die Konsole ausgegeben ---------------------------------------------------------------------------------------------------------------------------------- -- SearchVarByTip -- Sucht anhand des Begriffs in der aktuellen Editorzeile innerhalb der vorhandenen Variablentipps nach -- Übereinstimmungen. Treffer werden in einer Userlist zur Auswahl angezeigt. -- Die Variable des ausgewählten Treffers wird an der Position des Suchbegriffs im Editor eingefügt. -- Alternativ können alle Variablen, in deren Beschreibung das Suchwort enthalten ist, in die Konsole ausgegeben werden. -- -- !!! WICHTIG !!! -- Um die Auswahl in der Userliste feststellen zu können ist zusätzlich die Datei "VarGetTip_ListEvent.lua" erforderlich. -- Diese muss in der "SciTEStartup.lua" aufgerufen werden, etwa so sollte es aussehen: -- -- ============== Auszug aus: SciTEStartup.lua ====================================================================== -- ..... -- ..... -- ..... -- -- Start up the events (Calls OnStartup()). -- EventClass:BeginEvents() ----< erst nach diesem Eintrag Event-Skripts laden! -- -- LoadLuaFile("EdgingSelection.lua", props["Lua.User.Scripts.Path"].."\\") ---- paariges Einfassen -- LoadLuaFile("AutoStampSaveVersion.lua", props["Lua.User.Scripts.Path"].."\\") ---- Zeitstempel, Versionsbackup -- LoadLuaFile("EditOperations.lua", props["Lua.User.Scripts.Path"].."\\") ---- Repeat, Go, Delete, SwapLines -- LoadLuaFile("VarGetTip_ListEvent.lua", props["Lua.User.Scripts.Path"].."\\") ---- Listenzugriff VarGetTip -- ================================================================================================================== -- -- In der "SciTEUser.properties" wird ein Hotkey zum Aufruf der Funktion hinterlegt -- # 48 Suche Variable mit Tipp -- command.name.48.*.au3=Variable Search by Tip -- command.48.*.au3=dostring assert(loadfile(props["Lua.User.Scripts.Path"].."\\VarGetTipp.lua"))("s") -- command.mode.48.*.au3=subsystem:lua,savebefore:no -- command.shortcut.48.*.au3=Ctrl+Alt+S -- ---------------------------------------------------------------------------------------------------------------------------------- -- Aufruf mit Parameter local tArg = {...} local sParam = tArg[1] local GetVarFromCursor = function() local iCaret = editor.CurrentPos local iTmp = iCaret local sSel = string.char(editor.CharAt[iCaret]) if (string.byte(sSel) == 13) or (sSel == ' ') or (sSel == ',') then iCaret = iCaret -1 end local sLeft = string.char(editor.CharAt[iTmp-1]) local iLine = editor:LineFromPosition(iCaret) local iLine1stPos = editor:PositionFromLine(iLine) local iDiffPos = iCaret - iLine1stPos +1 local sLine = editor:GetLine(iLine) local sPatternNormal = '%$[%w_]+%s*[^[]' local function SearchVar(_sLine, _sPattern, _iCursor) local tVars = {} local iMatchStart iMatchEnd = 0 while true do iMatchStart, iMatchEnd = _sLine:find(_sPattern, iMatchEnd +1) if iMatchStart == nil then break end table.insert(tVars, {iMatchStart, iMatchEnd}) end if table.getn(tVars) > 0 then for i = 1, table.getn(tVars) do if ( _iCursor >= tVars[i][1] ) and ( _iCursor <= tVars[i][2] ) then return string.sub(_sLine, tVars[i][1], tVars[i][2]) end end end return nil end local sVarUnderCursor local fLeftVar = false fRightVar = false if sLeft:find('[%w_$]') ~= nil then fLeftVar = true else if sSel == '$' then fRightVar = true end end if not fLeftVar and not fRightVar then return '' end sVarUnderCursor = SearchVar(sLine, sPatternNormal, iDiffPos) if sVarUnderCursor == nil then return '' end if sVarUnderCursor:find('%.$') then return '' end sVarUnderCursor = sVarUnderCursor:sub(sVarUnderCursor:find('%$[%w_]+')) return sVarUnderCursor, iCaret end -- GetVarFromCursor() local GetFuncFromCursor = function() local iCaret = editor.CurrentPos local sSel = string.char(editor.CharAt[iCaret]) if (string.byte(sSel) == 13) or (sSel == ' ') or (sSel == ',') then return nil end local sLine = editor:GetLine(editor:LineFromPosition(iCaret)) if string.char(editor.CharAt[iCaret -1]) ~= ' ' then editor:WordLeft() end editor:WordRightExtend() local sCurrWord = editor:GetSelText() editor:SetSel(iCaret, iCaret) if sCurrWord:find('[^%w_)]') then return '' end if sLine:find(sCurrWord..'%s*%b()') then return sCurrWord, iCaret else return '' end end -- GetFuncFromCursor() local Output = function(sText1, sText2) if tonumber(props['Variable.Tipp.CallTip.*.au3']) == 1 then if sText2 ~= nil then sText1 = sText1..'\n'..sText2:gsub('\\n', '\n') end editor:CallTipShow(editor.CurrentPos, sText1) else print('!> '..sText1) if sText2 ~= nil then print('>> '..sText2:gsub('\\n', '\n>> ')) end end end -- Output local GetAllTip = function() local tTip = {} local s = editor:GetText() -- in vorhergehender Zeile deklariert for p, tip in s:gmatch('()\n[\t%s]*;%-1%s*([^\r\n]+)') do local _, _, var = editor:GetLine(editor:LineFromPosition(p) -1):find('(%$[%w_]+)') table.insert(tTip, {var,tip,p,'global'}) end -- mit "at"-Tag gesetzter Tipp for p, var, tip in s:gmatch('()\n[\t%s]*;@%s-(%$[%w_]+)%s([^\r\n]+)') do table.insert(tTip, {var,tip,p,'global'}) end -- in Region gesetzte Tipps local tReg = {} for p in s:gmatch("()#[Rr]egion %- [Vv]ariablen%-[Tt]ipp") do table.insert(tReg, p) end if table.getn(tReg) > 0 then for i=1,table.getn(tReg) do local line = editor:LineFromPosition(tReg[i]) while not editor:GetLine(line):find('#[Ee]nd[Rr]egion') do line = line +1 local _, _, var, tip = editor:GetLine(line):find(';%s-(%$[%w_]+)%s([^\r\n]+)') if var then table.insert(tTip, {var,tip,tReg[i],'global'}) end end end end if sParam == 'v' then -- Funktionstipps, nur bei Aufruf mit Parameter 'v' for p, tip in s:gmatch('()\n[\t%s]*;%-f%s*([^\r\n]+)') do local _, _, sFunc = editor:GetLine(editor:LineFromPosition(p) -1):find('([%w_]+)%s*%b()') table.insert(tTip, {sFunc,tip,p,sFunc}) -- Alles OK ! end end return tTip end -- GetAllTip local GetFuncs = function() -- Ermitteln aller Funktionsdeklarationen (Startpos, Endpos, Funktionsname) local tFuncs = {} for iStart, sFunc in editor:GetText():gmatch('()[Ff][Uu][Nn][Cc]%s+([%w_]+)%s*%b()') do local iLine, iEnd = editor:LineFromPosition(iStart) while true do iLine = iLine +1 iEnd = editor:GetLine(iLine):find('[Ee][Nn][Dd][Ff][Uu][Nn][Cc]') if iEnd ~= nil then break end end table.insert(tFuncs, {iStart, editor:PositionFromLine(iLine), sFunc}) end return tFuncs end -- GetFuncs if sParam == 'v' then local varCurr, varPos = GetVarFromCursor() local fIsFuncTip = false if varCurr == '' then varCurr, varPos = GetFuncFromCursor() if varCurr ~= '' then fIsFuncTip = true end end local tFuncs, tTip, fMatch, fMatchFunc, fInFunc, sFunc, sTip = GetFuncs(), GetAllTip(), false, false, false local GetTip = function(_var, _scope) _scope = _scope or 'global' for i=1,table.getn(tTip) do if tTip[i][1]:lower() == _var:lower() and tTip[i][4] == _scope then return tTip[i][2] end end return nil end -- GetTip if table.getn(tTip) > 0 and table.getn(tFuncs) > 0 then -- den Tipps die Funktionen zuordnen for i=1,table.getn(tTip) do for j=1,table.getn(tFuncs) do if tTip[i][3] >= tFuncs[j][1] and tTip[i][3] <= tFuncs[j][2] then tTip[i][4] = tFuncs[j][3] break end end end end local IsVarInFunc = function(_var, _pos) if table.getn(tFuncs) == 0 then return false, nil end for i=1,table.getn(tFuncs) do if _pos >= tFuncs[i][1] and _pos <= tFuncs[i][2] then return true, tFuncs[i][3] -- Rückgabe: True/False, Funktionsname end end return false, nil end -- IsVarInFunc if table.getn(tTip) == 0 then Output('Keine Tipps hinterlegt!') else if varCurr == '' then Output('Cursor steht nicht auf einer Variablen\noder einem Funktionsaufruf!') else if not fIsFuncTip then fInFunc, sFunc = IsVarInFunc(varCurr, varPos) end if fInFunc then sTip = GetTip(varCurr, sFunc) if sTip ~= nil then Output(varCurr..' [ Local: Func '..sFunc..'() ]', sTip) else sTip = GetTip(varCurr, 'global') if sTip ~= nil then Output(varCurr..' [ Global ]', sTip) else Output(varCurr, 'Es ist kein Tipp hinterlegt!') end end elseif fIsFuncTip then sTip = GetTip(varCurr, varCurr) if sTip ~= nil then Output(varCurr..'( )', sTip) else Output(varCurr..'( )', 'Es ist kein Tipp hinterlegt!') end else sTip = GetTip(varCurr, 'global') if sTip ~= nil then Output(varCurr..' [ Global ]', sTip) else Output(varCurr, 'Es ist kein Tipp hinterlegt!') end end end end elseif sParam == 's' then local tTip = GetAllTip() -- {variable, tipp, position, scope} local sWord = AutoItTools:GetWord() local tFound, sFound, sep, iS, sTipN = {}, '', ';' if sWord:gsub('[%s]+', '') == '' or table.getn(tTip) == 0 then return end local fList = false if props['Userlist.VarGetTip'] == '1' then fList = true end local OutputGrouped = function(_fList) local iMax, sOut, sLineEnd = 0, '', '\n' if _fList then sLineEnd = sep end for i=1,table.getn(tFound) do if tFound[i][2]:len() > iMax then iMax = tFound[i][2]:len() end end for i=1,table.getn(tFound) do sOut = sOut..tFound[i][1]..'...'..tFound[i][2]..('.'):rep(iMax-tFound[i][2]:len()+3)..tFound[i][3]..sLineEnd end return sOut end local SelectCurrentWord = function() local iCaret = editor.CurrentPos local iLine = editor:LineFromPosition(iCaret) local iLine1stPos = editor:PositionFromLine(iLine) local iDiffPos = iCaret - iLine1stPos +1 local sLine = editor:GetLine(iLine) local sWord = props["CurrentWord"] if sWord == '' then return end local s, p = sLine:find(sWord) local tMatch = {} while s ~= nil do table.insert(tMatch, {s,p}) s, p = sLine:find(sWord, s+1) end if table.getn(tMatch) > 0 then for i=1, table.getn(tMatch) do if iDiffPos >= tMatch[i][1] and iDiffPos <= tMatch[i][2] then editor:SetSel(iLine1stPos-1 +tMatch[i][1], iLine1stPos +tMatch[i][2]) break end end end end for i=1,table.getn(tTip) do iS = tTip[i][2]:lower():find(sWord:lower()) if iS then sTipN = tTip[i][2]:gsub('\\n', ' \[LINEBREAK\] ') table.insert(tFound, {tTip[i][4], tTip[i][1], sTipN}) end end if table.getn(tFound) > 0 then sFound = OutputGrouped(fList) else sFound = 'Kein Tipp mit diesem Begriff vorhanden.' end SelectCurrentWord() if not fList then print(sFound) editor:ReplaceSel('') return end editor.AutoCSeparator = string.byte(sep) editor:UserListShow(99, sFound) editor.AutoCSeparator = string.byte(' ') end ----------------------------------------------------------------------------------------------------------------------------------