]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/treesit.el (treesit-show-paren-data--categorize): Fix it.
authorJuri Linkov <juri@linkov.net>
Mon, 30 Dec 2024 17:54:39 +0000 (19:54 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 4 Jan 2025 20:26:04 +0000 (21:26 +0100)
Copy the implementation of treesit-parent-until here, and call
its treesit-node-match-p with the argument IGNORE-MISSING set to t
that causes it to fail silently instead of raising an error when
the predicate 'sexp-list' is not defined in an embedded language.
(treesit-major-mode-setup): Set show-paren-data-function to
treesit-show-paren-data only when 'sexp-list' thing is defined
that is used by treesit-show-paren-data--categorize (bug#75198).

(cherry picked from commit 4068948a74586056cf03a22cae2448d7b4e4a7bd)

lisp/treesit.el

index 3f79b9590a46f34004581ef86da89faabef88cb9..8f72a33f5ef3d3ca7c2a570b5eaaf9d9a93396ae 100644 (file)
@@ -3385,7 +3385,9 @@ 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-parent-until (treesit-node-at (if end-p (1- pos) pos)) pred))
+         (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))))
          (first (when parent (treesit-node-child parent 0)))
          (first-start (when first (treesit-node-start first)))
          (first-end (when first (treesit-node-end first)))
@@ -3409,13 +3411,13 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
       (unless (bobp) (treesit-show-paren-data--categorize (point) t))
       (when show-paren-when-point-in-periphery
         (let* ((ind-pos (save-excursion (back-to-indentation) (point)))
-              (eol-pos
-               (save-excursion
-                 (end-of-line) (skip-chars-backward " \t" ind-pos) (point))))
+               (eol-pos
+                (save-excursion
+                  (end-of-line) (skip-chars-backward " \t" ind-pos) (point))))
           (cond
            ((<= (point) ind-pos)
             (or (treesit-show-paren-data--categorize ind-pos)
-               (unless (bobp)
+                (unless (bobp)
                   (treesit-show-paren-data--categorize (1- eol-pos)))))
            ((>= (point) eol-pos)
             (unless (bobp)
@@ -3559,7 +3561,8 @@ before calling this function."
     (setq-local forward-sexp-function #'treesit-forward-sexp-list)
     (setq-local forward-list-function #'treesit-forward-list)
     (setq-local down-list-function #'treesit-down-list)
-    (setq-local up-list-function #'treesit-up-list))
+    (setq-local up-list-function #'treesit-up-list)
+    (setq-local show-paren-data-function 'treesit-show-paren-data))
 
   (when (treesit-thing-defined-p 'sentence nil)
     (setq-local forward-sentence-function #'treesit-forward-sentence))
@@ -3581,8 +3584,6 @@ before calling this function."
     (setq-local outline-search-function #'treesit-outline-search
                 outline-level #'treesit-outline-level))
 
-  (setq-local show-paren-data-function 'treesit-show-paren-data)
-
   ;; Remove existing local parsers.
   (dolist (ov (overlays-in (point-min) (point-max)))
     (when-let ((parser (overlay-get ov 'treesit-parser)))