Index: scripts/coder_format/coder_format.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/coder_format.inc,v
retrieving revision 1.2.4.10
diff -u -r1.2.4.10 coder_format.inc
--- scripts/coder_format/coder_format.inc	21 Jan 2008 21:41:12 -0000	1.2.4.10
+++ scripts/coder_format/coder_format.inc	22 Jan 2008 00:53:29 -0000
@@ -144,9 +144,12 @@
  *   $in_case bool
  *      Is true after case and default. Is false after break and return, if
  *      $braces_in_case is not greater than 0.
- *   $braces_in_case int Count of braces
+ *   $switches int Switch level
+ *      Nested switches need to have extra indents added to them.
+ *   $braces_in_case array Count of braces
  *      The number of currently opened curly braces in a case. This is needed
  *      to support arbitrary function exits inside of a switch control strucure.
+ *      This is an array to allow for nested switches.
  *   $parenthesis int Parenthesis level
  *      The number of currently opened parenthesis. This
  *      - prevents line feeds in brackets (f.e. in arguments of for()).
@@ -238,8 +241,9 @@
   // Indent controls:
   $_coder_indent  = 0;
   $in_case        = false;
+  $switches       = 0;
   $parenthesis    = 0;
-  $braces_in_case = 0;
+  $braces_in_case = array();
   $in_brace       = false;
   $in_heredoc     = false;
   $first_php_tag  = true;
@@ -296,7 +300,8 @@
           // (T_DOLLAR_OPEN_CURLY_BRACES exists but is never assigned.)
           if (!$in_variable && !$in_quote && !$in_object && substr(rtrim($result), -1) != '$' || substr(rtrim($result), -1) == ')') {
             if ($in_case) {
-              ++$braces_in_case;
+              ++$braces_in_case[$switches];
+              $_coder_indent += $switches - 1;
             }
             ++$_coder_indent;
             $result = rtrim($result) .' '. $text;
@@ -311,14 +316,20 @@
         case '}':
           if (!$in_quote && !$in_brace && !$in_heredoc) {
             if ($in_case) {
-              --$braces_in_case;
+              --$braces_in_case[$switches];
             }
             --$_coder_indent;
-            if ($braces_in_case < 0) {
+            if ($braces_in_case[$switches] < 0) {
               // Decrease indent if last case in a switch is not terminated.
               --$_coder_indent;
-              $in_case = false;
-              $braces_in_case = 0;
+              $in_case = FALSE;
+              $braces_in_case[$switches] = 0;
+            }
+            elseif ($switches && !$braces_in_case[$switches]) {
+              --$switches;
+              if ($switches > 0) {
+                $in_case = TRUE;
+              }
             }
             $result = rtrim($result);
             if (substr($result, -1) != '{') {
@@ -365,7 +376,7 @@
           }
           else {
             if ($in_case) {
-              ++$_coder_indent;
+              $_coder_indent++;
             }
             $result = rtrim($result) . $text;
             coder_br($result);
@@ -623,10 +634,12 @@
           $in_variable = FALSE;
           break;
 
+        case T_SWITCH:
+          $switches++;
+          // Purposely fall through.
         case T_IF:
         case T_FOR:
         case T_FOREACH:
-        case T_SWITCH:
         case T_GLOBAL:
         case T_STATIC:
         case T_ECHO:
@@ -667,7 +680,7 @@
 
         case T_CASE:
         case T_DEFAULT:
-          $braces_in_case = 0;
+          $braces_in_case[$switches] = 0;
           $result         = rtrim($result);
           $after_case     = true;
           if (!$in_case) {
@@ -690,14 +703,14 @@
           $result = rtrim($result);
           coder_br($result);
           $result .= trim($text);
-          if ($in_case && !$braces_in_case) {
+          if ($in_case && !$braces_in_case[$switches]) {
             --$_coder_indent;
             $in_case = false;
           }
           break;
 
         case T_RETURN:
-          if ($in_case && !$braces_in_case) {
+          if ($in_case && !$braces_in_case[$switches]) {
             // Defer reduction of indent for later.
             ++$_coder_indent;
             $after_return_in_case = true;
@@ -706,7 +719,7 @@
           coder_add_space($result);
           $result .= trim($text) .' ';
           // Decrease indent only if we're not in a control structure inside a case.
-          if ($in_case && !$braces_in_case) {
+          if ($in_case && !$braces_in_case[$switches]) {
             --$_coder_indent;
             $in_case = false;
           }
Index: scripts/coder_format/tests/tests/control.phpt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/tests/tests/Attic/control.phpt,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 control.phpt
--- scripts/coder_format/tests/tests/control.phpt	21 Jan 2008 23:46:39 -0000	1.1.2.5
+++ scripts/coder_format/tests/tests/control.phpt	22 Jan 2008 00:43:20 -0000
@@ -69,15 +69,17 @@
       switch ($long) {
         case 0:
           return t('Lines and paragraphs break automatically.');
+
         case 1:
-          return t('Lines and paragraphs are automatically recognized. The &lt;br /&gt; line break, &lt;p&gt; paragraph and &lt;/p&gt; close paragraph tags are inserted automatically. If paragraphs are not recognized simply add a couple blank lines.');
+          return t('Lines and paragraphs are automatically recognized.');
       }
       break;
+
     case 2:
       return t('Web page addresses and e-mail addresses turn into links automatically.');
   }
 }
 
 --INPUT--
 function language_url_rewrite(&$path, &$options) {
   switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) {
