CC MODE Version 5 Documentation. Node: Other Commands

PREV Indentation Commands UP Commands next

5.2: Other Commands

CC Mode contains other useful command for moving around in C code.

M-x c-beginning-of-defun

Moves point back to the least-enclosing brace. This function is analogous to the Emacs built-in command 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.

M-x c-end-of-defun

Moves point to the end of the current top-level definition. This function is analogous to the Emacs built-in command 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-c C-u (c-up-conditional)

Move point back to the containing preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move point forward to the end of the containing preprocessor conditional. When going backwards, #elif is treated like #else followed by #if. When going forwards, #elif is ignored.

C-c C-p (c-backward-conditional)

Move point back over a preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move forward.

C-c C-n (c-forward-conditional)

Move point forward across a preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move backward.

M-a (c-beginning-of-statement)

Move point to the beginning of the innermost C statement. If point is already at the beginning of a statement, it moves to the beginning of the closest preceding statement, even if that means moving into a block (you can use M-C-b to move over a balanced block). With prefix argument n, move back n ­ 1 statements.

If point is within a comment, or next to a comment, this command moves by sentences instead of statements.

When called from a program, this function takes three optional arguments: the numeric prefix argument, a buffer position limit (used as a starting point for syntactic parsing and as a limit for backward movement), and a flag to indicate whether movement should be by statements (if nil) or sentence (if non-nil).

M-e (c-end-of-statement)

Move point to the end of the innermost C statement. If point is at the end of a statement, move to the end of the next statement, even if it's inside a nested block (use M-C-f to move to the other side of the block). With prefix argument n, move forward n ­ 1 statements.

If point is within a comment, or next to a comment, this command moves by sentences instead of statements.

When called from a program, this function takes three optional arguments: the numeric prefix argument, a buffer position limit (used as a starting point for syntactic parsing and as a limit for backward movement), and a flag to indicate whether movement should be by statements (if nil) or sentence (if non-nil).

M-x c-forward-into-nomenclature

A popular programming style, especially for object-oriented languages such as C++ is to write symbols in a mixed case format, where the first letter of each word is capitalized, and not separated by underscores. E.g. `SymbolsWithMixedCaseAndNoUnderlines'.

This command moves point forward to next capitalized word. With prefix argument n, move n times.

M-x c-backward-into-nomenclature

Move point backward to beginning of the next capitalized word. With prefix argument n, move n times. If n is negative, move forward.

C-c : (c-scope-operator)

In C++, it is also sometimes desirable to insert the double-colon scope operator without performing the electric behavior of colon insertion. C-c : does just this.

M-q (fill-paragraph)

The command is used to fill a block style (C) or line style (C++) comment, in much the same way that text in the various text modes can be filled[1]. You should never attempt to fill non-comment code sections; you'll end up with garbage! Two variables control how C style block comments are filled, specifically how the comment start and end delimiters are handled.

The variable c-hanging-comment-starter-p controls whether comment start delimiters which appear on a line by themselves, end up on a line by themselves after the fill. When the value is nil, the comment starter will remain on its own line[2]. Otherwise, text on the next line will be put on the same line as the comment starter. This is called hanging because the following text hangs on the line with the comment starter[3]

The variable c-hanging-comment-ender-p controls the analogous behavior for the block comment end delimiter. When the value is nil, the comment ender will remain on its own line after the file[4]. Otherwise, the comment end delimiter will be placed at the end of the previous line.


[1] You should not use specialized filling packages such as filladapt with CC Mode. They don't work as well for filling as c-fill-paragraph

[2] It will not be placed on a separate line if it is not already on a separate line.

[3] This variable is t by default, except in java-mode. Hanging comment starters mess up Javadoc style comments.

[4] The same caveat as above holds true.

PREV Indentation Commands UP Commands next