templ / misc / templ.vim

The default branch has multiple heads

  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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
" Vim syntax file
" Language:	templ
" Maintainer:	Brian Mearns <Brian.Mearns@apcc.com>
" Last Change:	2012 Aug 05

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

syn sync fromstart
syn case match

" Nested syntax.
" matchgroup is what's used for the text that matches the "start" and "end"
" patterns, not the stuff in betwee. That's what "Snip" is for.
hi link Snip SpecialComment

"Vimtip #857
" Adds a nested syntax region which is highlighted as though syntax is
" "filetype". Region is bound by patterns "start" and "end", and "textSnipHl"
" is the highlight class to use for highlighting the actual start and end tags
" (not the stuff inbetween them, that's highlighted using the specified
" syntax.)
function! TextEnableCodeSnip(filetype,start,end,textSnipHl) abort
  let ft=toupper(a:filetype)
  let group='textGroup'.ft
  if exists('b:current_syntax')
    let s:current_syntax=b:current_syntax
    " Remove current syntax definition, as some syntax files (e.g. cpp.vim)
    " do nothing if b:current_syntax is defined.
    unlet b:current_syntax
  endif
  execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
  try
    execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
  catch
  endtry
  if exists('s:current_syntax')
    let b:current_syntax=s:current_syntax
  else
    unlet b:current_syntax
  endif
  execute 'syntax region textSnip'.ft.'
  \ matchgroup='.a:textSnipHl.'
  \ start="'.a:start.'" end="'.a:end.'"
  \ contains=@'.group
endfunction

function! AddKnownFunction(tag)
    execute 'syntax match templKnownFunctions contained containedin=templTag /' . a:tag . '\(\_\s\|}\)/'
endfunction

"This is special purpose nested for templ.
" use a "don't" comment and then "syntax LANG" specifying the appropriate
" LANG. It can be spread out across arbitrary whitespace and lines, and can 
" even include a % comment at the end (but not in between).
function! TemplCodeSnip(filetyp,)
        call TextEnableCodeSnip(a:filetyp,
                \ '{\_\s*\(dont\_\s\+\)\?syntax\_\s\+'.a:filetyp.'\_\s*\(%.*\_$\)*\_\s*}',
                \ '{\_\s*\(dont\_\s\+\)\?end-syntax\_\s\+'.a:filetyp.'\_\s*\(%.*\_$\)*\_\s*}',
                \ 'SpecialComment')
endfunction
call TemplCodeSnip("c")
call TemplCodeSnip("cpp")
call TemplCodeSnip("java")
call TemplCodeSnip("python")
call TemplCodeSnip("xml")
call TemplCodeSnip("html")
call TemplCodeSnip("xhtml")
call TemplCodeSnip("javascript")
call TemplCodeSnip("css")
call TemplCodeSnip("tex")
call TemplCodeSnip("php")
call TemplCodeSnip("yacc")
call TemplCodeSnip("rest")

" Tags inside comments
syn     match       templDocTagTodo        "TODO\c"                    contained
syn     match       templDocTagFixme       "FIXME\c"                   contained
syn     match       templDocTagXXX         "XXX"                       contained
syn     match       templDocTagWarning     "WARN:\c"he=e-1             contained
syn     match       templDocTagError       "ERROR:\c"he=e-1            contained
syn     match       templDocTagCust        "![^:]*:"hs=s+1,he=e-1      contained
syn cluster templDocTag contains=templDocTag.*

"basically any templCode.
syn cluster templCode contains=templList,MLineComment,templTag,templEOLComment,templStringLiteral,templEmbedded

"A templ list. Just bounded by { } unless escaped. It can contain any
"additional templcode.
syn region templList matchgroup=Delimiter start="\(^\|[^\\]\){"hs=s+1 matchgroup=Delimiter end="}" contains=@templCode

"An embedded template. Contained in a templList, contains anything the top can
"contain (TOP) except string literals (they can be contained in templLists inside the embed).
syn region templEmbedded matchgroup=Operator start='<<<' end='>>>' contained containedin=templList contains=TOP,templStringLiteral

