aboutsummaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--indent/beancount.vim26
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