Next: Text, Previous: Major Modes, Up: Top
This chapter describes the Emacs commands that add, remove, or adjust indentation.
newline-and-indent).
delete-indentation).
This would cancel the effect of a preceding C-j.
split-line).
back-to-indentation).
indent-region).
indent-rigidly).
tab-to-tab-stop).
In most major modes, the <TAB> key runs the command
indent-for-tab-command, which either performs indentation or
inserts whitespace at point, depending on the situation.
In programming modes such as Lisp mode and C mode, <TAB> indents the current line if the region is inactive. If the region is active, it indents every line in the region (see Mark). Indentation means adding or removing some combination of space and tab characters (whitespace characters) at the start of the line, in a way that makes sense given the text in the preceding lines. Exactly how indentation is performed depends on the major mode. See Program Indent.
In text modes, <TAB> inserts some whitespace characters to advance point to the next tab stop (see Tab Stops). For the purposes of this command, the position of the first non-whitespace character on the preceding line is treated as an additional tab stop. You can therefore use <TAB> to “align” point with the preceding line. If the region is active, <TAB> performs this action on every line in the region.
Indentation is often performed with the help of tab characters
(ASCII code 9), which are displayed as a stretch of empty space
extending to the next display tab stop. By default, there is
one display tab stop every eight columns; the number of columns is
determined by the variable tab-width. You can insert a single
tab character by typing C-q <TAB>. See Text Display.
The command M-i (tab-to-tab-stop) adjusts the
whitespace characters around point, inserting just enough whitespace
to advance point up to the next tab stop. By default, this involves
deleting the existing whitespace and inserting a single tab character.
Normally, most of these indentation commands insert an optimal mix of tabs and spaces to align to the desired column. See Just Spaces, for how to disable use of tabs. However, C-q <TAB> always inserts a tab, even when tabs are disabled for the indentation commands.