Link accounts in balance report / register|account report
stapelberg opened this issue · comments
By default, lines in ledger reg
reports contain links to the line in the journal that defines them. So far, so good.
But what I’m wondering is: In a ledger bal
report, can we also link accounts so that clicking on them opens an account
report?
(Similarly, I think the link in the reg
report should be split into multiple parts, and clicking on an individual account there should also bring you to the account
report.)
Given that ledger and ledger-mode are quite old, I’m wondering if I’m missing something fundamental here. It seems like a very useful feature, so others must have longed for it before me…?
Thanks
That sounds like a reasonable idea, although personally, I think it's actually not that annoying to instead: press S
(bound to ledger-report
in the report buffer), select account
, and type in enough of the account name to be auto-completed. I didn't find any requests for a feature like this when searching through past issues on this repo (although I've only been active on this project for a short while so I don't know if anything was previously discussed before it moved to GitHub, for example).
Here are some possible obstacles I thought of just now, although there may be others:
- A user may not have an
account
report defined, and if they do, it may not correspond to the default one. The assumption this link would have to make is that there is such a report, and that it takes an%(account)
argument in the command line. - ledger-cli doesn't specially mark the part of the output text that constitutes the account name. There could maybe be some way to use the
--account STR
flag to prefix accounts with a special string that could be searched for and removed, but otherwise ledger-mode would somehow have to figure out which part of the buffer actually corresponds to account names, despite the fact that users can customize the format of thereg
report. - Accounts may be automatically abbreviated (e.g.,
Expenses:Food:Drinks:Coffee
could becomeEx:F:Dr:Coffee
). This could be fixed by expanding the--prepend-format
flag currently passed inledger-report--compute-extra-args
to include the full account name (%A
) and then parsing and hiding that part of each line the same way filenames and line numbers are currently link-ified.
(3) seems at least somewhat easy to do, and we could start by stashing the account name in a text property on each line like the source location currently is. Then, we could maybe make S
default to the account name in the text property at point, if the selected report would prompt for an account name? (We'd also have to make sure it prompts before clearing the buffer, rather than after, as it currently does).
Thanks for your reply, I appreciate you taking the time to think through this suggestion.
I have a few comments:
Here are some possible obstacles I thought of just now, although there may be others:
- A user may not have an
account
report defined, and if they do, it may not correspond to the default one. The assumption this link would have to make is that there is such a report, and that it takes an%(account)
argument in the command line.
Yes. We could — perhaps in a later step — make the link customizeable (with a format string) so that users who want to customize more can do so while still enjoying the linking.
- ledger-cli doesn't specially mark the part of the output text that constitutes the account name. There could maybe be some way to use the
--account STR
flag to prefix accounts with a special string that could be searched for and removed, but otherwise ledger-mode would somehow have to figure out which part of the buffer actually corresponds to account names, despite the fact that users can customize the format of thereg
report.
The ledger accounts
command lists all known accounts. Couldn’t we use that and just do textual matching?
- Accounts may be automatically abbreviated (e.g.,
Expenses:Food:Drinks:Coffee
could becomeEx:F:Dr:Coffee
). This could be fixed by expanding the--prepend-format
flag currently passed inledger-report--compute-extra-args
to include the full account name (%A
) and then parsing and hiding that part of each line the same way filenames and line numbers are currently link-ified.(3) seems at least somewhat easy to do, and we could start by stashing the account name in a text property on each line like the source location currently is. Then, we could maybe make
S
default to the account name in the text property at point, if the selected report would prompt for an account name? (We'd also have to make sure it prompts before clearing the buffer, rather than after, as it currently does).
Cool! Having S
default to the account name at point sounds like a great improvement :)
How do you suggest to proceed? Would you want to suggest a change, or are we relying on contributors here? [My Emacs knowledge and time are both very limited.]