"Multiline comment is a "dont" command, which has to contain well formed but
"not valid templ code. Except we just call it "commentedCode" so it doesn't
"get highlighted as though it's working code.
syn region MLineComment	matchgroup=CommentDelimiter start="\(^\|[^\\]\){\_\s*dont\_\s\+" end="}" extend fold contains=commentedCode,@templDocTag
syn region MLineComment	matchgroup=CommentDelimiter start="\(^\|[^\\]\){\_\s*rem\_\s\+" end="}" extend fold contains=commentedCode,@templDocTag
syn region MLineComment	matchgroup=CommentDelimiter start="\(^\|[^\\]\){\_\s*\#\_\s\+" end="}" extend fold contains=commentedCode,@templDocTag
syn region MLineComment	matchgroup=CommentDelimiter start="\(^\|[^\\]\){\_\s*syn\_\s\+" end="}" extend fold contains=commentedCode,@templDocTag
syn region MLineComment	matchgroup=CommentDelimiter start="\(^\|[^\\]\){\_\s*syntax\_\s\+" end="}" extend fold contains=commentedCode,@templDocTag
syn region MLineComment	matchgroup=CommentDelimiter start="\(^\|[^\\]\){\_\s*end-syn\_\s\+" end="}" extend fold contains=commentedCode,@templDocTag
syn region MLineComment	matchgroup=CommentDelimiter start="\(^\|[^\\]\){\_\s*end-syntax\_\s\+" end="}" extend fold contains=commentedCode,@templDocTag

syn region commentedCode contained start="\(^\|[^\\]\){" skip='/"[^"]*"/' end="}"	contains=commentedCode

"an end of line comment.
syn match templEOLComment "%.*" contained containedin=templList

"String literals. I stole this from c.vim.
syn region templStringLiteral start=+"+ skip=+\\\\\|\\"+ end=+"+ containedin=templList

"The first symbol in a templList, except string lits. Doesn't work if the
"curly brace and tag are on separate lines, not sure why.
syn match templTag '{\@<=\_\s*[^{ \t\n\r"}]\+' contained containedin=templList contains=templKnownFunctions

"Keywords can include any printable characters except space and curly braces.
setlocal iskeyword=33-122,124,126

