summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
m---------.emacs.d/lisp/cmake-font-lock0
-rw-r--r--.emacs.d/lisp/cmake-mode.el64
2 files changed, 45 insertions, 19 deletions
diff --git a/.emacs.d/lisp/cmake-font-lock b/.emacs.d/lisp/cmake-font-lock
-Subproject 0d6111b36a66013aa9b452e664c93308df3b07e
+Subproject a6038e916bcca807ae695f7d7e5c300c3f38f41
diff --git a/.emacs.d/lisp/cmake-mode.el b/.emacs.d/lisp/cmake-mode.el
index 8224d9e..b5e5ff4 100644
--- a/.emacs.d/lisp/cmake-mode.el
+++ b/.emacs.d/lisp/cmake-mode.el
@@ -41,8 +41,8 @@ set the path with these commands:
:group 'cmake)
;; Keywords
-(defconst cmake-keywords-block-open '("IF" "MACRO" "FOREACH" "ELSE" "ELSEIF" "WHILE" "FUNCTION"))
-(defconst cmake-keywords-block-close '("ENDIF" "ENDFOREACH" "ENDMACRO" "ELSE" "ELSEIF" "ENDWHILE" "ENDFUNCTION"))
+(defconst cmake-keywords-block-open '("BLOCK" "IF" "MACRO" "FOREACH" "ELSE" "ELSEIF" "WHILE" "FUNCTION"))
+(defconst cmake-keywords-block-close '("ENDBLOCK" "ENDIF" "ENDFOREACH" "ENDMACRO" "ELSE" "ELSEIF" "ENDWHILE" "ENDFUNCTION"))
(defconst cmake-keywords
(let ((kwds (append cmake-keywords-block-open cmake-keywords-block-close nil)))
(delete-dups kwds)))
@@ -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))
-
;------------------------------------------------------------------------------
@@ -288,6 +279,39 @@ This puts the mark at the end, and point at the beginning."
;------------------------------------------------------------------------------
+(defun cmake--syntax-propertize-until-bracket-close (syntax)
+ ;; This function assumes that a previous search has matched the
+ ;; beginning of a bracket_comment or bracket_argument and that the
+ ;; second capture group has matched the equal signs between the two
+ ;; opening brackets
+ (let* ((mb (match-beginning 2))
+ (me (match-end 2))
+ (cb (format "]%s]" (buffer-substring mb me))))
+ (save-match-data
+ (if (search-forward cb end 'move)
+ (progn
+ (setq me (match-end 0))
+ (put-text-property
+ (1- me)
+ me
+ 'syntax-table
+ (string-to-syntax syntax)))
+ (setq me end)))
+ (put-text-property
+ (match-beginning 1)
+ me
+ 'syntax-multiline
+ t)))
+
+(defconst cmake--syntax-propertize-function
+ (syntax-propertize-rules
+ ("\\(#\\)\\[\\(=*\\)\\["
+ (1
+ (prog1 "!" (cmake--syntax-propertize-until-bracket-close "!"))))
+ ("\\(\\[\\)\\(=*\\)\\["
+ (1
+ (prog1 "|" (cmake--syntax-propertize-until-bracket-close "|"))))))
+
;; Syntax table for this mode.
(defvar cmake-mode-syntax-table nil
"Syntax table for CMake mode.")
@@ -313,17 +337,19 @@ 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.
(set (make-local-variable 'indent-line-function) 'cmake-indent)
; 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)
+ (set (make-local-variable 'comment-start) "#")
+ ;; Setup syntax propertization
+ (set (make-local-variable 'syntax-propertize-function) cmake--syntax-propertize-function)
+ (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil t))
; Help mode starts here
@@ -336,7 +362,7 @@ optional argument topic will be appended to the argument list."
(interactive "s")
(let* ((bufname (if buffer buffer (concat "*CMake" type (if topic "-") topic "*")))
(buffer (if (get-buffer bufname) (get-buffer bufname) (generate-new-buffer bufname)))
- (command (concat cmake-mode-cmake-executable " " type " " topic))
+ (command (concat cmake-mode-cmake-executable " " type " " (if topic (shell-quote-argument topic) topic)))
;; Turn of resizing of mini-windows for shell-command.
(resize-mini-windows nil)
)
@@ -355,7 +381,7 @@ optional argument topic will be appended to the argument list."
(interactive "s")
(let* ((bufname (if buffer buffer (concat "*CMake" type (if topic "-") topic "*")))
(buffer (if (get-buffer bufname) (get-buffer bufname) (generate-new-buffer bufname)))
- (command (concat cmake-mode-cmake-executable " " type " " topic))
+ (command (concat cmake-mode-cmake-executable " " type " " (if topic (shell-quote-argument topic) topic)))
;; Turn of resizing of mini-windows for shell-command.
(resize-mini-windows nil)
)