I have improved the vim syntax file for ledger, c.f. attachment.
Features: - The fold gets the amount (in the first transaction) even when a note or currency or commodity follows it. - It accepts "." and "," as a decimal separator.
This commit is contained in:
parent
6cd2a14542
commit
e1b0203f5e
1 changed files with 25 additions and 16 deletions
41
ledger.vim
41
ledger.vim
|
|
@ -1,19 +1,24 @@
|
||||||
" Vim syntax file
|
" Vim syntax file
|
||||||
" filetype: ledger
|
" filetype: ledger
|
||||||
" Version: 0.0.2
|
" Version: 0.0.4
|
||||||
|
" by Stefan Karrmann; Use according to the terms of the GPL>=2.
|
||||||
" by Wolfgang Oertl; Use according to the terms of the GPL>=2.
|
" by Wolfgang Oertl; Use according to the terms of the GPL>=2.
|
||||||
" Revision history
|
" Revision history
|
||||||
" 2005-02-05 first version (partly copied from ledger.vim 0.0.1)
|
" 2009-01-28 S.Karrmann: minor fixes
|
||||||
|
" 2009-01-27 third version by S.Karrmann.
|
||||||
|
" better extraction of the amount of the transaction
|
||||||
|
" decimal separator can be one of '.' and ','.
|
||||||
|
" 2005-02-05 first version (partly copied from ledger.vim 0.0.1)
|
||||||
|
|
||||||
if version < 600
|
if version < 600
|
||||||
syntax clear
|
syntax clear
|
||||||
elseif exists("b:current_sytax")
|
elseif exists("b:current_sytax")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" for debugging
|
" for debugging
|
||||||
syntax clear
|
syntax clear
|
||||||
|
|
||||||
" region: a normal transaction
|
" region: a normal transaction
|
||||||
syn region transNorm start=/^\d/ skip=/^\s/ end=/^/ fold keepend transparent contains=transDate
|
syn region transNorm start=/^\d/ skip=/^\s/ end=/^/ fold keepend transparent contains=transDate
|
||||||
syn match transDate /^\d\S\+/ contained
|
syn match transDate /^\d\S\+/ contained
|
||||||
|
|
@ -21,26 +26,30 @@ syn match Comment /^;.*$/
|
||||||
" highlight default link transNorm Question
|
" highlight default link transNorm Question
|
||||||
highlight default link Comment SpecialKey
|
highlight default link Comment SpecialKey
|
||||||
highlight default link transDate Question
|
highlight default link transDate Question
|
||||||
|
|
||||||
" folding: how to represent a transaction in one line.
|
" folding: how to represent a transaction in one line.
|
||||||
function! MyFoldText()
|
function! LedgerFoldText()
|
||||||
let line = strpart(getline(v:foldstart), 0, 65)
|
let line = strpart(getline(v:foldstart), 0, 99)
|
||||||
" get the amount at the end of the second line
|
" get the amount at the end of the second line
|
||||||
let line2 = getline(v:foldstart+1)
|
let line2 = getline(v:foldstart+1)
|
||||||
let pos = match(line2, "[0-9.]*$")
|
let lst = matchlist(line2,'\([0-9]\+\%([,.][0-9]\+\)\=\|[,.][0-9]\+\)\s*\%([A-Za-z$€¢]\+\s*\)\=\%(\s*;.*\)\=$')
|
||||||
let line2 = strpart(line2, pos)
|
if (len(lst) == 0)
|
||||||
|
let line2 = ""
|
||||||
|
else
|
||||||
|
let line2 = lst[1]
|
||||||
|
endif
|
||||||
let pad_len = 80 - strlen(line) - strlen(line2)
|
let pad_len = 80 - strlen(line) - strlen(line2)
|
||||||
if (pad_len < 0) then
|
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 . line2
|
||||||
endfunction
|
endfunction
|
||||||
set foldtext=MyFoldText()
|
set foldtext=LedgerFoldText()
|
||||||
set foldmethod=syntax
|
set foldmethod=syntax
|
||||||
|
|
||||||
" syncinc is easy: search for the first transaction.
|
" syncinc is easy: search for the first transaction.
|
||||||
syn sync clear
|
syn sync clear
|
||||||
syn sync match ledgerSync grouphere transNorm "^\d"
|
syn sync match ledgerSync grouphere transNorm "^\d"
|
||||||
|
|
||||||
let b:current_syntax = "ledger"
|
let b:current_syntax = "ledger"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue