cmake-mode.el: Minor clean-up
Superficial changes to use more conventional Emacs Lisp idioms.
This commit is contained in:
parent
280dde34dd
commit
9d5082b26e
|
@ -71,20 +71,16 @@ set the path with these commands:
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
|
|
||||||
;;
|
;; Line indentation helper functions
|
||||||
;; Helper functions for line indentation function.
|
|
||||||
;;
|
|
||||||
(defun cmake-line-starts-inside-string ()
|
(defun cmake-line-starts-inside-string ()
|
||||||
"Determine whether the beginning of the current line is in a string."
|
"Determine whether the beginning of the current line is in a string."
|
||||||
(if (save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(let ((parse-end (point)))
|
(let ((parse-end (point)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(nth 3 (parse-partial-sexp (point) parse-end))
|
(nth 3 (parse-partial-sexp (point) parse-end))
|
||||||
)
|
)
|
||||||
)
|
|
||||||
t
|
|
||||||
nil
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -111,57 +107,40 @@ set the path with these commands:
|
||||||
;; Line indentation function.
|
;; Line indentation function.
|
||||||
;;
|
;;
|
||||||
(defun cmake-indent ()
|
(defun cmake-indent ()
|
||||||
"Indent current line as CMAKE code."
|
"Indent current line as CMake code."
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (cmake-line-starts-inside-string)
|
(unless (cmake-line-starts-inside-string)
|
||||||
()
|
|
||||||
(if (bobp)
|
(if (bobp)
|
||||||
(cmake-indent-line-to 0)
|
(cmake-indent-line-to 0)
|
||||||
(let (cur-indent)
|
(let (cur-indent)
|
||||||
|
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
|
|
||||||
(let ((point-start (point))
|
(let ((point-start (point))
|
||||||
(case-fold-search t) ;; case-insensitive
|
(case-fold-search t) ;; case-insensitive
|
||||||
token)
|
token)
|
||||||
|
|
||||||
; Search back for the last indented line.
|
; Search back for the last indented line.
|
||||||
(cmake-find-last-indented-line)
|
(cmake-find-last-indented-line)
|
||||||
|
|
||||||
; Start with the indentation on this line.
|
; Start with the indentation on this line.
|
||||||
(setq cur-indent (current-indentation))
|
(setq cur-indent (current-indentation))
|
||||||
|
|
||||||
; Search forward counting tokens that adjust indentation.
|
; Search forward counting tokens that adjust indentation.
|
||||||
(while (re-search-forward cmake-regex-token point-start t)
|
(while (re-search-forward cmake-regex-token point-start t)
|
||||||
(setq token (match-string 0))
|
(setq token (match-string 0))
|
||||||
(if (string-match (concat "^" cmake-regex-paren-left "$") token)
|
(when (or (string-match (concat "^" cmake-regex-paren-left "$") token)
|
||||||
(setq cur-indent (+ cur-indent cmake-tab-width))
|
(and (string-match cmake-regex-block-open token)
|
||||||
)
|
(looking-at (concat "[ \t]*" cmake-regex-paren-left))))
|
||||||
(if (string-match (concat "^" cmake-regex-paren-right "$") token)
|
(setq cur-indent (+ cur-indent cmake-tab-width)))
|
||||||
(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)))
|
||||||
(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))
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
(goto-char point-start)
|
(goto-char point-start)
|
||||||
|
;; If next token closes the block, decrease indentation
|
||||||
; If this is the end of a block, decrease indentation.
|
(when (looking-at cmake-regex-block-close)
|
||||||
(if (looking-at cmake-regex-block-close)
|
(setq cur-indent (- cur-indent cmake-tab-width))
|
||||||
(setq cur-indent (- cur-indent cmake-tab-width))
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
; Indent this line by the amount selected.
|
; Indent this line by the amount selected.
|
||||||
(if (< cur-indent 0)
|
(cmake-indent-line-to (max cur-indent 0))
|
||||||
(cmake-indent-line-to 0)
|
|
||||||
(cmake-indent-line-to cur-indent)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue