27.3.4 Commands for C Indentation

Here are special features for indentation in C mode and related modes:

C-c C-q

Reindent the current top-level function definition or aggregate type declaration (c-indent-defun in CC mode, c-ts-mode-indent-defun in c-ts-mode based on tree-sitter).


Reindent each line in the balanced expression (see Expressions with Balanced Parentheses), also known as “sexp”, that follows point. In CC mode, this invokes c-indent-exp; in tree-sitter based c-ts-mode this invokes a more general prog-indent-sexp. A prefix argument inhibits warning messages about invalid syntax.


Reindent the current line, active region, or block starting on this line (c-indent-line-or-region). With prefix argument, rigidly reindent the balanced expression which starts on the current line, if the current line needs reindentation.

If c-tab-always-indent is t, this command always reindents the current line and does nothing else. This is the default.

If that variable is nil, this command reindents the current line only if point is at the left margin or in the line’s indentation; otherwise, it inserts a tab (or the equivalent number of spaces, if indent-tabs-mode is nil).

Any other value (not nil or t) means always reindent the line, and also insert a tab if within a comment or a string.

To reindent the whole current buffer, type C-x h C-M-\. This first selects the whole buffer as the region, then reindents that region.

To reindent the current block, use C-M-u C-M-q. This moves to the front of the block and then reindents it all.