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

Xref backend for beancount-mode #50

Merged
merged 3 commits into from
Jun 3, 2024
Merged

Xref backend for beancount-mode #50

merged 3 commits into from
Jun 3, 2024

Conversation

vkazanov
Copy link
Contributor

@vkazanov vkazanov commented May 22, 2024

Hello again,

I've added another quality-of-life improvement I felt was both useful and easy enough to implement: an Xref backend. This adds support for:

  1. Jumping up account definitions (aka open directive) under point using the default =M-.= binding
  2. finding account under point references using =M-?=.
  3. grepping through known symbol references and definitions using apropos like search with =C-M-.=.

While it is not hard to use basic tools such as grep with Beancount files, I felt that working from standard tooling aligns well with other modes supporting Xref and would be helpful to people used to default keybindings.

I checked it in Emacs 26, 27, 28, 29. It was not without some complications (a backported function) but should work everywhere out of the box.

Let me know if something needs tweaking.

Thanks!

@dnicolodi
Copy link
Collaborator

I felt that working from standard tooling aligns well with other modes supporting Xref and would be helpful to people used to default keybindings.

Thanks @vkazanov, this is exactly the kind of addition to beancount-mode that I would like to have!

beancount-tests.el Show resolved Hide resolved
beancount-tests.el Outdated Show resolved Hide resolved
beancount-tests.el Show resolved Hide resolved
beancount-tests.el Outdated Show resolved Hide resolved
beancount-tests.el Outdated Show resolved Hide resolved
beancount.el Show resolved Hide resolved
beancount.el Show resolved Hide resolved
@vkazanov
Copy link
Contributor Author

vkazanov commented May 25, 2024

@dnicolodi, BTW, I have this other idea I want to experiment with: specialize outline-minor-mode's approach a bit to beancount-mode's needs.

The plan:

  1. come up with a function that makes it possible to hide or show subsets of the file based on transaction-related info. Think outline-minor-mode but smarter than just section delimiters. The buffer is editable, with non-relevant things hidden. I do have a prototype already but it's not ready for prime time yet.
  2. a function to only show transactions with a certain tag/link (tags/links would become clickable then).
  3. a function to only show transactions within a certain date interval.
  4. a function to only transactions related to a certain account.

Given how large the files tend to become this should help quite a bit

Would you be open to such an improvement?

Obviously, I'd finish the xref backend first.

@vkazanov
Copy link
Contributor Author

vkazanov commented Jun 1, 2024

@dnicolodi sorry for nudging (gently). Any updates necessary? Thank you

@dnicolodi dnicolodi force-pushed the main branch 2 times, most recently from c2acc6e to 7c930fa Compare June 3, 2024 14:48
vkazanov added 2 commits June 3, 2024 16:49
This will allow to use the same code for the xref backend.
beancount.el Outdated
(defconst beancount-open-directive-regexp
(concat "^\\(" beancount-date-regexp "\\) +"
"\\(open\\) +"
"\\(" beancount-account-regexp "\\) +"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic as it requires the open directive to have a space after the account name, but one is not required:

2024-06-03 open Assets:Foo

is a valid open directive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops. Should be good now.

@dnicolodi dnicolodi merged commit bdd71c5 into beancount:main Jun 3, 2024
10 checks passed
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

Successfully merging this pull request may close these issues.

2 participants