1;; -*- lisp-interaction -*-
2;; -*- emacs-lisp -*-
3;;
4;; Set emacs up for editing code using CVS indentation conventions.
5;; See HACKING for more on what those conventions are.
6;; To use, put in your .emacs:
7;;   (load "c-mode")
8;;   (load "cvs-format.el")
9;; You need to load c-mode first or else when c-mode autoloads it will
10;; clobber the settings from cvs-format.el.  Using c-mode-hook perhaps would
11;; be a cleaner way to handle that.  Or see below about (set-c-style "BSD").
12;;
13;; Credits: Originally from the personal .emacs file of Rich Pixley,
14;;      then rich@cygnus.com, circa 1992.  He sez "feel free to copy."
15;;
16;; If you have an Emacs that does not have "c-mode", but does have
17;; "cc-mode" then put this into your .emacs:
18;;   (require 'cc-mode)
19;;   (load "cvs-format.el")
20;;   (add-hook 'c-mode-hook '(lambda () (c-set-style "cvshome")))
21;;
22;; Credit: From the personal .emacs file of Mark D. Baushke
23;  circa 2005. Feel free to do anything you want with it.
24
25;;
26;;
27;;	This section sets constants used by c-mode for formating
28;;
29;;
30
31;;  If `c-auto-newline' is non-`nil', newlines are inserted both
32;;before and after braces that you insert, and after colons and semicolons.
33;;Correct C indentation is done on all the lines that are made this way.
34
35(if (boundp 'c-auto-newline)
36    (setq c-auto-newline nil))
37
38
39;;*Non-nil means TAB in C mode should always reindent the current line,
40;;regardless of where in the line point is when the TAB command is used.
41;;It might be desirable to set this to nil for CVS, since unlike GNU
42;; CVS often uses comments over to the right separated by TABs.
43;; Depends some on whether you're in the habit of using TAB to
44;; reindent.
45;(setq c-tab-always-indent nil)
46
47;;; It seems to me that
48;;;    `M-x set-c-style BSD RET'
49;;; or
50;;;    (set-c-style "BSD")
51;;; takes care of the indentation parameters correctly.
52
53
54;;  C does not have anything analogous to particular function names for which
55;;special forms of indentation are desirable.  However, it has a different
56;;need for customization facilities: many different styles of C indentation
57;;are in common use.
58;;
59;;  There are six variables you can set to control the style that Emacs C
60;;mode will use.
61;;
62;;`c-indent-level'
63;;     Indentation of C statements within surrounding block.  The surrounding
64;;     block's indentation is the indentation of the line on which the
65;;     open-brace appears.
66
67(if (boundp 'c-indent-level)
68    (setq c-indent-level 4))
69
70;;`c-continued-statement-offset'
71;;     Extra indentation given to a substatement, such as the then-clause of
72;;     an if or body of a while.
73
74(if (boundp 'c-continued-statement-offset)
75    (setq c-continued-statement-offset 4))
76
77;;`c-brace-offset'
78;;     Extra indentation for line if it starts with an open brace.
79
80(if (boundp 'c-brace-offset)
81    (setq c-brace-offset -4))
82
83;;`c-brace-imaginary-offset'
84;;     An open brace following other text is treated as if it were this far
85;;     to the right of the start of its line.
86
87(if (boundp 'c-brace-imaginary-offset)
88    (setq c-brace-imaginary-offset 0))
89
90;;`c-argdecl-indent'
91;;     Indentation level of declarations of C function arguments.
92
93(if (boundp 'c-argdecl-indent)
94    (setq c-argdecl-indent 4))
95
96;;`c-label-offset'
97;;     Extra indentation for line that is a label, or case or default.
98;;  This doesn't quite do the right thing for CVS switches, which use the
99;;    switch (foo)
100;;    {
101;;        case 0:
102;;            break;
103;;  style.  But if one manually aligns the first case, then the rest
104;;  should work OK.
105(if (boundp 'c-label-offset)
106    (setq c-label-offset -2))
107
108;;
109;;
110;;	This section sets constants used by cc-mode for formating
111;;
112;;
113
114;; Folks that are using cc-mode in the more modern version of Emacs
115;; will likely find this useful
116
117(if (and (fboundp 'featurep)
118	 (featurep 'cc-styles)
119	 (fboundp 'c-add-style))
120    (c-add-style "cvshome"
121		 '((c-brace-offset . -4)
122		   (c-basic-offset . 4)
123		   (c-continued-statement-offset . (4 . 4))
124		   (c-offsets-alist
125		    . ((statement-block-intro . +)
126		       (knr-argdecl-intro . 4)
127		       (substatement-open . 0)
128		       (label . 2)
129		       (case-label . 2)
130		       (statement-case-open . +)
131		       (statement-cont . +)
132		       (arglist-intro . c-lineup-arglist-intro-after-paren)
133		       (arglist-close . c-lineup-arglist)
134		       (inline-open . 0)
135		       (brace-list-open . 0)))
136		   (c-special-indent-hook . c-gnu-impose-minimum)
137		   (c-block-comment-prefix . ""))))
138
139;; You may now use the following when you wish to make use of the style:
140;;     `M-x c-set-style RET cvshome RET'
141;; or
142;;     (c-set-style "cvshome")
143;; to take care of things.
144
145;;;; eof
146