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

Utilizing tree-sitter #344

Open
josephmturner opened this issue Dec 3, 2022 · 6 comments
Open

Utilizing tree-sitter #344

josephmturner opened this issue Dec 3, 2022 · 6 comments

Comments

@josephmturner
Copy link
Contributor

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.

@enderw88
Copy link
Member

enderw88 commented Dec 3, 2022 via email

@josephmturner
Copy link
Contributor Author

@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
Copy link
Contributor Author

josephmturner commented Dec 5, 2022

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
Copy link
Contributor Author

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

@mistotebe
Copy link

Would this make completion easier?

@purcell
Copy link
Member

purcell commented Jan 11, 2024

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.

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

4 participants