diff options
author | Nathan Grigg | 2015-04-14 15:59:23 -0700 |
---|---|---|
committer | Nathan Grigg | 2015-04-15 10:09:33 -0700 |
commit | 927ac097e93f897727f79381e5ce33c9d99d1f64 (patch) | |
tree | c61673a8d0b5565feb0b76b497ec8b7c994a43d7 /indent | |
parent | 6a18500db9546ad1d2fcbf6b61e55c35b25003b5 (diff) | |
download | vim-beancount-927ac097e93f897727f79381e5ce33c9d99d1f64.tar.gz |
Preliminary support for automatic indentation.
This assumes that the only indented lines are legs of a transaction.
It works best if you put blank lines between transactions.
If you do not use blank lines to end a transaction, it will usually work
anyway, since it forces any line starting with a date to be all the way
left.
Diffstat (limited to 'indent')
-rw-r--r-- | indent/beancount.vim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/indent/beancount.vim b/indent/beancount.vim new file mode 100644 index 0000000..da8fed2 --- /dev/null +++ b/indent/beancount.vim @@ -0,0 +1,26 @@ +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetBeancountIndent(v:lnum) + +if exists("*GetBeancountIndent") + finish +endif + +function GetBeancountIndent(line_num) + let this_line = getline(a:line_num) + let prev_line = getline(a:line_num - 1) + " This is a new directive or previous line is blank. + echom this_line + echom prev_line + if this_line =~ '\v^\s*\d{4}-\d{2}-\d{2}' || prev_line =~ '^\s*$' + return 0 + endif + " Previous line is the beginning of a transaction. + if prev_line =~ '\v^\s*\d{4}-\d{2}-\d{2}\s+(txn\s+)?.\s+' + return &shiftwidth + endif + return -1 +endfunction |