diff options
author | Wynn Wolf Arbor | 2020-03-10 17:37:03 +0100 |
---|---|---|
committer | Wynn Wolf Arbor | 2020-04-28 17:59:15 +0200 |
commit | 9f853addd1fdb44966eaaf904114542061a38c5b (patch) | |
tree | 126393f337a17262711f2cdefdbe46bf3297caca /autoload | |
parent | 22eb7ac8970394a881946f408a5bc972a72c785d (diff) | |
download | vim-beancount-9f853addd1fdb44966eaaf904114542061a38c5b.tar.gz |
Replace AlignCommodity with bean-format
AlignCommodity replicates the functionality of the bean-format command
that is shipped with beancount itself. Therefore, we can fully replace
it by having vim invoke bean-format through formatprg.
Even though bean-format's output might differ from AlignCommodity in
significant ways, we feel that using one unified tool is superior to
having several (possibly incompatible) custom implementations. That way,
if bean-format is improved upon in the future, all downstream consumers
profit. For regular usage, however, this change should be transparent.
Note that while bean-format supports a few different ways of formatting
the ledger, we have opted to hard-code one specific setting. This will
match the default behaviour of fava, aligning currencies in column 61.
Managing the arguments passed to bean-format dynamically is considered
out of scope, especially given the fact that the user need only override
formatprg to get a custom setting.
This commit will also drop the g:beancount_separator_col variable and
the tests for AlignCommodity. Ideally, testing will now done upstream
for bean-format itself.
Diffstat (limited to '')
-rw-r--r-- | autoload/beancount.vim | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/autoload/beancount.vim b/autoload/beancount.vim index c5d8f97..91f6999 100644 --- a/autoload/beancount.vim +++ b/autoload/beancount.vim @@ -6,52 +6,6 @@ function! s:startswith(string, prefix) abort return strpart(a:string, 0, strlen(a:prefix)) == a:prefix endfunction -" Align currency on decimal point. -function! beancount#align_commodity(line1, line2) abort - " Save cursor position to adjust it if necessary. - let l:cursor_col = col('.') - let l:cursor_line = line('.') - - " Increment at start of loop, because of continue statements. - let l:current_line = a:line1 - 1 - while l:current_line < a:line2 - let l:current_line += 1 - let l:line = getline(l:current_line) - " This matches an account name followed by a space in one of the two - " following cases: - " - A posting line, i.e., the line starts with indentation followed - " by an optional flag and the account. - " - A balance directive, i.e., the line starts with a date followed - " by the 'balance' keyword and the account. - " - A price directive, i.e., the line starts with a date followed by - " the 'price' keyword and a currency. - let l:end_account = matchend(l:line, '^\v' . - \ '[\-/[:digit:]]+\s+balance\s+([A-Z][A-Za-z0-9\-]+)(:[A-Z][A-Za-z0-9\-]*)+ ' . - \ '|[\-/[:digit:]]+\s+price\s+\S+ ' . - \ '|\s+([!&#?%PSTCURM]\s+)?([A-Z][A-Za-z0-9\-]+)(:[A-Z][A-Za-z0-9\-]*)+ ' - \ ) - if l:end_account < 0 - continue - endif - - " Where does the number begin? - let l:begin_number = matchend(l:line, '^ *', l:end_account) - - " Look for a minus sign and a number (possibly containing commas) and - " align on the next column. - let l:separator = matchend(l:line, '^\v([-+])?[,[:digit:]]+', l:begin_number) + 1 - if l:separator < 0 | continue | endif - let l:has_spaces = l:begin_number - l:end_account - let l:need_spaces = g:beancount_separator_col - l:separator + l:has_spaces - if l:need_spaces < 0 | continue | endif - call setline(l:current_line, l:line[0 : l:end_account - 1] . repeat(' ', l:need_spaces) . l:line[ l:begin_number : -1]) - if l:current_line == l:cursor_line && l:cursor_col >= l:end_account - " Adjust cursor position for continuity. - call cursor(0, l:cursor_col + l:need_spaces - l:has_spaces) - endif - endwhile -endfunction - function! s:count_expression(text, expression) abort return len(split(a:text, a:expression, 1)) - 1 endfunction |