Go to the first, previous, next, last section, table of contents.

C Mode

In addition to the facilities of typical programming language major modes (see section Major Modes for Programming Languages), C mode has various special facilities.

M-a
M-e
In C mode, M-a and M-e move by complete C statements (c-beginning-of-statement and c-end-of-statement). These commands do ordinary, textual sentence motion when in or next to a comment.
M-q
M-q in C mode runs c-fill-paragraph, which is designed for filling C comments. (We assume you don't want to fill the actual C code in a C program.)
C-c C-u
Move back to the containing preprocessor conditional, setting the mark at the starting point (c-up-conditional). A numeric argument acts as a repeat count. With a negative argument, this command moves forward to the end of the containing preprocessor conditional. When going backwards, `#elif' acts like `#else' followed by `#if'. When going forwards, `#elif' is ignored.
C-c C-n
Move forward across the next preprocessor conditional, setting the mark at the starting point (c-forward-conditional).
C-c C-p
Move backward across the previous preprocessor conditional, setting the at the starting point (c-backward-conditional).
M-x c-macro-expand
When you are debugging C code that uses macros, sometimes it is hard to figure out precisely how the macros expand. The command M-x c-macro-expand runs the C preprocessor and shows you what expansion results from the region. The portion of the buffer before the region is also included in preprocessing, for the sake of macros defined there, but the output from this part isn't shown.
M-x c-backslash-region
Insert or align `\' characters at the ends of the lines of the region, except for the last such line. This is useful after writing or editing a C macro definition. If a line already ends in `\', this command adjusts the amount of whitespace before it. Otherwise, it inserts a new `\'.
M-x cpp-highlight-buffer
Highlight parts of the text according to its preprocessor conditionals. This command displays another buffer named `*CPP Edit*', which serves as a graphic menu for selecting how to display particular kinds of conditionals and their contents. After changing various settings, click on `[A]pply these settings' (or go to that buffer and type a) to rehighlight the C mode buffer accordingly.

C++ mode is like C mode, except that it understands C++ comment syntax and certain other differences between C and C++. It also has a command M-x fill-c++-comment, which fills a paragraph made of C++ comment lines.

The command comment-region is useful in C++ mode for commenting out several consecutive lines, or removing the commenting out of such lines. (You don't need this command with C comment syntax because you don't need to put comment delimiters on each line.) See section Manipulating Comments.


Go to the first, previous, next, last section, table of contents.