Skip to content

Commit c5efa74

Browse files
committed
improve responsiveness on vim 7.4 (issue 12)
1 parent 1cac92d commit c5efa74

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

syntax/ledger.vim

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ elseif exists("b:current_sytax")
1111
finish
1212
endif
1313

14+
" Force old regex engine (:help two-engines)
15+
let s:oe = v:version < 704 ? '' : '\%#=1'
16+
1417
" for debugging
1518
syntax clear
1619

@@ -26,8 +29,10 @@ syn match ledgerPosting /^\s\+[^[:blank:];][^;]*\ze\%($\|;\)/
2629
\ contained transparent contains=ledgerAccount,ledgerAmount,ledgerMetadata
2730
" every space in an account name shall be surrounded by two non-spaces
2831
" every account name ends with a tab, two spaces or the end of the line
29-
syn match ledgerAccount /^\s\+\zs\%(\S\@<= \S\|\S\)\+\ze\%( \|\t\|\s*$\)/ contained
30-
syn match ledgerAmount /\S\@<=\%( \|\t\)\s*\zs\%([^;[:space:]]\|\s\+[^;[:space:]]\)\+/ contained
32+
exe 'syn match ledgerAccount '.
33+
\ '/'.s:oe.'^\s\+\zs\%(\S\@1<= \S\|\S\)\+\ze\%( \|\t\|\s*$\)/ contained'
34+
exe 'syn match ledgerAmount '.
35+
\ '/'.s:oe.'\S\@1<=\%( \|\t\)\s*\zs\%([^;[:space:]]\|\s\+[^;[:space:]]\)\+/ contained'
3136

3237
syn region ledgerPreDeclaration start=/^\(account\|payee\|commodity\|tag\)/ skip=/^\s/ end=/^/
3338
\ keepend transparent
@@ -40,17 +45,22 @@ syn match ledgerComment /^;.*$/
4045
" comments at eol must be preceeded by at least 2 spaces / 1 tab
4146
syn region ledgerMetadata start=/\%( \|\t\|^\s\+\);/ skip=/^\s\+;/ end=/^/
4247
\ keepend contained contains=ledgerTags,ledgerValueTag,ledgerTypedTag
43-
syn match ledgerTags /\%(\%(;\s*\|^tag\s\+\)\)\@<=:[^:[:space:]][^:]*\%(::\?[^:[:space:]][^:]*\)*:\s*$/
44-
\ contained contains=ledgerTag
48+
exe 'syn match ledgerTags '.
49+
\ '/'s:oe.'\%#=1\%(\%(;\s*\|^tag\s\+\)\)\@<='.
50+
\ ':[^:[:space:]][^:]*\%(::\?[^:[:space:]][^:]*\)*:\s*$/ '.
51+
\ 'contained contains=ledgerTag'
4552
syn match ledgerTag /:\zs[^:]\+\ze:/ contained
46-
syn match ledgerValueTag /\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+:\ze.\+$/ contained
47-
syn match ledgerTypedTag /\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+::\ze.\+$/ contained
53+
exe 'syn match ledgerValueTag '.
54+
\ '/\%#=1\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+:\ze.\+$/ contained'
55+
exe 'syn match ledgerTypedTag '.
56+
\ '/\%#=1\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+::\ze.\+$/ contained'
4857

4958
syn region ledgerApply
5059
\ matchgroup=ledgerStartApply start=/^apply\>/
5160
\ matchgroup=ledgerEndApply end=/^end\s\+apply\>/
5261
\ contains=ledgerApplyHead,ledgerApply,ledgerTransaction,ledgerComment
53-
syn match ledgerApplyHead /\%(^apply\s\+\)\@<=\S.*$/ contained
62+
exe 'syn match ledgerApplyHead '.
63+
\ '/\%#=1\%(^apply\s\+\)\@<=\S.*$/ contained'
5464

5565
highlight default link ledgerComment Comment
5666
highlight default link ledgerTransactionDate Constant

0 commit comments

Comments
 (0)