robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
710431c696
master
1" Vim indent file 2" Language: beancount 3" Maintainer: Nathan Grigg 4" Latest Revision: 2017-03-20 5 6if exists ( 'b:did_indent' ) 7finish 8endif 9let b: did_indent = 1 10 11setlocal indentexpr = GetBeancountIndent (v:lnum) 12 13let b: undo_indent = "setl inde<" 14 15if exists ( '*GetBeancountIndent' ) 16finish 17endif 18 19function ! s: IsDirective ( str ) 20return a: str =~# '\v^\s*(\d{4}-\d{2}-\d{2}|pushtag|poptag|option|plugin|include)' 21endfunction 22 23function ! s: IsPosting ( str ) 24return a: str =~# '\v^\s*[A-Z]\w+:' 25endfunction 26 27function ! s: IsMetadata ( str ) 28return a: str =~# '\v^\s*[a-z][a-zA-Z0-9\-_]+:' 29endfunction 30 31function ! s: IsTransaction ( str ) 32" The final \S represents the flag (e.g. * or !). 33return a: str =~# '\v^\s*\d{4}-\d{2}-\d{2}\s+(txn\s+)?\S(\s|$)' 34endfunction 35 36function GetBeancountIndent ( line_num ) 37let l: this_line = getline ( a: line_num ) 38let l: prev_line = getline ( a: line_num - 1 ) 39" Don't touch comments 40if l: this_line =~# '\v^\s*;' |return -1 |endif 41" This is a new directive or previous line is blank. 42if l: prev_line =~# '^\s*$' || s: IsDirective ( l: this_line ) |return 0 |endif 43" Previous line is transaction or this is a posting. 44if s: IsTransaction ( l: prev_line ) || s: IsPosting ( l: this_line ) |return & shiftwidth |endif 45if s: IsMetadata ( l: this_line ) 46let l: this_indent = indent ( a: line_num - 1 ) 47if ! s: IsMetadata ( l: prev_line ) |let l: this_indent += & shiftwidth |endif 48return l: this_indent 49endif 50return -1 51endfunction