summaryrefslogtreecommitdiffstats
path: root/after/syntax/zsh.vim
blob: cf4f92462ea053d0e7d46b2d5821d58548352a2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
if polyglot#init#is_disabled(expand('<sfile>:p'), 'zinit', 'after/syntax/zsh.vim')
  finish
endif

" Copyright (c) 2019 Sebastian Gniazdowski
"
" Syntax highlighting for Zinit commands in any file of type `zsh'.
" It adds definitions for the Zinit syntax to the ones from the
" existing zsh.vim definitions-file.

" Main Zinit command.
" Should be the only TOP rule for the whole syntax.
syntax match ZinitCommand     /\<zinit\>\s/me=e-1
            \ skipwhite
            \ nextgroup=ZinitSubCommands,ZinitPluginSubCommands,ZinitSnippetSubCommands
            \ contains=ZinitSubCommands,ZinitPluginSubCommands,ZinitSnippetSubCommands

" TODO: add options for e.g. light
syntax match ZinitSubCommands /\s\<\%(ice\|compinit\|env-whitelist\|cdreplay\|cdclear\|update\)\>\s/ms=s+1,me=e-1
            \ contained

syntax match ZinitPluginSubCommands /\s\<\%(light\|load\)\>\s/ms=s+1,me=e-1
            \ skipwhite nextgroup=ZinitPlugin1,ZinitPlugin2,ZinitPlugin3
            \ contains=ZinitPlugin1,ZinitPlugin2,ZinitPlugin3

syntax match ZinitSnippetSubCommands /\s\<\%(snippet\)\>\s/ms=s+1,me=e-1
            \ skipwhite
            \ nextgroup=ZinitSnippetShorthands1,ZinitSnippetShorthands2
            \ contains=ZinitSnippetShorthands1,ZinitSnippetShorthands2

" "user/plugin"
syntax match ZinitPlugin1 /\s["]\%([!-_]*\%(\/[!-_]\+\)\+\|[!-_]\+\)["]/ms=s+1,hs=s+2,he=e-1
            \ contained
            \ nextgroup=ZinitTrailingWhiteSpace
            \ contains=ZinitTrailingWhiteSpace

" 'user/plugin'
syntax match ZinitPlugin2 /\s[']\%([!-_]*\%(\/[!-_]\+\)\+\|[!-_]\+\)[']/ms=s+1,hs=s+2,he=e-1
            \ contained
            \ nextgroup=ZinitTrailingWhiteSpace
            \ contains=ZinitTrailingWhiteSpace

" user/plugin
syntax match ZinitPlugin3 /\s\%([!-_]*\%(\/[!-_]\+\)\+\|[!-_]\+\)/ms=s+1,me=e+2 
            \ contained
            \ nextgroup=ZinitTrailingWhiteSpace
            \ contains=ZinitTrailingWhiteSpace

" OMZ:: or PZT::
" TODO: 'OMZ:: or 'PZT::
syntax match ZinitSnippetShorthands1 /\s\<\%(\%(OMZ\|PZT\)\>::\|\)/hs=s+1,he=e-2
            \ contained
            \ skipwhite
            \ nextgroup=ZinitSnippetUrl1,ZinitSnippetUrl2
            \ contains=ZinitSnippetUrl1,ZinitSnippetUrl2

