| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.1 Indentation Commands 6.2 Movement Commands 6.3 Other Commands
See also 5. Text Filling and Line Breaking, for commands concerning that bit.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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(19).
These commands are useful when indenting code:
c-indent-command)
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.
c-indent-exp)
c-indent-defun)
indent-region)
c-mark-function)
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
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
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
nil, then tabs can be used
in a line's indentation, otherwise only spaces can be used.
c-progress-interval
nil to
inhibit the progress messages, or set it to an integer which is the
interval in seconds that progress messages are displayed.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
CC Mode contains some useful command for moving around in C code.
beginning-of-defun,
except it eliminates the constraint that the top-level opening brace
must be in column zero. See beginning-of-defun for more
information.
Depending on the coding style being used, you might prefer
c-beginning-of-defun to beginning-of-defun. If so,
consider binding C-M-a to the former instead. For backwards
compatibility reasons, the default binding remains in effect.
end-of-defun,
except it eliminates the constraint that the top-level opening brace of
the defun must be in column zero. See beginning-of-defun for more
information.
Depending on the coding style being used, you might prefer
c-end-of-defun to end-of-defun. If so,
consider binding C-M-e to the former instead. For backwards
compatibility reasons, the default binding remains in effect.
c-up-conditional)
`#elif' is treated like `#else' followed by `#if', so the function stops at them when going backward, but not when going forward.
c-up-conditional that also stops at `#else'
lines. Normally those lines are ignored.
`#elif' is treated like `#else' followed by `#if', so the function stops at them when going forward, but not when going backward.
c-down-conditional that also stops at `#else'
lines. Normally those lines are ignored.
c-backward-conditional)
c-forward-conditional)
c-beginning-of-statement)
If point is within or next to a comment or a string which spans more than one line, this command moves by sentences instead of statements.
When called from a program, this function takes three optional arguments: the repetition count, a buffer position limit which is the farthest back to search for the syntactic context, and a flag saying whether to do sentence motion in or near comments and multiline strings.
c-end-of-statement)
If point is within or next to a comment or a string which spans more than one line, this command moves by sentences instead of statements.
When called from a program, this function takes three optional arguments: the repetition count, a buffer position limit which is the farthest back to search for the syntactic context, and a flag saying whether to do sentence motion in or near comments and multiline strings.
This command moves point forward to next capitalized word. With prefix argument n, move n times.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
CC Mode contains a few other useful commands:
c-scope-operator)
c-backslash-region)
With no prefix argument, it inserts any missing backslashes and aligns
them to the column specified by the c-backslash-column style
variable. With a prefix argument, it deletes any backslashes.
The function does not modify blank lines at the start of the region. If the region ends at the start of a line, it always deletes the backslash (if any) at the end of the previous line.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |