summaryrefslogtreecommitdiffstats
path: root/Auxiliary/cmake-mode.el
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2020-12-11 21:08:33 (GMT)
committerJoerg Bornemann <joerg.bornemann@qt.io>2020-12-11 21:13:42 (GMT)
commit901386f646ea9949b44c5cc3b41e62bb285ffcc4 (patch)
tree364fa828b89e533e851ac99beb9059b691d82007 /Auxiliary/cmake-mode.el
parent0064981f6fb5ab96cb09bfdc456f6250ee4cb311 (diff)
downloadCMake-901386f646ea9949b44c5cc3b41e62bb285ffcc4.zip
CMake-901386f646ea9949b44c5cc3b41e62bb285ffcc4.tar.gz
CMake-901386f646ea9949b44c5cc3b41e62bb285ffcc4.tar.bz2
cmake-mode.el: Add navigation by function and macro
Add the functions cmake-beginning-of-defun and cmake-end-of-defun that jump to the beginning/end of the nearest function or macro. Add the function cmake-mark-defun that marks the current function. Bind those functions to the usual keys in cmake-mode-map.
Diffstat (limited to 'Auxiliary/cmake-mode.el')
-rw-r--r--Auxiliary/cmake-mode.el61
1 files changed, 61 insertions, 0 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el
index 6137ea9..190fdf5 100644
--- a/Auxiliary/cmake-mode.el
+++ b/Auxiliary/cmake-mode.el
@@ -190,6 +190,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 +297,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