[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

U.3.1 Basic Program Indentation Commands

The basic indentation commands indent a single line according to the usual conventions of the language you are editing.

TAB
Adjust indentation of current line.
C-j
Equivalent to RET followed by TAB (newline-and-indent).
LINEFEED
This key, if the keyboard has it, is another way to enter C-j.

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 indent-for-tab-command in Lisp mode, c-indent-command in C mode, etc. These functions understand the syntax and conventions of different languages, but they all do conceptually the same job: 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 was inside the whitespace at the beginning of the line, TAB puts it at the end of that whitespace; otherwise, TAB keeps 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 at the end of a line creates a blank line and then gives it the appropriate indentation.

TAB indents lines that start within a parenthetical grouping each under the preceding line (or the text after the parenthesis). Therefore, if you manually give one of these lines a nonstandard indentation, 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 U.2.1 Left Margin Convention, for more information on this.

Normally, lines are indented with tabs and spaces. If you want Emacs to use spaces only, see S.3 Tabs vs. Spaces.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 2, 2002 using texi2html