manpagez: man pages & more
info emacs
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

31.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.


Adjust indentation of current line.


Insert a newline, then adjust indentation of following line (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-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 character at point.

When entering lines of new code, use C-j (newline-and-indent), which inserts a newline and then adjusts indentation after it. (It also deletes any trailing whitespace which remains before the new newline.) Thus, C-j at the end of a line creates a blank line with appropriate indentation. In programming language modes, it is equivalent to <RET> <TAB>.

<TAB> indents a line that starts within a parenthetical grouping under the preceding line within the grouping, 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.

In some modes, 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. This speeds up indentation commands. If you will be editing text which contains opening delimiters in column zero that aren't the beginning of a functions, even inside strings or comments, you must set open-paren-in-column-0-is-defun-start. See section Left Margin Convention, for more information on this.

Normally, lines are indented with tabs and spaces. If you want Emacs to use spaces only, set indent-tabs-mode (see section Tabs vs. Spaces).

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© 2000-2017
Individual documents may contain additional copyright information.