diff --git a/runtime/compiler/zsh.vim b/runtime/compiler/zsh.vim new file mode 100644 index 0000000000..5703c1fc44 --- /dev/null +++ b/runtime/compiler/zsh.vim @@ -0,0 +1,23 @@ +" Vim compiler file +" Compiler: Zsh +" Maintainer: Doug Kearns +" Last Change: 2020 Sep 6 + +if exists("current_compiler") + finish +endif +let current_compiler = "zsh" + +if exists(":CompilerSet") != 2 " older Vim always used :setlocal + command -nargs=* CompilerSet setlocal +endif + +let s:cpo_save = &cpo +set cpo&vim + +CompilerSet makeprg=zsh\ -n\ --\ %:S +CompilerSet errorformat=%f:\ line\ %l:\ %m, + \%-G%.%# + +let &cpo = s:cpo_save +unlet s:cpo_save diff --git a/runtime/ftplugin/zsh.vim b/runtime/ftplugin/zsh.vim index fe8efc59ab..53ce1417dd 100644 --- a/runtime/ftplugin/zsh.vim +++ b/runtime/ftplugin/zsh.vim @@ -2,7 +2,7 @@ " Language: Zsh shell script " Maintainer: Christian Brabandt " Previous Maintainer: Nikolai Weibull -" Latest Revision: 2017-11-22 +" Latest Revision: 2020-09-01 " License: Vim (see :h license) " Repository: https://github.com/chrisbra/vim-zsh @@ -14,11 +14,26 @@ let b:did_ftplugin = 1 let s:cpo_save = &cpo set cpo&vim -let b:undo_ftplugin = "setl com< cms< fo<" - setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql -let b:match_words = ',\:\:\:\' +let b:undo_ftplugin = "setl com< cms< fo< " + +if executable('zsh') + if !has('gui_running') && executable('less') + command! -buffer -nargs=1 RunHelp silent exe '!MANPAGER= zsh -ic "autoload -Uz run-help; run-help 2>/dev/null | LESS= less"' | redraw! + elseif has('terminal') + command! -buffer -nargs=1 RunHelp silent exe ':term zsh -ic "autoload -Uz run-help; run-help "' + else + command! -buffer -nargs=1 RunHelp echo system('zsh -ic "autoload -Uz run-help; run-help 2>/dev/null"') + endif + if !exists('current_compiler') + compiler zsh + endif + setlocal keywordprg=:RunHelp + let b:undo_ftplugin .= 'keywordprg<' +endif + +let b:match_words = '\:\:\:\' \ . ',\:^\s*([^)]*):\' \ . ',\<\%(select\|while\|until\|repeat\|for\%(each\)\=\)\>:\' let b:match_skip = 's:comment\|string\|heredoc\|subst' diff --git a/runtime/syntax/zsh.vim b/runtime/syntax/zsh.vim index 3eba438aa7..819c419228 100644 --- a/runtime/syntax/zsh.vim +++ b/runtime/syntax/zsh.vim @@ -2,7 +2,7 @@ " Language: Zsh shell script " Maintainer: Christian Brabandt " Previous Maintainer: Nikolai Weibull -" Latest Revision: 2018-05-12 +" Latest Revision: 2020-11-21 " License: Vim (see :h license) " Repository: https://github.com/chrisbra/vim-zsh @@ -13,32 +13,44 @@ endif let s:cpo_save = &cpo set cpo&vim -if v:version > 704 || (v:version == 704 && has("patch1142")) - syn iskeyword @,48-57,_,192-255,#,- -else - setlocal iskeyword+=- -endif +function! s:ContainedGroup() + " needs 7.4.2008 for execute() function + let result='TOP' + " vim-pandoc syntax defines the @langname cluster for embedded syntax languages + " However, if no syntax is defined yet, `syn list @zsh` will return + " "No syntax items defined", so make sure the result is actually a valid syn cluster + for cluster in ['markdownHighlightzsh', 'zsh'] + try + " markdown syntax defines embedded clusters as @markdownhighlight, + " pandoc just uses @, so check both for both clusters + let a=split(execute('syn list @'. cluster), "\n") + if len(a) == 2 && a[0] =~# '^---' && a[1] =~? cluster + return '@'. cluster + endif + catch /E392/ + " ignore + endtry + endfor + return result +endfunction + +let s:contained=s:ContainedGroup() + +syn iskeyword @,48-57,_,192-255,#,- if get(g:, 'zsh_fold_enable', 0) setlocal foldmethod=syntax endif -syn keyword zshTodo contained TODO FIXME XXX NOTE - -syn region zshComment oneline start='\%(^\|\s\+\)#' end='$' - \ contains=zshTodo,@Spell fold - -syn region zshComment start='^\s*#' end='^\%(\s*#\)\@!' - \ contains=zshTodo,@Spell fold - -syn match zshPreProc '^\%1l#\%(!\|compdef\|autoload\).*$' - +syn match zshPOSIXQuoted '\\[xX][0-9a-fA-F]\{1,2}' +syn match zshPOSIXQuoted '\\[0-7]\{1,3}' +syn match zshPOSIXQuoted '\\u[0-9a-fA-F]\{1,4}' +syn match zshPOSIXQuoted '\\U[1-9a-fA-F]\{1,8}' syn match zshQuoted '\\.' syn region zshString matchgroup=zshStringDelimiter start=+"+ end=+"+ \ contains=zshQuoted,@zshDerefs,@zshSubst fold syn region zshString matchgroup=zshStringDelimiter start=+'+ end=+'+ fold -" XXX: This should probably be more precise, but Zsh seems a bit confused about it itself syn region zshPOSIXString matchgroup=zshStringDelimiter start=+\$'+ - \ end=+'+ contains=zshQuoted + \ skip=+\\[\\']+ end=+'+ contains=zshPOSIXQuoted,zshQuoted syn match zshJobSpec '%\(\d\+\|?\=\w\+\|[%+-]\)' syn keyword zshPrecommand noglob nocorrect exec command builtin - time @@ -112,7 +124,7 @@ syn keyword zshCommands alias autoload bg bindkey break bye cap cd \ enable eval exec exit export false fc fg \ functions getcap getln getopts hash history \ jobs kill let limit log logout popd print - \ printf pushd pushln pwd r read readonly + \ printf pushd pushln pwd r read \ rehash return sched set setcap shift \ source stat suspend test times trap true \ ttyctl type ulimit umask unalias unfunction @@ -125,7 +137,7 @@ syn keyword zshCommands alias autoload bg bindkey break bye cap cd " Create a list of option names from zsh source dir: " #!/bin/zsh " topdir=/path/to/zsh-xxx -" grep '^pindex([A-Za-z_]*)$' $topdir/Src/Doc/Zsh/optionsyo | +" grep '^pindex([A-Za-z_]*)$' $topdir/Doc/Zsh/options.yo | " while read opt " do " echo ${${(L)opt#pindex\(}%\)} @@ -136,6 +148,7 @@ syn case ignore syn match zshOptStart /^\s*\%(\%(\%(un\)\?setopt\)\|set\s+[-+]o\)/ nextgroup=zshOption skipwhite syn match zshOption / \ \%(\%(\\)\| + \ \%(\%(\\)\|\%(\%(no_\?\)\?alias_func_def\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?all_export\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?always_last_prompt\>\)\|\%(\%(no_\?\)\?always_lastprompt\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?always_to_end\>\)\| @@ -165,10 +178,13 @@ syn match zshOption / \ \%(\%(\\)\|\%(\%(no_\?\)\?case_match\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?c_bases\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?cdable_vars\>\)\|\%(\%(no_\?\)\?cd_able_vars\>\)\| + \ \%(\%(\\)\|\%(\%(no_\?\)\?cd_silent\>\)\|\%(\%(no_\?\)\?cd_silent\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?chase_dots\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?chase_links\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?check_jobs\>\)\| + \ \%(\%(\\)\|\%(\%(no_\?\)\?check_running_jobs\>\)\| \ \%(\%(\\)\| + \ \%(\%(\\)\|\%(\%(no_\?\)\?clobber_empty\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?combining_chars\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?complete_aliases\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?complete_in_word\>\)\| @@ -188,7 +204,7 @@ syn match zshOption / \ \%(\%(\\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?err_exit\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?err_return\>\)\| - \ \%(\%(\\)\|\%(\%(no_\?\)\?eval_lineno\>\)\| \ \%(\%(\\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?extended_glob\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?extended_history\>\)\| @@ -309,6 +325,7 @@ syn match zshOption / \ \%(\%(\\)\|\%(\%(no_\?\)\?sh_nullcmd\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?sh_option_letters\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?short_loops\>\)\| + \ \%(\%(\\)\|\%(\%(no_\?\)\?short_repeat\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?sh_word_split\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?single_command\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?single_line_zle\>\)\| @@ -322,10 +339,13 @@ syn match zshOption / \ \%(\%(\\)\| \ \%(\%(\\)\| \ \%(\%(\\)\| + \ \%(\%(\\)\|\%(\%(no_\?\)\?warn_nested_var\>\)\| \ \%(\%(\\)\|\%(\%(no_\?\)\?warn_create_global\>\)\| \ \%(\%(\\)\| \ \%(\%(\\)/ nextgroup=zshOption,zshComment skipwhite contained +syn case match + syn keyword zshTypes float integer local typeset declare private readonly " XXX: this may be too much @@ -339,31 +359,42 @@ syn match zshNumber '[+-]\=\d\+\.\d\+\>' " TODO: $[...] is the same as $((...)), so add that as well. syn cluster zshSubst contains=zshSubst,zshOldSubst,zshMathSubst -syn region zshSubst matchgroup=zshSubstDelim transparent - \ start='\$(' skip='\\)' end=')' contains=TOP fold +exe 'syn region zshSubst matchgroup=zshSubstDelim transparent start=/\$(/ skip=/\\)/ end=/)/ contains='.s:contained. ' fold' syn region zshParentheses transparent start='(' skip='\\)' end=')' fold syn region zshGlob start='(#' end=')' syn region zshMathSubst matchgroup=zshSubstDelim transparent - \ start='\$((' skip='\\)' end='))' + \ start='\%(\$\?\)[<=>]\@' +syn keyword zshTodo contained TODO FIXME XXX NOTE + +syn region zshComment oneline start='\%(^\|\s\+\)#' end='$' + \ contains=zshTodo,@Spell fold + +syn region zshComment start='^\s*#' end='^\%(\s*#\)\@!' + \ contains=zshTodo,@Spell fold + +syn match zshPreProc '^\%1l#\%(!\|compdef\|autoload\).*$' + hi def link zshTodo Todo hi def link zshComment Comment hi def link zshPreProc PreProc hi def link zshQuoted SpecialChar +hi def link zshPOSIXQuoted SpecialChar hi def link zshString String hi def link zshStringDelimiter zshString hi def link zshPOSIXString zshString