AutoHotkey Community

It is currently May 26th, 2012, 8:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Syntax file for VIM
PostPosted: April 3rd, 2005, 11:09 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
Yes, I've finally cracked the mysteries of the VIM syntax file, and here are the results. It uses regex for nearly all of the matching, so let me know if I goofed somewhere because I based it off of my coding style. The only problem that I can foresee is that it won't match most function calls if you don't put in the first comma like I do.

On the other hand, the regex matching removes the need to parse the syntax files, so this ought to be alright until major syntax changes occur. Just drop this (make sure it's called ahk.vim) file in your $VIM/syntax directory and follow the instructions at the top to make it turn on automagically.a

Code:
" Vim syntax file

" Language:   Autohotkey from www.autohotkey.com
" Maintainer:   savage - kallen19918 AT earthlink DOT net

"Usage:
"1) Copy this file into your $VIM/syntax directory.
"2) Add this line to filetype.vim:
"au BufNewFile,BufRead *.ahk setf ahk



" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

sy case ignore

sy keyword ahkKeyword ahk_id ahk_pid ahk_class ahk_group ahk_parent true false

sy match ahkFunction "^\s*\w\{1,},"
sy match ahkFunction "\w\{1,}," contained
sy match ahkFunction "^\s*\w\{1,}\s*$" contains=ahkStatement
sy match ahkFunction "\w\{1,}\s*$" contained

sy match ahkNewFunction "\s*\w\{1,}(.*)"
sy match ahkNewFunctionParams "(\@<=.*)\@=" containedin=ahkNewFunction

sy match ahkEscape "`." containedin=ahkFunction,ahkLabel,ahkVariable,ahkNewFunctionParams

sy match ahkVariable "%.*%" containedin=ahkNewFunctionParams
sy match ahkVariable "%.*%"



sy match ahkKey "[!#^+]\{1,4}`\=.\n" contains=ahkEscape
sy match ahkKey "[!#^+]\{0,4}{.\{-}}"


sy match ahkDirective "^#[a-zA-Z]\{2,\}"

sy match ahkLabel "^\w\+:\s*$"
sy match ahkLabel "^[^,]\+:\{2\}\(\w\+,\)\="  contains=ahkFunction
sy match ahkLabel "^[^,]\+:\{2\}\w\+\s*$" contains=ahkFunction
sy match ahkLabel "^:.\+:.*::"
sy keyword ahkLabel return containedin=ahkFunction

sy match ahkStatement "^\s*if\w*\(,\)\="
sy keyword ahkStatement If Else Loop Loop, exitapp containedin=ahkFunction

sy match ahkComment "`\@<!;.*" contains=NONE
sy match ahkComment "\/\*\_.\{-}\*\/" contains=NONE


hi def link ahkKeyword Special
hi def link ahkEscape Special
hi def link ahkComment Comment
hi def link ahkStatement Conditional
hi def link ahkFunction Type
hi def link ahkDirective Include
hi def link ahkLabel Label
hi def link ahkKey Special
hi def link ahkVariable Constant
hi def link ahkNewFunction Type

sy sync fromstart
let b:current_syntax = "ahk"


Enjoy :)

PS: I had fun writing this - I love goofing with regular expressions :mrgreen:

EDIT: Already some changes, fixed escaped characters in hotkeys and labels, and added highlighting for operators

EDIT: 4/16/05 New version with support for new functions, c -style comments, some fixes, and removed operator highlighting - it was just a pain in the ass

_________________
<enormous animated gif>


Last edited by savage on April 16th, 2005, 7:34 pm, edited 6 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2005, 7:26 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for providing this. I will include it in the next release in the following path:

\Extras\Editors\Vim\ahk.vim

I've altered the "usage" section inside the file as follows:
"Usage:
"1) Copy this file into your $VIM/syntax directory.
"2) Add this line to filetype.vim:
"au BufNewFile,BufRead *.ahk setf ahk

If you would like your name or any contact details added to the file header, I'd be happy to do so.

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2005, 3:29 am 
Offline

Joined: September 2nd, 2004, 1:08 am
Posts: 124
Location: Sunnyvale
Sweet!! Thanks savage!

_________________
I am he of whom he speaks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2005, 3:17 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
Yeah chris, go ahead and add my email - kallen19918 at earthlink dot net, though I can't check it now because sprint's authentication server for employee accounts has been down for a week now :evil: .

_________________
<enormous animated gif>


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2005, 12:08 am 
Offline

Joined: May 24th, 2004, 7:45 pm
Posts: 23
Location: Bellevue, WA USA
A couple of things to add to make your file more standard (to prevent stepping on itself if it's loaded multiple times) put this at the beginning:

Code:
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif


And this at the end:

Code:
let b:current_syntax = "ahk"


Thanks for putting this together. Maybe I'll try to add some support for the /* */ C-style comments and see how that goes.

_________________
Tommy


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2005, 3:32 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
Thanks for the pointers. I've never done a syntax file for vim before and it's still a little mysterious to me. :) I completely forgot about the c style comments, and probably a number of other things as well. I added really basic highlighting for functions, but it needs work before I post it. I also realized that not all operator combinations are highlighted. I've been busy with other projects lately, so it might be awhile before I get around to it again.

_________________
<enormous animated gif>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2005, 1:37 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I can apply the changes above to the distributed file if they've been tested and no one objects.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2005, 5:40 pm 
Offline

Joined: July 2nd, 2004, 11:53 pm
Posts: 207
The new version above has those changes incorporated.

Let me know if anything isn't highlighting right. It's pretty hard to make this work. For instance I discovered that "{enter}" highlighted correctly but "{enter} blahblah {enter}" highlighted the whole thing. That's fixed, btw.

_________________
<enormous animated gif>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2005, 8:10 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for all the improvements! I'll include the new file with the next update.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 29th, 2007, 3:09 pm 
Offline

Joined: November 1st, 2006, 8:33 pm
Posts: 21
Location: Chicago, IL
The current ahk.vim file specifies the highlighting of variables using "greedy" wildcarding ("%.*%") which results in all characters between two variables on the same line being highlighted.
Example: a := %b% + %c%
This can be corrected by using "lazy" wildcarding ("%.\{-}%") which will highlight only the variables:
Example: a := %b% + %c%

The change is implemented by replacing the two "sy match ahkVariable ..." lines in the $VIM/syntax/ahk.vim file with:
Code:
sy match ahkVariable " % " containedin=ahkNewFunctionParams
sy match ahkVariable "%[^ ]\{-}%" containedin=ahkNewFunctionParams
sy match ahkVariable " % "
sy match ahkVariable "%[^ ]\{-}%"

Note: The code above has been changed to correctly handle the use of the lone "%" to force an expression (1/28/2007).

Thanks Savage for taking the time to implement AHK syntax support for VIM.
TL


Last edited by TL on January 29th, 2008, 12:57 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2007, 1:56 am 
Offline

Joined: March 16th, 2006, 5:01 pm
Posts: 150
Savage: this is great. This is the best parsing I've seen for any editor. I had a different vim syntax file, and this one is much better.

I found a problem though.

Image

second instance of Menu is not highlighted.

Thanks

PS: sorry, I don't know why the img doesn't show.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2007, 3:29 am 
Offline

Joined: March 16th, 2006, 5:01 pm
Posts: 150
by the way, have you seen this other vim syntax file?
Now that I'm starting to understand how vim colors things, it may be more flexible... or not.
http://vim.cybermirror.org/runtime/synt ... hotkey.vim


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher and 4 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