aboutsummaryrefslogblamecommitdiffstats
path: root/indent/beancount.vim
blob: 686cbdce910b4121a3728e9c24bc11de2daa109f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                        








                                                                     
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.
    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