Function: c-indent-line
c-indent-line is a byte-compiled function defined in cc-cmds.el.gz.
Signature
(c-indent-line &optional SYNTAX QUIET IGNORE-POINT-POS)
Documentation
Indent the current line according to the syntactic context,
if c-syntactic-indentation is non-nil. Optional SYNTAX is the
syntactic information for the current line. Be silent about syntactic
errors if the optional argument QUIET is non-nil, even if
c-report-syntactic-errors is non-nil. Normally the position of
point is used to decide where the old indentation is on a lines that
is otherwise empty (ignoring any line continuation backslash), but
that's not done if IGNORE-POINT-POS is non-nil. Returns the amount of
indentation change (in columns).
Probably introduced at or before Emacs version 19.26.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-indent-line (&optional syntax quiet ignore-point-pos)
"Indent the current line according to the syntactic context,
if `c-syntactic-indentation' is non-nil. Optional SYNTAX is the
syntactic information for the current line. Be silent about syntactic
errors if the optional argument QUIET is non-nil, even if
`c-report-syntactic-errors' is non-nil. Normally the position of
point is used to decide where the old indentation is on a lines that
is otherwise empty (ignoring any line continuation backslash), but
that's not done if IGNORE-POINT-POS is non-nil. Returns the amount of
indentation change \(in columns)."
(let ((line-cont-backslash (save-excursion
(end-of-line)
(eq (char-before) ?\\)))
(c-fix-backslashes c-fix-backslashes)
bs-col
shift-amt)
(when (and (not ignore-point-pos)
(save-excursion
(beginning-of-line)
(looking-at (if line-cont-backslash
;; Don't use "\\s " - ^L doesn't count as WS
;; here
"\\([ \t]*\\)\\\\$"
"\\([ \t]*\\)$")))
(<= (point) (match-end 1)))
;; Delete all whitespace after point if there's only whitespace
;; on the line, so that any code that does back-to-indentation
;; or similar gets the current column in this case. If this
;; removes a line continuation backslash it'll be restored
;; at the end.
(unless c-auto-align-backslashes
;; Should try to keep the backslash alignment
;; in this case.
(save-excursion
(goto-char (match-end 0))
(setq bs-col (1- (current-column)))))
(delete-region (point) (match-end 0))
(setq c-fix-backslashes t))
(if c-syntactic-indentation
(setq c-parsing-error
(or (let ((c-parsing-error nil)
(c-syntactic-context
(or syntax
(and (boundp 'c-syntactic-context)
c-syntactic-context))))
(c-save-buffer-state (indent)
(unless c-syntactic-context
(setq c-syntactic-context (c-guess-basic-syntax)))
(setq indent (c-get-syntactic-indentation
c-syntactic-context))
(and (not (c-echo-parsing-error quiet))
c-echo-syntactic-information-p
(message "syntax: %s, indent: %d"
c-syntactic-context indent))
(setq shift-amt (- indent (current-indentation))))
(c-shift-line-indentation shift-amt)
(run-hooks 'c-special-indent-hook)
c-parsing-error)
c-parsing-error))
(let ((indent 0))
(save-excursion
(while (and (= (forward-line -1) 0)
(if (looking-at "\\s *\\\\?$")
t
(setq indent (current-indentation))
nil))))
(setq shift-amt (- indent (current-indentation)))
(c-shift-line-indentation shift-amt)))
(when (and c-fix-backslashes line-cont-backslash)
(if bs-col
(save-excursion
(indent-to bs-col)
(insert ?\\))
(when c-auto-align-backslashes
;; Realign the line continuation backslash.
(c-backslash-region (point) (point) nil t))))
shift-amt))