[comp.emacs] C-mode indentation weirdness

pz@munsell.UUCP (Paul Czarnecki) (03/23/88)

Why does Gnu emacs indent this C code like this?  It is clearly not
what is wanted.  Is there a coding style or emacs variable that I need
to change?

{
	switch (bar(class, form)) {
	    case bar(CLASS_UNIV, FORM_STRING):
		    printf("got a string\n");
		    process_string();
		    break;
		case bar(CLASS_UNIV, FORM_INT):
			printf("got an int\n");
		    process_int();
		    break;
		case bar(CLASS_UNIV, FORM_TIME):
			printf("got a time\n");
		    process_time();
		    break;
		default:
		    printf("default\n");
		    break;
	    }
}


I have the following lines in my ~/.emacs files.

;;; indent c code by 8 spaces
(setq c-indent-level 8)
(setq c-continued-statement-offset 8)
(setq c-argdecl-indent 8)
(setq c-label-offset -4)

I am running a stock 18.41 Gnu emacs on a Sun running 3.4.

					pZ

-- 
		       Paul Czarnecki -- Spam, spam, spam, Usenet, and spam
	{{harvard,ll-xn}!adelie,{decvax,allegra,talcott}!encore}!munsell!pz

bd@hpsemc.HP.COM (bob desinger) (03/29/88)

Paul Czarnecki (pz@munsell.UUCP) asks:
> Why does Gnu emacs indent this C code like this?

RMS likes it that way.  It looks weird to my taste, too, but then
he probably hates my style so we're even.

> Is there a coding style or emacs variable that I need to change?

Here are the relevant lines from my .emacs.  I sure wish I remembered
where I got them from.  (An info-node somewhere?)

;; C-mode (kernel style)
(setq c-tab-always-indent nil)	; \t inserts itself if point is at midline
(setq c-indent-level 8)		; \t indents this much
(setq c-continued-statement-offset 8)	; indent "then" clauses, etc.
(setq c-brace-offset -8)	; begin hanging braces under keyword
(setq c-argdecl-indent 8)	; function arg decls indented this much
(setq c-label-offset -8)	; "case" lines inside of switches


-- bd

pz@munsell.UUCP (Paul Czarnecki) (04/01/88)

In article <690007@hpsemc.HP.COM> bd@hpsemc.HP.COM (bob desinger) writes:
>Paul Czarnecki (pz@munsell.UUCP) asks:
>> Why does Gnu emacs indent this C code like this?
>
>RMS likes it that way.  It looks weird to my taste, too, but then
>he probably hates my style so we're even.

NO no no...

It is buggy.  Try this:

switch (c) {
    case foo():
	    i = 7;
	    break;
	case bar():
		j = 8;
	    break;
	case quux():
		k = 9;
	    break;
	default:
	    l = 10;
	    break;
    }
	
switch (c) {
    case 'a':
	i = 7;
	break;
    case 'b':
	j = 8;
	break;
    case 8:
	k = 9;
	break;
    default:
	l = 10;
	break;
}

The problem is with the function calls on the case line.  Both of the
above code fragments were indented in the same emacs.  I'm running
18.41.  I've been told it was fixed in 18.50.  I've been promised the
fixes but I haven't received them yet.

(And for those of you who scream, "You can't have function calls on
the case line!", you are only half wrong.  Remember that MACROS can
look like function calls.)

					pZ
-- 
		       Paul Czarnecki -- Spam, spam, spam, Usenet, and spam
	{{harvard,ll-xn}!adelie,{decvax,allegra,talcott}!encore}!munsell!pz

tk@moss.ATT.COM (04/04/88)

In article <1630@pinney.munsell.UUCP> pz@pinney.UUCP (Paul Czarnecki) writes:
> . . .
>
>(And for those of you who scream, "You can't have function calls on
>the case line!", you are only half wrong.  Remember that MACROS can
>look like function calls.)

Well, of course you can you use macros to bastardize the language in almost
any way you please, including your example of using things that look like
function calls as labels in a switch statement. Why should a C-code indenter
be expected to deal with your mangled syntax, since it is not C?

dsill@NSWC-OAS.ARPA (Dave Sill) (04/07/88)

>>(And for those of you who scream, "You can't have function calls on
>>the case line!", you are only half wrong.  Remember that MACROS can
>>look like function calls.)
>
>Well, of course you can you use macros to bastardize the language in almost
>any way you please, including your example of using things that look like
>function calls as labels in a switch statement. Why should a C-code indenter
>be expected to deal with your mangled syntax, since it is not C?

But it *is* C.  A common instance of the usage of macros with
arguments in switch statements is the processing of control characters
using the ubiquitous CTRL, CTL, Ctl, et cetera.

=========
The opinions expressed above are mine.

"The 80x86 world has no excuse for the mess it has gotten itself into."
					-- Doug Gwyn

dsill@NSWC-OAS.ARPA (Dave Sill) (04/07/88)

>>(And for those of you who scream, "You can't have function calls on
>>the case line!", you are only half wrong.  Remember that MACROS can
>>look like function calls.)
>
>Well, of course you can you use macros to bastardize the language in almost
>any way you please, including your example of using things that look like
>function calls as labels in a switch statement. Why should a C-code indenter
>be expected to deal with your mangled syntax, since it is not C?

But it *is* C.  A common instance of the usage of macros with
arguments in switch statements is the processing of control characters
using the ubiquitous CTRL, CTL, Ctl, et cetera.

=========
The opinions expressed above are mine 

"The 80x86 world has no excuse for the mess it has gotten itself into."
					-- Doug Gwyn