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 ledgerComment ";.*"
16 syn match ledgerNumberOdd /[0-9][0-9]*/ contained
17 syn match ledgerNumber /[0-9][0-9]*/ contained
18 syn match ledgerAccountSeparator ":" contained
19 syn match ledgerAccountSeparatorOdd ":" contained
20 syn match ledgerAccountParen /[()]/ contained
21 syn match ledgerAccountParenOdd /[()]/ contained
22 syn match ledgerAccountBracket /[[\]]/ contained
23 syn match ledgerAccountBracketOdd /[[\]]/ contained
25 syn region ledgerInclude start=/^!include/ end=/^/
26 syn region ledgerDirective start=/^[A-Z]/ end=/^/ contains=ledgerComment
28 syn region ledgerTransaction start=/^\d[^ ]\+/ end=/^\s*$/
29 syn match ledgerTransactionHead "^[0-9/-]\+\( [0-9:]\+\)\?\(=[0-9/-]\+\( [0-9:]\+\)\?\)\?\(\s\+[!*]\)\?" contained containedin=ledgerTransaction nextgroup=ledgerTransactionDescription
30 syn match ledgerTransactionDate "[0-9/-]\+\( [0-9:]\+\)\?" contained containedin=ledgerTransactionHead
31 syn match ledgerTransactionDescription "\s[^;]\+"ms=s+1 contained containedin=ledgerTransaction
32 syn match ledgerTransactionComment ";.*" contained containedin=ledgerTransaction,ledgerPosting,ledgerPostingOdd
34 syn match ledgerPostingAmountOdd " \(\s*[^; ]\+\)\+"ms=s+0 contained containedin=ledgerPostingOdd contains=ledgerNumberOdd
35 syn match ledgerPostingAmount " \(\s*[^; ]\+\)\+"ms=s+0 contained containedin=ledgerPosting contains=ledgerNumber
36 syn match ledgerPostingAccountOdd "^\s\+[^; ]\([^; ]\|\s[^; ]\+\)*" contained containedin=ledgerPostingOdd nextgroup=ledgerPostingAmountOdd contains=ledgerNumberOdd,ledgerAccountSeparatorOdd,ledgerAccountParenOdd,ledgerAccountBracketOdd
37 syn match ledgerPostingAccount "^\s\+[^; ]\([^; ]\|\s[^; ]\+\)*" contained containedin=ledgerPosting nextgroup=ledgerPostingAmount contains=ledgerNumber,ledgerAccountSeparator,ledgerAccountParen,ledgerAccountBracket
38 syn region ledgerPostingOdd start=/^\s\+[^; ]/ end=/^/ contained containedin=ledgerTransaction nextgroup=ledgerPosting
39 syn region ledgerPosting start=/^\s\+[^; ]/ end=/^/ contained containedin=ledgerTransaction nextgroup=ledgerPostingOdd
41 syn match ledgerTag /[^;, :]\+:[^;,]*/ contained containedin=ledgerTransactionComment nextgroup=ledgerTagValue
42 syn match ledgerTagValue /[^;, :]:[^,;]*/ms=s+2 contained containedin=ledgerTag
44 if version >= 508 || !exists("did_ledger_syntax_inits")
46 let did_ledger_syntax_inits = 1
47 command! -nargs=+ HiLink hi link <args>
49 command! -nargs=+ HiLink hi def link <args>
51 hi SpecialKey gui=bold guifg=lightgoldenrod
52 hi Comment term=bold cterm=bold ctermfg=6 ctermbg=0 gui=bold guifg=#4169E1
53 hi Comment term=bold cterm=bold ctermfg=6 ctermbg=0 gui=bold guifg=#4169E1
54 HiLink ledgerComment Comment
55 hi ledgerInclude term=bold cterm=bold gui=bold
56 hi ledgerDirective term=bold cterm=bold gui=bold
57 hi ledgerAccountSeparatorOdd term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=gray90
58 hi ledgerAccountParenOdd term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=gray90
59 hi ledgerAccountBracketOdd term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=gray90
60 hi ledgerAccountSeparator term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=lightgreen
61 hi ledgerAccountParen term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=lightgreen
62 hi ledgerAccountBracket term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=lightgreen
63 hi ledgerNumberOdd term=bold cterm=bold ctermfg=4 ctermbg=none gui=bold guifg=blue guibg=gray90
64 hi ledgerNumber term=bold cterm=bold ctermfg=4 ctermbg=none gui=bold guifg=blue guibg=lightgreen
65 hi ledgerPostingOdd cterm=bold ctermbg=none guibg=NONE
66 hi ledgerPosting cterm=bold ctermbg=none guibg=NONE
67 hi ledgerPostingAccountOdd term=underline cterm=bold ctermfg=0 ctermbg=none guifg=gray30 guibg=gray90
68 hi ledgerPostingAccount term=underline cterm=bold ctermfg=0 ctermbg=none guifg=gray30 guibg=lightgreen
69 hi ledgerPostingAmountOdd cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=gray90
70 hi ledgerPostingAmount cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=DarkGoldenrod2 guibg=lightgreen
71 hi ledgerTag term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=orange
72 hi ledgerTagValue term=bold cterm=bold ctermfg=1 ctermbg=none gui=NONE guifg=red
73 hi ledgerTransaction cterm=bold ctermbg=none gui=bold
74 hi ledgerTransactionComment term=bold cterm=bold ctermfg=6 ctermbg=none gui=bold guifg=#4169E1
75 hi ledgerTransactionDate cterm=bold ctermfg=5 ctermbg=none gui=bold guibg=lightgoldenrod
76 hi ledgerTransactionDescription cterm=bold ctermfg=5 ctermbg=none gui=bold
77 hi ledgerTransactionHead term=bold cterm=bold ctermfg=3 ctermbg=none gui=bold guifg=purple guibg=lightgoldenrod
81 let b:current_syntax = "ledger"