Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Vim syntax file for zsh

* Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx> [Dec 09, 2004 21:20]:
> First, a bug:  The zshVariable rule (after the "How safe is this?"
> comment) is misfiring on any [ that follows word characters.  For
> instance, add "echo hi[" early in a zsh script, and the entire script
> should become the Identifier color.

Well, that [ should be quoted, so I'm not persuaded yet.

> I don't know enough vim-syntax to fix this, so I just added XXXXX to
> the beginning of the "start" spec on that line, and the problem went
> away for now.

Well, just remove the whole line?

> I noticed that | and > are colored in the Operator color, but ; and &
> are not.  I'd prefer to see them all colored as operators.

I can't remember my reasoning here, but I believe it was that | and >
are rather more special than ; and &.  The & will also be highlighted in
&&.  Also, &! should be highlighted if & is.  However, I fear that
perhaps none of them should be highlighted, as they add too much color
to things that are obvious enough as it is.

Question: Who wants what here?  Personally, I'm contemplating on
removing them all, i.e., zshRedir will be gone.  It would be a bit
assymetrical if we leave zshHereDoc in, but they are rather more useful
to highlight.

Anyways, I added matching for them for now.  Tell me what you think, and
remember that syntax highlighting only helps if important things are
highlighted and background noise is kept as such.

> I like the sh/bash string idiom where the quotes are colored as
> operator characters instead of as string characters (since they
> delimit the string).  I simply changed the 3 uses of
> matchgroup=zshString into matchgroup=Operator, and it now works the
> way I want it to.

Yeah, well I hate it and I hate any syntax definition that does this to
me.  It annoys my eyes when two characters next to each other have
similar, but different, colors, especially when one is not much more
than 6 pixels altogether.  However, I may stretch it and have a
matchgroup=zshStringDelimiter that is linked to zshString by default and
then you may change it in your ~/.vim/after/syntax/zsh.vim.

> I don't like the highlighting of command-line options in the same
> color as a variable.  I just removed all the zshSwitches stuff, making
> them the default text color.

Well, it's not; it's highlighted as Special.  I could, however, agree
with you that it is of limited value and should probably be removed, or
at least not enabled by default.

> That's just my $.02.  Thanks for working on this!

No problem, suggestions are always welcome.

::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,lisp,war3 :::
" Vim syntax file
" Language:	    Zsh shell script
" Maintainer:	    Nikolai Weibull <source@xxxxxxxxxxxxx>
" URL:		    http://www.pcppopper.org/vim/syntax/pcp/zsh/
" Latest Revision:  2004-12-09
" arch-tag:	    2e2c7097-99cb-4b87-a771-3a819b69995e

if version < 600
  syntax clear
elseif exists("b:current_syntax")

" Set iskeyword since we need `-' (and potentially others) in keywords.
" For version 5.x: Set it globally
" For version 6.x: Set it locally
if version >= 600
  command -nargs=1 SetIsk setlocal iskeyword=<args>
  command -nargs=1 SetIsk set iskeyword=<args>
SetIsk @,48-57,_,-
delcommand SetIsk

" Todo
syn keyword zshTodo         contained TODO FIXME XXX NOTE

" Comments
syn region  zshComment      matchgroup=zshComment start='\(^\|\s\)#' end='$' contains=zshTodo

" PreProc
syn match   zshPreProc	    '^\%1l#\(!\|compdef\|autoload\).*$'

" Strings
syn match   zshQuoted       '\\.'
syn region  zshString       matchgroup=zshStringDelimiter start=+"+ end=+"+ contains=zshQuoted,@zshDerefs,zshSubst
syn region  zshString       matchgroup=zshStringDelimiter start=+'+ end=+'+
" 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
syn match   zshJobSpec      '%\(\d\+\|?\=\w\+\|[%+-]\)'

" Precommand Modifiers
syn keyword zshPrecommand   noglob nocorrect exec command builtin - time

" Delimiters
syn keyword zshDelimiter    do done

" Conditionals
syn keyword zshConditional  if then elif else fi case in esac select

" Loops
syn keyword zshRepeat       for while until repeat foreach

" Exceptions
syn keyword zshException    always

" Keywords
syn keyword zshKeyword      function nextgroup=zshKSHFunction skipwhite

" Functions
syn match   zshKSHFunction  contained '\k\+'
syn match   zshFunction     '\k\+\s*\ze()'

" Operators
syn match   zshOperator	    '||\|&&\|;\|&!\='

" Redirections
syn match   zshRedir        '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)'
syn match   zshRedir        '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\='
syn match   zshRedir        '|&\='

" Here Documents
if version < 600
  " Do nothing for now TODO: do something
  syn region  zshHereDoc  matchgroup=zshRedir start='<<\s*\z(\S*\)' end='^\z1$'
  syn region  zshHereDoc  matchgroup=zshRedir start='<<-\s*\z(\S*\)' end='^\s*\z1$'
  syn region  zshHereDoc  matchgroup=zshRedir start='<<\s*\z(["'\\]\S*\)'  end='^\z1$'
  syn region  zshHereDoc  matchgroup=zshRedir start='<<-\s*\z(["'\\]\S*\)' end='^\s*\z1$'

