-
Notifications
You must be signed in to change notification settings - Fork 32
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
Tag/link filtering #51
base: main
Are you sure you want to change the base?
Conversation
Hm. For some reason the tests do not have the macro defined. I did run all the tests for 4 emacs version locally. I'll take a look today. |
Thanks for working on this. I like the idea of the functionality. I had just a very quick look at the implementation. I'm not familiar with most of the Emacs facilities used to implement this, thus I have not much to offer in terms of code review. However, the code looks clean. Only two important comments. From what I can tell, this makes the font-lock implementation significantly more expensive, and inherently incompatible with a font-lock implementation based on tree-sitter (on which I'm working on-and-off). I would therefore prefer if this would be off by default. Implementing it as a minor mode is probably the best fit. @monnier What do you think? I would use the |
@dnicolodi Thanks!
BTW, treesitter facilities would be easy to use for this kind of filtering. But what's interesting is that tree-sitter's parser might be an overkill for such a simple and regular file format as beancount: everything is line-based, indentation is meaningful, no complex expressions. |
From what I can tell, this makes the font-lock implementation significantly
more expensive,
I can't see why you think it would be significantly more expensive.
A rule like (,(concat "\\#[" beancount-tag-chars "]*") . 'beancount-tag)
does the same kind of while+re-search-forward with a `put-text-property`
inside and I don't expect `make-text-button` to be that much more costly
than `put-text-property`.
and inherently incompatible with a font-lock implementation
based on tree-sitter (on which I'm working on-and-off).
Can't treesit-font-lock make buttons? You might like to file a bug
report requesting that functionality.
I would therefore prefer if this would be off by default. Implementing
it as a minor mode is probably the best fit. @monnier What do
you think?
No opinion on that part.
W.r.t the code, I see various things that would benefit from being
tightened, e.g. `beancount-with-every-transaction` duplicates its body
argument. It's probably OK in practice given how it's currently used,
but it's better to avoid it. I think I'd just do
(unless (beancount-inside-transaction-p)
(beancount-goto-next-transaction))
before the `while` loop. Also the macro deserves a `(debug t)`
declaration and should use (indent 0) rather than (indent 1), since
(indent 1) means that the first arg is indented differently from the
rest (like we do for `prog1` or `with-current-buffer`).
Also, I'd use a single button kind (and command) for both which should
help reduce the code duplication.
Stefan
|
@dnicolodi I've taken both your and @monnier 's code-level comments into account in everything but the minor mode question. Here's the status quo:
What I can do is provide something a minor mode that would introduce clickable links and tags (and maybe more things in the future). What do you think? |
No opinion on the minor mode, so AFAICT the code looks OK (tho you
might want to "rework" the set of patches into a cleaner patchset).
Here are just thoughts that crossed my head, probably for future
development:
- Not sure I find it "natural" for a click on a tag/link to hide all the
other transactions. I can't think offhand of more a useful operation,
so it's probably fine, tho.
- Emacs being the inventor of the incremental search, I'd expect `M-x
beancount-show` to filter the transactions incrementally as I type the
tag/link name. 🙂
- I can't think of any reason why `beancount-show` should limit itself
to tags/links: we could let it match any other part of a transaction.
|
Yes, please 🙂
This is one of the reasons why I see this addition good for a minor mode and less suitable for default behavior. |
beancount.el
Outdated
@@ -568,7 +568,7 @@ With an argument move to the previous non cleared transaction." | |||
(lambda (string pred action) | |||
(if (null candidates) | |||
(setq candidates | |||
(sort (beancount-collect regexp 1) #'string<))) | |||
(sort (beancount-collect-unique regexp 1) #'string<))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the next hunk are bug fixes for the last PR. Please submit these as a separate PR with a proper commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I'll isolate these into a separate branch for now. This code definitely needs more unit tests.
@dnicolodi , I've cleaned up the patchset to restructure changes accumulated so far. But I respectfully disagree about user expectations around clicking on tags and links. Think Fava (or any other tools that utilise a concept of tags). If somebody sees a tag and clicks it - what should happen? Fava shows all transactions involving the tag clicked. Wordpress does this. Github does that as well. And this is exactly what I have as my personal use case for the feature. So I have lots of transactions, and some of them are marked as "#trip" and "#torquay-may-2024", which means its a family trip to Torquay, UK, and is also one of the trips that happened this year . Sometimes I want to tweak postings involved in that particular event, sometimes I just want to see how things look in general over time. Clicking/pressing a tag is a very natural way to just to get to an overview of things. With only basic font-lock facilities in place I would have to either do isearch or grep, and keep jumping around the buffer. Careful outline organisation gives the higher level structure to the buffer but does not help with this requirement. (beancount-show) with tag/link completion is a continuation of this line of thought. What if I am not sure which tags/links are available? What is available? What do I want to see? Anyway, you are the maintainer, I am just a happy user and an occasional contributor looking to support my use case. :-) |
@monnier with this patchset introducing basic hiding mechanisms, I have something better in mind: stacking filters. Here's my typical investigation:
This means I want to my filters to stack! But maybe that's a bit too ambitious for now. On incremental search and not limiting the search to tags/links. What do mean? A substring search? Regexp search? Something smarter? Thanks |
On incremental search and not limiting the search to tags/links. What do
mean? A substring search?
AFAICT currently you do substring search (with completion to enter tag
names and and link names) tho limited to the first line of each
transaction. So I'm suggesting to make it "official" (so you can filter
for names in the "..." comments) and maybe to search the rest of the
transaction as well (e.g. to filter for account names).
Regexp search?
It would be easy to generalize to regexps, but I don't know how
important that would be (it's mostly an issue of UI).
Stefan
|
So I've split this branch into 2 sets of changes:
|
I merge main just now but there remains an error.
Please fix and I'll merge this PR. |
Hi and hope you have a good day,
This is a first version of tag/link filtering. I use tags and links a lot to extract subsets of my ledger so this is already has value for me personally.
I tried to structure code as nicely as possible, introducing logic in atomic commits. Here's a breakdown of the commits:
The current public-facing UI makes possible to move the point to a tag and press RET to hide all irrelevant transactions. A mouse click works as well.
It is also possible to directly call (beancount-show-tag "#tag") to restrict view to tagged transactions. (beancount-show-all) cleans filtering.
Further improvements that I feel might be necessary:
In general, the code can be developed further to support advanced filters, e.g. by date intervals, account names, etc.
What do you think?
Thanks