Next: Indentation Engine Basics, Previous: Custom Auto-newlines, Up: Top
Clean-ups are mechanisms which remove (or exceptionally, add)
whitespace in specific circumstances and are complementary to colon
and brace hanging. You enable a clean-up by adding its symbol into
c-cleanup-list, e.g. like this:
(add-to-list 'c-cleanup-list 'space-before-funcall)
On the surface, it would seem that clean-ups overlap the functionality
provided by the c-hanging-*-alist variables. Clean-ups,
however, are used to adjust code “after-the-fact”, i.e. to adjust
the whitespace in constructs later than when they were typed.
Most of the clean-ups remove automatically inserted newlines, and are
only active when auto-newline minor mode is turned on. Others will
work all the time. Note that clean-ups are only performed when there
is nothing but whitespace appearing between the individual components
of the construct, and (apart from comment-close-slash) when the
construct does not occur within a literal (see Auto-newlines).
You configure CC Mode's clean-ups by setting the style variable
c-cleanup-list, which is a list of clean-up symbols. By default, CC Mode cleans up only thescope-operatorconstruct, which is necessary for proper C++ support.
These are the clean-ups that are only active when electric and auto-newline minor modes are enabled:
brace-else-brace void spam(int i)
{
if( i==7 ) {
dosomething();
}
else
{
appears like this after the last open brace is typed:
void spam(int i)
{
if( i==7 ) {
dosomething();
} else {
brace-elseif-bracebrace-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 last open parenthesis is typed:
void spam(int i)
{
if( i==7 ) {
dosomething();
} else if(
and like this after the last open brace is typed:
void spam(int i)
{
if( i==7 ) {
dosomething();
} else if( i==3 ) {
brace-catch-bracebrace-elseif-brace, but cleans up `} catch
(...) {' in C++ and Java mode.
empty-defun-braces class Spam
{
}
is transformed into this when the close brace is typed:
class Spam
{}
defun-close-semi class Spam
{
...
}
;
is transformed into this when the semicolon is typed:
class Spam
{
...
};
list-close-commadefun-close-semi.
scope-operatorscope-operator in the
c-cleanup-list when you are editing C++ code.
one-liner-defunc-max-one-liner-length is set, the cleanup is only done if the
resulting line would be no longer than the value of that variable.
For example, consider this AWK code:
BEGIN {
FS = "\t" # use <TAB> as a field separator
}
It gets compacted to the following when the closing brace is typed:
BEGIN {FS = "\t"} # use <TAB> as a field separator
The maximum length of the resulting line for which the clean-up
one-liner-defunwill be triggered. This length is that of the entire line, including any leading whitespace and any trailing comment. Its default value is 80. If the value is zero ornil, no limit applies.
The following clean-ups are always active when they occur on
c-cleanup-list, regardless of whether Electric minor mode or
Auto-newline minor mode are enabled:
space-before-funcallcompact-empty-funcallspace-before-funcall if you prefer the GNU function
call style for functions with arguments but think it looks ugly when
it's only an empty parenthesis pair. I.e. you will get `signal
(SIGINT, SIG_IGN)', but `abort()'. Clean up occurs when the
closing parenthesis is typed.
comment-close-slash[1] Certain C++ constructs introduce
ambiguous situations, so scope-operator clean-ups might not
always be correct. This usually only occurs when scoped identifiers
appear in switch label tags.