diff options
author | Roy Crihfield <rscrihf@gmail.com> | 2015-07-23 14:44:30 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-07-27 09:38:31 -0400 |
commit | 9d5082b26ebffe1e834c5c13e22bba02933e5c59 (patch) | |
tree | 646af6e62e347fe0f665be8d155ad5d08184c2ca /Auxiliary/cmake-mode.el | |
parent | 280dde34dda52559411376be17591755f4b6358f (diff) | |
download | cmake-9d5082b26ebffe1e834c5c13e22bba02933e5c59.tar.gz |
cmake-mode.el: Minor clean-up
Superficial changes to use more conventional Emacs Lisp idioms.
Diffstat (limited to 'Auxiliary/cmake-mode.el')
-rw-r--r-- | Auxiliary/cmake-mode.el | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el index 51663a8e10..7051cc8c02 100644 --- a/Auxiliary/cmake-mode.el +++ b/Auxiliary/cmake-mode.el @@ -71,20 +71,16 @@ set the path with these commands: ;------------------------------------------------------------------------------ -;; -;; Helper functions for line indentation function. -;; +;; Line indentation helper functions + (defun cmake-line-starts-inside-string () "Determine whether the beginning of the current line is in a string." - (if (save-excursion - (beginning-of-line) - (let ((parse-end (point))) - (goto-char (point-min)) - (nth 3 (parse-partial-sexp (point) parse-end)) - ) - ) - t - nil + (save-excursion + (beginning-of-line) + (let ((parse-end (point))) + (goto-char (point-min)) + (nth 3 (parse-partial-sexp (point) parse-end)) + ) ) ) @@ -111,57 +107,40 @@ set the path with these commands: ;; Line indentation function. ;; (defun cmake-indent () - "Indent current line as CMAKE code." + "Indent current line as CMake code." (interactive) - (if (cmake-line-starts-inside-string) - () + (unless (cmake-line-starts-inside-string) (if (bobp) (cmake-indent-line-to 0) (let (cur-indent) - (save-excursion (beginning-of-line) - (let ((point-start (point)) (case-fold-search t) ;; case-insensitive token) - ; Search back for the last indented line. (cmake-find-last-indented-line) - ; Start with the indentation on this line. (setq cur-indent (current-indentation)) - ; Search forward counting tokens that adjust indentation. (while (re-search-forward cmake-regex-token point-start t) (setq token (match-string 0)) - (if (string-match (concat "^" cmake-regex-paren-left "$") token) - (setq cur-indent (+ cur-indent cmake-tab-width)) - ) - (if (string-match (concat "^" cmake-regex-paren-right "$") token) - (setq cur-indent (- cur-indent cmake-tab-width)) - ) - (if (and - (string-match cmake-regex-block-open token) - (looking-at (concat "[ \t]*" cmake-regex-paren-left)) - ) - (setq cur-indent (+ cur-indent cmake-tab-width)) - ) + (when (or (string-match (concat "^" cmake-regex-paren-left "$") token) + (and (string-match cmake-regex-block-open token) + (looking-at (concat "[ \t]*" cmake-regex-paren-left)))) + (setq cur-indent (+ cur-indent cmake-tab-width))) + (when (string-match (concat "^" cmake-regex-paren-right "$") token) + (setq cur-indent (- cur-indent cmake-tab-width))) ) (goto-char point-start) - - ; If this is the end of a block, decrease indentation. - (if (looking-at cmake-regex-block-close) - (setq cur-indent (- cur-indent cmake-tab-width)) + ;; If next token closes the block, decrease indentation + (when (looking-at cmake-regex-block-close) + (setq cur-indent (- cur-indent cmake-tab-width)) ) ) ) - ; Indent this line by the amount selected. - (if (< cur-indent 0) - (cmake-indent-line-to 0) - (cmake-indent-line-to cur-indent) - ) + (cmake-indent-line-to (max cur-indent 0)) ) ) ) |