ledger-mode
ledger-mode copied to clipboard
Utilizing tree-sitter
With tree-sit.el merged into Emacs 29, have you considered using a tree-sitter grammar in ledger-mode?
A little searching revealed https://github.com/cbarrete/tree-sitter-ledger.
What would be the benefit?
Also, I use Aquamacs which is still based on EMACS 25
On Sat, Dec 3, 2022 at 2:41 PM josephmturner @.***> wrote:
With tree-sit.el merged into Emacs 29, have you considered using a tree-sitter grammar in ledger-mode?
A little searching revealed https://github.com/cbarrete/tree-sitter-ledger .
— Reply to this email directly, view it on GitHub https://github.com/ledger/ledger-mode/issues/344, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGWWLDRNFNGN7X5ZDBFQH3WLO5BHANCNFSM6AAAAAASS6QOGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
-- Craig, Corona De Tucson, AZ [image: missile_flyout] enderw88.wordpress.com
@enderw88 Possibly better syntax highlighting while editing? I'm not sure it would offer much benefit, I was just curious after I discovered the project I linked to above.
Some uses for tree-sitter elaborated in this talk from Emacsconf 2022 might be applicable to ledger:
- Imenu support. (video @6:40) You enumerate every field in your file, then pass that information to Imenu for fast navigation.
- Autocompletion of amounts for last account in xact. (video @8:40) While ledger supports implicit amounts for the final account in a xact, I prefer that each account explicitly display its amount. This value could be autocompleted by selecting the amounts for each prior account in the xact, summing them, then inserting the negated result.
- Better xact folding. (video @6:10) Currently, you can fold transactions with
(set-selective-display (* tab-width 1))and unfold with(set-selective-display (* tab-width 0)). However, this doesn't fold block comments.
@enderw88 Users of older Emacsen might be able to take advantage of code like this through third-party libraries like https://emacs-tree-sitter.github.io/
Would this make completion easier?
It's hard to maintain a major mode that uses tree-sitter only if enabled and in the latest Emacs and if the grammar is installed, and tree-sitter really can't be made to work usefully in older Emacs versions. So I wouldn't recommend we adopt it here.
Better would be for someone to first make a separate ledger-ts-mode package with the appropriate Emacs version dependencies, optionally make that major mode a derived mode of ledger-mode, and then we'd find out what the extension points might be.
In general I'm bullish about tree-sitter, but it's a currently a rocky time working with it in the Emacs world as most users don't have (or necessarily need) it.