From 847dc8abd0de4402b661b48d3cfde5a3cce25ee0 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Mon, 30 Dec 2024 19:54:39 +0200 Subject: [PATCH] * lisp/treesit.el (treesit-show-paren-data--categorize): Fix it. 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 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 3f79b9590a4..8f72a33f5ef 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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))) -- 2.39.5