From 91336c74698b09afe272f8dc044b84ecf71d0904 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 25 Jan 2024 17:28:08 +0100 Subject: cmake-mode.el: Simplify jumping to begin/end of functions/macros This change was spawned by the desire to use `narrow-to-defun` in CMake files. However, there was no "CMake version" of that function, and it turns out that we don't need one if we make `beginning-of-defun` and `end-of-defun` work in `cmake-mode`. In the setup code of `cmake-mode` we now set the local variables `beginning-of-defun-function` and `end-of-defun-function`. This makes `beginning-of-defun` and `end-of-defun` work as expected. Functions that use this facility also work now: `mark-defun` and `narrow-to-defun` and possibly others. We remove `cmake-mark-defun` since it's superfluous now. We remove the defun-related key bindings since the standard functions that are bound globally work fine with this patch. --- Auxiliary/cmake-mode.el | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el index 6bd23bf..b5e5ff4 100644 --- a/Auxiliary/cmake-mode.el +++ b/Auxiliary/cmake-mode.el @@ -258,15 +258,6 @@ Return t unless search stops due to end of buffer." (forward-line) t))) -(defun cmake-mark-defun () - "Mark the current CMake function or macro. - -This puts the mark at the end, and point at the beginning." - (interactive) - (cmake-end-of-defun) - (push-mark nil :nomsg :activate) - (cmake-beginning-of-defun)) - ;------------------------------------------------------------------------------ @@ -346,6 +337,10 @@ This puts the mark at the end, and point at the beginning." (define-derived-mode cmake-mode prog-mode "CMake" "Major mode for editing CMake source files." + ;; Setup jumping to beginning/end of a CMake function/macro. + (set (make-local-variable 'beginning-of-defun-function) #'cmake-beginning-of-defun) + (set (make-local-variable 'end-of-defun-function) #'cmake-end-of-defun) + ; Setup font-lock mode. (set (make-local-variable 'font-lock-defaults) '(cmake-font-lock-keywords)) ; Setup indentation function. @@ -356,11 +351,6 @@ This puts the mark at the end, and point at the beginning." (set (make-local-variable 'syntax-propertize-function) cmake--syntax-propertize-function) (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil t)) -;; Default cmake-mode key bindings -(define-key cmake-mode-map "\e\C-a" #'cmake-beginning-of-defun) -(define-key cmake-mode-map "\e\C-e" #'cmake-end-of-defun) -(define-key cmake-mode-map "\e\C-h" #'cmake-mark-defun) - ; Help mode starts here -- cgit v0.12