From 927ac097e93f897727f79381e5ce33c9d99d1f64 Mon Sep 17 00:00:00 2001 From: Nathan Grigg Date: Tue, 14 Apr 2015 15:59:23 -0700 Subject: 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. --- indent/beancount.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 indent/beancount.vim (limited to 'indent/beancount.vim') 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 -- cgit v1.2.3-2-gb3c3