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

Vim yodl syntax highlighting

I've sketched a Vim syntax file for zsh yodl files.  Not perfect yet but
better than no highlighting at all.

At this time there are two known issues:

- Parentheses that aren't part of a yodl macro confuse the parsing; example:
    chapter(foo (bar) baz)

- Macros nested within an underlined thing don't get underlined; example:
    sitem(foo)(bar tt(baz))


To test this, source it after opening a yodl file.

To install it permanently, save the attachment as ~/.vim/syntax/zyodl.vim
and put
    autocmd! BufRead,BufNewFile **/Doc/Zsh/*.yo	setfiletype zyodl
somewhere.  Putting it in vimrc is good enough, see ':help new-filetype'
for the official way.


I think all these macros are zsh specific (even 'chapter' and 'bf' are
defined in ztexi.yo), as opposed to yodl builtins.

Should this live in the zsh repository?  If it's useful to people it
should live alongside the code, but if it's just me, I'll throw it on my
personal github account.
"" Test case:
" if 0
" i
"   texinode()()()()
"   chapter(foo)
"   chapter(foo (foo) foo)
"   vindex(foo) 
"   foo tt(foo) var(foo) bf(foo) em(foo) foo
"   xitem(foo)
"   item(foo)(foo)
"   sitem(foo)(foo tt(foo) foo)
"   example(print *.c+LPAR()#q:s/#%+LPAR()#b+RPAR()s+LPAR()*+RPAR().c/'S${match[1]}.C'/+RPAR())
"   ifzman(zmanref(zshmisc))ifnzman(noderef(Redirection))
"   LPAR()foo 42 foo+RPAR()
" .
" endif

"" Syntax groups:
syn clear
syn cluster zyodlInline contains=zyodlTt,zyodlVar,zyodlBold,zyodlEmph,zyodlCond
syn region zyodlTt      start="\<tt("      end=")" contains=zyodlSpecial
syn region zyodlVar     start="\<var("     end=")" contains=zyodlSpecial
syn region zyodlBold    start="\<bf("      end=")" contains=zyodlSpecial
syn region zyodlEmph    start="\<em("      end=")" contains=zyodlSpecial
syn region zyodlIndex   start="\<.index("  end=")" contains=zyodlSpecial
syn match  zyodlSpecial "+\?\<\(LPAR\|RPAR\|PLUS\)()"
syn match  zyodlNumber  "\d\+"
syn region zyodlItem    start="\<xitem(" end=")" contains=zyodlSpecial,@zyodlInline
syn region zyodlItem    start="\<item("  end=")" contains=zyodlSpecial,@zyodlInline
syn region zyodlExample start="\<example(" end=")" contains=zyodlSpecial
syn region zyodlTitle   start="\<\(chapter\|subsect\|sect\)(" end=")" contains=zyodlSpecial,@zyodlInline
syn match  zyodlTitle   "^texinode\%x28.*$"

syn region zyodlCond    start="\<\(ifzman\|ifnzman\)(" end=")" contains=zyodlRef,zyodlSpecial,@zyodlInline
syn region zyodlRef     start="\<\(zmanref\|noderef\)(" end=")"

syn keyword zyodlKeyword sitem nextgroup=zyodlSItemArg1
syn region zyodlSItemArg1 oneline start="(" end=")" contains=zyodlSpecial,@zyodlInline nextgroup=zyodlSItemArg2 contained
syn region zyodlSItemArg2 start="(" end=")" contains=zyodlSpecial,@zyodlInline contained

"" Highlight groups:
hi def link zyodlTt Constant
hi def link zyodlVar Identifier
" Not ':hi def link zyodlBold Bold' since there's no such group.
hi def zyodlBold gui=bold cterm=bold
hi def link zyodlEmph Type
hi def link zyodlIndex Comment
hi def link zyodlSpecial Special
hi def link zyodlNumber Number
hi def link zyodlItem Keyword
hi def link zyodlExample String
hi def link zyodlTitle Title
hi def link zyodlCond Conditional
hi def link zyodlRef Include
hi def link zyodlSItemArg1 Macro
hi def link zyodlSItemArg2 Underlined

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