Johann Klähn: Added metadata support for ledger.vim
This commit is contained in:
parent
025af3c189
commit
ca42f2b9a7
1 changed files with 33 additions and 17 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
" Revision history
|
" Revision history
|
||||||
" 2009-01-28 S.Karrmann: minor fixes
|
" 2009-01-28 S.Karrmann: minor fixes
|
||||||
" 2009-01-27 third version by S.Karrmann.
|
" 2009-01-27 third version by S.Karrmann.
|
||||||
" better extraction of the amount of the posting
|
" better extraction of the amount of the transaction
|
||||||
" decimal separator can be one of '.' and ','.
|
" decimal separator can be one of '.' and ','.
|
||||||
" 2005-02-05 first version (partly copied from ledger.vim 0.0.1)
|
" 2005-02-05 first version (partly copied from ledger.vim 0.0.1)
|
||||||
|
|
||||||
|
|
@ -20,36 +20,52 @@ endif
|
||||||
syntax clear
|
syntax clear
|
||||||
|
|
||||||
" region: a normal posting
|
" region: a normal posting
|
||||||
syn region transNorm start=/^\d/ skip=/^\s/ end=/^/ fold keepend transparent contains=transDate
|
syn region postNorm start=/^\d/ skip=/^\s/ end=/^/ fold keepend transparent contains=postDate,Metadata
|
||||||
syn match transDate /^\d\S\+/ contained
|
syn match postDate /^\d\S\+/ contained
|
||||||
|
syn match Metadata /^\s\+;.*$/ contained
|
||||||
syn match Comment /^;.*$/
|
syn match Comment /^;.*$/
|
||||||
" highlight default link transNorm Question
|
|
||||||
highlight default link Comment SpecialKey
|
highlight default link Comment SpecialKey
|
||||||
highlight default link transDate Question
|
highlight default link Metadata SpecialKey
|
||||||
|
highlight default link postDate Question
|
||||||
|
|
||||||
" folding: how to represent a posting in one line.
|
" folding: how to represent a posting in one line.
|
||||||
function! LedgerFoldText()
|
function! LedgerFoldText()
|
||||||
let line = strpart(getline(v:foldstart), 0, 99)
|
let line = strpart(getline(v:foldstart), 0, 99)
|
||||||
" get the amount at the end of the second line
|
let amount = ""
|
||||||
let line2 = getline(v:foldstart+1)
|
|
||||||
let lst = matchlist(line2,'\([0-9]\+\%([,.][0-9]\+\)\=\|[,.][0-9]\+\)\s*\%([A-Za-z$€¢]\+\s*\)\=\%(\s*;.*\)\=$')
|
let delta = 1
|
||||||
if (len(lst) == 0)
|
while (delta >= 1 && delta < (v:foldend-v:foldstart+1))
|
||||||
let line2 = ""
|
let other_line = getline(v:foldstart+delta)
|
||||||
|
|
||||||
|
if len(matchstr(other_line, '^\s\+;')) != 0
|
||||||
|
" Skip metadata/leading comment
|
||||||
|
let delta = delta + 1
|
||||||
else
|
else
|
||||||
let line2 = lst[1]
|
" No comment, look for amount...
|
||||||
|
let delta = -1
|
||||||
|
let lst = matchlist(other_line,'\(\%([0-9]\+[,.]\)\=[0-9]\+\%([,.][0-9]\+\)\=\|[,.][0-9]\+\)\s*\%([A-Za-z$€¢]\+\s*\)\=\%(\s*;.*\)\=$')
|
||||||
|
if (len(lst) != 0)
|
||||||
|
let amount = lst[1]
|
||||||
endif
|
endif
|
||||||
let pad_len = 80 - strlen(line) - strlen(line2)
|
endif
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
" Replace each char with x prior to counting
|
||||||
|
" this fixes problems with multi byte characters
|
||||||
|
let pad_len = 80 - strlen(substitute(line, ".", "x", "g")) - strlen(substitute(amount, ".", "x", "g"))
|
||||||
|
|
||||||
if (pad_len < 0)
|
if (pad_len < 0)
|
||||||
pad_len = 0
|
pad_len = 0
|
||||||
endif
|
endif
|
||||||
let pad = strpart(" ", 0, pad_len)
|
let pad = strpart(" ", 0, pad_len)
|
||||||
return line . pad . line2
|
return line . pad . amount
|
||||||
endfunction
|
endfunction
|
||||||
set foldtext=LedgerFoldText()
|
set foldtext=LedgerFoldText()
|
||||||
set foldmethod=syntax
|
set foldmethod=syntax
|
||||||
|
|
||||||
" syncinc is easy: search for the first posting.
|
" syncinc is easy: search for the first posting.
|
||||||
syn sync clear
|
syn sync clear
|
||||||
syn sync match ledgerSync grouphere transNorm "^\d"
|
syn sync match ledgerSync grouphere postNorm "^\d"
|
||||||
|
|
||||||
let b:current_syntax = "ledger"
|
let b:current_syntax = "ledger"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue