Fixed slow regex for indentation.

This commit is contained in:
Brad King 2003-06-19 13:23:22 -04:00
parent a7cde5c005
commit 0ee768c914
1 changed files with 34 additions and 23 deletions

View File

@ -13,18 +13,22 @@
; Regular expressions used by line indentation function. ; Regular expressions used by line indentation function.
(defconst cmake-regex-quoted "\"\\([^\n\"\\\\]\\|\\\\.\\)*\"") (defconst cmake-regex-quoted "\"\\([^\n\"\\\\]\\|\\\\.\\)*\"")
(defconst cmake-regex-unquoted "\\([^\n \t()\\\\]\\|\\\\.\\)+")
(defconst cmake-regex-arguments (concat "\\(" cmake-regex-quoted (defconst cmake-regex-arguments (concat "\\(" cmake-regex-quoted
"\\|" cmake-regex-unquoted "\\|" "[^\n()\\\\]"
"\\|[ \t]\\)*")) "\\|" "\\\\."
(defconst cmake-regex-comment "\\(#[^\n]*\\)?") "\\)*"))
(defconst cmake-regex-comment "#[^\n]*")
(defconst cmake-regex-identifier "[A-Za-z][A-Za-z0-9_]*") (defconst cmake-regex-identifier "[A-Za-z][A-Za-z0-9_]*")
(defconst cmake-indent-comment-line (concat "^[ \t]*" cmake-regex-comment))
(defconst cmake-indent-blank-regex "^[ \t]*$") (defconst cmake-indent-blank-regex "^[ \t]*$")
(defconst cmake-indent-open-regex (concat "^[ \t]*" cmake-regex-identifier (defconst cmake-indent-open-regex (concat "^[ \t]*" cmake-regex-identifier
"[ \t]*(" cmake-regex-arguments "[ \t]*(" cmake-regex-arguments
cmake-indent-comment-regex "\n")) "\\(" cmake-regex-comment "\\)?"
"\n"))
(defconst cmake-indent-close-regex (concat "^" cmake-regex-arguments (defconst cmake-indent-close-regex (concat "^" cmake-regex-arguments
")[ \t]*" cmake-indent-comment-regex "\n")) ")[ \t]*"
"\\(" cmake-regex-comment "\\)?"
"\n"))
(defconst cmake-indent-begin-regex "^[ \t]*\\(IF\\|MACRO\\|FOREACH\\|ELSE\\)") (defconst cmake-indent-begin-regex "^[ \t]*\\(IF\\|MACRO\\|FOREACH\\|ELSE\\)")
(defconst cmake-indent-end-regex "^[ \t]*\\(ENDIF\\|ENDFOREACH\\|ENDMACRO\\|ELSE\\)") (defconst cmake-indent-end-regex "^[ \t]*\\(ENDIF\\|ENDFOREACH\\|ENDMACRO\\|ELSE\\)")
@ -43,28 +47,35 @@
(while (and (not (bobp)) (looking-at cmake-indent-blank-regex)) (while (and (not (bobp)) (looking-at cmake-indent-blank-regex))
(forward-line -1) (forward-line -1)
) )
; Start with previous non-blank line's indentation. ; Start with previous non-blank line's indentation.
(setq cur-indent (current-indentation)) (setq cur-indent (current-indentation))
; If previous line begins a block, we indent this line. ; If previous line is a comment line, just use its
(if (looking-at cmake-indent-begin-regex) ; indentation. Otherwise, adjust indentation based on the
(setq cur-indent (+ cur-indent cmake-tab-width)) ; line's contents.
) (if (not (looking-at cmake-indent-comment-line))
(progn
; If previous line opens a command invocation, we indent this line. ; If previous line begins a block, we indent this line.
(if (looking-at cmake-indent-open-regex) (if (looking-at cmake-indent-begin-regex)
(setq cur-indent (+ cur-indent cmake-tab-width)) (setq cur-indent (+ cur-indent cmake-tab-width))
) )
; If previous line closes a command invocation, we unindent ; If previous line opens a command invocation, we indent
; this line. ; this line.
(if (looking-at cmake-indent-close-regex) (if (looking-at cmake-indent-open-regex)
(setq cur-indent (- cur-indent cmake-tab-width)) (setq cur-indent (+ cur-indent cmake-tab-width))
) )
(if (looking-at "^[ \t]*#[^\n]*")
(setq cur-indent (current-indentation)) ; If previous line closes a command invocation, we unindent
; this line.
(if (looking-at cmake-indent-close-regex)
(setq cur-indent (- cur-indent cmake-tab-width))
)
)
) )
) )
; If this line ends a block, we unindent it. ; If this line ends a block, we unindent it.
(if (looking-at cmake-indent-end-regex) (if (looking-at cmake-indent-end-regex)