1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

* 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).
This commit is contained in:
Juri Linkov 2024-12-30 19:54:39 +02:00
parent 7671d50b14
commit 4068948a74

View file

@ -3393,7 +3393,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)))
@ -3417,13 +3419,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)
@ -3567,7 +3569,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))
@ -3589,8 +3592,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)))