7
|
1 " Vim syntax file
|
|
2 " Language: C-shell (tcsh)
|
775
|
3 " Maintainor: Gautam Iyer <gautam@math.uchicago.edu>
|
|
4 " Last Modified: Sat 11 Mar 2006 11:16:47 AM CST
|
7
|
5 "
|
|
6 " Description: We break up each statement into a "command" and an "end" part.
|
|
7 " All groups are either a "command" or part of the "end" of a statement (ie
|
|
8 " everything after the "command"). This is because blindly highlighting tcsh
|
|
9 " statements as keywords caused way too many false positives. Eg:
|
|
10 "
|
775
|
11 " set history=200
|
7
|
12 "
|
|
13 " causes history to come up as a keyword, which we want to avoid.
|
|
14
|
|
15 " Quit when a syntax file was already loaded
|
|
16 if exists("b:current_syntax")
|
|
17 finish
|
|
18 endif
|
|
19
|
|
20 syn case match
|
|
21
|
|
22 " ----- Clusters -----
|
|
23 syn cluster tcshModifiers contains=tcshModifier,tcshModifierError
|
|
24 syn cluster tcshQuoteList contains=tcshDQuote,tcshSQuote,tcshBQuote
|
|
25 syn cluster tcshStatementEnds contains=@tcshQuoteList,tcshComment,tcshUsrVar,TcshArgv,tcshSubst,tcshRedir,tcshMeta,tcshHereDoc,tcshSpecial,tcshArguement
|
|
26 syn cluster tcshStatements contains=tcshBuiltins,tcshCommands,tcshSet,tcshSetEnv,tcshAlias,tcshIf,tcshWhile
|
|
27 syn cluster tcshVarList contains=tcshUsrVar,tcshArgv,tcshSubst
|
|
28
|
|
29 " ----- Statements -----
|
|
30 " Tcsh commands: Any filename / modifiable variable (must be first!)
|
|
31 syn match tcshCommands '\v[a-zA-Z0-9\\./_$:-]+' contains=tcshSpecial,tcshUsrVar,tcshArgv,tcshVarError nextgroup=tcshStatementEnd
|
|
32
|
|
33 " Builtin commands except (un)set(env), (un)alias, if, while, else
|
|
34 syn keyword tcshBuiltins nextgroup=tcshStatementEnd alloc bg bindkey break breaksw builtins bye case cd chdir complete continue default dirs echo echotc end endif endsw eval exec exit fg filetest foreach getspath getxvers glob goto hashstat history hup inlib jobs kill limit log login logout ls ls-F migrate newgrp nice nohup notify onintr popd printenv pushd rehash repeat rootnode sched setpath setspath settc setty setxvers shift source stop suspend switch telltc time umask uncomplete unhash universe unlimit ver wait warp watchlog where which
|
|
35
|
|
36 " StatementEnd is anything after a builtin / command till the lexical end of a
|
|
37 " statement (;, |, ||, |&, && or end of line)
|
|
38 syn region tcshStatementEnd transparent contained matchgroup=tcshBuiltins start='' end='\v\\@<!(;|\|[|&]?|\&\&|$)' contains=@tcshStatementEnds
|
|
39
|
|
40 " set expressions (Contains shell variables)
|
|
41 syn keyword tcshShellVar contained afsuser ampm argv autocorrect autoexpand autolist autologout backslash_quote catalog cdpath color colorcat command complete continue continue_args correct cwd dextract dirsfile dirstack dspmbyte dunique echo echo_style edit ellipsis fignore filec gid group histchars histdup histfile histlit history home ignoreeof implicitcd inputmode killdup killring listflags listjobs listlinks listmax listmaxrows loginsh logout mail matchbeep nobeep noclobber noding noglob nokanji nonomatch nostat notify oid owd path printexitvalue prompt prompt2 prompt3 promptchars pushdtohome pushdsilent recexact recognize_only_executables rmstar rprompt savedirs savehist sched shell shlvl status symlinks tcsh term time tperiod tty uid user verbose version visiblebell watch who wordchars
|
|
42 syn keyword tcshSet nextgroup=tcshSetEnd set unset
|
|
43 syn region tcshSetEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshShellVar,@tcshStatementEnds
|
|
44
|
|
45 " setenv expressions (Contains enviorenment variables)
|
|
46 syn keyword tcshEnvVar contained AFSUSER COLUMNS DISPLAY EDITOR GROUP HOME HOST HOSTTYPE HPATH LANG LC_CTYPE LINES LS_COLORS MACHTYPE NOREBIND OSTYPE PATH PWD REMOTEHOST SHLVL SYSTYPE TERM TERMCAP USER VENDOR VISUAL
|
|
47 syn keyword tcshSetEnv nextgroup=tcshEnvEnd setenv unsetenv
|
|
48 syn region tcshEnvEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshEnvVar,@tcshStatementEnds
|
|
49
|
|
50 " alias and unalias (contains special aliases)
|
|
51 syn keyword tcshAliases contained beemcmd cwdcmd jobcmd helpcommand periodic precmd postcmd shell
|
|
52 syn keyword tcshAlias nextgroup=tcshAliEnd alias unalias
|
|
53 syn region tcshAliEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="$\|;" contains=tcshAliases,@tcshStatementEnds
|
|
54
|
|
55 " if statements (contains expressions / operators)
|
|
56 syn keyword tcshIf nextgroup=tcshIfEnd if
|
|
57 syn region tcshIfEnd contained matchgroup=tcshBuiltins start='' skip="\\$" end="\v<then>|$" contains=tcshOperator,tcshNumber,@tcshStatementEnds
|
|
58
|
|
59 " else statements (nextgroup if)
|
|
60 syn keyword tcshElse nextgroup=tcshIf skipwhite else
|
|
61
|
|
62 " while statements (contains expressions / operators)
|
|
63 syn keyword tcshWhile nextgroup=tcshWhEnd while
|
|
64 syn region tcshWhEnd contained transparent matchgroup=tcshBuiltins start='' skip="\\$" end="\v$" contains=tcshOperator,tcshNumber,@tcshStatementEnds
|
|
65
|
|
66 " Expressions start with @.
|
|
67 syn match tcshExprStart "\v\@\s+" nextgroup=tcshExprVar
|
|
68 syn match tcshExprVar contained "\v\h\w*%(\[\d+\])?" contains=tcshShellVar,tcshEnvVar nextgroup=tcshExprOp
|
|
69 syn match tcshExprOp contained "++\|--"
|
|
70 syn match tcshExprOp contained "\v\s*\=" nextgroup=tcshExprEnd
|
|
71 syn match tcshExprEnd contained "\v.*$"hs=e+1 contains=tcshOperator,tcshNumber,@tcshVarList
|
|
72 syn match tcshExprEnd contained "\v.{-};"hs=e contains=tcshOperator,tcshNumber,@tcshVarList
|
|
73
|
|
74 " ----- Comments: -----
|
|
75 syn match tcshComment "#.*" contains=tcshTodo,tcshCommentTi,tcshCommentSp,@Spell
|
|
76 syn match tcshSharpBang "^#! .*$"
|
|
77 syn match tcshCommentTi contained '\v#\s*\u\w*(\s+\u\w*)*:'hs=s+1 contains=tcshTodo
|
|
78 syn match tcshCommentSp contained '\v<\u{3,}>' contains=tcshTodo
|
|
79 syn match tcshTodo contained '\v\c<todo>'
|
|
80
|
|
81 " ----- Strings -----
|
|
82 " Tcsh does not allow \" in strings unless the "backslash_quote" shell
|
|
83 " variable is set. Set the vim variable "tcsh_backslash_quote" to 0 if you
|
|
84 " want VIM to assume that no backslash quote constructs exist.
|
|
85
|
|
86 " Backquotes are treated as commands, and are not contained in anything
|
|
87 if(exists("tcsh_backslash_quote") && tcsh_backslash_quote == 0)
|
|
88 syn region tcshSQuote keepend contained start="\v\\@<!'" end="'" contains=@Spell
|
|
89 syn region tcshDQuote keepend contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
|
|
90 syn region tcshBQuote keepend start='\v\\@<!`' end='`' contains=@tcshStatements
|
|
91 else
|
|
92 syn region tcshSQuote contained start="\v\\@<!'" skip="\v\\\\|\\'" end="'" contains=@Spell
|
|
93 syn region tcshDQuote contained start='\v\\@<!"' end='"' contains=@tcshVarList,tcshSpecial,@Spell
|
|
94 syn region tcshBQuote keepend matchgroup=tcshBQuoteGrp start='\v\\@<!`' skip='\v\\\\|\\`' end='`' contains=@tcshStatements
|
|
95 endif
|
|
96
|
|
97 " ----- Variables -----
|
|
98 " Variable Errors. Must come first! \$ constructs will be flagged by
|
|
99 " tcshSpecial, so we don't consider them here.
|
|
100 syn match tcshVarError '\v\$\S*' contained
|
|
101
|
|
102 " Modifiable Variables without {}.
|
|
103 syn match tcshUsrVar contained "\v\$\h\w*%(\[\d+%(-\d+)?\])?" nextgroup=@tcshModifiers contains=tcshShellVar,tcshEnvVar
|
|
104 syn match tcshArgv contained "\v\$%(\d+|\*)" nextgroup=@tcshModifiers
|
|
105
|
|
106 " Modifiable Variables with {}.
|
|
107 syn match tcshUsrVar contained "\v\$\{\h\w*%(\[\d+%(-\d+)?\])?%(:\S*)?\}" contains=@tcshModifiers,tcshShellVar,tcshEnvVar
|
|
108 syn match tcshArgv contained "\v\$\{%(\d+|\*)%(:\S*)?\}" contains=@tcshModifiers
|
|
109
|
|
110 " UnModifiable Substitutions. Order is important here.
|
|
111 syn match tcshSubst contained "\v\$[?#$!_<]" nextgroup=tcshModifierError
|
|
112 syn match tcshSubst contained "\v\$[%#?]%(\h\w*|\d+)" nextgroup=tcshModifierError contains=tcshShellVar,tcshEnvVar
|
|
113 syn match tcshSubst contained "\v\$\{[%#?]%(\h\w*|\d+)%(:\S*)?\}" contains=tcshModifierError contains=tcshShellVar,tcshEnvVar
|
|
114
|
|
115 " Variable Name Expansion Modifiers (order important)
|
|
116 syn match tcshModifierError contained '\v:\S*'
|
|
117 syn match tcshModifier contained '\v:[ag]?[htreuls&qx]' nextgroup=@tcshModifiers
|
|
118
|
|
119 " ----- Operators / Specials -----
|
|
120 " Standard redirects (except <<) [<, >, >>, >>&, >>!, >>&!]
|
|
121 syn match tcshRedir contained "\v\<|\>\>?\&?!?"
|
|
122
|
|
123 " Metachars
|
|
124 syn match tcshMeta contained "\v[]{}*?[]"
|
|
125
|
|
126 " Here Documents (<<)
|
|
127 syn region tcshHereDoc contained matchgroup=tcshRedir start="\v\<\<\s*\z(\h\w*)" end="^\z1$" contains=@tcshVarList,tcshSpecial
|
|
128 syn region tcshHereDoc contained matchgroup=tcshRedir start="\v\<\<\s*'\z(\h\w*)'" start='\v\<\<\s*"\z(\h\w*)"$' start="\v\<\<\s*\\\z(\h\w*)$" end="^\z1$"
|
|
129
|
|
130 " Operators
|
|
131 syn match tcshOperator contained "&&\|!\~\|!=\|<<\|<=\|==\|=\~\|>=\|>>\|\*\|\^\|\~\|||\|!\|%\|&\|+\|-\|/\|<\|>\||"
|
|
132 syn match tcshOperator contained "[(){}]"
|
|
133
|
|
134 " Numbers
|
|
135 syn match tcshNumber contained "\v<-?\d+>"
|
|
136
|
|
137 " Arguements
|
|
138 syn match tcshArguement contained "\v\s@<=-(\w|-)*"
|
|
139
|
|
140 " Special charectors
|
|
141 syn match tcshSpecial contained "\v\\@<!\\(\d{3}|.)"
|
|
142
|
|
143 " ----- Syncronising -----
|
|
144 if exists("tcsh_minlines")
|
|
145 exec "syn sync minlines=" . tcsh_minlines
|
|
146 else
|
|
147 syn sync minlines=15 " Except 'here' documents, nothing is long
|
|
148 endif
|
|
149
|
|
150 " Define highlighting of syntax groups
|
|
151 hi def link tcshBuiltins statement
|
|
152 hi def link tcshShellVar preproc
|
|
153 hi def link tcshEnvVar tcshShellVar
|
|
154 hi def link tcshAliases tcshShellVar
|
|
155 hi def link tcshCommands identifier
|
|
156 hi def link tcshSet tcshBuiltins
|
|
157 hi def link tcshSetEnv tcshBuiltins
|
|
158 hi def link tcshAlias tcshBuiltins
|
|
159 hi def link tcshIf tcshBuiltins
|
|
160 hi def link tcshElse tcshBuiltins
|
|
161 hi def link tcshWhile tcshBuiltins
|
|
162 hi def link tcshExprStart tcshBuiltins
|
|
163 hi def link tcshExprVar tcshUsrVar
|
|
164 hi def link tcshExprOp tcshOperator
|
|
165 hi def link tcshExprEnd tcshOperator
|
|
166 hi def link tcshComment comment
|
|
167 hi def link tcshCommentTi preproc
|
775
|
168 hi def link tcshCommentSp tcshCommentTi
|
|
169 hi def link tcshSharpBang tcshCommentTi
|
7
|
170 hi def link tcshTodo todo
|
|
171 hi def link tcshSQuote constant
|
|
172 hi def link tcshDQuote tcshSQuote
|
|
173 hi def link tcshBQuoteGrp include
|
|
174 hi def link tcshVarError error
|
|
175 hi def link tcshUsrVar type
|
|
176 hi def link tcshArgv tcshUsrVar
|
|
177 hi def link tcshSubst tcshUsrVar
|
|
178 hi def link tcshModifier tcshArguement
|
|
179 hi def link tcshModifierError tcshVarError
|
|
180 hi def link tcshMeta tcshSubst
|
|
181 hi def link tcshRedir tcshOperator
|
|
182 hi def link tcshHereDoc tcshSQuote
|
|
183 hi def link tcshOperator operator
|
|
184 hi def link tcshNumber number
|
|
185 hi def link tcshArguement special
|
|
186 hi def link tcshSpecial specialchar
|
|
187
|
|
188 let b:current_syntax = "tcsh"
|