From 50f21afd71d71d2392df14b1ec764e6eb69a6444 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Fri, 1 Sep 2023 22:30:21 -0700 Subject: [PATCH] Fix treesit-thing-definition * lisp/treesit.el (treesit-thing-definition): Add LANGUAGE parameter. (treesit-major-mode-setup): Update treesit-thing-definition. Don't enable tree-sitter sexp transpose if sexp isn't defined. --- lisp/treesit.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 63d6c213f09..7fda533861a 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -1934,11 +1934,17 @@ nil.") "The delimiter used to connect several defun names. This is used in `treesit-add-log-current-defun'.") -(defun treesit-thing-definition (thing) - "Return the predicate for THING if it's defined. +(defun treesit-thing-definition (thing language) + "Return the predicate for THING if it's defined for LANGUAGE. A thing is considered defined if it has an entry in +`treesit-thing-settings'. + +If LANGUAGE is nil, return the first definition for THING in `treesit-thing-settings'." - (alist-get thing treesit-thing-settings)) + (if language + (car (alist-get thing (alist-get language + treesit-thing-settings))) + (car (alist-get thing (mapcan #'cdr treesit-thing-settings))))) (defalias 'treesit-thing-defined-p 'treesit-thing-definition "Return non-nil if THING is defined.") @@ -2554,7 +2560,8 @@ before calling this function." (setq-local indent-line-function #'treesit-indent) (setq-local indent-region-function #'treesit-indent-region)) ;; Navigation. - (when (or treesit-defun-type-regexp (treesit-thing-defined-p 'defun)) + (when (or treesit-defun-type-regexp + (treesit-thing-defined-p 'defun nil)) (keymap-set (current-local-map) " " #'treesit-beginning-of-defun) (keymap-set (current-local-map) " " @@ -2573,10 +2580,11 @@ before calling this function." (setq-local add-log-current-defun-function #'treesit-add-log-current-defun)) - (when (treesit-thing-defined-p 'sexp) - (setq-local forward-sexp-function #'treesit-forward-sexp)) - (setq-local transpose-sexps-function #'treesit-transpose-sexps) - (when (treesit-thing-defined-p 'sentence) + (when (treesit-thing-defined-p 'sexp nil) + (setq-local forward-sexp-function #'treesit-forward-sexp) + (setq-local transpose-sexps-function #'treesit-transpose-sexps)) + + (when (treesit-thing-defined-p 'sentence nil) (setq-local forward-sentence-function #'treesit-forward-sentence)) ;; Imenu. -- 2.39.2