Function: c-indent-command

c-indent-command is an interactive and byte-compiled function defined in cc-cmds.el.gz.

Signature

(c-indent-command &optional ARG)

Documentation

Indent current line as C code, and/or insert some whitespace.

If c-tab-always-indent is t, always just indent the current line. If nil, indent the current line only if point is at the left margin or in the line's indentation; otherwise insert some whitespace[*]. If other than nil or t, then some whitespace[*] is inserted only within literals (comments and strings), but the line is always reindented.

If c-syntactic-indentation is t, indentation is done according to the syntactic context. A numeric argument, regardless of its value, means indent rigidly all the lines of the expression starting after point so that this line becomes properly indented. The relative indentation among the lines of the expression is preserved.

If c-syntactic-indentation is nil, the line is just indented one step according to c-basic-offset. In this mode, a numeric argument indents a number of such steps, positive or negative, and an empty prefix argument is equivalent to -1.

  [*] The amount and kind of whitespace inserted is controlled by the
  variable c-insert-tab-function, which is called to do the actual
  insertion of whitespace. Normally the function in this variable
  just inserts a tab character, or the equivalent number of spaces,
  depending on the variable indent-tabs-mode(var)/indent-tabs-mode(fun).

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
;; commands to indent lines, regions, defuns, and expressions
(defun c-indent-command (&optional arg)
  "Indent current line as C code, and/or insert some whitespace.

If `c-tab-always-indent' is t, always just indent the current line.
If nil, indent the current line only if point is at the left margin or
in the line's indentation; otherwise insert some whitespace[*].  If
other than nil or t, then some whitespace[*] is inserted only within
literals (comments and strings), but the line is always reindented.

If `c-syntactic-indentation' is t, indentation is done according to
the syntactic context.  A numeric argument, regardless of its value,
means indent rigidly all the lines of the expression starting after
point so that this line becomes properly indented.  The relative
indentation among the lines of the expression is preserved.

If `c-syntactic-indentation' is nil, the line is just indented one
step according to `c-basic-offset'.  In this mode, a numeric argument
indents a number of such steps, positive or negative, and an empty
prefix argument is equivalent to -1.

  [*] The amount and kind of whitespace inserted is controlled by the
  variable `c-insert-tab-function', which is called to do the actual
  insertion of whitespace.  Normally the function in this variable
  just inserts a tab character, or the equivalent number of spaces,
  depending on the variable `indent-tabs-mode'."

  (interactive "P")
  (c-with-string-fences
   (let ((indent-function
	  (if c-syntactic-indentation
	      (symbol-function 'indent-according-to-mode)
	    (lambda ()
	      (let ((c-macro-start c-macro-start)
		    (steps (if (equal arg '(4))
			       -1
			     (prefix-numeric-value arg))))
		(c-shift-line-indentation (* steps c-basic-offset))
		(when (and c-auto-align-backslashes
			   (save-excursion
			     (end-of-line)
			     (eq (char-before) ?\\))
			   (c-query-and-set-macro-start))
		  ;; Realign the line continuation backslash if inside a macro.
		  (c-backslash-region (point) (point) nil t)))
	      ))))
     (if (and c-syntactic-indentation arg)
	 ;; If c-syntactic-indentation and got arg, always indent this
	 ;; line as C and shift remaining lines of expression the same
	 ;; amount.
	 (let ((shift-amt (save-excursion
			    (back-to-indentation)
			    (current-column)))
	       beg end)
	   (c-indent-line)
	   (setq shift-amt (- (save-excursion
				(back-to-indentation)
				(current-column))
			      shift-amt))
	   (save-excursion
	     (if (eq c-tab-always-indent t)
		 (beginning-of-line)) ; FIXME!!! What is this here for?  ACM 2005/10/31
	     (setq beg (point))
	     (c-forward-sexp 1)
	     (setq end (point))
	     (goto-char beg)
	     (forward-line 1)
	     (setq beg (point)))
	   (if (> end beg)
	       (indent-code-rigidly beg end shift-amt "#")))
       ;; Else use c-tab-always-indent to determine behavior.
       (cond
	;; CASE 1: indent when at column zero or in line's indentation,
	;; otherwise insert a tab
	((not c-tab-always-indent)
	 (if (save-excursion
	       (skip-chars-backward " \t")
	       (not (bolp)))
	     (funcall c-insert-tab-function)
	   (funcall indent-function)))
	;; CASE 2: just indent the line
	((eq c-tab-always-indent t)
	 (funcall indent-function))
	;; CASE 3: if in a literal, insert a tab, but always indent the
	;; line
	(t
	 (if (c-save-buffer-state () (c-in-literal))
	     (funcall c-insert-tab-function))
	 (funcall indent-function)
	 ))))))