]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix treesit-thing-definition
authorYuan Fu <casouri@gmail.com>
Sat, 2 Sep 2023 05:30:21 +0000 (22:30 -0700)
committerYuan Fu <casouri@gmail.com>
Sat, 2 Sep 2023 05:30:21 +0000 (22:30 -0700)
* 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

index 63d6c213f0928a1a629b7054d2d2a979f3cf4733..7fda533861a1ee9f67ab8f76a769315579004f3c 100644 (file)
@@ -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) "<remap> <beginning-of-defun>"
                 #'treesit-beginning-of-defun)
     (keymap-set (current-local-map) "<remap> <end-of-defun>"
@@ -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.