summaryrefslogtreecommitdiff
path: root/contrib/vim
diff options
context:
space:
mode:
authorJohann Klähn <kljohann@gmail.com>2011-01-28 07:59:32 +0100
committerJohann Klähn <kljohann@gmail.com>2011-05-09 19:57:50 +0200
commit976d9e5d8b4301eb2f296b176161185bdeff9fb5 (patch)
tree01e5e6e1e8570fdc875ad05e42b0d8cb828f32bb /contrib/vim
parent3896214336c880a8dcb13b79b01f616f25403919 (diff)
downloadfork-ledger-976d9e5d8b4301eb2f296b176161185bdeff9fb5.tar.gz
fork-ledger-976d9e5d8b4301eb2f296b176161185bdeff9fb5.tar.bz2
fork-ledger-976d9e5d8b4301eb2f296b176161185bdeff9fb5.zip
vim. correctly parse first lines of transactions
This fixes trailing comments being chopped of and later readded with too few spaces. (when calling format_head())
Diffstat (limited to 'contrib/vim')
-rw-r--r--contrib/vim/ftplugin/ledger.vim18
1 files changed, 14 insertions, 4 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim
index d1c8e1a9..52579fd0 100644
--- a/contrib/vim/ftplugin/ledger.vim
+++ b/contrib/vim/ftplugin/ledger.vim
@@ -293,7 +293,15 @@ function! s:transaction.from_lnum(lnum) dict "{{{2
let trans['head'] = head
let trans['tail'] = tail
- let parts = split(getline(head), '\s\+')
+ " split off eventual comments at the end of line
+ let line = split(getline(head), '\ze\s*\%(\t\| \);', 1)
+ if len(line) > 1
+ let trans['appendix'] = join(line[1:], '')
+ endif
+
+ " parse rest of line
+ " FIXME (minor): will not preserve spacing (see 'join(parts)')
+ let parts = split(line[0], '\s\+')
if parts[0] ==# '~'
let trans['expr'] = join(parts[1:])
return trans
@@ -318,8 +326,6 @@ function! s:transaction.from_lnum(lnum) dict "{{{2
call remove(parts, 0)
endfor
- " FIXME: this will break comments at the end of this 'head' line
- " they need 2 spaces in front of the semicolon
let trans['description'] = join(parts)
return trans
endf "}}}
@@ -402,7 +408,11 @@ function! s:transaction.format_head() dict "{{{2
if has_key(self, 'code') | call add(parts, '('.self['code'].')') | endif
if has_key(self, 'state') | call add(parts, self['state']) | endif
if has_key(self, 'description') | call add(parts, self['description']) | endif
- return join(parts)
+
+ let line = join(parts)
+ if has_key(self, 'appendix') | let line .= self['appendix'] | endif
+
+ return line
endf "}}}
"}}}