From 8b38bed6d9d12813bdbb7ef4d5ca47699f299c00 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 5 Jan 2025 09:43:22 +0200 Subject: [PATCH] * lisp/treesit.el: Fix treesit-show-paren-data (bug#75198) (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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index ab4345687d4..99368a4db83 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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))) -- 2.39.5