Usage
- Right-click when hovering over a function name in the Notepad++ Function List (and tooltip appears) >> Inserts the function name and parameter definition into your script. Added benefit: also saves you from having to type the function name.
- Control & Right-click >> Inserts a comment block into your script that contains the function definitions from your #Include files so that they will be added to the Function List pane (after saving your file), which allows you to auto-insert their definitions by right-clicking on them also. Does not add function definitions that have no parameters.
- If you haven't done so already, add AHK support for Notepad++'s Function List feature per ahkDustVorteX (et al). Note that it has been updated later in the thread to handle certain cases correctly and to add support for classes, and the updates have not yet been incorporated into the first post of the thread. Kudos to everyone in that thread for their work on this very useful feature.
- Run the script below.
Code: Select all
#If WinActive("ahk_exe notepad++.exe") && WinExist("ahk_class tooltips_class32") && IsControlUnderMouse("SysTreeView322") RButton:: ControlGetText, FuncDef,, ahk_class tooltips_class32 ClipSave := ClipboardAll Clipboard := RTrim(FuncDef, " {`t`n`r") Send, ^v Clipboard := ClipSave return #If WinActive("ahk_exe notepad++.exe") ^RButton:: WinGetTitle, NppTitle, A NppTitle := LTrim(NppTitle, "*") StringTrimRight, ScriptFullPath, NppTitle, 12 SplitPath, NppTitle,, ScriptDir FileRead, ScriptText, %ScriptFullPath% OutText := "/* ----- Function definitions from #Include files -----`n" Loop, Parse, ScriptText, `n, `r { if (SubStr(Trim(A_LoopField), 1, 8) = "#Include") { RegExMatch(A_LoopField, "i)#Include,*\s*\K[^;]+", IncFilePath) IncFilePath := Trim(IncFilePath) SplitPath, IncFilePath,,,,, IncDrive OutText .= GetFuncDefs((IncDrive ? IncFilePath : ScriptDir "\" IncFilePath)) } } OutText .= "*/`n" ClipSave := ClipboardAll Clipboard := OutText Send, ^v Clipboard := ClipSave return #if IsControlUnderMouse(refCtrl) { MouseGetPos,,,, ctrl return ctrl = refCtrl } GetFuncDefs(scriptPath) ; does not include those with a definition of "()" (no parameters) { defs := "" FileRead, rawScript, %scriptPath% ; remove comment blocks: cleanScript := "`n" ; start with `n so RegEx can know a func def is preceded by one even if first line blockStart := 0 Loop, Parse, rawScript, `n, `r { if blockStart { if (SubStr(LTrim(A_LoopField), 1, 2) = "*/") blockStart := 0 } else { if (SubStr(LTrim(A_LoopField), 1, 2) = "/*") blockStart := 1 else cleanScript .= A_LoopField "`n" } } ; get function definitions: startPos := 1 Loop { ; original: if (foundPos := RegExMatch(cleanScript, "\n\s*\K[\w#@$]+\([^\n;]+\)(?=\s*(;[^n]*)*\n*{)", match, startPos)) if (foundPos := RegExMatch(cleanScript, "U)\n\s*\K[ \t]*(?!(if\(|while\(|for\())([\w#!^+&<>*~$])+\d*\([^)]+\)([\s]|(/\*.*?\*)/|((?<=[\s]);[^\r\n]*?$))*?[\s]*\n*(?=\{)", match, startPos)) { defs .= Trim(RegExReplace(match, "\s*\n\s*$")) " {`n" startPos := InStr(cleanScript, "`n",, foundPos) ; start at next line } } until !foundPos return defs }
If the function definition is so short that it is not wider than the Function List pane, it will not display a tooltip and can't be inserted by this tool. I don't find this to be a problem since functions with parameters (especially multiple ones) will be long enough to display a tooltip.
EDIT: Incorporated a modified version Nightwolf85's RegEx to allow it to find multi-line function definitions.