Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link accounts in balance report / register|account report #403

Open
stapelberg opened this issue Mar 15, 2024 · 2 comments
Open

Link accounts in balance report / register|account report #403

stapelberg opened this issue Mar 15, 2024 · 2 comments

Comments

@stapelberg
Copy link

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

@bcc32
Copy link
Collaborator

bcc32 commented Mar 16, 2024

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:

  1. 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.
  2. 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 the reg report.
  3. Accounts may be automatically abbreviated (e.g., Expenses:Food:Drinks:Coffee could become Ex:F:Dr:Coffee). This could be fixed by expanding the --prepend-format flag currently passed in ledger-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).

@stapelberg
Copy link
Author

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:

  1. 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.

  1. 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 the reg report.

The ledger accounts command lists all known accounts. Couldn’t we use that and just do textual matching?

  1. Accounts may be automatically abbreviated (e.g., Expenses:Food:Drinks:Coffee could become Ex:F:Dr:Coffee). This could be fixed by expanding the --prepend-format flag currently passed in ledger-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.]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants