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