From: Yuan Fu Date: Wed, 22 May 2024 05:40:32 +0000 (-0700) Subject: Address a common pitfall in tree-sitter's manual section (bug#71048) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d3b91e545ade4944181525aabe082a78186906fe;p=emacs.git Address a common pitfall in tree-sitter's manual section (bug#71048) * doc/lispref/parsing.texi (Multiple Languages): Add example for treesit-language-at-point-function. (cherry picked from commit e947e63b066680bbc7e027f73c9e68e26a47d0dd) --- diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 1bc0acfacd0..6afdce37728 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -1894,12 +1894,29 @@ directly translate into operations shown above. :host 'html '((script_element (raw_text) @@capture)) @end group - @group :embed 'css :host 'html '((style_element (raw_text) @@capture)))) @end group +@group +;; Major modes with multiple languages should always set +`treesit-language-at-point-function' (which see). +(setq treesit-language-at-point-function + (lambda (pos) + (let* ((node (treesit-node-at pos 'html)) + (parent (treesit-node-parent node))) + (cond + ((and node parent + (equal (treesit-node-type node) "raw_text") + (equal (treesit-node-type parent) "script_element")) + 'javascript) + ((and node parent + (equal (treesit-node-type node) "raw_text") + (equal (treesit-node-type parent) "style_element")) + 'css) + (t 'html))))) +@end group @end example @defun treesit-range-rules &rest query-specs