[net.emacs] Super C mode for emacs

ray@othervax.UUCP (08/28/84)

----

I have available a super-C mode for use in Emacs (Gosling/Unipress flavour).

The mode (known as C+ - hate those long mode names) gives totally automatic
selective format generation both when typing new code and editing existing -
AS THE TEXT IS TYPED/EDITED.

The main features are in the handling of indentation - both when creating an
indent on a new line and getting the cursor to the correct indent position on
an existing line, the indent is computed and generated automatically;
automatic insertion of (indented) new-lines and spaces where required as key
characters are typed (e.g. ";", "," etc);  automatic comment-mode which
handles line overflows and prefix stringing;  automatic closing of all open
paren levels;  etc etc.

All the features are user parameterizable (including the ability to inhibit)
and an example of the parameter file is given below as a summary of what the
program does (with the parameters set to approximate what the indent program
does - yug!).

In addition, a re-format function is provided which will take an existing file
and re-format it according to the given parameters (a la indent, but much more
controllable).

The mode has been in use at this site by several people for several months and
is now apparently bug free.  It has been found to be a VERY significant time
saver.

If I receive enough requests, I will post the mlisp sources to the net (> 1000
lines of mlisp)

Work is also currently being done (on an as-time-permits basis) to enhance the
emacs syntax routines to correctly handle parens and un-matched quotes inside
comments (including '\\'!!!) to enable backward-paren etc to work correctly.
This I can also make available for those of you with emacs source.

Ray Dunn.        mail:  ...allegra!ihnp4!philabs!micomvax!othervax!ray




; Formatting parameters for C+ mode and beautify-c.
;
; Any or all of these may be personally defined in the file
;	~/maclib/c-layout.ml
; which will be automatically loaded whenever c-plus mode is entered.

(setq c-unit-indent		4) 	;# of spaces for each indent (tabs are
 					; substituted where possible)

(setq indent-on-bracket	        1)	;# of spaces to indent on new lines
 					; within an open '(' bracket.
 					;normally = 1 so next line will indent
 					; to first character of bracketted
 					; expression, e.g.
 					; 	nextthing (first parameter,
					;       	   second parameter);
 					;if given any negative value then such
 					; lines will indent as a normal indent
 					; using c-unit-indent
 					; e.g. if c-unit-indent = 4 then
 					;	nextthing (first parameter,
					;	    second parameter);

(setq newline-before-{ 		0)	;= 1  an indented newline is inserted
 					;     before each '{' typed
 					;= 0  "spaces-before-{" spaces are
 					;     inserted before each '{'
(setq newline-after-{ 		1)	;= 1  an indented newline is inserted
 					;     after each '{'
 					;= 0  "spaces-after-{" spaces are
 					;     inserted after each '{'

(setq spaces-before-{           1)	;# of spaces to insert before '{'
 					;if newline-before-{ = 1 then
 					; indent will look like e.g.
 					;	if (........)
 					;        {  a = 5;
 					;if newline-before-{ = 0 and '{' is
 					; the first significant character on
 					; the line, no spaces are inserted
(setq spaces-after-{            1)	;# of spaces to insert after '{'
 					; only relevant if newline-before-{ &
 					; newline-after-{ are both zero

(setq newline-before-} 		1)	;= 1  an indented newline is inserted
 					;     before each '}' unless the
 					;     matching '{' is on the same line
 					;     in which case "spaces-before-}"
 					;     spaces are inserted before '}'
 					;= 0  "spaces-before-}" spaces are
 					;     inserted before each '}'
(setq newline-after-} 		1)	;= 1  an indented newline is inserted
 					;     after each '}'
 					;= 0  "spaces-after-}" spaces are
 					;     inserted after each '}'
(setq spaces-before-}           1)	;# of spaces to insert before '}'
 					;if newline-before-} = 1 only inserted
 					; if the matching '{' is on the same
 					; line
(setq spaces-after-}            1)	;# of spaces to insert after '}'
 					; not relevant if newline-after-} = 1

(setq spaces-before-bracket	1)	;# of spaces to insert before each '('
 					; typed (unless the '(' is the first
					; significant character on the line or
					; is preceded by a '(' space or tab
					;even if zero, will ensure at least one
					; space is inserted after "if", "for",
					; "while" and "switch"

(setq spaces-after-comma	1)	;# of spaces to insert after each ','
 					; typed

(setq label-protrusion 	       -2)	;number of spaces to indent labels from
 					; current indent position. Normally
 					; negative so labels protrude left.
 					;if large negative number then labels
 					; will be justified hard left on line
(setq case-protrusion	       -2) 	;same as preceding for 'case....:'
 					; lines
 					;Note: The label or case is recognized
  					; and the "protrusion" executed when
 					; the ":" is typed

(setq newline-after-label	1)	;= 1  an indented newline is inserted
 					;     when the ':' following a label
 					;     or case is typed.
 					;Warning: if statements are typed on
 					; the same line as a label, the indent-
 					; ing procedure may not work properly
 					; To be recognised as such only spaces
 					; or tabs can precede a label or case,
 					; and no space must appear between the
 					; label and the colon

(setq newline-after-semicolon	1)	;= 1  an indented newline is inserted
 					;     after each semi-colon is typed
 					;     unless within an open '(' on the
 					;     same line

(setq comment-column	        0)	;column position to automatically start
 					; comments when '/*' typed
 					;if = 0 or '/*' typed at start of line,
 					; or at a position greater than
 					; comment-column, then the comment
 					; starts at the current cursor
 					; position

(setq comment-start-string  "/* ")	;comment start string
 					; - must include "/*" but could have a
 					;   trailing space for example
(setq comment-prefix-string  " * ")	;the string which prefixes subsequent
 					;   lines of a comment
 					; - would normally be the same length
 					;   as the comment-start-string to
 					;   ensure lines line up
(setq comment-end-string     " */")	;comment end string
 					; - must include "*/" but could have a
 					;   leading space for example
(setq newline-after-comment     1)	;= 1  an indented newline is inserted
 					;     after the "*/"

(setq indent-options "-l80 -i4 -ndj -d1 -bl")
 					;parameters for ESC-J formatter

dixon@ihuxl.UUCP (D. A. Dixon) (09/04/84)

Please post to the net your Super-C mode for emacs. Thank you.

D A Dixon
ihnp4!ihuxl!dixon