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

Tree-sitter support for Emacs 29+ #282

Merged
merged 1 commit into from
Sep 19, 2024
Merged

Tree-sitter support for Emacs 29+ #282

merged 1 commit into from
Sep 19, 2024

Conversation

c-alpha
Copy link
Contributor

@c-alpha c-alpha commented Sep 19, 2024

er-basic-expansions.el (er/mark-ts-node): New function for expanding the region using Tree-sitter parse tree nodes when Tree-sitter is available and can parse the buffer around point. The new function is safe to add to the global base value of er/try-expand-list since it leaves the region unchanged when Tree-sitter information is not available.

I presume this tries to achieve very similar goals as PR #279, but uses a different approach. Instead of iterating some list of languages, it adds Tree-sitter region expansion to the global default value of er/try-expand-list. The new expansion function checks whether Tree-sitter support is available in this instance of Emacs, and for the stuff around point, and stays out of the way when it isn't. Since Tree-sitter support in Emacs 29+ requires the user to make some extra configuration steps, such as installing external language grammars, selecting which <language>-ts-modes to use etc., it is impossible to predict for which languages Tree-sitter support is available for a particular user, or not. Hence the generic approach of adding it to the basic expansion try list, and allowing it to kick in when a Tree-sitter parse tree is available only. Whenever the user will add a new Tree-sitter grammar to his/her configuration in the future, expand-region will instantly start working in that language, too.

Warning re. tests: The new expansion function is added to the end of er/try-expand-list, but may still break existing tests. To devise new tests for the new function, the approach would need to be something along the lines of: pick a language for which there is a built-in <language>-ts-mode, but which is not supported by expand-region, and for which the person running the tests has a Tree-sitter language grammar installed and activated Tree-sitter support in Emacs. Since it seems close to impossible to reliably guess the state of Tree-sitter language support in everybody's copy of Emacs, It does not seem realistically feasible to come up with a test case which will work on everyone's Emacs 29+.

er-basic-expansions.el (er/mark-ts-node): New function for expanding
the region using Tree-sitter parse tree nodes when Tree-sitter is
available and can parse the buffer around point. The new function is
safe to add to the global base value of `er/try-expand-list` since it
leaves the region unchanged when Tree-sitter information is not
available.
@magnars
Copy link
Owner

magnars commented Sep 19, 2024

Thanks this looks pretty great! Would you say it is ready for use?

@c-alpha
Copy link
Contributor Author

c-alpha commented Sep 19, 2024

That was a swift response of yours indeed!

I have been using it for two weeks without any issues now. In that light, and given the low complexity of the change: yes, ready for use.

@magnars
Copy link
Owner

magnars commented Sep 19, 2024

Excellent, thank you! I'm sorry that I have to ask this, but what is your status regarding the Emacs copyright paperwork?

@c-alpha
Copy link
Contributor Author

c-alpha commented Sep 19, 2024

Excellent, thank you! I'm sorry that I have to ask this, but what is your status regarding the Emacs copyright paperwork?

No worries, that is a very valid question. I have signed the FSF copyright assignment for contributions to Emacs. I am thus fine with your licence, and having my code on ELPA.

@magnars
Copy link
Owner

magnars commented Sep 19, 2024

Perfect, thank you! 🙏

@magnars magnars merged commit 541d971 into magnars:master Sep 19, 2024
@magnars magnars mentioned this pull request Sep 19, 2024
4 tasks
@c-alpha
Copy link
Contributor Author

c-alpha commented Sep 19, 2024

👍 Thank you for taking my proposal on board, and so fast; glad you found it helpful.
Happy hacking! 🎉🥳

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