" Variable Assignments
syn match   zshVariable	    '\<\h\w*\ze+\=='
" XXX: how safe is this?
syn region  zshVariable	    matchgroup=zshVariable start='\$\@<!\<\h\w*\[' end='\]\ze+\==' contains=@zshSubst

" Variable Dereferencing
syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref

if !exists("g:zsh_syntax_variables")
  let s:zsh_syntax_variables = 'all'
  let s:zsh_syntax_variables = g:zsh_syntax_variables

if s:zsh_syntax_variables =~ 'short\|all'
  syn match zshShortDeref   '\$[!#$*@?_-]\w\@!'
  syn match zshShortDeref   '\$[=^~]*[#+]*\d\+\>'

if s:zsh_syntax_variables =~ 'long\|all'
  syn match zshLongDeref    '\$\(ARGC\|argv\|status\|pipestatus\|CPUTYPE\|EGID\|EUID\|ERRNO\|GID\|HOST\|LINENO\|LOGNAME\)'
  syn match zshLongDeref    '\$\(MACHTYPE\|OLDPWD OPTARG\|OPTIND\|OSTYPE\|PPID\|PWD\|RANDOM\|SECONDS\|SHLVL\|signals\)'

if s:zsh_syntax_variables =~ 'all'
  syn match zshDeref     '\$[=^~]*[#+]*\h\w*\>'

" Commands
syn match   zshCommands     '\s[.:]\s'
syn keyword zshCommands     alias autoload bg bindkey break bye cap cd chdir
syn keyword zshCommands     clone comparguments compcall compctl compdescribe
syn keyword zshCommands     compfiles compgroups compquote comptags comptry
syn keyword zshCommands     compvalues continue declare dirs disable disown
syn keyword zshCommands     echo echotc echoti emulate enable eval exec exit
syn keyword zshCommands     export false fc fg functions getcap getln
syn keyword zshCommands     getopts hash history jobs kill let limit
syn keyword zshCommands     log logout popd print printf pushd pushln
syn keyword zshCommands     pwd r read readonly rehash return sched set
syn keyword zshCommands     setcap setopt shift source stat suspend test times
syn keyword zshCommands     trap true ttyctl type ulimit umask unalias
syn keyword zshCommands     unfunction unhash unlimit unset unsetopt vared
syn keyword zshCommands     wait whence where which zcompile zformat zftp zle
syn keyword zshCommands     zmodload zparseopts zprof zpty zregexparse zsocket
syn keyword zshCommands     zstyle ztcp

" Types
syn keyword zshTypes        float integer local typeset

" Switches
" XXX: this may be too much
syn match   zshSwitches     '\s\zs--\=[a-zA-Z0-9-]\+'

" Numbers
syn match   zshNumber       '\<-\=\(\d\+#\|0x\=\)\=\d\+\>'
syn match   zshNumber       '\<-\=\d\+.\d\+\>'

" Substitution
" XXX: is this right?  something may be wrong here
syn cluster zshSubst	    contains=zshSubst,zshBrackets
syn region  zshBrackets	    transparent start='(' skip='\\)' end=')' contains=TOP
syn region  zshBrackets	    transparent start='{' skip='\\}' end='}' contains=TOP
syn region  zshSubst        matchgroup=zshDeref transparent start='\$(' skip='\\)' end=')' contains=TOP
syn region  zshSubst        matchgroup=zshDeref transparent start='\$((' end='))' contains=TOP
syn region  zshSubst	    matchgroup=zshSubst start='\${' skip='\\}' end='}' contains=@zshSubst
syn region  zshOldSubst	    matchgroup=zshOldSubst start=+`+ skip=+\\`+ end=+`+ contains=TOP,zshOldSubst

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_zsh_syn_inits")
  if version < 508
    let did_zsh_syn_inits = 1
    command -nargs=+ HiLink hi link <args>
    command -nargs=+ HiLink hi def link <args>

  HiLink zshTodo	    Todo
  HiLink zshComment	    Comment
  HiLink zshPreProc	    PreProc
  HiLink zshQuoted	    SpecialChar
  HiLink zshString	    String
  HiLink zshStringDelimiter zshString
  HiLink zshPOSIXString	    zshString
  HiLink zshJobSpec	    Special
  HiLink zshPrecommand	    Special
  HiLink zshDelimiter	    Keyword
  HiLink zshConditional	    Conditional
  HiLink zshException	    Exception
  HiLink zshRepeat	    Repeat
  HiLink zshKeyword	    Keyword
  HiLink zshFunction	    Function
  HiLink zshKSHFunction	    zshFunction
  HiLink zshHereDoc	    String
  HiLink zshOperator	    Operator
  HiLink zshRedir	    Operator
  HiLink zshVariable	    Identifier
  HiLink zshShortDeref	    zshDeref
  HiLink zshLongDeref	    zshDeref
  HiLink zshDeref	    PreProc
  HiLink zshCommands	    Keyword
  HiLink zshTypes	    Type
  HiLink zshSwitches	    Special
  HiLink zshNumber	    Number
  HiLink zshSubst	    zshDeref
  HiLink zshOldSubst	    zshSubst

  delcommand HiLink

let b:current_syntax = "zsh"

" vim: set sts=2 sw=2:

Messages sorted by: Reverse Date, Date, Thread, Author