[gnu.emacs] help on indenting

carroll@s.cs.uiuc.edu (05/05/89)

While I'm normally a VI-user, I've been forced to use Emacs for the time
being. Emacs is generally ok, if slow, but I find the indenting form for
C code very unpleasing. I've tried fiddling the various variable values, but
I have yet to get any satisfactory results. The rules I like are

+ function headers in column 0
+ variables declared outside functions in column 0
+ comments outside functions in column 0
+ parm declarations in column 8 (or 4, anything >0 would be ok)
+ braces indented 4, interior code at same level
+ closing brace same level as opening brace
+ contents of case's in switch indented 4 from case
+ continued lines of statement indented 4, *always*. Emacs seems to do
  strange things inside parentheses.

The major difference is that I consider braces part of the interior block,
while Emacs thinks they're part of the surrounding code. If I could just
set brace lines to have extra indentation, that would be ok, but setting
c-brace-offset causes more problems than it solves - i.e., it doesn just
move brace lines, it affects subsequent indentation. I'm trying to understand
the c-mode.el code, but I have so far not been able to make any real sense
of it. Please send e-mail if possible - I'm sure that few others are
interested in how to set up my personal indent style.

flame_level = Mild;
I was told that Emacs was worth it because it was so customizable, etc.
Yet one of the things that is most important to me is apparently only 
doable by spending weeks (or months) becoming an Emacs-wizard. The people I
asked about this locally all said "You just have to accept whatever style
Emacs gives you". Now that's user friendly. If anyone can solve this for me,
I'll speak more kindly of Emacs in the future.
flame_level = Off;

P.S. Is there a way to get Lisp-Mode to have the indentation calculated as
n*<number of open parens>, where n is some settable value? 

Some example code -

static int yowza;
struct fred doug[] =
    {
	{ 1 , 43 , "loser" },	/* it would be ok if these closing braces */
	{ 2 ,  2 , "winner" },	/* had to be on seperate lines, e.g. */
	{ 3 , 22 , "neutral"	/* like this */
	},
	{
	4 , 19 , "zam!"		/* or this */
	}
    }

main(argc,argv)
	int argc;
	char **argv;
    {
    int i;

    for ( i=0 ; i < 10 ; ++i )
	{
	x = x + 1;
	yowza = *p - 3
	    + 35
	    - i;
	}
    
    switch (i)
	{
	case 4 :
	    x = x + 1;
	    break;
	case 9 :
	    break;
	}

    if (i < 3)
	i += 1;
    else
	{
	yowza -= 2;
	q++;
	}
    strcat(strcat(strcpy(fname,"base"),
	"symphony"),
	"otherstuff"
	);

    }


;
(defun move-page (dir &optional count) "Move pages, default 1"	; nest 0
  (if (not count) (setq count 1))    ; default is 1		; nest 1
  (setq count							; nest 1
    (*								; nest 2
      count							; nest 3
      (- (window-height) 2)					; nest 3
    ) 								; nest 2
  )								; nest 1
  (if (> dir 0)							; nest 1
    (next-line count)						; nest 2
    (previous-line count)					; nest 2
  )								; nest 1
)								; nest 0

Alan M. Carroll                "And there you are
carroll@s.cs.uiuc.edu           Saying 'We have the Moon, so now the Stars...'"
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll