GNU Info

Info Node: (ccmode)Clean-ups

(ccmode)Clean-ups


Prev: Other Electric Commands Up: Auto-newline Insertion
Enter node , (file) or (file)node

Clean-ups
---------

   "Clean-ups" are mechanisms 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.  Clean-ups are however
used to adjust code "after-the-fact," i.e. to adjust the whitespace in
constructs after they are typed.

   Most of the clean-ups are only applicable to counteract automatically
inserted newlines, and will therefore only have any effect if the
auto-newline minor mode is turned on.  Others will work all the time.

   You can 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 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 (Note: Auto-newline
Insertion), and when there is nothing but whitespace appearing
between the individual components of the construct.

   These are the clean-ups that only are active in the auto-newline
minor mode:

   * `brace-else-brace' -- Clean 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 )
              {

     and like this after the open brace 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' -- Clean 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' -- Clean 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' -- Clean up commas following braces in array
     and aggregate initializers.  Clean up occurs when the comma is
     typed.

   * `scope-operator' -- Clean 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.


   The following clean-ups are always active when they occur on
`c-cleanup-list', and are thus not affected by the auto-newline minor
mode:

   * `space-before-funcall' -- Insert a space between the function name
     and the opening parenthesis of a function call.  This produces
     function calls in the style mandated by the GNU coding standards,
     e.g. `signal (SIGINT, SIG_IGN)' and `abort ()'.  Clean up occurs
     when the opening parenthesis is typed.

   * `compact-empty-funcall' -- Clean up any space between the function
     name and the opening parenthesis of a function call that have no
     arguments.  This is typically used together with
     `space-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.


   ---------- 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.


automatically generated by info2www version 1.2.2.9