tcl.vim 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. " Vim syntax file
  2. " Language: Tcl/Tk
  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: 2021 Nov 16
  10. " Version: 1.14 plus improvements from PR #8948
  11. " URL: (removed, no longer worked)
  12. " quit when a syntax file was already loaded
  13. if exists("b:current_syntax")
  14. finish
  15. endif
  16. " Basic Tcl commands: http://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm
  17. syn keyword tclCommand after append array bgerror binary cd chan clock close concat
  18. syn keyword tclCommand dde dict encoding eof error eval exec exit expr fblocked
  19. syn keyword tclCommand fconfigure fcopy file fileevent flush format gets glob
  20. syn keyword tclCommand global history http incr info interp join lappend lassign
  21. syn keyword tclCommand lindex linsert list llength lmap load lrange lrepeat
  22. syn keyword tclCommand lreplace lreverse lsearch lset lsort memory my namespace
  23. syn keyword tclCommand next nextto open package pid puts pwd read refchan regexp
  24. syn keyword tclCommand registry regsub rename scan seek self set socket source
  25. syn keyword tclCommand split string subst tell time trace unknown unload unset
  26. syn keyword tclCommand update uplevel upvar variable vwait
  27. " The 'Tcl Standard Library' commands: http://www.tcl.tk/man/tcl8.6/TclCmd/library.htm
  28. syn keyword tclCommand auto_execok auto_import auto_load auto_mkindex auto_reset
  29. syn keyword tclCommand auto_qualify tcl_findLibrary parray tcl_endOfWord
  30. syn keyword tclCommand tcl_startOfNextWord tcl_startOfPreviousWord
  31. syn keyword tclCommand tcl_wordBreakAfter tcl_wordBreakBefore
  32. " Global variables used by Tcl: http://www.tcl.tk/man/tcl8.6/TclCmd/tclvars.htm
  33. syn keyword tclVars auto_path env errorCode errorInfo tcl_library tcl_patchLevel
  34. syn keyword tclVars tcl_pkgPath tcl_platform tcl_precision tcl_rcFileName
  35. syn keyword tclVars tcl_traceCompile tcl_traceExec tcl_wordchars
  36. syn keyword tclVars tcl_nonwordchars tcl_version argc argv argv0 tcl_interactive
  37. " Strings which expr accepts as boolean values, aside from zero / non-zero.
  38. syn keyword tclBoolean true false on off yes no
  39. syn keyword tclProcCommand apply coroutine proc return tailcall yield yieldto
  40. syn keyword tclConditional if then else elseif switch
  41. syn keyword tclConditional catch try throw finally
  42. syn keyword tclLabel default
  43. syn keyword tclRepeat while for foreach break continue
  44. syn keyword tcltkSwitch contained insert create polygon fill outline tag
  45. " WIDGETS
  46. " commands associated with widgets
  47. syn keyword tcltkWidgetSwitch contained background highlightbackground insertontime cget
  48. syn keyword tcltkWidgetSwitch contained selectborderwidth borderwidth highlightcolor insertwidth
  49. syn keyword tcltkWidgetSwitch contained selectforeground cursor highlightthickness padx setgrid
  50. syn keyword tcltkWidgetSwitch contained exportselection insertbackground pady takefocus
  51. syn keyword tcltkWidgetSwitch contained font insertborderwidth relief xscrollcommand
  52. syn keyword tcltkWidgetSwitch contained foreground insertofftime selectbackground yscrollcommand
  53. syn keyword tcltkWidgetSwitch contained height spacing1 spacing2 spacing3
  54. syn keyword tcltkWidgetSwitch contained state tabs width wrap
  55. " button
  56. syn keyword tcltkWidgetSwitch contained command default
  57. " canvas
  58. syn keyword tcltkWidgetSwitch contained closeenough confine scrollregion xscrollincrement yscrollincrement orient
  59. " checkbutton, radiobutton
  60. syn keyword tcltkWidgetSwitch contained indicatoron offvalue onvalue selectcolor selectimage state variable
  61. " entry, frame
  62. syn keyword tcltkWidgetSwitch contained show class colormap container visual
  63. " listbox, menu
  64. syn keyword tcltkWidgetSwitch contained selectmode postcommand selectcolor tearoff tearoffcommand title type
  65. " menubutton, message
  66. syn keyword tcltkWidgetSwitch contained direction aspect justify
  67. " scale
  68. syn keyword tcltkWidgetSwitch contained bigincrement digits from length resolution showvalue sliderlength sliderrelief tickinterval to
  69. " scrollbar
  70. syn keyword tcltkWidgetSwitch contained activerelief elementborderwidth
  71. " image
  72. syn keyword tcltkWidgetSwitch contained delete names types create
  73. " variable reference
  74. " ::optional::namespaces
  75. syn match tclVarRef "$\(\(::\)\?\([[:alnum:]_]*::\)*\)\a[[:alnum:]_]*"
  76. " ${...} may contain any character except '}'
  77. syn match tclVarRef "${[^}]*}"
  78. " Used to facilitate hack to utilize string background for certain color
  79. " schemes, e.g. inkpot and lettuce.
  80. syn cluster tclVarRefC add=tclVarRef
  81. syn cluster tclSpecialC add=tclSpecial
  82. " The syntactic unquote-splicing replacement for [expand].
  83. syn match tclExpand '\s{\*}'
  84. syn match tclExpand '^{\*}'
  85. " menu, mane add
  86. syn keyword tcltkWidgetSwitch contained active end last none cascade checkbutton command radiobutton separator
  87. syn keyword tcltkWidgetSwitch contained activebackground actveforeground accelerator background bitmap columnbreak
  88. syn keyword tcltkWidgetSwitch contained font foreground hidemargin image indicatoron label menu offvalue onvalue
  89. syn keyword tcltkWidgetSwitch contained selectcolor selectimage state underline value variable
  90. syn keyword tcltkWidgetSwitch contained add clone configure delete entrycget entryconfigure index insert invoke
  91. syn keyword tcltkWidgetSwitch contained post postcascade type unpost yposition activate
  92. "syn keyword tcltkWidgetSwitch contained
  93. "syn match tcltkWidgetSwitch contained
  94. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<button\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  95. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<scale\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  96. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<canvas\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  97. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<checkbutton\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  98. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<entry\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  99. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<frame\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  100. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<image\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  101. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<listbox\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  102. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<menubutton\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  103. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<message\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  104. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<radiobutton\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  105. syn region tcltkWidget matchgroup=tcltkWidgetColor start="\<scrollbar\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  106. " These words are dual purpose.
  107. " match switches
  108. "syn match tcltkWidgetSwitch contained "-text"hs=s+1
  109. syn match tcltkWidgetSwitch contained "-text\(var\)\?"hs=s+1
  110. syn match tcltkWidgetSwitch contained "-menu"hs=s+1
  111. syn match tcltkWidgetSwitch contained "-label"hs=s+1
  112. " match commands - 2 lines for pretty match.
  113. "variable
  114. " Special case - If a number follows a variable region, it must be at the end of
  115. " the pattern, by definition. Therefore, (1) either include a number as the region
  116. " end and exclude tclNumber from the contains list, or (2) make variable
  117. " keepend. As (1) would put variable out of step with everything else, use (2).
  118. syn region tcltkCommand matchgroup=tcltkCommandColor start="^\<variable\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tclString,tclNumber,tclVarRef,tcltkCommand
  119. 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
  120. " menu
  121. syn region tcltkWidget matchgroup=tcltkWidgetColor start="^\<menu\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  122. 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
  123. " label
  124. syn region tcltkWidget matchgroup=tcltkWidgetColor start="^\<label\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tclNumber,tclVarRef
  125. 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
  126. " text
  127. syn region tcltkWidget matchgroup=tcltkWidgetColor start="^\<text\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkWidget,tcltkWidgetSwitch,tcltkSwitch,tclNumber,tclVarRef,tclString
  128. 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
  129. " This isn't contained (I don't think) so it's OK to just associate with the Color group.
  130. " TODO: This could be wrong.
  131. syn keyword tcltkWidgetColor toplevel
  132. 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
  133. syn region tcltkPackConf matchgroup=tcltkPackConfColor start="\<cget\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"me=e-1 contains=tclLineContinue,tcltkWidgetSwitch,tclString,tcltkSwitch,tcltkPackConfSwitch,tclNumber,tclVarRef
  134. " NAMESPACE
  135. " commands associated with namespace
  136. syn keyword tcltkNamespaceSwitch contained children code current delete eval
  137. syn keyword tcltkNamespaceSwitch contained export forget import inscope origin
  138. syn keyword tcltkNamespaceSwitch contained parent qualifiers tail which command variable
  139. syn region tcltkCommand matchgroup=tcltkCommandColor start="\<namespace\>" matchgroup=NONE skip="^\s*$" end="{\|}\|]\|\"\|[^\\]*\s*$"me=e-1 contains=tclLineContinue,tcltkNamespaceSwitch
  140. " EXPR
  141. " commands associated with expr
  142. syn keyword tcltkMaths contained abs acos asin atan atan2 bool ceil cos cosh double entier
  143. syn keyword tcltkMaths contained exp floor fmod hypot int isqrt log log10 max min pow rand
  144. syn keyword tcltkMaths contained round sin sinh sqrt srand tan tanh wide
  145. 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
  146. " format
  147. 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
  148. " PACK
  149. " commands associated with pack
  150. syn keyword tcltkPackSwitch contained forget info propagate slaves
  151. syn keyword tcltkPackConfSwitch contained after anchor before expand fill in ipadx ipady padx pady side
  152. 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
  153. " STRING
  154. " commands associated with string
  155. syn keyword tcltkStringSwitch contained compare first index last length match range tolower toupper trim trimleft trimright wordstart wordend
  156. syn region tcltkCommand matchgroup=tcltkCommandColor start="\<string\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkStringSwitch,tclNumber,tclVarRef,tclString,tcltkCommand
  157. " ARRAY
  158. " commands associated with array
  159. syn keyword tcltkArraySwitch contained anymore donesearch exists get names nextelement size startsearch set
  160. " match from command name to ] or EOL
  161. syn region tcltkCommand matchgroup=tcltkCommandColor start="\<array\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkArraySwitch,tclNumber,tclVarRef,tclString,tcltkCommand
  162. " LSORT
  163. " switches for lsort
  164. syn keyword tcltkLsortSwitch contained ascii dictionary integer real command increasing decreasing index
  165. " match from command name to ] or EOL
  166. syn region tcltkCommand matchgroup=tcltkCommandColor start="\<lsort\>" matchgroup=NONE skip="^\s*$" end="]\|[^\\]*\s*$"he=e-1 contains=tclLineContinue,tcltkLsortSwitch,tclNumber,tclVarRef,tclString,tcltkCommand
  167. syn keyword tclTodo contained TODO
  168. " Sequences which are backslash-escaped: http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M16
  169. " Octal, hexadecimal, Unicode codepoints, and the classics.
  170. " Tcl takes as many valid characters in a row as it can, so \xAZ in a string is newline followed by 'Z'.
  171. syn match tclSpecial contained '\\\(\o\{1,3}\|x\x\{1,2}\|u\x\{1,4}\|[abfnrtv]\)'
  172. syn match tclSpecial contained '\\[\[\]\{\}\"\$]'
  173. " Command appearing inside another command or inside a string.
  174. syn region tclEmbeddedStatement start='\[' end='\]' contained contains=tclCommand,tclNumber,tclLineContinue,tclString,tclVarRef,tclEmbeddedStatement
  175. " A string needs the skip argument as it may legitimately contain \".
  176. " Match at start of line
  177. syn region tclString start=+^"+ end=+"+ contains=@tclSpecialC,@Spell skip=+\\\\\|\\"+
  178. "Match all other legal strings.
  179. syn region tclString start=+[^\\]"+ms=s+1 end=+"+ contains=@tclSpecialC,@tclVarRefC,tclEmbeddedStatement,@Spell skip=+\\\\\|\\"+
  180. " Line continuation is backslash immediately followed by newline.
  181. syn match tclLineContinue '\\$'
  182. if exists('g:tcl_warn_continuation')
  183. syn match tclNotLineContinue '\\\s\+$'
  184. endif
  185. "integer number, or floating point number without a dot and with "f".
  186. syn case ignore
  187. syn match tclNumber "\<\d\+\(u\=l\=\|lu\|f\)\>"
  188. "floating point number, with dot, optional exponent
  189. syn match tclNumber "\<\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=\>"
  190. "floating point number, starting with a dot, optional exponent
  191. syn match tclNumber "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
  192. "floating point number, without dot, with exponent
  193. syn match tclNumber "\<\d\+e[-+]\=\d\+[fl]\=\>"
  194. "hex number
  195. syn match tclNumber "0x\x\+\(u\=l\=\|lu\)\>"
  196. "syn match tclIdentifier "\<\h\w*\>"
  197. syn case match
  198. syn region tclComment start="^\s*\#" skip="\\$" end="$" contains=tclTodo,@Spell
  199. syn region tclComment start=/;\s*\#/hs=s+1 skip="\\$" end="$" contains=tclTodo,@Spell
  200. "syn match tclComment /^\s*\#.*$/
  201. "syn match tclComment /;\s*\#.*$/hs=s+1
  202. "syn sync ccomment tclComment
  203. " Define the default highlighting.
  204. " Only when an item doesn't have highlighting yet
  205. hi def link tcltkSwitch Special
  206. hi def link tclExpand Special
  207. hi def link tclLabel Label
  208. hi def link tclConditional Conditional
  209. hi def link tclRepeat Repeat
  210. hi def link tclNumber Number
  211. hi def link tclError Error
  212. hi def link tclCommand Statement
  213. hi def link tclProcCommand Type
  214. hi def link tclString String
  215. hi def link tclComment Comment
  216. hi def link tclSpecial Special
  217. hi def link tclTodo Todo
  218. " Below here are the commands and their options.
  219. hi def link tcltkCommandColor Statement
  220. hi def link tcltkWidgetColor Structure
  221. hi def link tclLineContinue WarningMsg
  222. if exists('g:tcl_warn_continuation')
  223. hi def link tclNotLineContinue ErrorMsg
  224. endif
  225. hi def link tcltkStringSwitch Special
  226. hi def link tcltkArraySwitch Special
  227. hi def link tcltkLsortSwitch Special
  228. hi def link tcltkPackSwitch Special
  229. hi def link tcltkPackConfSwitch Special
  230. hi def link tcltkMaths Special
  231. hi def link tcltkNamespaceSwitch Special
  232. hi def link tcltkWidgetSwitch Special
  233. hi def link tcltkPackConfColor Identifier
  234. hi def link tclVarRef Identifier
  235. let b:current_syntax = "tcl"
  236. " vim: ts=8 noet nolist