GNU Emacs Manual. Node: Multi-line Indent

PREVBasic Indent UPProgram Indent NEXTLisp Indent

20.5.2: Indenting Several Lines

When you wish to reindent several lines of code which have been altered or moved to a different level in the list structure, you have several commands available.


Reindent all the lines within one list (indent-sexp).

C-u TAB Shift an entire list rigidly sideways so that its first line is properly indented.
C-M-\ Reindent all lines in the region (indent-region).

You can reindent the contents of a single list by positioning point before the beginning of it and typing C-M-q (indent-sexp in Lisp mode, c-indent-exp in C mode; also bound to other suitable commands in other modes). The indentation of the line the sexp starts on is not changed; therefore, only the relative indentation within the list, and not its position, is changed. To correct the position as well, type a TAB before the C-M-q.

If the relative indentation within a list is correct but the indentation of its first line is not, go to that line and type C-u TAB. TAB with a numeric argument reindents the current line as usual, then reindents by the same amount all the lines in the grouping starting on the current line. In other words, it reindents the whole grouping rigidly as a unit. It is clever, though, and does not alter lines that start inside strings, or C preprocessor lines when in C mode.

Another way to specify the range to be reindented is with the region. The command C-M-\ (indent-region) applies TAB to every line whose first character is between point and mark.

PREVBasic Indent UPProgram Indent NEXTLisp Indent