Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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-mode
s 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+.