-
Notifications
You must be signed in to change notification settings - Fork 119
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
Consider using tree-sitter for syntax highlighting? #658
Comments
If you use this plugin https://github.com/cjohansson/emacs-phps-mode syntax highlightning is done asynchronously and according to PHP 8.0 lex analyzer but also in pure elisp |
@Gleek Thank you for suggestion. Next week is a Japanese holiday, so I'll consider other syntax highlighting issues as well. |
It's highly probable that https://archive.casouri.cat/note/2021/emacs-tree-sitter/ will be part of Emacs 29. I suggest testing with that, and offering feedback if you're able. See also https://www.reddit.com/r/emacs/comments/pxpq8d/rfc_emacs_treesitter_integration/ |
I'm a bit new to the ecosystem, but my understanding is that tree-sitter will in fact be part of Emacs 29. In fact, emacs-devel is pushing to update built-in major modes for emacs 29: https://lists.gnu.org/archive/html/emacs-devel/2022-10/msg00707.html What does I'm a bit familiar with tree-sitter from other editors, and I'd be delighted to help out on this, if so desired. |
BTW one thing I recall from my past work with tree-sitter-php is that it literally only supports PHP, so any support for HTML included in a PHP file would be lost (probably not a huge deal), as would highlighting of phpDoc comments (which probably is a big deal) and anything else that's not strictly PHP. tree-sitter handles such things by handing them off to other tree-sitter parsers via what they call "injections". These are pretty easy to work with, as I recall, but require that buffers can work highlighting via multiple modes. (Again, I'm new around here, so maybe this won't be an issue, but I see several other open issues about mmm/poly-mode, etc, so maybe it will be an issue?) Thanks again! |
Any updates on this? Any plans and such? Tree-sitter based parsing also plays well with packages like Combobulate. |
@KaranAhlawat the initial was around tree-sitter started here https://github.com/emacs-php/php-ts-mode but it's going to take some time. |
This is great news! And I also understand it takes time and effort, both of which aren't free. I'm developing a TS mode myself, for Scala. |
For reference, the work is being done to ship |
emacs-tree-sitter works by using tree-sitter grammar files to incrementally do syntax highlighting. It also has a support for php using php-grammar. Considering that the grammar files are higher type language than regex, these would provide more accurate syntax highlighting than it's regex counterparts.
In my testing it also gives a much smoother experience for large files than the default php-mode highlighting.
On my machine for large files
php-syntax-propertize-hash-line-comment
>(move-beginning-of-line 2)
>(line-move)
takes a lot of time while normal typingAnd
php-syntax-propertize-extend-region
takes minutes sometimes when adding a stray quote.These problems don't exist on tree-sitter and disabling these problematic functions to only use tree-sitter gives about ~50ms typing latency, irrespective of the file size. This isn't real-time as well but these aren't clean benchmarks and I had other applications running in the background at the time. For reference typing latency in fundamental mode was ~25ms on the same file. For default php-mode even though the latency in small files is low large files showed about 600ms to 2.5secs. This does not include typing in quotes (
'
) which completely freezes emacs for multiple seconds, if not a minute or two.These are the changes I did to the php-mode function after enabling tree-sitter to get the results above.
I'm unaware of the feasibility or the complexity involved in integrating these two packages, but thought we can start the discussion around this, considering the benefits it might yield.
Debug info
The text was updated successfully, but these errors were encountered: