aboutsummaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
authorxentac2017-03-26 10:47:01 -0700
committerGitHub2017-03-26 10:47:01 -0700
commitb893e138381be12a7a03a1a3b738907067b0348f (patch)
tree1809329c0ba34f6d0ab6e3dd94b27f3ae316699b /indent
parent4c19b4957ab7931fc2467b225b7a61b1215c6581 (diff)
parent6600558bc68b5a42ac59cca8fd2cac4dac7f8417 (diff)
downloadvim-beancount-b893e138381be12a7a03a1a3b738907067b0348f.tar.gz
Merge pull request #39 from yagebu/fixes-and-lint
Fixes and lint
Diffstat (limited to 'indent')
-rw-r--r--indent/beancount.vim32
1 files changed, 16 insertions, 16 deletions
diff --git a/indent/beancount.vim b/indent/beancount.vim
index cfc8aa6..4303986 100644
--- a/indent/beancount.vim
+++ b/indent/beancount.vim
@@ -1,44 +1,44 @@
-if exists("b:did_indent")
+if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetBeancountIndent(v:lnum)
-if exists("*GetBeancountIndent")
+if exists('*GetBeancountIndent')
finish
endif
function! s:IsDirective(str)
- return a:str =~ '\v^\s*(\d{4}-\d{2}-\d{2}|pushtag|poptag|option|plugin|include)'
+ return a:str =~# '\v^\s*(\d{4}-\d{2}-\d{2}|pushtag|poptag|option|plugin|include)'
endfunction
-function! s:IsPost(str)
- return a:str =~ '\v^\s*(Assets|Liabilities|Expenses|Equity|Income):'
+function! s:IsPosting(str)
+ return a:str =~# '\v^\s*[A-Z]\w+:'
endfunction
function! s:IsMetadata(str)
- return a:str =~ '\v^\s*\w+:\s'
+ return a:str =~# '\v^\s*[a-z][a-zA-Z0-9\-_]+:'
endfunction
function! s:IsTransaction(str)
" The final \S represents the flag (e.g. * or !).
- return a:str =~ '\v^\s*\d{4}-\d{2}-\d{2}\s+(txn\s+)?\S(\s|$)'
+ return a:str =~# '\v^\s*\d{4}-\d{2}-\d{2}\s+(txn\s+)?\S(\s|$)'
endfunction
function GetBeancountIndent(line_num)
- let this_line = getline(a:line_num)
- let prev_line = getline(a:line_num - 1)
+ let l:this_line = getline(a:line_num)
+ let l:prev_line = getline(a:line_num - 1)
" Don't touch comments
- if this_line =~ '\v^\s*;' | return -1 | endif
+ if l:this_line =~# '\v^\s*;' | return -1 | endif
" This is a new directive or previous line is blank.
- if prev_line =~ '^\s*$' || s:IsDirective(this_line) | return 0 | endif
+ if l:prev_line =~# '^\s*$' || s:IsDirective(l:this_line) | return 0 | endif
" Previous line is transaction or this is a posting.
- if s:IsTransaction(prev_line) || s:IsPost(this_line) | return &sw | endif
- if s:IsMetadata(this_line)
- let this_indent = indent(a:line_num - 1)
- if ! s:IsMetadata(prev_line) | let this_indent += &sw | endif
- return this_indent
+ if s:IsTransaction(l:prev_line) || s:IsPosting(l:this_line) | return &shiftwidth | endif
+ if s:IsMetadata(l:this_line)
+ let l:this_indent = indent(a:line_num - 1)
+ if ! s:IsMetadata(l:prev_line) | let l:this_indent += &shiftwidth | endif
+ return l:this_indent
endif
return -1
endfunction