diff options
author | John Wiegley <johnw@newartisans.com> | 2012-04-22 14:48:46 -0700 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-04-22 14:48:46 -0700 |
commit | 04574bc5117fe951947f483cdc5f2c37f15b9a43 (patch) | |
tree | 407473768879c56957d2688d158cd680211c36e3 /contrib/vim/indent/ledger.vim | |
parent | ee641f353c9a2216533800464d26afe86f1b028e (diff) | |
parent | 76ab0acaaa30b61b8482c4854f7f54eb92d0b6e8 (diff) | |
download | fork-ledger-04574bc5117fe951947f483cdc5f2c37f15b9a43.tar.gz fork-ledger-04574bc5117fe951947f483cdc5f2c37f15b9a43.tar.bz2 fork-ledger-04574bc5117fe951947f483cdc5f2c37f15b9a43.zip |
Merge pull request #64 from kljohann/vim
Vim: Update syntax file, create indentation file, set commentstring (Bugs 528, 529)
Diffstat (limited to 'contrib/vim/indent/ledger.vim')
-rw-r--r-- | contrib/vim/indent/ledger.vim | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/contrib/vim/indent/ledger.vim b/contrib/vim/indent/ledger.vim new file mode 100644 index 00000000..ce5d508d --- /dev/null +++ b/contrib/vim/indent/ledger.vim @@ -0,0 +1,46 @@ +" Vim filetype indent file +" filetype: ledger +" by Johann Klähn; Use according to the terms of the GPL>=2. +" vim:ts=2:sw=2:sts=2:foldmethod=marker + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setl autoindent +setl indentexpr=GetLedgerIndent() + +if exists("*GetLedgerIndent") + finish +endif + +function GetLedgerIndent(...) + " You can pass in a line number when calling this function manually. + let lnum = a:0 > 0 ? a:1 : v:lnum + " If this line is empty look at (the indentation of) the last line. + " Note that inside of a transaction no blank lines are allowed. + let line = getline(lnum) + let prev = getline(lnum - 1) + + if line =~ '^\s\+\S' + " Lines that already are indented (→postings, sub-directives) keep their indentation. + return &sw + elseif line =~ '^\s*$' + " Current line is empty, try to guess its type based on the previous line. + if prev =~ '^\([[:digit:]~=]\|\s\+\S\)' + " This is very likely a posting or a sub-directive. + " While lines following the start of a transaction are automatically + " indented you will have to indent the first line following a + " pre-declaration manually. This makes it easier to type long lists of + " 'account' pre-declarations without sub-directives, for example. + return &sw + else + return 0 + endif + else + " Everything else is not indented: + " start of transactions, pre-declarations, apply/end-lines + return 0 + endif +endf |