An important function of each major mode is to customize the <TAB> key to indent properly for the language being edited. This section describes the mechanism of the <TAB> key and how to control it. The functions in this section return unpredictable values.
This is the command bound to <TAB> in most editing modes. Its usual action is to indent the current line, but it can alternatively insert a tab character or indent a region.
Here is what it does:
- First, it checks whether Transient Mark mode is enabled and the region is active. If so, it called
indent-region
to indent all the text in the region (see Region Indent).- Otherwise, if the indentation function in
indent-line-function
isindent-to-left-margin
(a trivial command that inserts a tab character), or if the variabletab-always-indent
specifies that a tab character ought to be inserted (see below), then it inserts a tab character.- Otherwise, it indents the current line; this is done by calling the function in
indent-line-function
. If the line is already indented, and the value oftab-always-indent
iscomplete
(see below), it tries completing the text at point.If rigid is non-
nil
(interactively, with a prefix argument), then after this command indents a line or inserts a tab, it also rigidly indents the entire balanced expression which starts at the beginning of the current line, in order to reflect the new indentation. This argument is ignored if the command indents the region.
This variable's value is the function to be used by
indent-for-tab-command
, and various other indentation commands, to indent the current line. It is usually assigned by the major mode; for instance, Lisp mode sets it tolisp-indent-line
, C mode sets it toc-indent-line
, and so on. The default value isindent-relative
. See Auto-Indentation.
This command calls the function in
indent-line-function
to indent the current line in a way appropriate for the current major mode.
This function inserts a newline, then indents the new line (the one following the newline just inserted) according to the major mode. It does indentation by calling
indent-according-to-mode
.
This command reindents the current line, inserts a newline at point, and then indents the new line (the one following the newline just inserted). It does indentation on both lines by calling
indent-according-to-mode
.
This variable can be used to customize the behavior of the <TAB> (
indent-for-tab-command
) command. If the value ist
(the default), the command normally just indents the current line. If the value isnil
, the command indents the current line only if point is at the left margin or in the line's indentation; otherwise, it inserts a tab character. If the value iscomplete
, the command first tries to indent the current line, and if the line was already indented, it callscompletion-at-point
to complete the text at point (see Completion in Buffers).