[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 02e046566e 3/3: Set beginning/end-of-defun-function in treesit-
From: |
Yuan Fu |
Subject: |
emacs-29 02e046566e 3/3: Set beginning/end-of-defun-function in treesit-major-mode-setup |
Date: |
Thu, 22 Dec 2022 03:46:23 -0500 (EST) |
branch: emacs-29
commit 02e046566e2c70cf268f359ef29802268ab43de1
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Set beginning/end-of-defun-function in treesit-major-mode-setup
* lisp/treesit.el (treesit-major-mode-setup): Set them.
---
lisp/treesit.el | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index a7882dda2c..ec5b3e399f 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -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