diff options
author | Brad King <brad.king@kitware.com> | 2020-12-17 14:09:55 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-12-17 14:10:41 (GMT) |
commit | 215bd0e72b48b2fb2b8e62a53765a60064d7b4b0 (patch) | |
tree | 0227d302da1e906a57613bac73b69100bc26835b | |
parent | cf2486fada0030319a56746a8c7e8012c8077732 (diff) | |
parent | 591d4bbdafea42292f6ef7acaf033c22361f8c26 (diff) | |
download | CMake-215bd0e72b48b2fb2b8e62a53765a60064d7b4b0.zip CMake-215bd0e72b48b2fb2b8e62a53765a60064d7b4b0.tar.gz CMake-215bd0e72b48b2fb2b8e62a53765a60064d7b4b0.tar.bz2 |
Merge topic 'emacs-extend-cmake-mode'
591d4bbdaf cmake-mode.el: Require the rx package
901386f646 cmake-mode.el: Add navigation by function and macro
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5605
-rw-r--r-- | Auxiliary/cmake-mode.el | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el index 6137ea9..52f2d41 100644 --- a/Auxiliary/cmake-mode.el +++ b/Auxiliary/cmake-mode.el @@ -28,6 +28,7 @@ ;; (require 'rst) +(require 'rx) (defcustom cmake-mode-cmake-executable "cmake" "*The name of the cmake executable. @@ -190,6 +191,61 @@ the indentation. Otherwise it retains the same position on the line" ) ) + +;------------------------------------------------------------------------------ + +;; +;; Navigation / marking by function or macro +;; + +(defconst cmake--regex-defun-start + (rx line-start + (zero-or-more space) + (or "function" "macro") + (zero-or-more space) + "(")) + +(defconst cmake--regex-defun-end + (rx line-start + (zero-or-more space) + "end" + (or "function" "macro") + (zero-or-more space) + "(" (zero-or-more (not ")")) ")")) + +(defun cmake-beginning-of-defun () + "Move backward to the beginning of a CMake function or macro. + +Return t unless search stops due to beginning of buffer." + (interactive) + (when (not (region-active-p)) + (push-mark)) + (let ((case-fold-search t)) + (when (re-search-backward cmake--regex-defun-start nil 'move) + t))) + +(defun cmake-end-of-defun () + "Move forward to the end of a CMake function or macro. + +Return t unless search stops due to end of buffer." + (interactive) + (when (not (region-active-p)) + (push-mark)) + (let ((case-fold-search t)) + (when (re-search-forward cmake--regex-defun-end nil 'move) + (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)) + + ;------------------------------------------------------------------------------ ;; @@ -242,6 +298,12 @@ the indentation. Otherwise it retains the same position on the line" ; Setup comment syntax. (set (make-local-variable 'comment-start) "#")) +;; 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 |