Clean-ups
---------
"Clean-ups" are a mechanism complementary to colon and brace
hanging. On the surface, it would seem that clean-ups overlap the
functionality provided by the `c-hanging-*-alist' variables, and
similarly, clean-ups are only enabled when auto-newline minor mode is
enabled. Clean-ups are used however to adjust code "after-the-fact",
i.e. to eliminate some whitespace that is inserted by electric
commands, or whitespace that contains intervening constructs.
You can configure CC Mode's clean-ups by setting the variable
`c-cleanup-list', which is a list of clean-up symbols. By default, CC
Mode cleans up only the `scope-operator' construct, which is necessary
for proper C++ support. Note that clean-ups are only performed when
the construct does not occur within a literal (see *Note Auto-newline
insertion::), and when there is nothing but whitespace appearing
between the individual components of the construct.
There are currently only five specific constructs that CC Mode can
clean up, as indicated by these symbols:
* `brace-else-brace' -- cleans up `} else {' constructs by placing
the entire construct on a single line. Clean-up occurs when the
open brace after the `else' is typed. So for example, this:
void spam(int i)
{
if( i==7 )
{
dosomething();
}
else
{
appears like this after the open brace is typed:
void spam(int i)
{
if( i==7 ) {
dosomething();
} else {
* `brace-elseif-brace' -- similar to the `brace-else-brace'
clean-up, but this cleans up `} else if (...) {' constructs. For
example:
void spam(int i)
{
if( i==7 )
{
dosomething();
}
else if( i==3 ) {
appears like this after the open parenthesis is typed:
void spam(int i)
{
if( i==7 ) {
dosomething();
} else if( i==3 ) {
* `brace-catch-brace' -- analogous to `brace-elseif-brace', but
cleans up `} catch (...) {' in C++ and Java mode.
* `empty-defun-braces' -- cleans up braces following a top-level
function or class definition that contains no body. Clean up
occurs when the closing brace is typed. Thus the following:
class Spam
{
}
is transformed into this when the close brace is typed:
class Spam
{}
* `defun-close-semi' -- cleans up the terminating semi-colon on
top-level function or class definitions when they follow a close
brace. Clean up occurs when the semi-colon is typed. So for
example, the following:
class Spam
{
}
;
is transformed into this when the semi-colon is typed:
class Spam
{
};
* `list-close-comma' -- cleans up commas following braces in array
and aggregate initializers. Clean up occurs when the comma is
typed.
* `scope-operator' -- cleans up double colons which may designate a
C++ scope operator split across multiple lines(1). Clean up
occurs when the second colon is typed. You will always want
`scope-operator' in the `c-cleanup-list' when you are editing C++
code.
---------- Footnotes ----------
(1) Certain C++ constructs introduce ambiguous situations, so
`scope-operator' clean-ups may not always be correct. This usually
only occurs when scoped identifiers appear in switch label tags.