GNU Info

Info Node: (efaq)Indenting switch statements

(efaq)Indenting switch statements


Next: Customizing C and C++ indentation Prev: Compiler error messages Up: Common requests
Enter node , (file) or (file)node

How do I change the indentation for `switch'?
=============================================

   Many people want to indent their `switch' statements like this:

     f()
     {
       switch(x) {
         case A:
           x1;
           break;
         case B:
           x2;
           break;
         default:
           x3;
       }
     }

   The solution at first appears to be: set `c-indent-level' to 4 and
`c-label-offset' to -2.  However, this will give you an indentation
spacing of four instead of two.

   The _real_ solution is to use `cc-mode' (the default mode for C
programming in Emacs 20 and later) and add the following line to yoyr
`.emacs':

     (c-set-offset 'case-label '+)

   There appears to be no way to do this with the old `c-mode'.


automatically generated by info2www version 1.2.2.9