ledger / ledger-mode

Emacs Lisp files for interacting with the C++Ledger accounting system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reports using both `account` and `month` expansions fail

grgbrn opened this issue · comments

When creating custom reports, using the %(month) expansion seems to prevent the %(account) expansion from working.

Adding a new report that uses both:

  (ledger-reports-add "foo"
                      "%(binary) -f %(ledger-file) reg --strict --period %(month) %(account)")

When executed:

Report: foo
Command: ledger -f /home/greg/Documents/ledger/main.ledger reg --strict --period 2024-4 %(account)
============================================================================

/bin/bash: -c: line 1: syntax error near unexpected token `('
/bin/bash: -c: line 1: `ledger --prepend-format\=\%\(filename\)\:\%\(beg_line\)\: --columns 77 --color --force-color -f /home/greg/Documents/ledger/main.ledger reg --strict --period 2024-4 %(account)'

so all of the expansions except %(account) work. If I remove %(month), then the %(account) expansion works again. It's not related to the total number of expansions performed, hard-coding the binary and ledger file paths don't fix the problem.

I updated to the latest version from melpa (20240414.2206) and am still seeing the problem.

I haven't looked into this any further, just wanted to file a bug while I was thinking about it. I'm not much of an elisp hacker but
I'll see if I can find time to poke at it a bit later in the week

Nice catch.

There appears to be a bug in general when a format specifier expands into something shorter than the original specifier, and then there is another format specifier that follows closely. ledger-report-expand-format-specifiers is incorrectly rescanning the string from the index where the last search ended not taking into account that the index may have changed if the replacement text is a different length.