Next: , Previous: , Up: Commands   [Contents][Index]

4.4 Filling and Line Breaking Commands

Since there’s a lot of normal text in comments and string literals, CC Mode provides features to edit these like in text mode. The goal is to do it seamlessly, i.e., you can use auto fill mode, sentence and paragraph movement, paragraph filling, adaptive filling etc. wherever there’s a piece of normal text without having to think much about it. CC Mode keeps the indentation, fixes suitable comment line prefixes, and so on.

You can configure the exact way comments get filled and broken, and where Emacs does auto-filling (see Customizing Filling and Line Breaking). Typically, the style system (see Styles) will have set this up for you, so you probably won’t have to bother.

Line breaks are by default handled (almost) the same regardless of whether they are made by auto fill mode (see Auto Fill in GNU Emacs Manual), by paragraph filling (e.g., with M-q), or explicitly with M-j or similar methods. In string literals, the new line gets the same indentation as the previous nonempty line.6.

M-q (c-fill-paragraph)

This command fills multiline string literals and both block and line style comments. In Java buffers, the Javadoc markup words are recognized as paragraph starters. The line oriented Pike autodoc markup words are recognized in the same way in Pike mode.

The formatting of the starters (/*) and enders (*/) of block comments are kept as they were before the filling. I.e., if either the starter or ender were on a line of its own, then it stays on its own line; conversely, if the delimiter has comment text on its line, it keeps at least one word of that text with it on the line.

This command is the replacement for fill-paragraph in CC Mode buffers.

M-j (c-indent-new-comment-line)

This breaks the current line at point and indents the new line. If point was in a comment, the new line gets the proper comment line prefix. If point was inside a macro, a backslash is inserted before the line break. It is the replacement for indent-new-comment-line.

M-x c-context-line-break

Insert a line break suitable to the context: If the point is inside a comment, the new line gets the suitable indentation and comment line prefix like c-indent-new-comment-line. In normal code it’s indented like newline-and-indent would do. In macros it acts like newline-and-indent but additionally inserts and optionally aligns the line ending backslash so that the macro remains unbroken. See Customizing Macros, for details about the backslash alignment. In a string, a backslash is inserted only if the string is within a macro7.

This function is not bound to a key by default, but it’s intended to be used on the RET key. If you like the behavior of newline-and-indent on RET, you should consider switching to this function. See Sample Init File.

M-x c-context-open-line

This is to C-o (M-x open-line) as c-context-line-break is to RET. I.e., it works just like c-context-line-break but leaves the point before the inserted line break.


Footnotes

(6)

You can change this default by setting the string syntactic symbol (see Syntactic Symbols and see Customizing Indentation)

(7)

In GCC, unescaped line breaks within strings are valid.

Next: Minor Modes, Previous: Movement Commands, Up: Commands   [Contents][Index]