]> git.eshelyaron.com Git - emacs.git/commitdiff
Set beginning/end-of-defun-function in treesit-major-mode-setup
authorYuan Fu <casouri@gmail.com>
Thu, 22 Dec 2022 08:41:58 +0000 (00:41 -0800)
committerYuan Fu <casouri@gmail.com>
Thu, 22 Dec 2022 08:42:49 +0000 (00:42 -0800)
* lisp/treesit.el (treesit-major-mode-setup): Set them.

lisp/treesit.el

index a7882dda2cc99b64bc5cd727cd517ab5463fae31..ec5b3e399f9b441def174012ab19dc3fc8a58e5b 100644 (file)
@@ -1941,7 +1941,16 @@ before calling this function."
     (keymap-set (current-local-map) "<remap> <beginning-of-defun>"
                 #'treesit-beginning-of-defun)
     (keymap-set (current-local-map) "<remap> <end-of-defun>"
-                #'treesit-end-of-defun)))
+                #'treesit-end-of-defun)
+    ;; `end-of-defun' will not work completely correctly in nested
+    ;; defuns due to its implementation.  However, many lisp programs
+    ;; use `beginning/end-of-defun', so we should still set
+    ;; `beginning/end-of-defun-function' so they still mostly work.
+    ;; This is also what `cc-mode' does: rebind user commands and set
+    ;; the variables.  In future we should update `end-of-defun' to
+    ;; work with nested defuns.
+    (setq-local beginning-of-defun-function #'treesit-beginning-of-defun)
+    (setq-local end-of-defun-function #'treesit-end-of-defun)))
 
 ;;; Debugging