Copyright (C) 2000-2012 |
GNU Info (ccmode)Indentation CommandsIndentation Commands ==================== The following list of commands re-indent C constructs. Note that when you change your coding style, either interactively or through some other means, your file does _not_ automatically get re-indented. You will need to execute one of the following commands to see the effects of your changes. Also, variables like `c-hanging-*' and `c-cleanup-list' only affect how on-the-fly code is formatted. Changing the "hanginess" of a brace and then re-indenting, will not move the brace to a different line. For this, you're better off getting an external program like GNU `indent', which will re-arrange brace location, among other things. Re-indenting large sections of code can take a long time. When CC Mode reindents a region of code, it is essentially equivalent to hitting `TAB' on every line of the region. Especially vulnerable is code generator output(1). These commands are useful when indenting code: `TAB' (`c-indent-command') Indents the current line. The actual behavior is controlled by several variables, described below. See `c-tab-always-indent', `c-insert-tab-function', and `indent-tabs-mode'. With a numeric argument, this command rigidly indents the region, preserving the relative indentation among the lines. `M-C-q' (`c-indent-exp') Indent an entire balanced brace or parenthesis expression. Note that point must be on the opening brace or parenthesis of the expression you want to indent. `C-c C-q' (`c-indent-defun') Indents the entire top-level function or class definition encompassing point. It leaves point unchanged. This function can't be used to re-indent a nested brace construct, such as a nested class or function, or a Java method. The top-level construct being re-indented must be complete, i.e. it must have both a beginning brace and an ending brace. `M-C-\' (`indent-region') Indents an arbitrary region of code. This is a standard Emacs command, tailored for C code in a CC Mode buffer. Note that of course, point and mark must delineate the region you want to indent. `M-C-h' (`c-mark-function') While not strictly an indentation command, this is useful for marking the current top-level function or class definition as the current region. As with `c-indent-defun', this command operates on top-level constructs, and can't be used to mark say, a Java method. These variables are also useful when indenting code: `c-tab-always-indent' This variable controls how `TAB' `c-indent-command' operates. When this variable is `t', `TAB' always just indents the current line. When it is `nil', the line is indented only if point is at the left margin, or on or before the first non-whitespace character on the line, otherwise some whitespace is inserted. If this variable is the symbol `other', then some whitespace is inserted only within strings and comments (literals), an inside preprocessor directives, but the line is always reindented. `c-insert-tab-function' When "some whitespace" is inserted as described above, what actually happens is that the function stored in `c-insert-tab-function' is called. Normally, this just inserts a real tab character, or the equivalent number of spaces, depending on `indent-tabs-mode'. Some people, however, set `c-insert-tab-function' to `tab-to-tab-stop' so as to get hard tab stops when indenting. `indent-tabs-mode' This is a standard Emacs variable that controls how line indentation is composed. When this variable is non-`nil', then tabs can be used in a line's indentation, otherwise only spaces can be used. `c-progress-interval' When indenting large regions of code, this variable controls how often a progress message is displayed. Set this variable to `nil' to inhibit the progress messages, or set it to an integer which is the interval in seconds that progress messages are displayed. ---------- Footnotes ---------- (1) In particular, I have had people complain about the speed with which `lex(1)' output is re-indented. Lex, yacc, and other code generators usually output some pretty perversely formatted code. Re-indenting such code will be slow. |