annotate lisp/modes/c-style.el @ 104:cf808b4c4290 r20-1b4

Import from CVS: tag r20-1b4
author cvs
date Mon, 13 Aug 2007 09:16:51 +0200
parents b82b59fe008d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; c-style.el --- sets c-style control variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
17 ;; along with XEmacs; see the file COPYING. If not, write to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
18 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
19 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; c-style|Daniel LaLiberte|liberte@cs.uiuc.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; |sets c-style control variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; |Thu Feb 27 13:42:57 CST 1992|Version: 2.1|~/as-is/c-src-doc.el.Z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; There are several ways to call set-c-style described below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; None of these methods reindent your program - they only affect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; new indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; - Just call set-c-style in your c-mode-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Without style argument, default-c-style will be used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; With style argument, this will set the style for every
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; c-mode buffer the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; - Call set-c-style from the Local Variables list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; e.g. "eval:(set-c-style 'C++)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; - Call set-c-style interactively. It prompts for the style name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; with completion using default-c-style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; For convenience, put one of the following in your .emacs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; (autoload 'set-c-style "c-style" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; or (load "c-style")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; =====================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defvar default-c-style 'GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "*The default value of c-style. Set this in your .emacs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; The following predefined styles are all I know about.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; If you learn of another style that has a "big" following, please
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; send me the parameters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defvar c-style-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 '((GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (c-indent-level 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (c-continued-statement-offset 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (c-argdecl-indent 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (c-label-offset -2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (c-indent-level 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (c-continued-statement-offset 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (c-brace-offset -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (c-argdecl-indent 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (c-label-offset -8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (K&R
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (c-indent-level 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (c-continued-statement-offset 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (c-brace-offset -5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (c-argdecl-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (c-label-offset -5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (BS ; was C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (c-indent-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (c-brace-offset -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (c-argdecl-indent 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (c-label-offset -4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; From Lynn Slater
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (LRS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (c-indent-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (c-argdecl-indent 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (c-auto-newline nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (Plauger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (c-indent-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (c-continued-statement-offset 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (c-continued-brace-offset -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (c-brace-offset 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (c-brace-imaginary-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (c-argdecl-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (c-label-offset -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (c-auto-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (c-tab-always-indent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; From Jozsef A Toth <jtoth+@pitt.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; Is this really the Whitesmith style?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (Alman
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (c-argdecl-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (c-brace-imaginary-offset 2) ;;; ????
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (c-continued-statement-offset 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (c-indent-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (c-auto-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (comment-column 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (tab-width 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (fill-column '79))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (Gould
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (c-indent-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (c-brace-offset -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (c-argdecl-indent 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (c-brace-imaginary-offset 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; From Joan Eslinger <wombat@kilimanjaro.key.amdahl.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (WRS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (c-indent-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (c-continued-statement-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (c-brace-offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (c-argdecl-indent 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (c-label-offset -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (c-brace-imaginary-offset 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (c-continued-brace-offset -4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defvar c-style nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "The buffer local c-mode indentation style.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; Add style name to mode line. Assumes minor-mode-alist is not buffer local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; Thanks to Joan Eslinger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defvar c-style-name nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "The style name for a c-mode indentation style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 This is to be set by set-c-style, and used by the mode line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (or (assq 'c-style-name minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (append minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; use undocumented feature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 '((c-style-name c-style-name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defun set-c-style (&optional style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "Set up the c-mode style variables from STYLE if it is given, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 default-c-style otherwise. It makes the c indentation style variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 buffer local."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (let ((c-styles (mapcar 'car c-style-alist))) ; for completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (let ((style-string ; Get style name with completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (format "Set c-mode indentation style to (default %s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 default-c-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (vconcat c-styles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (function (lambda (arg) (memq arg c-styles)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if (string-equal "" style-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 default-c-style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (intern style-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; If style is nil, use default-c-style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (setq style (or style default-c-style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (make-local-variable 'c-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if (memq style c-styles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (setq c-style style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (error "Undefined c style: %s" style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (message "c-style: %s" c-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; Set the c-style-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (make-local-variable 'c-style-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (setq c-style-name (format " %s" c-style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; Finally, set the indentation style variables making each one local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (mapcar (function (lambda (c-style-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (make-local-variable (car c-style-pair))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (set (car c-style-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (car (cdr c-style-pair)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (cdr (assq c-style c-style-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 c-style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ))