CC Mode contains some useful commands for moving around in C code.
c-beginning-of-defun
) ¶c-end-of-defun
)Move to the beginning or end of the current or next function. Other constructs (such as a structs or classes) which have a brace block also count as “functions” here. To move over several functions, you can give these commands a repeat count.
The start of a function is at its header. The end of the function is
after its closing brace, or after the semicolon of a construct (such
as a struct
) which doesn’t end at the brace. These two
commands try to leave point at the beginning of a line near the actual
start or end of the function. This occasionally causes point not to
move at all.
By default, these commands will recognize functions contained within a
declaration scope such as a C++ class
or namespace
construct, should the point start inside it. If CC Mode fails to find
function beginnings or ends inside the current declaration scope, it
will search the enclosing scopes. If you want CC Mode to recognize
functions only at the top level5, set c-defun-tactic
to
t
.
These functions are analogous to the Emacs built-in commands
beginning-of-defun
and end-of-defun
, except they
eliminate the constraint that the top-level opening brace of the defun
must be in column zero. See Defuns in GNU Emacs Manual, for more information.
c-awk-beginning-of-defun
) ¶c-awk-end-of-defun
)Move to the beginning or end of the current or next AWK defun. These
commands can take prefix-arguments, their functionality being entirely
equivalent to beginning-of-defun
and end-of-defun
.
AWK Mode defuns are either pattern/action pairs (either of which might be implicit) or user defined functions. Having the ‘{’ and ‘}’ (if there are any) in column zero, as is suggested for some modes, is neither necessary nor helpful in AWK mode.
c-beginning-of-statement
) ¶c-end-of-statement
)Move to the beginning or end of the innermost C statement. If point is already there, move to the next beginning or end of a statement, even if that means moving into a block. (Use C-M-b or C-M-f to move over a balanced block.) A prefix argument n means move over n statements.
If point is within or next to a comment or a string which spans more than one line, these commands move by sentences instead of statements.
When called from a program, these functions take 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-up-conditional
) ¶Move back to the containing preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move forward to the end of the containing preprocessor conditional.
‘#elif’ is treated like ‘#else’ followed by ‘#if’, so the function stops at them when going backward, but not when going forward.
This key sequence is not bound in AWK Mode, which doesn’t have preprocessor statements.
A variety of c-up-conditional
that also stops at ‘#else’
lines. Normally those lines are ignored.
Move forward into the next nested preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move backward into the previous nested preprocessor conditional.
‘#elif’ is treated like ‘#else’ followed by ‘#if’, so the function stops at them when going forward, but not when going backward.
A variety of c-down-conditional
that also stops at ‘#else’
lines. Normally those lines are ignored.
c-backward-conditional
) ¶c-forward-conditional
)Move backward or forward across a preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move in the opposite direction.
These key sequences are not bound in AWK Mode, which doesn’t have preprocessor statements.
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’.
These commands move backward or forward to the beginning of the next capitalized word. With prefix argument n, move n times. If n is negative, move in the opposite direction.
Note that these two commands have been superseded by
c-subword-mode
, which you should use instead. See Subword Movement and Editing. They might be removed from a future release of CC Mode.