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
Depending on the coding style being used, you might prefer
|
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
Depending on the coding style being used, you might prefer
|
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, |
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 |
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 |
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. ` 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
The variable |
[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.