Function: cmake-indent
cmake-indent is an interactive and natively compiled function defined
in cmake-mode.el.
Signature
(cmake-indent)
Documentation
Indent current line as CMake code.
Key Bindings
This command is not in any keymaps.
Source Code
;; Defined in /nix/store/xpmgnbrvz0j5ic5m3q6fvh28ca8a9avm-emacs-packages-deps/share/emacs/site-lisp/elpa/cmake-mode-20261002.1529/cmake-mode.el
;;
;; Line indentation function.
;;
(defun cmake-indent ()
"Indent current line as CMake code."
(interactive)
(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))
(closing-parens-only (looking-at cmake-regex-closing-parens-line))
(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))
(if closing-parens-only
(let ((open-parens 0))
(while (re-search-forward cmake-regex-token point-start t)
(setq token (match-string 0))
(cond
((string-match cmake-regex-token-paren-left token)
(setq open-parens (+ open-parens 1)))
((string-match cmake-regex-token-paren-right token)
(setq open-parens (- open-parens 1)))))
;; Don't outdent if last indented line has open parens
(unless (> open-parens 0)
(setq cur-indent (- cur-indent cmake-tab-width))))
;; Skip detailed analysis if last indented line is a 'closing
;; parens only line'
(unless (looking-at cmake-regex-closing-parens-line)
;; Search forward counting tokens that adjust indentation.
(while (re-search-forward cmake-regex-token point-start t)
(setq token (match-string 0))
(when (or (string-match cmake-regex-token-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 cmake-regex-token-paren-right token)
(setq cur-indent (- cur-indent cmake-tab-width)))
))
(goto-char point-start)
;; If next token closes the block, decrease indentation
(when (looking-at cmake-regex-close)
(setq cur-indent (- cur-indent cmake-tab-width))
)
)
)
)
;; Indent this line by the amount selected.
(cmake-indent-line-to (max cur-indent 0))
)
)
)
)