summaryrefslogtreecommitdiff
path: root/Auxiliary
diff options
context:
space:
mode:
authormontag451 <montag451@laposte.net>2022-06-16 09:12:19 +0200
committermontag451 <montag451@laposte.net>2022-06-17 12:43:23 +0200
commit364ca22b128a650e12ee998f856404bd29dce5dd (patch)
tree0eb8e4b080e918e8806b7f0af52bcb3a439dd296 /Auxiliary
parent696b87217a866aa7b4330971b8b53c5b8855e670 (diff)
downloadcmake-364ca22b128a650e12ee998f856404bd29dce5dd.tar.gz
cmake-mode.el: add support for bracket_comment and bracket_argument
Diffstat (limited to 'Auxiliary')
-rw-r--r--Auxiliary/cmake-mode.el38
1 files changed, 37 insertions, 1 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el
index 8224d9e0b1..2de9b98eac 100644
--- a/Auxiliary/cmake-mode.el
+++ b/Auxiliary/cmake-mode.el
@@ -288,6 +288,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.")
@@ -318,7 +351,10 @@ This puts the mark at the end, and point at the beginning."
; Setup indentation function.
(set (make-local-variable 'indent-line-function) 'cmake-indent)
; Setup comment syntax.
- (set (make-local-variable 'comment-start) "#"))
+ (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))
;; Default cmake-mode key bindings
(define-key cmake-mode-map "\e\C-a" #'cmake-beginning-of-defun)