3 " Maintainer: Taylor Venable <taylor@metasyntax.net>
4 " (previously Brett Cannon <brett@python.org>)
5 " (previously Dean Copsey <copsey@cs.ucdavis.edu>)
6 " (previously Matt Neumann <mattneu@purpleturtle.com>)
7 " (previously Allan Kelly <allan@fruitloaf.co.uk>)
8 " Original: Robin Becker <robin@jessikat.demon.co.uk>
9 " Last Change: 2009/04/06 02:38:36
11 " URL: http://real.metasyntax.net:2357/cvs/cvsweb.cgi/Config/vim/syntax/tcl.vim
13 " Keywords TODO: click anchor
15 " For version 5.x: Clear all syntax items
16 " For version 6.x: Quit when a syntax file was already loaded
19 elseif exists("b:current_syntax")
23 " Basic Tcl commands: http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm
24 syn keyword tclCommand after append apply array bgerror binary catch cd chan clock
25 syn keyword tclCommand close concat dde dict encoding eof error eval exec exit
26 syn keyword tclCommand expr fblocked fconfigure fcopy file fileevent filename flush
27 syn keyword tclCommand format gets glob global history incr info interp join
28 syn keyword tclCommand lappend lassign lindex linsert list llength load lrange lrepeat
29 syn keyword tclCommand lreplace lreverse lsearch lset lsort memory namespace open package
30 syn keyword tclCommand pid proc puts pwd read regexp registry regsub rename return
31 syn keyword tclCommand scan seek set socket source split string subst tell time
32 syn keyword tclCommand trace unknown unload unset update uplevel upvar variable vwait
34 " The 'Tcl Standard Library' commands: http://www.tcl.tk/man/tcl8.5/TclCmd/library.htm
35 syn keyword tclCommand auto_execok auto_import auto_load auto_mkindex auto_mkindex_old
36 syn keyword tclCommand auto_qualify auto_reset parray tcl_endOfWord tcl_findLibrary
37 syn keyword tclCommand tcl_startOfNextWord tcl_startOfPreviousWord tcl_wordBreakAfter
38 syn keyword tclCommand tcl_wordBreakBefore
40 " Commands that were added in Tcl 8.6
42 syn keyword tclCommand my oo::copy oo::define oo::objdefine self
43 syn keyword tclCommand coroutine tailcall throw yield
45 " Global variables used by Tcl: http://www.tcl.tk/man/tcl8.5/TclCmd/tclvars.htm
46 syn keyword tclVars env errorCode errorInfo tcl_library tcl_patchLevel tcl_pkgPath
47 syn keyword tclVars tcl_platform tcl_precision tcl_rcFileName tcl_traceCompile
48 syn keyword tclVars tcl_traceExec tcl_wordchars tcl_nonwordchars tcl_version argc argv
49 syn keyword tclVars argv0 tcl_interactive geometry
51 " Strings which expr accepts as boolean values, aside from zero / non-zero.
52 syn keyword tclBoolean true false on off yes no
54 syn keyword tclLabel case default
55 syn keyword tclConditional if then else elseif switch
56 syn keyword tclConditional try finally
57 syn keyword tclRepeat while for foreach break continue
58 syn keyword tcltkSwitch contained insert create polygon fill outline tag
61 " commands associated with widgets
62 syn keyword tcltkWidgetSwitch contained background highlightbackground insertontime cget
63 syn keyword tcltkWidgetSwitch contained selectborderwidth borderwidth highlightcolor insertwidth
64 syn keyword tcltkWidgetSwitch contained selectforeground cursor highlightthickness padx setgrid
65 syn keyword tcltkWidgetSwitch contained exportselection insertbackground pady takefocus
66 syn keyword tcltkWidgetSwitch contained font insertborderwidth relief xscrollcommand
67 syn keyword tcltkWidgetSwitch contained foreground insertofftime selectbackground yscrollcommand
68 syn keyword tcltkWidgetSwitch contained height spacing1 spacing2 spacing3
69 syn keyword tcltkWidgetSwitch contained state tabs width wrap
71 syn keyword tcltkWidgetSwitch contained command default
73 syn keyword tcltkWidgetSwitch contained closeenough confine scrollregion xscrollincrement yscrollincrement orient
74 " checkbutton, radiobutton
75 syn keyword tcltkWidgetSwitch contained indicatoron offvalue onvalue selectcolor selectimage state variable
77 syn keyword tcltkWidgetSwitch contained show class colormap container visual
79 syn keyword tcltkWidgetSwitch contained selectmode postcommand selectcolor tearoff tearoffcommand title type
81 syn keyword tcltkWidgetSwitch contained direction aspect justify
83 syn keyword tcltkWidgetSwitch contained bigincrement digits from length resolution showvalue sliderlength sliderrelief tickinterval to
85 syn keyword tcltkWidgetSwitch contained activerelief elementborderwidth
87 syn keyword tcltkWidgetSwitch contained delete names types create
89 " ::optional::namespaces
90 syn match tclVarRef "$\(\(::\)\?\([[:alnum:]_]*::\)*\)\a[[:alnum:]_]*"
91 " ${...} may contain any character except '}'
92 syn match tclVarRef "${[^}]*}"
94 " The syntactic unquote-splicing replacement for [expand].
95 syn match tclExpand '\s{\*}'
96 syn match tclExpand '^{\*}'
99 syn keyword tcltkWidgetSwitch contained active end last none cascade checkbutton command radiobutton separator
100 syn keyword tcltkWidgetSwitch contained activebackground actveforeground accelerator background bitmap columnbreak
101 syn keyword tcltkWidgetSwitch contained font foreground hidemargin image indicatoron label menu offvalue onvalue
102 syn keyword tcltkWidgetSwitch contained selectcolor selectimage state underline value variable
103 syn keyword tcltkWidgetSwitch contained add clone configure delete entrycget entryconfigure index insert invoke
104 syn keyword tcltkWidgetSwitch contained post postcascade type unpost yposition activate
105 "syn keyword tcltkWidgetSwitch contained
106 "syn match tcltkWidgetSwitch contained
107 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<button\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
108 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<scale\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
110 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<canvas\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
111 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<checkbutton\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
112 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<entry\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
113 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<frame\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
114 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<image\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
115 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<listbox\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
116 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<menubutton\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
117 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<message\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
118 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<radiobutton\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
119 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<scrollbar\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
120 " These words are dual purpose.
122 "syn match tcltkWidgetSwitch contained "-text"hs=s+1
123 syn match tcltkWidgetSwitch contained "-text\(var\)\?"hs=s+1
124 syn match tcltkWidgetSwitch contained "-menu"hs=s+1
125 syn match tcltkWidgetSwitch contained "-label"hs=s+1
126 " match commands - 2 lines for pretty match.
128 " Special case - If a number follows a variable region, it must be at the end of
129 " the pattern, by definition. Therefore, (1) either include a number as the region
130 " end and exclude tclNumber from the contains list, or (2) make variable
131 " keepend. As (1) would put variable out of step with everything else, use (2).
132 syn region tcltkCommand matchgroup=tcltkCommandColor start="^\<variable\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tclString,tclNumber,tclVarRef,tcltkCommand
133 syn region tcltkCommand matchgroup=tcltkCommandColor start="\s\<variable\>\|\[\<variable\>"hs=s+1 matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tclString,tclNumber,tclVarRef,tcltkCommand
135 syn region tcltkWidget matchgroup=tcltkWidgetColor start="^\<menu\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
136 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\s\<menu\>\|\[\<menu\>"hs=s+1 matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
138 syn region tcltkWidget matchgroup=tcltkWidgetColor start="^\<label\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
139 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\s\<label\>\|\[\<label\>"hs=s+1 matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
141 syn region tcltkWidget matchgroup=tcltkWidgetColor start="^\<text\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidget,tcltkWidgetSwitch,tcltkSwitch,tclNumber,tclVarRef,tclString
142 syn region tcltkWidget matchgroup=tcltkWidgetColor start="\s\<text\>\|\[\<text\>"hs=s+1 matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidget,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
144 " This isn't contained (I don't think) so it's OK to just associate with the Color group.
145 " TODO: This could be wrong.
146 syn keyword tcltkWidgetColor toplevel
149 syn region tcltkPackConf matchgroup=tcltkPackConfColor start="\<configure\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tcltkPackConfSwitch,tclNumber,tclVarRef keepend
150 syn region tcltkPackConf matchgroup=tcltkPackConfColor start="\<cget\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"me=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tcltkPackConfSwitch,tclNumber,tclVarRef
154 " commands associated with namespace
155 syn keyword tcltkNamespaceSwitch contained children code current delete eval
156 syn keyword tcltkNamespaceSwitch contained export forget import inscope origin
157 syn keyword tcltkNamespaceSwitch contained parent qualifiers tail which command variable
158 syn region tcltkCommand matchgroup=tcltkCommandColor start="\<namespace\>" matchgroup=NONE skip="^\s*$" end="{\|}\|]\|\"\|[^\\]*\s*$"me=e-1 contains=tclLineContinue,tcltkNamespaceSwitch
161 " commands associated with expr
162 syn keyword tcltkMaths contained abs acos asin atan atan2 bool ceil cos cosh double entier
163 syn keyword tcltkMaths contained exp floor fmod hypot int isqrt log log10 max min pow rand
164 syn keyword tcltkMaths contained round sin sinh sqrt srand tan tanh wide
166 syn region tcltkCommand matchgroup=tcltkCommandColor start="\<expr\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"me=e-1 contains=tclLineContinue,tcltkMaths,tclNumber,tclVarRef,tclString,tcltlWidgetSwitch,tcltkCommand,tcltkPackConf
169 syn region tcltkCommand matchgroup=tcltkCommandColor start="\<format\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"me=e-1 contains=tclLineContinue,tcltkMaths,tclNumber,tclVarRef,tclString,tcltlWidgetSwitch,tcltkCommand,tcltkPackConf
172 " commands associated with pack
173 syn keyword tcltkPackSwitch contained forget info propogate slaves
174 syn keyword tcltkPackConfSwitch contained after anchor before expand fill in ipadx ipady padx pady side
175 syn region tcltkCommand matchgroup=tcltkCommandColor start="\<pack\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkPackSwitch,tcltkPackConf,tcltkPackConfSwitch,tclNumber,tclVarRef,tclString,tcltkCommand keepend
178 " commands associated with string
179 syn keyword tcltkStringSwitch contained compare first index last length match range tolower toupper trim trimleft trimright wordstart wordend
180 syn region tcltkCommand matchgroup=tcltkCommandColor start="\<string\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkStringSwitch,tclNumber,tclVarRef,tclString,tcltkCommand
183 " commands associated with array
184 syn keyword tcltkArraySwitch contained anymore donesearch exists get names nextelement size startsearch set
185 " match from command name to ] or EOL
186 syn region tcltkCommand matchgroup=tcltkCommandColor start="\<array\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkArraySwitch,tclNumber,tclVarRef,tclString,tcltkCommand
190 syn keyword tcltkLsortSwitch contained ascii dictionary integer real command increasing decreasing index
191 " match from command name to ] or EOL
192 syn region tcltkCommand matchgroup=tcltkCommandColor start="\<lsort\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkLsortSwitch,tclNumber,tclVarRef,tclString,tcltkCommand
194 syn keyword tclTodo contained TODO
196 " Sequences which are backslash-escaped: http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M16
197 " Octal, hexadecimal, unicode codepoints, and the classics.
198 " Tcl takes as many valid characters in a row as it can, so \xAZ in a string is newline followed by 'Z'.
199 syn match tclSpecial contained '\\\([0-7]\{1,3}\|x\x\{1,2}\|u\x\{1,4}\|[abfnrtv]\)'
200 syn match tclSpecial contained '\\[\[\]\{\}\"\$]'
202 " Command appearing inside another command or inside a string.
203 syn region tclEmbeddedStatement start='\[' end='\]' contained contains=tclCommand,tclNumber,tclLineContinue,tclString,tclVarRef,tclEmbeddedStatement
204 " A string needs the skip argument as it may legitimately contain \".
205 " Match at start of line
206 syn region tclString start=+^"+ end=+"+ contains=tclSpecial skip=+\\\\\|\\"+
207 "Match all other legal strings.
208 syn region tclString start=+[^\\]"+ms=s+1 end=+"+ contains=tclSpecial,tclVarRef,tclEmbeddedStatement skip=+\\\\\|\\"+
210 " Line continuation is backslash immediately followed by newline.
211 syn match tclLineContinue '\\$'
213 if exists('g:tcl_warn_continuation')
214 syn match tclNotLineContinue '\\\s\+$'
217 "integer number, or floating point number without a dot and with "f".
219 syn match tclNumber "\<\d\+\(u\=l\=\|lu\|f\)\>"
220 "floating point number, with dot, optional exponent
221 syn match tclNumber "\<\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=\>"
222 "floating point number, starting with a dot, optional exponent
223 syn match tclNumber "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
224 "floating point number, without dot, with exponent
225 syn match tclNumber "\<\d\+e[-+]\=\d\+[fl]\=\>"
227 syn match tclNumber "0x[0-9a-f]\+\(u\=l\=\|lu\)\>"
228 "syn match tclIdentifier "\<[a-z_][a-z0-9_]*\>"
231 syn region tclComment start="^\s*\#" skip="\\$" end="$" contains=tclTodo
232 syn region tclComment start=/;\s*\#/hs=s+1 skip="\\$" end="$" contains=tclTodo
234 "syn sync ccomment tclComment
236 " Define the default highlighting.
237 " For version 5.7 and earlier: only when not done already
238 " For version 5.8 and later: only when an item doesn't have highlighting yet
239 if version >= 508 || !exists("did_tcl_syntax_inits")
241 let did_tcl_syntax_inits = 1
242 command -nargs=+ HiLink hi link <args>
244 command -nargs=+ HiLink hi def link <args>
247 HiLink tcltkSwitch Special
248 HiLink tclExpand Special
249 HiLink tclLabel Label
250 HiLink tclConditional Conditional
251 HiLink tclRepeat Repeat
252 HiLink tclNumber Number
253 HiLink tclError Error
254 HiLink tclCommand Statement
255 HiLink tclString String
256 HiLink tclComment Comment
257 HiLink tclSpecial Special
259 " Below here are the commands and their options.
260 HiLink tcltkCommandColor Statement
261 HiLink tcltkWidgetColor Structure
262 HiLink tclLineContinue WarningMsg
263 if exists('g:tcl_warn_continuation')
264 HiLink tclNotLineContinue ErrorMsg
266 HiLink tcltkStringSwitch Special
267 HiLink tcltkArraySwitch Special
268 HiLink tcltkLsortSwitch Special
269 HiLink tcltkPackSwitch Special
270 HiLink tcltkPackConfSwitch Special
271 HiLink tcltkMaths Special
272 HiLink tcltkNamespaceSwitch Special
273 HiLink tcltkWidgetSwitch Special
274 HiLink tcltkPackConfColor Identifier
275 HiLink tclVarRef Identifier
280 let b:current_syntax = "tcl"