Next: , Up: Program Indent

26.3.1 Basic Program Indentation Commands

<TAB>
Adjust indentation of current line (indent-for-tab-command).
C-j
Insert a newline, then adjust indentation of following line (newline-and-indent).

The basic indentation command is <TAB> (indent-for-tab-command), which was documented in Indentation. In programming language modes, <TAB> indents the current line, based on the indentation and syntactic content of the preceding lines; if the region is active, <TAB> indents each line within the region, not just the current line.

The command C-j (newline-and-indent), which was documented in Indentation Commands, does the same as <RET> followed by <TAB>: it inserts a new line, then adjusts the line's indentation.

When indenting a line that starts within a parenthetical grouping, Emacs usually places the start of the line under the preceding line within the group, or under the text after the parenthesis. If you manually give one of these lines a nonstandard indentation (e.g., for aesthetic purposes), the lines below will follow it.

The indentation commands for most programming language modes assume that a open-parenthesis, open-brace or other opening delimiter at the left margin is the start of a function. If the code you are editing violates this assumption—even if the delimiters occur in strings or comments—you must set open-paren-in-column-0-is-defun-start to nil for indentation to work properly. See Left Margin Paren.