1
1
" Vim syntax file
2
2
" Language: vim-drvo plugin
3
3
" Maintainer: matveyt
4
- " Last Change: 2021 Aug 16
4
+ " Last Change: 2021 Aug 22
5
5
" License: https://unlicense.org
6
6
" URL: https://github.com/matveyt/vim-drvo
7
7
@@ -13,34 +13,50 @@ let b:current_syntax = 'drvo'
13
13
let s: save_cpo = &cpo
14
14
set cpo &vim
15
15
16
- function s: glyph (ix) abort
17
- return exists (' g:drvo_glyph' ) ? ' cchar=' ..nr2char (g: drvo_glyph [a: ix ]) : ' '
18
- endfunction
16
+ function s: synmatch (group, pat, opts, arg = v: null ) abort
17
+ let l: arg = (type (a: arg ) == v: t_list ) ? join (a: arg , ' \|' ) : a: arg
18
+ let l: case = &fileignorecase ? ' c' : ' C'
19
+ let l: slash = drvo#slash ()
20
+ let l: pat = substitute (a: pat , ' $\(\a\+\)' , ' \=eval(submatch(1))' , ' g' )
19
21
20
- function s: syncontained (group, pat) abort
21
- if empty (a: pat )
22
- return
23
- endif
22
+ let l: cmd = printf (' syntax match %s /%s/' , a: group , l: pat )
23
+ for [l: key , l: value ] in items (a: opts )
24
+ if ! empty (l: value )
25
+ let l: cmd .= ' ' . l: key
26
+ if type (l: value ) == v: t_string
27
+ let l: cmd .= ' =' . l: value
28
+ endif
29
+ endif
30
+ endfor
24
31
25
- let l: pat = type (a: pat ) == v: t_string ? a: pat :
26
- \ printf (' \V\%%(%s\)\$' , join (a: pat , ' \|' ))
27
- execute printf (' syntax match %s /.\+%s%s/ contained' , a: group ,
28
- \ &fileignorecase ? ' \c' : ' \C' , l: pat )
32
+ return execute (l: cmd )
29
33
endfunction
30
34
31
35
" drvoDir is {drvoDirRoot/}{drvoDirTrunk}{/}
32
- syntax match drvoDir / ^.*[\/ ]$/ contains =drvoDirRoot
33
- execute ' syntax match drvoDirRoot nextgroup=drvoDirTrunk,drvoMark /^.*[\/]\ze./'
34
- \ ' contained conceal' s: glyph (0 )
35
- syntax match drvoDirTrunk nextgroup =drvoLastSlash / [^\/ ]\+ / contained
36
- syntax match drvoLastSlash / [\/ ]/ contained conceal
36
+ call s: synmatch (' drvoDir' , ' ^.*[$slash]$' , #{contains: ' drvoDirRoot' })
37
+ call s: synmatch (' drvoDirRoot' , ' ^.*[$slash]\ze.' , #{nextgroup: ' drvoDirTrunk,drvoMark' ,
38
+ \ contained: v: true , conceal: v: true , cchar: exists (' g:drvo_glyph[0]' ) ?
39
+ \ nr2char (g: drvo_glyph [0 ]) : 0 })
40
+ call s: synmatch (' drvoDirTrunk' , ' [^$slash]\+' , #{nextgroup: ' drvoLastSlash' ,
41
+ \ contained: v: true })
42
+ call s: synmatch (' drvoLastSlash' , ' [$slash]' , #{contained: v: true , conceal: v: true })
37
43
" drvoFile is {drvoFileRoot/}{drvoFileXXX}
38
- syntax match drvoFile / ^.*[^\/ ]$/ contains =drvoFileRoot
39
- execute ' syntax match drvoFileRoot nextgroup=drvoFileExecutable,drvoFileIgnore,'
40
- \ ' drvoFileSuffixes,drvoMark /^.*[\/]/ contained conceal' s: glyph (1 )
41
- call s: syncontained (' drvoFileExecutable' , split ($PATHEXT , ' ;' ))
42
- call s: syncontained (' drvoFileIgnore' , g: ft_ignore_pat )
43
- call s: syncontained (' drvoFileSuffixes' , split (&suffixes , ' ,' ))
44
+ call s: synmatch (' drvoFile' , ' ^.*[^$slash]$' , #{contains: ' drvoFileRoot' })
45
+ call s: synmatch (' drvoFileRoot' , ' ^.*[$slash]' , #{nextgroup:
46
+ \ ' drvoFileExecutable,drvoFileIgnore,drvoFileSuffixes,drvoMark' , contained: v: true ,
47
+ \ conceal: v: true , cchar: exists (' g:drvo_glyph[1]' ) ? nr2char (g: drvo_glyph [1 ]) : 0 })
48
+ if ! empty (getenv (' PATHEXT' ))
49
+ call s: synmatch (' drvoFileExecutable' , ' .\+\$case\V\%($arg\)\$' , #{contained: v: true },
50
+ \ split ($PATHEXT , ' ;' ))
51
+ endif
52
+ if ! empty (get (g: , ' ft_ignore_pat' ))
53
+ call s: synmatch (' drvoFileIgnore' , ' .\+\$case$arg' , #{contained: v: true },
54
+ \ g: ft_ignore_pat )
55
+ endif
56
+ if ! empty (&suffixes )
57
+ call s: synmatch (' drvoFileSuffixes' , ' .\+\$case\V\%($arg\)\$' , #{contained: v: true },
58
+ \ split (&suffixes , ' ,' ))
59
+ endif
44
60
45
61
" default colors
46
62
highlight default link drvoDirTrunk Directory
0 commit comments