]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/treesit.el: Fix treesit-show-paren-data (bug#75198)
authorJuri Linkov <juri@linkov.net>
Sun, 5 Jan 2025 07:43:22 +0000 (09:43 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 5 Jan 2025 12:18:50 +0000 (13:18 +0100)
(treesit-show-paren-data--categorize): Use 'treesit-thing-defined-p'
to check if the thing exists for the language at POS before calling
'treesit-parent-until' that raises an error for an undefined thing.
(treesit-thing-defined-p): Add the alias signature to the docstring.

(cherry picked from commit 47ff8ab307da2a1ccfe3e701db871f47c1d3b380)

lisp/treesit.el

index ab4345687d4c33872ce26581ecd3597ecc4b0ab9..99368a4db8371c1872052d41212ffd293aa539ae 100644 (file)
@@ -2724,7 +2724,9 @@ If LANGUAGE is nil, return the first definition for THING in
                                   treesit-thing-settings)))))
 
 (defalias 'treesit-thing-defined-p #'treesit-thing-definition
-  "Return non-nil if THING is defined.")
+  "Return non-nil if THING is defined for LANGUAGE.
+
+\(fn THING LANGUAGE)")
 
 (defun treesit-beginning-of-thing (thing &optional arg tactic)
   "Like `beginning-of-defun', but generalized into things.
@@ -3408,9 +3410,10 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
 
 (defun treesit-show-paren-data--categorize (pos &optional end-p)
   (let* ((pred 'sexp-list)
-         (parent (treesit-node-at (if end-p (1- pos) pos)))
-         (_ (while (and parent (not (treesit-node-match-p parent pred t)))
-              (setq parent (treesit-node-parent parent))))
+         (parent (when (treesit-thing-defined-p
+                        'sexp-list (treesit-language-at pos))
+                   (treesit-parent-until
+                    (treesit-node-at (if end-p (1- pos) pos)) pred)))
          (first (when parent (treesit-node-child parent 0)))
          (first-start (when first (treesit-node-start first)))
          (first-end (when first (treesit-node-end first)))