ledger-mode icon indicating copy to clipboard operation
ledger-mode copied to clipboard

Utilizing tree-sitter

Open josephmturner opened this issue 3 years ago • 6 comments

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.

josephmturner avatar Dec 03 '22 21:12 josephmturner

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 avatar Dec 03 '22 23:12 enderw88

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

josephmturner avatar Dec 04 '22 01:12 josephmturner

Some uses for tree-sitter elaborated in this talk from Emacsconf 2022 might be applicable to ledger:

  1. Imenu support. (video @6:40) You enumerate every field in your file, then pass that information to Imenu for fast navigation.
  2. 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.
  3. 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.

josephmturner avatar Dec 05 '22 02:12 josephmturner

@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/

josephmturner avatar Dec 05 '22 02:12 josephmturner

Would this make completion easier?

mistotebe avatar Jan 11 '24 16:01 mistotebe

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.

purcell avatar Jan 11 '24 16:01 purcell