call AddKnownFunction( "!=" )
call AddKnownFunction( "!==" )
call AddKnownFunction( "\\$" )
call AddKnownFunction( "\\$\\$" )
call AddKnownFunction( "\\$=" )
call AddKnownFunction( "#" )
call AddKnownFunction( "&&" )
call AddKnownFunction( "'" )
call AddKnownFunction( "\\*" )
call AddKnownFunction( "\\*\\*" )
call AddKnownFunction( "+" )
call AddKnownFunction( ",=" )
call AddKnownFunction( "\\-" )
call AddKnownFunction( ":" )
call AddKnownFunction( "::" )
call AddKnownFunction( "<" )
call AddKnownFunction( "<=" )
call AddKnownFunction( "==" )
call AddKnownFunction( "===" )
call AddKnownFunction( ">" )
call AddKnownFunction( ">\\*<" )
call AddKnownFunction( "><" )
call AddKnownFunction( ">=" )
call AddKnownFunction( "?" )
call AddKnownFunction( "@" )
syn keyword templKnownFunctions contained containedin=templTag
    \ acos
    \ add
    \ aliases
    \ all
    \ and
    \ any
    \ append
    \ arc-cosine
    \ arc-sine
    \ arc-tangent
    \ arc-tangent-quad
    \ asin
    \ at
    \ atan
    \ atan-quad
    \ atanq
    \ block
    \ bool
    \ bool.f
    \ bool.new
    \ bool.t
    \ buffer
    \ buffer-to
    \ caaar
    \ caadr
    \ caar
    \ cadar
    \ caddr
    \ cadr
    \ call
    \ car
    \ cat
    \ ccb
    \ cdaar
    \ cdadr
    \ cddar
    \ cdddr
    \ cddr
    \ cdr
    \ ceil
    \ char-at
    \ chars
    \ chr
    \ close
    \ cons
    \ cons.len
    \ cons.new
    \ cos
    \ cosine
    \ deg
    \ div
    \ div.mode
    \ divmod
    \ doc
    \ dont
    \ eccb
    \ echo
    \ embed
    \ empty
    \ end-syn
    \ end-syntax
    \ eocb
    \ eol
    \ eq
    \ equal
    \ equiv
    \ error
    \ eval
    \ exe-name
    \ exe.is
    \ exec
    \ exec-block
    \ exename
    \ exists
    \ exp
    \ exp.and
    \ exp.block
    \ exp.call
    \ exp.echo
    \ exp.join
    \ exp.let
    \ exp.or
    \ exp.scope
    \ false
    \ fields
    \ file.close
    \ file.open
    \ file.read
    \ file.write
    \ filepos
    \ filepos-plist
    \ filepos-tuple
    \ find
    \ first
    \ first-of-first
    \ first-of-first-of-first
    \ first-of-first-of-rest
    \ first-of-rest
    \ first-of-rest-of-first
    \ first-of-rest-of-rest
    \ flatten
    \ floor
    \ for
    \ for.gen
    \ for.loop
    \ gen
    \ gen-loop
    \ gen-while
    \ get
    \ getf
    \ getset
    \ glue
    \ gmtime
    \ gt
    \ gte
    \ hasf
    \ idxf
    \ if
    \ imp
    \ implode
    \ in
    \ in-str
    \ include
    \ include-as-list
    \ insert
    \ invoke
    \ is-empty
    \ is-exe
    \ is-false
    \ is-list
    \ is-null
    \ is-str
    \ is-true
    \ join
    \ lambda
    \ len
    \ let
    \ list
    \ list.append
    \ list.at
    \ list.cat
    \ list.empty
    \ list.filepos
    \ list.find
    \ list.flatten
    \ list.has
    \ list.in
    \ list.insert
    \ list.is
    \ list.len
    \ list.new
    \ list.nil
    \ list.reverse
    \ list.slice
    \ list.sort
    \ list.splice
    \ list.version
    \ ln
    \ lnbrk
    \ localtime
    \ log
    \ loop
    \ loop.gen
    \ loop.loop
    \ lt
    \ lte
    \ math.add
    \ math.div
    \ math.divmod
    \ math.e
    \ math.exp
    \ math.mult
    \ math.neg
    \ math.pow
    \ math.sub
    \ mod
    \ mt
    \ mult
    \ neg
    \ neq
    \ nequiv
    \ nil
    \ not
    \ not-equal
    \ null.is
    \ ocb
    \ open
    \ or
    \ ord
    \ ord-1
    \ pck.block
    \ pck.call
    \ pck.echo
    \ pck.join
    \ pck.let
    \ pck.scope
    \ pi
    \ pipe
    \ pipe-both
    \ plist.fields
    \ plist.filepos
    \ plist.find
    \ plist.get
    \ plist.idx
    \ plist.in
    \ plist.len
    \ plist.version
    \ pow
    \ rad
    \ rand
    \ rand-float
    \ randint
    \ random.float
    \ random.int
    \ range
    \ read
    \ redirect
    \ rem
    \ rest
    \ rest-of-first-of-first
    \ rest-of-first-of-rest
    \ rest-of-rest
    \ rest-of-rest-of-first
    \ rest-of-rest-of-rest
    \ return
    \ reverse
    \ round
    \ scope
    \ set
    \ sin
    \ sine
    \ slice
    \ sort
    \ spit
    \ splice
    \ sqrt
    \ stamp
    \ stderr
    \ stdin
    \ stdout
    \ str
    \ str.at
    \ str.cat
    \ str.filepos
    \ str.find
    \ str.in
    \ str.is
    \ str.len
    \ str.list
    \ str.lower
    \ str.new
    \ str.reverse
    \ str.slice
    \ str.upper
    \ str.version
    \ strlen
    \ strpos
    \ sub
    \ substr
    \ syn
    \ syntax
    \ system
    \ tab
    \ tan
    \ tangent
    \ tau
    \ time
    \ time-plist
    \ time.stamp
    \ time.time
    \ time.toPlist
    \ time.utctime
    \ to-lower
    \ to-upper
    \ true
    \ try
    \ unpack
    \ unret
    \ utctime
    \ v
    \ value-of-the-argument
    \ vars
    \ version
    \ version-plist
    \ version-tuple
    \ void
    \ vota
    \ while
    \ while.gen
    \ while.loop
    \ write
    \ xor


"Highlighting.
hi      link    templList               Special
hi      link    templTag                Statement
hi      link    templKnownFunctions     Function
hi      link    MLineComment            Comment
hi      link    templEOLComment         Comment
hi      link    commentedCode           Comment
hi      link    CommentDelimiter        SpecialComment
hi      link    templStringLiteral      String
hi      link    templDocTag             Todo
hi      link    templDocTagTodo         templDocTag
hi      link    templDocTagFixme        templDocTag
hi      link    templDocTagXXX          templDocTag
hi      link    templDocTagCust         templDocTag
hi      link    templDocTagError        error
hi      link    templDocTagWarning      templDocTag


let b:current_syntax = "templ"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.