Subject: bug#41923: CC Mode 5.33.2 (AWK//l); Bad indentation of gawk switch cases

From: Alan Mackenzie <[email-masked]>
Date: Thu, 18 Jun 2020 18:56:17 +0000

Hello, Peter.

On Wed, Jun 17, 2020 at 18:54:55 +0200, Peter Kozich wrote:
> Package: cc-mode

> Indentation of the case labels of the gawk switch is somehow strange:
> the AWK mode does not seem to recognize the case keyword when indenting
> (although it recognizes it as a keyword when coloring):

> {

>   switch (msg)
>   {
>     case 1:
>       break;
      
>       case 2:
>         break;
        
>         case 3:
>           break;
          
>           default:
>             break;
>   }
  
> }

> In a C buffer, the indentatation of the same works as expected:

[ .... ]

> Is this a bug, or am I missing something in my .emacs file?

This is indeed a bug.  At the time AWK Mode was written, switch didn't
exist in AWK, so special steps were taken to exclude switch and case
from AWK's indentation engine.  When it was introduced, CC Mode failed
to get updated to match.

The following patch puts switch/case/default into AWK Mode.  Would you
please apply it to ...../emacs/lisp/progmodes/cc-langs.el and
byte-compile all of CC Mode (i.e. ...../emacs/lisp/progmodes/cc-*.el).
(If you would like any help with the patching or byte-compilation, feel
free to send me private email.)  On reloading CC Mode (possibly, by
restarting Emacs), the indentation of case etc. should work.

Please then get back to me, confirming the patch works, or saying what
still needs fixing.  Thanks!

diff -r fd31432873bd cc-langs.el
--- a/cc-langs.el	Thu Jun 11 10:50:35 2020 +0000
+++ b/cc-langs.el	Thu Jun 18 18:53:00 2020 +0000
@@ -2772,7 +2772,7 @@
   java '("for" "if" "switch" "while" "catch" "synchronized")
   idl  nil
   pike '("for" "if" "switch" "while" "foreach")
-  awk  '("for" "if" "while"))
+  awk  '("for" "if" "switch" "while"))
 
 (c-lang-defconst c-block-stmt-2-key
   ;; Regexp matching the start of any statement followed by a paren sexp
@@ -2851,8 +2851,7 @@
 (c-lang-defconst c-case-kwds
   "The keyword(s) which introduce a \"case\" like construct.
 This construct is \"<keyword> <expression> :\"."
-  t '("case")
-  awk nil)
+  t '("case"))
 
 (c-lang-defconst c-case-kwds-regexp
   ;; Adorned regexp matching any "case"-like keyword.

> br
> pk

> Emacs  : GNU Emacs 26.3 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.24.13)
>  of 2020-01-28
> Package: CC Mode 5.33.2 (AWK//l)
> Buffer Style: cello
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-string-delim gen-comment-delim syntax-properties 1-bit)

[ CC Mode state dump snipped, but appreciated. ]

-- 
Alan Mackenzie (Nuremberg, Germany).