mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 23:30:35 -06:00
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.
This commit is contained in:
committed by
Brad King
parent
8533a8505c
commit
91336c7469
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user