" "OMZ:: or "PZT::
syntax match ZinitSnippetShorthands2 /\s["]\%(\%(OMZ\|PZT\)\>::\|\)/hs=s+2,he=e-2
            \ contained
            \ skipwhite
            \ nextgroup=ZinitSnippetUrl3,ZinitSnippetUrl4
            \ contains=ZinitSnippetUrl3,ZinitSnippetUrl4

syntax match ZinitSnippetUrl3 /\<\%(http:\/\/\|https:\/\/\|ftp:\/\/\|\$HOME\|\/\)[!-_]\+\%(\/[!-_]\+\)*\/\?["]/he=e-1
            \ contained
            \ nextgroup=ZinitTrailingWhiteSpace
            \ contains=ZinitTrailingWhiteSpace

" TODO: Fix ZinitTrailingWhiteSpace not matching
syntax match ZinitSnippetUrl4 /\%(\%(OMZ\|PZT\)::\)[!-_]\+\%(\/[!-_]\+\)*\/\?["]/hs=s+5,he=e-1
            \ contained
            \ nextgroup=ZinitTrailingWhiteSpace
            \ contains=ZinitTrailingWhiteSpace

" http://… or https://… or ftp://… or $HOME/… or /…
" TODO: Fix $HOME/… and /… not matching
syntax match ZinitSnippetUrl1 /\<\%(http:\/\/\|https:\/\/\|ftp:\/\/\|\$HOME\|\/\)[!-_]\+\%(\/[!-_]\+\)*\/\?/
            \ contained
            \ nextgroup=ZinitTrailingWhiteSpace
            \ contains=ZinitTrailingWhiteSpace

" TODO: Fix ZinitTrailingWhiteSpace not matching
syntax match ZinitSnippetUrl2 /\<\%(\%(OMZ\|PZT\)::\)[!-_]\+\%(\/[!-_]\+\)*\/\?/hs=s+5
            \ contained
            \ nextgroup=ZinitTrailingWhiteSpace
            \ contains=ZinitTrailingWhiteSpace

syntax match ZinitTrailingWhiteSpace /[[:space:]]\+$/ contained

" TODO: differentiate the no-value ices
" TODO: use contained
syntax match ZinitIceSubCommand /\sice\s/ms=s+1,me=e-1 nextgroup=ZinitIceModifiers
syntax match ZinitIceModifiers  /\s\<\%(svn\|proto\|from\|teleid\|bindmap\|cloneopts\|id-as\|depth\|if\|wait\|load\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(unload\|blockf\|on-update-of\|subscribe\|pick\|bpick\|src\|as\|ver\|silent\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(lucid\|notify\|mv\|cp\|atinit\|atclone\|atload\|atpull\|nocd\|run-atpull\|has\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(cloneonly\|make\|service\|trackbinds\|multisrc\|compile\|nocompile\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(nocompletions\|reset-prompt\|wrap-track\|reset\|aliases\|sh\|bash\|ksh\|csh\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(\\!sh\|!sh\|\\!bash\|!bash\|\\!ksh\|!ksh\|\\!csh\|!csh\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(blockf\|silent\|lucid\|trackbinds\|cloneonly\|nocd\|run-atpull\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(\|sh\|\!sh\|bash\|\!bash\|ksh\|\!ksh\|csh\|\!csh\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(nocompletions\|svn\|aliases\|trigger-load\)\>/ms=s+1
syntax match ZinitIceModifiers  /\s\<\%(light-mode\|is-snippet\|countdown\|ps-on-unload\|ps-on-update\)\>/ms=s+1
            
" Include also ices added by the existing annexes
syntax match ZinitIceModifiers  /\s\<\%(test\|zman\|submod\|dl\|patch\|fbin\|sbin\|fsrc\|ferc\|fmod\|gem\|node\|rustup\|cargo\)\>/ms=s+1
        
" Additional Zsh and Zinit functions
syntax match ZshAndZinitFunctions     /\<\%(compdef\|compinit\|zpcdreplay\|zpcdclear\|zpcompinit\|zpcompdef\)\>/

" Link
highlight def link ZshAndZinitFunctions    Keyword
highlight def link ZinitCommand            Statement
highlight def link ZinitSubCommands        Title
highlight def link ZinitPluginSubCommands  Title
highlight def link ZinitSnippetSubCommands Title
highlight def link ZinitIceModifiers       Type
highlight def link ZinitSnippetShorthands1 Keyword
highlight def link ZinitSnippetShorthands2 Keyword
highlight def link ZinitPlugin1            Macro
highlight def link ZinitPlugin2            Macro
highlight def link ZinitPlugin3            Macro
highlight def link ZinitSnippetUrl1        Macro
highlight def link ZinitSnippetUrl2        Macro
highlight def link ZinitSnippetUrl3        Macro
highlight def link ZinitSnippetUrl4        Macro
highlight def link ZinitTrailingWhiteSpace Error