Next: , Previous: Primitive Indent, Up: Indentation

32.17.2 Indentation Controlled by Major Mode

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.

— Variable: indent-line-function

This variable's value is the function to be used by <TAB> (and various commands) to indent the current line. The command indent-according-to-mode does little more than call this function.

In Lisp mode, the value is the symbol lisp-indent-line; in C mode, c-indent-line; in Fortran mode, fortran-indent-line. The default value is indent-relative. See Auto-Indentation.

— Command: indent-according-to-mode

This command calls the function in indent-line-function to indent the current line in a way appropriate for the current major mode.

— Command: indent-for-tab-command &optional rigid

This command calls the function in indent-line-function to indent the current line; however, if that function is indent-to-left-margin, insert-tab is called instead. (That is a trivial command that inserts a tab character.) If rigid is non-nil, this function also rigidly indents the entire balanced expression that starts at the beginning of the current line, to reflect change in indentation of the current line.

— Command: newline-and-indent

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 the current indent-line-function. In programming language modes, this is the same thing <TAB> does, but in some text modes, where <TAB> inserts a tab, newline-and-indent indents to the column specified by left-margin.

— Command: reindent-then-newline-and-indent

This command reindents the current line, inserts a newline at point, and then indents the new line (the one following the newline just inserted).

This command does indentation on both lines according to the current major mode, by calling the current value of indent-line-function. In programming language modes, this is the same thing <TAB> does, but in some text modes, where <TAB> inserts a tab, reindent-then-newline-and-indent indents to the column specified by left-margin.