Mercurial > vim
annotate runtime/syntax/zsh.vim @ 27552:60f12889d36b
Added tag v8.2.4302 for changeset 845e518cda115ee5d88c6f7f9077e436ae518b59
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 05 Feb 2022 19:15:04 +0100 |
parents | f0d7cb510ce3 |
children | fee9eccee266 |
rev | line source |
---|---|
7 | 1 " Vim syntax file |
6823 | 2 " Language: Zsh shell script |
3 " Maintainer: Christian Brabandt <cb@256bit.org> | |
4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se> | |
23047 | 5 " Latest Revision: 2020-11-21 |
6823 | 6 " License: Vim (see :h license) |
11400 | 7 " Repository: https://github.com/chrisbra/vim-zsh |
7 | 8 |
1125 | 9 if exists("b:current_syntax") |
7 | 10 finish |
11 endif | |
12 | |
1125 | 13 let s:cpo_save = &cpo |
14 set cpo&vim | |
15 | |
19646 | 16 function! s:ContainedGroup() |
23047 | 17 " needs 7.4.2008 for execute() function |
19646 | 18 let result='TOP' |
19 " vim-pandoc syntax defines the @langname cluster for embedded syntax languages | |
20 " However, if no syntax is defined yet, `syn list @zsh` will return | |
21 " "No syntax items defined", so make sure the result is actually a valid syn cluster | |
22 for cluster in ['markdownHighlightzsh', 'zsh'] | |
23 try | |
24 " markdown syntax defines embedded clusters as @markdownhighlight<lang>, | |
25 " pandoc just uses @<lang>, so check both for both clusters | |
26 let a=split(execute('syn list @'. cluster), "\n") | |
27 if len(a) == 2 && a[0] =~# '^---' && a[1] =~? cluster | |
28 return '@'. cluster | |
29 endif | |
30 catch /E392/ | |
31 " ignore | |
32 endtry | |
33 endfor | |
34 return result | |
35 endfunction | |
36 | |
37 let s:contained=s:ContainedGroup() | |
38 | |
39 syn iskeyword @,48-57,_,192-255,#,- | |
8246
f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
40 if get(g:, 'zsh_fold_enable', 0) |
f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
41 setlocal foldmethod=syntax |
f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
42 endif |
1125 | 43 |
26708 | 44 syn match zshQuoted '\\.' |
19646 | 45 syn match zshPOSIXQuoted '\\[xX][0-9a-fA-F]\{1,2}' |
46 syn match zshPOSIXQuoted '\\[0-7]\{1,3}' | |
47 syn match zshPOSIXQuoted '\\u[0-9a-fA-F]\{1,4}' | |
48 syn match zshPOSIXQuoted '\\U[1-9a-fA-F]\{1,8}' | |
26708 | 49 |
1125 | 50 syn region zshString matchgroup=zshStringDelimiter start=+"+ end=+"+ |
8246
f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
51 \ contains=zshQuoted,@zshDerefs,@zshSubst fold |
f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
52 syn region zshString matchgroup=zshStringDelimiter start=+'+ end=+'+ fold |
1125 | 53 syn region zshPOSIXString matchgroup=zshStringDelimiter start=+\$'+ |
19646 | 54 \ skip=+\\[\\']+ end=+'+ contains=zshPOSIXQuoted,zshQuoted |
1125 | 55 syn match zshJobSpec '%\(\d\+\|?\=\w\+\|[%+-]\)' |
56 | |
57 syn keyword zshPrecommand noglob nocorrect exec command builtin - time | |
58 | |
6823 | 59 syn keyword zshDelimiter do done end |
1125 | 60 |
61 syn keyword zshConditional if then elif else fi case in esac select | |
62 | |
1698 | 63 syn keyword zshRepeat while until repeat |
64 | |
65 syn keyword zshRepeat for foreach nextgroup=zshVariable skipwhite | |
1125 | 66 |
67 syn keyword zshException always | |
68 | |
69 syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite | |
70 | |
8246
f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents:
7924
diff
changeset
|
71 syn match zshKSHFunction contained '\w\S\+' |
1125 | 72 syn match zshFunction '^\s*\k\+\ze\s*()' |
73 | |
74 syn match zshOperator '||\|&&\|;\|&!\=' | |
7 | 75 |
1125 | 76 syn match zshRedir '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)' |
77 syn match zshRedir '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\=' | |
78 syn match zshRedir '|&\=' | |
79 | |
1698 | 80 syn region zshHereDoc matchgroup=zshRedir |
81 \ start='<\@<!<<\s*\z([^<]\S*\)' | |
82 \ end='^\z1\>' | |
13912 | 83 \ contains=@zshSubst,@zshDerefs,zshQuoted,zshPOSIXString |
1698 | 84 syn region zshHereDoc matchgroup=zshRedir |
85 \ start='<\@<!<<\s*\\\z(\S\+\)' | |
86 \ end='^\z1\>' | |
13912 | 87 \ contains=@zshSubst,@zshDerefs,zshQuoted,zshPOSIXString |
1125 | 88 syn region zshHereDoc matchgroup=zshRedir |
1698 | 89 \ start='<\@<!<<-\s*\\\=\z(\S\+\)' |
90 \ end='^\s*\z1\>' | |
13912 | 91 \ contains=@zshSubst,@zshDerefs,zshQuoted,zshPOSIXString |
1125 | 92 syn region zshHereDoc matchgroup=zshRedir |
6823 | 93 \ start=+<\@<!<<\s*\(["']\)\z(\S\+\)\1+ |
1698 | 94 \ end='^\z1\>' |
95 syn region zshHereDoc matchgroup=zshRedir | |
96 \ start=+<\@<!<<-\s*\(["']\)\z(\S\+\)\1+ | |
1125 | 97 \ end='^\s*\z1\>' |
98 | |
1698 | 99 syn match zshVariable '\<\h\w*' contained |
100 | |
101 syn match zshVariableDef '\<\h\w*\ze+\==' | |
1125 | 102 " XXX: how safe is this? |
1698 | 103 syn region zshVariableDef oneline |
11400 | 104 \ start='\$\@<!\<\h\w*\[' end='\]\ze+\?=\?' |
1125 | 105 \ contains=@zshSubst |
106 | |
11400 | 107 syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref,zshDollarVar |
7 | 108 |
11400 | 109 syn match zshShortDeref '\$[!#$*@?_-]\w\@!' |
110 syn match zshShortDeref '\$[=^~]*[#+]*\d\+\>' | |
1125 | 111 |
11400 | 112 syn match zshLongDeref '\$\%(ARGC\|argv\|status\|pipestatus\|CPUTYPE\|EGID\|EUID\|ERRNO\|GID\|HOST\|LINENO\|LOGNAME\)' |
113 syn match zshLongDeref '\$\%(MACHTYPE\|OLDPWD OPTARG\|OPTIND\|OSTYPE\|PPID\|PWD\|RANDOM\|SECONDS\|SHLVL\|signals\)' | |
114 syn match zshLongDeref '\$\%(TRY_BLOCK_ERROR\|TTY\|TTYIDLE\|UID\|USERNAME\|VENDOR\|ZSH_NAME\|ZSH_VERSION\|REPLY\|reply\|TERM\)' | |
7 | 115 |
11400 | 116 syn match zshDollarVar '\$\h\w*' |
117 syn match zshDeref '\$[=^~]*[#+]*\h\w*\>' | |
7 | 118 |
1125 | 119 syn match zshCommands '\%(^\|\s\)[.:]\ze\s' |
120 syn keyword zshCommands alias autoload bg bindkey break bye cap cd | |
121 \ chdir clone comparguments compcall compctl | |
122 \ compdescribe compfiles compgroups compquote | |
123 \ comptags comptry compvalues continue dirs | |
124 \ disable disown echo echotc echoti emulate | |
125 \ enable eval exec exit export false fc fg | |
126 \ functions getcap getln getopts hash history | |
127 \ jobs kill let limit log logout popd print | |
18456 | 128 \ printf pushd pushln pwd r read |
11400 | 129 \ rehash return sched set setcap shift |
1125 | 130 \ source stat suspend test times trap true |
131 \ ttyctl type ulimit umask unalias unfunction | |
11400 | 132 \ unhash unlimit unset vared wait |
1125 | 133 \ whence where which zcompile zformat zftp zle |
13912 | 134 \ zmodload zparseopts zprof zpty zrecompile |
135 \ zregexparse zsocket zstyle ztcp | |
1125 | 136 |
26708 | 137 " Options, generated by from the zsh source with the make-options.zsh script. |
6823 | 138 syn case ignore |
26708 | 139 syn match zshOptStart |
140 \ /\v^\s*%(%(un)?setopt|set\s+[-+]o)/ | |
141 \ nextgroup=zshOption skipwhite | |
142 syn match zshOption nextgroup=zshOption,zshComment skipwhite contained /\v | |
143 \ <%(no_?)?%( | |
144 \ auto_?cd|auto_?pushd|cdable_?vars|cd_?silent|chase_?dots|chase_?links|posix_?cd|pushd_?ignore_?dups|pushd_?minus|pushd_?silent|pushd_?to_?home|always_?last_?prompt|always_?to_?end|auto_?list|auto_?menu|auto_?name_?dirs|auto_?param_?keys|auto_?param_?slash|auto_?remove_?slash|bash_?auto_?list|complete_?aliases|complete_?in_?word|glob_?complete|hash_?list_?all|list_?ambiguous|list_?beep|list_?packed|list_?rows_?first|list_?types|menu_?complete|rec_?exact|bad_?pattern|bare_?glob_?qual|brace_?ccl|case_?glob|case_?match|case_?paths|csh_?null_?glob|equals|extended_?glob|force_?float|glob|glob_?assign|glob_?dots|glob_?star_?short|glob_?subst|hist_?subst_?pattern|ignore_?braces|ignore_?close_?braces|ksh_?glob|magic_?equal_?subst|mark_?dirs|multibyte|nomatch|null_?glob|numeric_?glob_?sort|rc_?expand_?param|rematch_?pcre|sh_?glob|unset|warn_?create_?global|warn_?nested_?var|warnnestedvar|append_?history|bang_?hist|extended_?history|hist_?allow_?clobber|hist_?beep|hist_?expire_?dups_?first|hist_?fcntl_?lock|hist_?find_?no_?dups|hist_?ignore_?all_?dups|hist_?ignore_?dups|hist_?ignore_?space|hist_?lex_?words|hist_?no_?functions|hist_?no_?store|hist_?reduce_?blanks|hist_?save_?by_?copy|hist_?save_?no_?dups|hist_?verify|inc_?append_?history|inc_?append_?history_?time|share_?history|all_?export|global_?export|global_?rcs|rcs|aliases|clobber|clobber_?empty|correct|correct_?all|dvorak|flow_?control|ignore_?eof|interactive_?comments|hash_?cmds|hash_?dirs|hash_?executables_?only|mail_?warning|path_?dirs|path_?script|print_?eight_?bit|print_?exit_?value|rc_?quotes|rm_?star_?silent|rm_?star_?wait|short_?loops|short_?repeat|sun_?keyboard_?hack|auto_?continue|auto_?resume|bg_?nice|check_?jobs|check_?running_?jobs|hup|long_?list_?jobs|monitor|notify|posix_?jobs|prompt_?bang|prompt_?cr|prompt_?sp|prompt_?percent|prompt_?subst|transient_?rprompt|alias_?func_?def|c_?bases|c_?precedences|debug_?before_?cmd|err_?exit|err_?return|eval_?lineno|exec|function_?argzero|local_?loops|local_?options|local_?patterns|local_?traps|multi_?func_?def|multios|octal_?zeroes|pipe_?fail|source_?trace|typeset_?silent|typeset_?to_?unset|verbose|xtrace|append_?create|bash_?rematch|bsd_?echo|continue_?on_?error|csh_?junkie_?history|csh_?junkie_?loops|csh_?junkie_?quotes|csh_?nullcmd|ksh_?arrays|ksh_?autoload|ksh_?option_?print|ksh_?typeset|ksh_?zero_?subscript|posix_?aliases|posix_?argzero|posix_?builtins|posix_?identifiers|posix_?strings|posix_?traps|sh_?file_?expansion|sh_?nullcmd|sh_?option_?letters|sh_?word_?split|traps_?async|interactive|login|privileged|restricted|shin_?stdin|single_?command|beep|combining_?chars|emacs|overstrike|single_?line_?zle|vi|zle|brace_?expand|dot_?glob|hash_?all|hist_?append|hist_?expand|log|mail_?warn|one_?cmd|physical|prompt_?vars|stdin|track_?all|no_?match | |
145 \)>/ | |
23047 | 146 syn case match |
147 | |
12968 | 148 syn keyword zshTypes float integer local typeset declare private readonly |
7 | 149 |
1125 | 150 " XXX: this may be too much |
151 " syn match zshSwitches '\s\zs--\=[a-zA-Z0-9-]\+' | |
7 | 152 |
1125 | 153 syn match zshNumber '[+-]\=\<\d\+\>' |
154 syn match zshNumber '[+-]\=\<0x\x\+\>' | |
155 syn match zshNumber '[+-]\=\<0\o\+\>' | |
156 syn match zshNumber '[+-]\=\d\+#[-+]\=\w\+\>' | |
157 syn match zshNumber '[+-]\=\d\+\.\d\+\>' | |
7 | 158 |
1698 | 159 " TODO: $[...] is the same as $((...)), so add that as well. |
1125 | 160 syn cluster zshSubst contains=zshSubst,zshOldSubst,zshMathSubst |
19646 | 161 exe 'syn region zshSubst matchgroup=zshSubstDelim transparent start=/\$(/ skip=/\\)/ end=/)/ contains='.s:contained. ' fold' |
7924
00d64eb49ce1
commit https://github.com/vim/vim/commit/681baaf4a4c81418693dcafb81421a8614832e91
Christian Brabandt <cb@256bit.org>
parents:
7477
diff
changeset
|
162 syn region zshParentheses transparent start='(' skip='\\)' end=')' fold |
11400 | 163 syn region zshGlob start='(#' end=')' |
1125 | 164 syn region zshMathSubst matchgroup=zshSubstDelim transparent |
23047 | 165 \ start='\%(\$\?\)[<=>]\@<!((' skip='\\)' end='))' |
1125 | 166 \ contains=zshParentheses,@zshSubst,zshNumber, |
26708 | 167 \ @zshDerefs,zshString fold |
19646 | 168 " The ms=s+1 prevents matching zshBrackets several times on opening brackets |
169 " (see https://github.com/chrisbra/vim-zsh/issues/21#issuecomment-576330348) | |
170 syn region zshBrackets contained transparent start='{'ms=s+1 skip='\\}' | |
7924
00d64eb49ce1
commit https://github.com/vim/vim/commit/681baaf4a4c81418693dcafb81421a8614832e91
Christian Brabandt <cb@256bit.org>
parents:
7477
diff
changeset
|
171 \ end='}' fold |
19646 | 172 exe 'syn region zshBrackets transparent start=/{/ms=s+1 skip=/\\}/ end=/}/ contains='.s:contained. ' fold' |
173 | |
1125 | 174 syn region zshSubst matchgroup=zshSubstDelim start='\${' skip='\\}' |
7924
00d64eb49ce1
commit https://github.com/vim/vim/commit/681baaf4a4c81418693dcafb81421a8614832e91
Christian Brabandt <cb@256bit.org>
parents:
7477
diff
changeset
|
175 \ end='}' contains=@zshSubst,zshBrackets,zshQuoted,zshString fold |
19646 | 176 exe 'syn region zshOldSubst matchgroup=zshSubstDelim start=/`/ skip=/\\[\\`]/ end=/`/ contains='.s:contained. ',zshOldSubst fold' |
7 | 177 |
6823 | 178 syn sync minlines=50 maxlines=90 |
1698 | 179 syn sync match zshHereDocSync grouphere NONE '<<-\=\s*\%(\\\=\S\+\|\(["']\)\S\+\1\)' |
180 syn sync match zshHereDocEndSync groupthere NONE '^\s*EO\a\+\>' | |
181 | |
23047 | 182 syn keyword zshTodo contained TODO FIXME XXX NOTE |
183 | |
184 syn region zshComment oneline start='\%(^\|\s\+\)#' end='$' | |
185 \ contains=zshTodo,@Spell fold | |
186 | |
187 syn region zshComment start='^\s*#' end='^\%(\s*#\)\@!' | |
188 \ contains=zshTodo,@Spell fold | |
189 | |
190 syn match zshPreProc '^\%1l#\%(!\|compdef\|autoload\).*$' | |
191 | |
1125 | 192 hi def link zshTodo Todo |
193 hi def link zshComment Comment | |
194 hi def link zshPreProc PreProc | |
195 hi def link zshQuoted SpecialChar | |
19646 | 196 hi def link zshPOSIXQuoted SpecialChar |
1125 | 197 hi def link zshString String |
198 hi def link zshStringDelimiter zshString | |
199 hi def link zshPOSIXString zshString | |
200 hi def link zshJobSpec Special | |
201 hi def link zshPrecommand Special | |
202 hi def link zshDelimiter Keyword | |
203 hi def link zshConditional Conditional | |
204 hi def link zshException Exception | |
205 hi def link zshRepeat Repeat | |
206 hi def link zshKeyword Keyword | |
207 hi def link zshFunction None | |
208 hi def link zshKSHFunction zshFunction | |
209 hi def link zshHereDoc String | |
6823 | 210 hi def link zshOperator None |
211 hi def link zshRedir Operator | |
1125 | 212 hi def link zshVariable None |
1698 | 213 hi def link zshVariableDef zshVariable |
1125 | 214 hi def link zshDereferencing PreProc |
11400 | 215 hi def link zshShortDeref zshDereferencing |
216 hi def link zshLongDeref zshDereferencing | |
217 hi def link zshDeref zshDereferencing | |
218 hi def link zshDollarVar zshDereferencing | |
1125 | 219 hi def link zshCommands Keyword |
11400 | 220 hi def link zshOptStart Keyword |
221 hi def link zshOption Constant | |
1125 | 222 hi def link zshTypes Type |
223 hi def link zshSwitches Special | |
224 hi def link zshNumber Number | |
225 hi def link zshSubst PreProc | |
226 hi def link zshMathSubst zshSubst | |
227 hi def link zshOldSubst zshSubst | |
228 hi def link zshSubstDelim zshSubst | |
11400 | 229 hi def link zshGlob zshSubst |
7 | 230 |
231 let b:current_syntax = "zsh" | |
232 | |
1125 | 233 let &cpo = s:cpo_save |
234 unlet s:cpo_save |