newline-and-indent
).
The basic indentation command is TAB, which gives the current line
the correct indentation as determined from the previous lines. The
function that TAB runs depends on the major mode; it is lisp-indent-line
in Lisp mode, c-indent-line
in C mode, etc. These functions
understand different syntaxes for different languages, but they all do
about the same thing. TAB in any programming-language major mode
inserts or deletes whitespace at the beginning of the current line,
independent of where point is in the line. If point is inside the
whitespace at the beginning of the line, TAB leaves it at the end of
that whitespace; otherwise, TAB leaves point fixed with respect to
the characters around it.
Use C-q TAB to insert a tab at point.
When entering lines of new code, use C-j (newline-and-indent
),
which is equivalent to a RET followed by a TAB. C-j creates
a blank line and then gives it the appropriate indentation.
TAB indents the second and following lines of the body of a parenthetical grouping each under the preceding one; therefore, if you alter one line's indentation to be nonstandard, the lines below will tend to follow it. This behavior is convenient in cases where you have overridden the standard result of TAB because you find it unaesthetic for a particular line.
Remember that an open-parenthesis, open-brace or other opening delimiter at the left margin is assumed by Emacs (including the indentation routines) to be the start of a function. Therefore, you must never have an opening delimiter in column zero that is not the beginning of a function, not even inside a string. This restriction is vital for making the indentation commands fast; you must simply accept it. See section Defuns, for more information on this.
Go to the first, previous, next, last section, table of contents.