2 " License: GNU General Public License, version 3 or later (at your option)
3 " Maintainer: Julien Moutinho <julm+hcompta@autogeree.net>
4 " URL: http://doc.autogeree.net/coop/hcompta
5 " Usage: autocmd BufNewFile,BufRead *.ledger,*.journal setfiletype ledger
7 if exists("b:current_syntax")
15 syn match ledgerNumberOdd /[0-9][0-9]*/ contained
16 syn match ledgerNumber /[0-9][0-9]*/ contained
17 syn match ledgerAccountSep ":" contained
18 syn match ledgerAccountSepOdd ":" contained
19 syn match ledgerAccountParen /[()]/ contained
20 syn match ledgerAccountParenOdd /[()]/ contained
21 syn match ledgerAccountBracket /[[\]]/ contained
22 syn match ledgerAccountBracketOdd /[[\]]/ contained
23 syn region ledgerDirective start=/^[A-Z]\s/ end=/^/ contains=ledgerComment
24 syn region ledgerInclude start=/^!include/ end=/^/
26 syn region ledgerChart start=/^\([^0-9 !][^ ]\|\d\+[^/-]\|[^ ;!]$\)/ end=/^\(\s*$\|\d\+[/-]\)/me=e-5
27 syn match ledgerChartAccount "^[^:; ]\([^; ]\| [^; ]\+\)*" contained containedin=ledgerChart contains=ledgerChartAccountSep,ledgerChartNumber
28 syn match ledgerChartComment ";.*" contained containedin=ledgerChart,ledgerChartLine
29 syn match ledgerChartAccountSep ":" contained
30 syn match ledgerChartNumber /[0-9][0-9]*/ contained
31 syn region ledgerChartLine start=/^\s\+[^; ]/ end=/^\(\s[^ ;]\|[^ ]\)/me=e-2 contained containedin=ledgerChart nextgroup=ledgerChartLine
32 syn match ledgerChartTag /^[^;, :]\+\(:[^:;,]*\)*/ contained containedin=ledgerChartLine nextgroup=ledgerChartTagValue
33 syn match ledgerChartTagValueSep ":" contained containedin=ledgerChartTagValue,ledgerChartTagValueEnd,ledgerChartTag
34 syn match ledgerChartTagValueEnd /[^;, :]:[^;:]*\(\s\|;\)/ms=s+1,me=e-1 contained containedin=ledgerChartTag
35 syn match ledgerChartTagValue /[^;, :]:[^;:]\+$/ms=s+1 contained containedin=ledgerChartTag
37 syn region ledgerTransaction start=/^\d\+[/-]/ end=/^\([^ ;]\)/me=e-1
38 syn match ledgerTransactionDate "^\(\d\+/\)\?\d\d\?/\d\d\?\(_[0-9:]\+\(_\?[A-Z]\+\|[+-]\d\d\d\d\)\?\)\?" contained containedin=ledgerTransaction nextgroup=ledgerTransactionStatus
39 syn match ledgerTransactionStatus "\(\s\+[!*]\)\?" contained nextgroup=ledgerTransactionDescription
40 syn match ledgerTransactionDateNum "\d\+" contained containedin=ledgerTransactionDate
41 syn match ledgerTransactionDateSep "[/+_:-]" contained containedin=ledgerTransactionDate
42 syn match ledgerTransactionDescription ".*" contained
43 syn match ledgerTransactionComment ";.*" contained containedin=ledgerTransaction,ledgerPosting,ledgerPostingOdd,ledgerTransactionDate,ledgerTransactionStatus,ledgerTransactionDescription
45 syn match ledgerPostingAmountOdd "\( \s\| \)\(\s*[^; ]\+\)\+"ms=s+0 contained containedin=ledgerPostingOdd contains=ledgerNumberOdd
46 syn match ledgerPostingAmount "\( \s\| \)\(\s*[^; ]\+\)\+"ms=s+0 contained containedin=ledgerPosting contains=ledgerNumber
47 syn match ledgerPostingAccountOdd "^\s\+[^; ]\([^; ]\|\s[^; ]\+\)*" contained containedin=ledgerPostingOdd nextgroup=ledgerPostingAmountOdd contains=ledgerNumberOdd,ledgerAccountSepOdd,ledgerAccountParenOdd,ledgerAccountBracketOdd
48 syn match ledgerPostingAccount "^\s\+[^; ]\([^; ]\| [^; ]\+\)*" contained containedin=ledgerPosting nextgroup=ledgerPostingAmount contains=ledgerNumber,ledgerAccountSep,ledgerAccountParen,ledgerAccountBracket
49 syn region ledgerPostingOdd start=/^\s\+[^; ]/ end=/^\(\s\+[^ ;]\|[^ ]\)/me=e-99 contained containedin=ledgerTransaction nextgroup=ledgerPosting
50 syn region ledgerPosting start=/^\s\+[^; ]/ end=/^\(\s\+[^ ;]\|[^ ]\)/me=e-99 contained containedin=ledgerTransaction nextgroup=ledgerPostingOdd
52 syn match ledgerTag /[^;, :]\+:[^;,]*/ contained containedin=ledgerTransactionComment nextgroup=ledgerTagValue,ledgerTagValueEnd
53 syn match ledgerTagValueSep /:/ contained containedin=ledgerTagValue,ledgerTagValueEnd,ledgerTag
54 syn match ledgerTagValue /[^;, :]:[^:]*,/ms=s+1,me=e-1 contained containedin=ledgerTag
55 syn match ledgerTagValueEnd /[^;, :]:[^:]*$/ms=s+1 contained containedin=ledgerTag
57 syn match ledgerComment ";.*"
59 if version >= 508 || !exists("did_ledger_syntax_inits")
61 let did_ledger_syntax_inits = 1
62 command! -nargs=+ HiLink hi link <args>
64 command! -nargs=+ HiLink hi def link <args>
66 HiLink ledgerChartComment Comment
67 HiLink ledgerComment Comment
68 HiLink ledgerTransactionComment Comment
69 hi Comment term=bold cterm=bold ctermfg=6 ctermbg=0 gui=bold guifg=#4169E1
70 hi ledgerAccountBracket term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=lightgreen
71 hi ledgerAccountBracketOdd term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=#F4F2E2
72 hi ledgerAccountParen term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=lightgreen
73 hi ledgerAccountParenOdd term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=#F4F2E2
74 hi ledgerAccountSep term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=#C4451D guibg=lightgreen
75 hi ledgerAccountSepOdd term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=#C4451D guibg=#F4F2E2
76 hi ledgerChart term=underline cterm=bold ctermfg=0 ctermbg=none gui=bold guifg=red guibg=NONE
77 hi ledgerChartLine cterm=bold ctermbg=none guibg=NONE
78 hi ledgerChartAccount term=underline cterm=bold ctermfg=0 ctermbg=none gui=bold guifg=black guibg=#F4F2E2
79 hi ledgerChartAccountSep term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=#C4451D guibg=#F4F2E2
80 hi ledgerChartNumber term=underline cterm=bold ctermfg=4 ctermbg=none gui=bold guifg=blue guibg=#F4F2E2
81 hi ledgerDirective term=bold cterm=bold gui=bold
82 hi ledgerInclude term=bold cterm=bold gui=bold
83 hi ledgerNumber term=bold cterm=bold ctermfg=4 ctermbg=none gui=bold guifg=blue guibg=lightgreen
84 hi ledgerNumberOdd term=bold cterm=bold ctermfg=4 ctermbg=none gui=bold guifg=blue guibg=#F4F2E2
85 hi ledgerPosting cterm=bold ctermbg=none guibg=NONE
86 hi ledgerPostingAccount term=underline cterm=bold ctermfg=0 ctermbg=none guifg=black guibg=lightgreen
87 hi ledgerPostingAccountOdd term=underline cterm=bold ctermfg=0 ctermbg=none guifg=black guibg=#F4F2E2
88 hi ledgerPostingAmount cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=#C4451D guibg=lightgreen
89 hi ledgerPostingAmountOdd cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=#C4451D guibg=#F4F2E2
90 hi ledgerPostingOdd cterm=bold ctermbg=none guibg=NONE
91 hi ledgerTag term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=orange
92 hi ledgerTagValue term=bold cterm=bold ctermfg=1 ctermbg=none gui=NONE guifg=grey30
93 hi ledgerTagValueEnd term=bold cterm=bold ctermfg=1 ctermbg=none gui=NONE guifg=grey30
94 hi ledgerTagValueSep term=bold cterm=bold ctermfg=0 ctermbg=none gui=bold guifg=#C4451D
95 hi ledgerChartTag term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=orange guibg=NONE
96 hi ledgerChartTagValue term=bold cterm=bold ctermfg=1 ctermbg=none gui=NONE guifg=grey30 guibg=NONE
97 hi ledgerChartTagValueEnd term=bold cterm=bold ctermfg=1 ctermbg=none gui=NONE guifg=gray30 guibg=NONE
98 hi ledgerChartTagValueSep term=bold cterm=bold ctermfg=0 ctermbg=none gui=bold guifg=#C4451D guibg=NONE
99 hi ledgerTransaction cterm=bold ctermbg=none gui=bold guifg=red
100 hi ledgerTransactionDate cterm=bold ctermfg=5 ctermbg=none gui=bold guifg=#000080 guibg=lightgoldenrod
101 hi ledgerTransactionDateNum cterm=bold ctermfg=5 ctermbg=none gui=bold guifg=black guibg=lightgoldenrod
102 hi ledgerTransactionDateSep cterm=bold ctermfg=5 ctermbg=none gui=bold guifg=#C4451D guibg=lightgoldenrod
103 hi ledgerTransactionDescription cterm=bold ctermfg=5 ctermbg=none gui=bold guifg=#C4451D
104 hi ledgerTransactionStatus term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2
108 let b:current_syntax = "ledger"