AutoHotkey Community

It is currently May 27th, 2012, 12:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Simple GoToSyntaxError()
PostPosted: January 3rd, 2011, 6:55 pm 
Offline

Joined: February 17th, 2008, 5:01 pm
Posts: 303
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2011, 10:19 am 
Offline

Joined: June 17th, 2008, 7:51 am
Posts: 243
Enjoying :D

_________________
Greetings
Rog


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2011, 10:48 am 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
In SciTE: just double-click the error line in the Output pane.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2011, 12:11 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
Nice idea! I looked over the code, where can I find SciteGotoLine() ?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: notsoobvious, rrhuffy and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group