summaryrefslogtreecommitdiffstats
path: root/Auxiliary
diff options
context:
space:
mode:
authorRoy Crihfield <rscrihf@gmail.com>2015-07-23 18:47:29 (GMT)
committerBrad King <brad.king@kitware.com>2015-07-27 13:39:09 (GMT)
commit63de609ef147e665ebd8d7622f580a74a417287b (patch)
tree80dd10b09364f25d1ead87dd9461c5811d3eb958 /Auxiliary
parent9d5082b26ebffe1e834c5c13e22bba02933e5c59 (diff)
downloadCMake-63de609ef147e665ebd8d7622f580a74a417287b.zip
CMake-63de609ef147e665ebd8d7622f580a74a417287b.tar.gz
CMake-63de609ef147e665ebd8d7622f580a74a417287b.tar.bz2
cmake-mode.el: Use `rx' for regexps
This allows the keywords be defined in a list and reused in different regexps.
Diffstat (limited to 'Auxiliary')
-rw-r--r--Auxiliary/cmake-mode.el42
1 files changed, 26 insertions, 16 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el
index 7051cc8..fe4a4c6 100644
--- a/Auxiliary/cmake-mode.el
+++ b/Auxiliary/cmake-mode.el
@@ -43,7 +43,14 @@ set the path with these commands:
(setenv \"PATH\" (concat (getenv \"PATH\") \":/usr/local/cmake/bin\"))"
:type 'file
: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
+ (let ((kwds (append cmake-keywords-block-open cmake-keywords-block-close nil)))
+ (delete-dups kwds)))
+
;; Regular expressions used by line indentation function.
;;
(defconst cmake-regex-blank "^[ \t]*$")
@@ -51,23 +58,26 @@ set the path with these commands:
(defconst cmake-regex-paren-left "(")
(defconst cmake-regex-paren-right ")")
(defconst cmake-regex-argument-quoted
- "\"\\([^\"\\\\]\\|\\\\\\(.\\|\n\\)\\)*\"")
+ (rx ?\" (* (or (not (any ?\" ?\\)) (and ?\\ anything))) ?\"))
(defconst cmake-regex-argument-unquoted
- "\\([^ \t\r\n()#\"\\\\]\\|\\\\.\\)\\([^ \t\r\n()#\\\\]\\|\\\\.\\)*")
-(defconst cmake-regex-token (concat "\\(" cmake-regex-comment
- "\\|" cmake-regex-paren-left
- "\\|" cmake-regex-paren-right
- "\\|" cmake-regex-argument-unquoted
- "\\|" cmake-regex-argument-quoted
- "\\)"))
-(defconst cmake-regex-indented (concat "^\\("
- cmake-regex-token
- "\\|" "[ \t\r\n]"
- "\\)*"))
+ (rx (or (not (any space "()#\"\\\n")) (and ?\\ nonl))
+ (* (or (not (any space "()#\\\n")) (and ?\\ nonl)))))
+(defconst cmake-regex-token
+ (rx-to-string `(group (or (regexp ,cmake-regex-comment)
+ ?( ?)
+ (regexp ,cmake-regex-argument-unquoted)
+ (regexp ,cmake-regex-argument-quoted)))))
+(defconst cmake-regex-indented
+ (rx-to-string `(and bol (* (group (or (regexp ,cmake-regex-token) (any space ?\n)))))))
(defconst cmake-regex-block-open
- "^\\(if\\|macro\\|foreach\\|else\\|elseif\\|while\\|function\\)$")
+ (rx-to-string `(and bow (or ,@(append cmake-keywords-block-open
+ (mapcar 'downcase cmake-keywords-block-open))) eow)))
(defconst cmake-regex-block-close
- "^[ \t]*\\(endif\\|endforeach\\|endmacro\\|else\\|elseif\\|endwhile\\|endfunction\\)[ \t]*(")
+ (rx-to-string `(and bow (or ,@(append cmake-keywords-block-close
+ (mapcar 'downcase cmake-keywords-block-close))) eow)))
+(defconst cmake-regex-close
+ (rx-to-string `(and bol (* space) (regexp ,cmake-regex-block-close)
+ (* space) (regexp ,cmake-regex-paren-left))))
;------------------------------------------------------------------------------
@@ -134,7 +144,7 @@ set the path with these commands:
)
(goto-char point-start)
;; If next token closes the block, decrease indentation
- (when (looking-at cmake-regex-block-close)
+ (when (looking-at cmake-regex-close)
(setq cur-indent (- cur-indent cmake-tab-width))
)
)