AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Syntax file for VIM

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources
View previous topic :: View next topic  
Author Message
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Sun Apr 03, 2005 11:09 pm    Post subject: Syntax file for VIM Reply with quote

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 Smile

PS: I had fun writing this - I love goofing with regular expressions Mr. Green

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 Sat Apr 16, 2005 7:34 pm; edited 6 times in total
Back to top
View user's profile Send private message AIM Address
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Apr 04, 2005 7:26 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Send e-mail
Atomhrt



Joined: 02 Sep 2004
Posts: 128
Location: Sunnyvale

PostPosted: Tue Apr 05, 2005 3:29 am    Post subject: Reply with quote

Sweet!! Thanks savage!
_________________
I am he of whom he speaks!
Back to top
View user's profile Send private message
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Tue Apr 05, 2005 3:17 pm    Post subject: Reply with quote

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 or Very Mad .
_________________
<enormous animated gif>
Back to top
View user's profile Send private message AIM Address
twwilliams



Joined: 24 May 2004
Posts: 23
Location: Bellevue, WA USA

PostPosted: Tue Apr 12, 2005 12:08 am    Post subject: A couple of vim standards for syntax files Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Tue Apr 12, 2005 3:32 pm    Post subject: Reply with quote

Thanks for the pointers. I've never done a syntax file for vim before and it's still a little mysterious to me. Smile 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>
Back to top
View user's profile Send private message AIM Address
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Apr 16, 2005 1:37 am    Post subject: Reply with quote

I can apply the changes above to the distributed file if they've been tested and no one objects.
Back to top
View user's profile Send private message Send e-mail
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Sat Apr 16, 2005 5:40 pm    Post subject: Reply with quote

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>
Back to top
View user's profile Send private message AIM Address
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Apr 16, 2005 8:10 pm    Post subject: Reply with quote

Thanks for all the improvements! I'll include the new file with the next update.
Back to top
View user's profile Send private message Send e-mail
TL



Joined: 01 Nov 2006
Posts: 9

PostPosted: Thu Nov 29, 2007 3:09 pm    Post subject: Fix for variable highlighting Reply with quote

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 Tue Jan 29, 2008 12:57 am; edited 1 time in total
Back to top
View user's profile Send private message
urlwolf



Joined: 16 Mar 2006
Posts: 100

PostPosted: Mon Dec 31, 2007 1:56 am    Post subject: Reply with quote

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.

[img]http://academicproductivity.com/temporary/clipboard12_31_2007_ 01_52_51.jpg[/img]

second instance of Menu is not highlighted.

Thanks

PS: sorry, I don't know why the img doesn't show.
Back to top
View user's profile Send private message
urlwolf



Joined: 16 Mar 2006
Posts: 100

PostPosted: Mon Dec 31, 2007 3:29 am    Post subject: Reply with quote

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/syntax/autohotkey.vim
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group