Heya. This is an EXTREMELY simple function that I find quite helpful and thought I'd share.
You know how when AHK finds a syntax error, how it tells you the line number? Wouldn't it be great if it also jumped you to the relevant line in your text editor, so you can get to work fixing it?
This simple function does this for me, but might need to be adapted for someone who doesn't, for example, use SciTE. Luckily, it's only got 22 lines of fairly simplistic code, so it should be very simple for you to adapt or extend. (In fact if you adapt it and make it better, I'll link to your post in big letters from this post.) Specifically, it assumes that the script with the syntax error is open in SciTE (presumably because you just introduced the error) and that you don't have many other AHK error windows open at the time.
Code:
#g::GotoSyntaxError()
; Error at line 3919. ... Error: This line does not contain a recognized action.
; Error at line 3919. ... Error: Duplicate label.
; Error: Call to nonexistent function ... ---> 3919: fname()
; Error: Target label does not exist. ... ---> 3919: Gosub, subname
;asdf()
;asdf
GotoSyntaxError() {
; ONLY LOOKS FOR FIRST MATCHING WINDOW, but that's enough for me.
OldTitleMatchMode := A_TitleMatchMode
SetTitleMatchMode, RegEx
; REGEX NOTES: i) makes it case-insensitive .ahk$ only looks for .ahk at the END of the string.
IfWinExist, i).AHK$ ahk_class #32770, Error
{
WinGetText, ErrorMsg
Regex1 := "--->\t(\d*):"
Regex2 := "Error at line (\d*)\."
; Thanks to Lexikos: http://www.autohotkey.com/forum/viewtopic.php?t=66793
If ( RegExMatch(ErrorMsg, Regex1, LineNo)
OR RegExMatch(ErrorMsg, Regex2, LineNo)) {
ControlClick, OK
IfWinExist, SciTE4AutoHotkey$ ahk_class SciTEWindow
{
WinActivate
SciteGotoLine(LineNo1)
}
}
StringReplace, ErrorMsg, ErrorMsg, %a_tab%, T, All
Result := "LineNo1=" LineNo1 "`nErrorMsg=" ErrorMsg
}
SetTitleMatchMode %OldTitleMatchMode%
}
Enjoy!