diff options
author | Brad King <brad.king@kitware.com> | 2022-06-17 15:31:58 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-06-17 15:32:20 (GMT) |
commit | 88a300d421c4cfec59197fcc7faac1ef526882c2 (patch) | |
tree | 06dc490956111e5ef3d1b9471fb82b74649fa18d /Auxiliary | |
parent | 6940a67d479e722521a3f84d816858b860d09e71 (diff) | |
parent | 364ca22b128a650e12ee998f856404bd29dce5dd (diff) | |
download | CMake-88a300d421c4cfec59197fcc7faac1ef526882c2.zip CMake-88a300d421c4cfec59197fcc7faac1ef526882c2.tar.gz CMake-88a300d421c4cfec59197fcc7faac1ef526882c2.tar.bz2 |
Merge topic 'cmake-mode-bracket-comment-argument'
364ca22b12 cmake-mode.el: add support for bracket_comment and bracket_argument
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7375
Diffstat (limited to 'Auxiliary')
-rw-r--r-- | Auxiliary/cmake-mode.el | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el index 8224d9e..2de9b98 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) |