Some small cleanups to make lintian happy / part 1
[zsh-lovers.git] / zsh.vim
1 " Vim syntax file
2 " Language:         Zsh shell script
3 " Maintainer:       Nikolai Weibull <source@pcppopper.org>
4 " URL:              http://www.pcppopper.org/vim/syntax/pcp/zsh/
5 " Latest Revision:  2004-12-12
6 " arch-tag:         2e2c7097-99cb-4b87-a771-3a819b69995e
7
8 if version < 600
9   syntax clear
10 elseif exists("b:current_syntax")
11   finish
12 endif
13
14 " Set iskeyword since we need `-' (and potentially others) in keywords.
15 " For version 5.x: Set it globally
16 " For version 6.x: Set it locally
17 if version >= 600
18   command -nargs=1 SetIsk setlocal iskeyword=<args>
19 else
20   command -nargs=1 SetIsk set iskeyword=<args>
21 endif
22 SetIsk @,48-57,_,-
23 delcommand SetIsk
24
25 " Todo
26 syn keyword zshTodo         contained TODO FIXME XXX NOTE
27
28 " Comments
29 syn region  zshComment      matchgroup=zshComment start='\%(^\|\s\)#' end='$' contains=zshTodo
30
31 " PreProc
32 syn match   zshPreProc      '^\%1l#\%(!\|compdef\|autoload\).*$'
33
34 " Strings
35 syn match   zshQuoted       '\\.'
36 syn region  zshString       matchgroup=zshStringDelimiter start=+"+ end=+"+ contains=zshQuoted,@zshDerefs,@zshSubst
37 syn region  zshString       matchgroup=zshStringDelimiter start=+'+ end=+'+
38 " XXX: This should probably be more precise, but Zsh seems a bit confused about it itself
39 syn region  zshPOSIXString  matchgroup=zshStringDelimiter start=+\$'+ end=+'+ contains=zshQuoted
40 syn match   zshJobSpec      '%\(\d\+\|?\=\w\+\|[%+-]\)'
41
42 " Precommand Modifiers
43 syn keyword zshPrecommand   noglob nocorrect exec command builtin - time
44
45 " Delimiters
46 syn keyword zshDelimiter    do done
47
48 " Conditionals
49 syn keyword zshConditional  if then elif else fi case in esac select
50
51 " Loops
52 syn keyword zshRepeat       for while until repeat foreach
53
54 " Exceptions
55 syn keyword zshException    always
56
57 " Keywords
58 syn keyword zshKeyword      function nextgroup=zshKSHFunction skipwhite
59
60 " Functions
61 syn match   zshKSHFunction  contained '\k\+'
62 syn match   zshFunction     '^\s*\k\+\ze\s*()'
63
64 " Operators
65 syn match   zshOperator     '||\|&&\|;\|&!\='
66
67 " Here Documents
68 if version < 600
69   " Do nothing for now TODO: do something
70 else
71   syn region  zshHereDoc  matchgroup=zshRedir start='<<\s*\z(\S*\)' end='^\z1$' contains=@zshSubst
72   syn region  zshHereDoc  matchgroup=zshRedir start='<<-\s*\z(\S*\)' end='^\s*\z1$' contains=@zshSubst
73   syn region  zshHereDoc  matchgroup=zshRedir start='<<\s*\(["']\)\z(\S*\)\1'  end='^\z1$'
74   syn region  zshHereDoc  matchgroup=zshRedir start='<<-\s*\(["']\)\z(\S*\)\1' end='^\s*\z1$'
75 endif
76
77 " Redirections
78 syn match   zshRedir        '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)'
79 syn match   zshRedir        '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\='
80 syn match   zshRedir        '|&\='
81
82 " Variable Assignments
83 syn match   zshVariable     '\<\h\w*\ze+\=='
84 " XXX: how safe is this?
85 syn region  zshVariable     oneline matchgroup=zshVariable start='\$\@<!\<\h\w*\[' end='\]\ze+\==' contains=@zshSubst
86
87 " Variable Dereferencing
88 syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref
89
90 if !exists("g:zsh_syntax_variables")
91   let s:zsh_syntax_variables = 'all'
92 else
93   let s:zsh_syntax_variables = g:zsh_syntax_variables
94 endif
95
96 syn match zshShortDeref   '\$[!#$*@?_-]\w\@!'
97 syn match zshShortDeref   '\$[=^~]*[#+]*\d\+\>'
98
99 syn match zshLongDeref    '\$\%(ARGC\|argv\|status\|pipestatus\|CPUTYPE\|EGID\|EUID\|ERRNO\|GID\|HOST\|LINENO\|LOGNAME\)'
100 syn match zshLongDeref    '\$\%(MACHTYPE\|OLDPWD OPTARG\|OPTIND\|OSTYPE\|PPID\|PWD\|RANDOM\|SECONDS\|SHLVL\|signals\)'
101 syn match zshLongDeref    '\$\%(TRY_BLOCK_ERROR\|TTY\|TTYIDLE\|UID\|USERNAME\|VENDOR\|ZSH_NAME\|ZSH_VERSION\|REPLY\|reply\|TERM\)'
102
103 syn match zshDeref        '\$[=^~]*[#+]*\h\w*\>'
104
105 " Commands
106 syn match   zshCommands     '\%(^\|\s\)[.:]\ze\s'
107 syn keyword zshCommands     alias autoload bg bindkey break bye cap cd chdir
108 syn keyword zshCommands     clone comparguments compcall compctl compdescribe
109 syn keyword zshCommands     compfiles compgroups compquote comptags comptry
110 syn keyword zshCommands     compvalues continue declare dirs disable disown
111 syn keyword zshCommands     echo echotc echoti emulate enable eval exec exit
112 syn keyword zshCommands     export false fc fg functions getcap getln
113 syn keyword zshCommands     getopts hash history jobs kill let limit
114 syn keyword zshCommands     log logout popd print printf pushd pushln
115 syn keyword zshCommands     pwd r read readonly rehash return sched set
116 syn keyword zshCommands     setcap setopt shift source stat suspend test times
117 syn keyword zshCommands     trap true ttyctl type ulimit umask unalias
118 syn keyword zshCommands     unfunction unhash unlimit unset unsetopt vared
119 syn keyword zshCommands     wait whence where which zcompile zformat zftp zle
120 syn keyword zshCommands     zmodload zparseopts zprof zpty zregexparse zsocket
121 syn keyword zshCommands     zstyle ztcp
122
123 " Types
124 syn keyword zshTypes        float integer local typeset
125
126 " Switches
127 " XXX: this may be too much
128 syn match   zshSwitches     '\s\zs--\=[a-zA-Z0-9-]\+'
129
130 " Numbers
131 syn match   zshNumber       '[-+]\=0x\x\+\>'
132 syn match   zshNumber       '[-+]\=0\o\+\>'
133 syn match   zshNumber       '[-+]\=\d\+#[-+]\=\w\+\>'
134 syn match   zshNumber       '[-+]\=\d\+\.\d\+\>'
135
136 " Substitution
137 syn cluster zshSubst        contains=zshSubst,zshOldSubst
138 syn region  zshSubst        matchgroup=zshSubstDelim transparent start='\$(' skip='\\)' end=')' contains=TOP
139 syn region  zshSubst        matchgroup=zshSubstDelim transparent start='\$((' skip='\\)' end='))' contains=TOP
140 syn region  zshSubst        matchgroup=zshSubstDelim start='\${' skip='\\}' end='}' contains=@zshSubst
141 syn region  zshOldSubst     matchgroup=zshSubstDelim start=+`+ skip=+\\`+ end=+`+ contains=TOP,zshOldSubst
142
143 " Define the default highlighting.
144 " For version 5.7 and earlier: only when not done already
145 " For version 5.8 and later: only when an item doesn't have highlighting yet
146 if version >= 508 || !exists("did_zsh_syn_inits")
147   if version < 508
148     let did_zsh_syn_inits = 1
149     command -nargs=+ HiLink hi link <args>
150   else
151     command -nargs=+ HiLink hi def link <args>
152   endif
153
154   HiLink zshTodo            Todo
155   HiLink zshComment         Comment
156   HiLink zshPreProc         PreProc
157   HiLink zshQuoted          SpecialChar
158   HiLink zshString          String
159   HiLink zshStringDelimiter zshString
160   HiLink zshPOSIXString     zshString
161   HiLink zshJobSpec         Special
162   HiLink zshPrecommand      Special
163   HiLink zshDelimiter       Keyword
164   HiLink zshConditional     Conditional
165   HiLink zshException       Exception
166   HiLink zshRepeat          Repeat
167   HiLink zshKeyword         Keyword
168   HiLink zshFunction        Function
169   HiLink zshKSHFunction     zshFunction
170   HiLink zshHereDoc         String
171   HiLink zshOperator        Operator
172   HiLink zshRedir           Operator
173   HiLink zshVariable        Identifier
174   HiLink zshDereferencing   PreProc
175   if s:zsh_syntax_variables =~ 'short\|all'
176     HiLink zshShortDeref    zshDereferencing
177   else
178     HiLink zshShortDeref    None
179   endif
180   if s:zsh_syntax_variables =~ 'long\|all'
181     HiLink zshLongDeref     zshDereferencing
182   else
183     HiLink zshLongDeref    None
184   endif
185   if s:zsh_syntax_variables =~ 'all'
186     HiLink zshDeref         zshDereferencing
187   else
188     HiLink zshDerefDeref    None
189   endif
190   HiLink zshCommands        Keyword
191   HiLink zshTypes           Type
192   HiLink zshSwitches        Special
193   HiLink zshNumber          Number
194   HiLink zshSubst           PreProc
195   HiLink zshOldSubst        zshSubst
196   HiLink zshSubstDelim      zshSubst
197
198   delcommand HiLink
199 endif
200
201 let b:current_syntax = "zsh"
202
203 " vim: set sts=2 sw=2: