/*
; The script extracts AHK function declarations from the clipboard and opens
; user.ahk.api file where you can paste the function declarations.
; Example usage:
; - open an AHK library file you've downloaded,
; - copy all code from within the file to the clipboard,
; - run the script (parse clipboard contents, open user.ahk.api file)
; - paste function declarations to user.ahk.api file
; - restart SciTE.
; Notes:
; - modify the path variables below if needed
; - good practice: rescan library catalog every time this script gets updated
; (vide script 1.0.0 skipped function declarations that had comments at
; the end)
;
; TODO:
; - enable/disable sorting option?
; - if @ found in string, pick other sign
; - import constants
; - check if any of fn names are AHK built-in function names - if yes, warn
; user (see my GetTypeInfo.ahk)
; - option to skip comments in file
; - GUI window?
;
; Version 1.0.4 (20120402)
;
; Changes since version 1.0.3 (20120402)
; - regular expressions upgraded thanks to rvcv32's Regex Sandbox
;
; Changes since version 1.0.2 (20120402)
; - remove duplicate entries
; - inform user if duplicate function names found (dup fn names, but not fn
; params / comments)
; - bug: ;? changed to ; - comment sign has to be present if text after
; trailing { (or '(')
;
; Changes since version 1.0.1 (20120401)
; - look for `n if `r`n not found in clipboard
; - display a warning if both `n and `r`n not found in clipboard
; - small tweaking of the script
;
; Changes since version 1.0.0 (20120327)
; - there can be comment sign and comments behind { sign. Updated RegEx
; pattern to handle that. Comment text is added to tooltip.
;
*/
editor_path := A_ProgramFiles "\Autohotkey\SciTE_rc1\SciTE.exe"
API_path := A_MyDocuments "\Autohotkey\SciTE\user.ahk.api"
; extract function declarations from clipboard, update clipboard contents
data := clipboard
output := ""
StringReplace, data, data, `r`n, @, All
if(ErrorLevel) { ; if `r`n missing in the string
StringReplace, data, data, `n, @, All
if(ErrorLevel) { ; if both `r`n and `n missing in the string
MsgBox, 4132, % "Single line in clipboard, Did you copy a single line"
. "of text to the clipboard?"
IfMsgBox, No
{
MsgBox, 4112, Error, % "End of line character could not be "
. "determined. Exiting."
ExitApp
}
}
}
Loop, Parse, data, @
{
; if fn declaration line found, modify line and save line in output
if(RegExMatch(A_LoopField, "^[a-zA-Z0-9_]* *\([^\)]*\) *\{? *$") )
; no comments after {
; this statement will cover most cases
output .= RegExReplace(A_LoopField, "^([a-zA-Z0-9_]*) *(\([^\)]*\)) *\{? *$", "$1 $2") . "`r`n"
; add a space between fn name and left bracket so SciTE parser
; would work properly. I.e. fun (), not fun()
; skip the trailing space and { if they are present
else if(RegExMatch(A_LoopField, "^[a-zA-Z0-9_]* *\([^\)]*\) *\{? +;.*$") )
; comments after {
output .= RegExReplace(A_LoopField, "^([a-zA-Z0-9_]*) *(\([^\)]*\)) *\{? +; *(.*)$", "$1 $2 \n$3") . "`r`n"
}
; Sort the output
Sort, output, U ; remove duplicates, case insinsitive for [a-zA-Z]
; Inform user if duplicate function names found
StringReplace, output, output, `r`n, @, All
oldLine := ""
Loop, Parse, output, @
{
line := A_LoopField
line1 := "", oldline1 := ""
StringSplit, line, line, `(
StringSplit, oldLine, oldLine, `(
if(line1 = oldLine1) { ; case insensitive
MsgBox, 64, % "Duplicate function names found., Duplicate function"
. " names found. User attention required."
break
}
oldLine := line
}
StringReplace, output, output, @, `r`n, All
clipboard := output
; open *.api file and exit
Run, "%editor_path%" "%API_path%"
ToolTip, Done
Sleep 1500
ToolTip
Extract function declarations from *.ahk lib to SciTE4AHK
Started by
trismarck
, Mar 28 2012 02:17 AM
4 replies to this topic
#1
Posted 28 March 2012 - 02:17 AM
This simple script facilitates extracting function declarations from within *.ahk library files into SciTE user.ahk.api file. After updating user.ahk.api file, SciTE now autocompletes the library function names.
#2
Posted 28 March 2012 - 08:02 AM
Very useful! I had never been using the user.ahk.api file, and it all seems very handy. I'll work on a version where you can get the functions from all (or selected) lib files.
It may also be noted that the editor path was not the same for me, but it didn't really matter
It may also be noted that the editor path was not the same for me, but it didn't really matter
#3
Posted 28 March 2012 - 06:36 PM
Glad you like it sumon 
Also: what was your editor's path? I thought I've defined the path quite uniformly.
Also: what was your editor's path? I thought I've defined the path quite uniformly.
#4
Posted 28 March 2012 - 08:33 PM
It's SciTE_beta4 on this computer, maybe something else on another. The problem is that different versions have different folder names
#5
Posted 28 March 2012 - 08:51 PM
That's not nice.




