Mercurial > emacs
comparison lisp/progmodes/cc-styles.el @ 83407:37d0562504bf
Merged in changes from CVS trunk.
Patches applied:
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-664
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-665
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-666
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-447
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Sat, 10 Dec 2005 21:18:28 +0000 |
parents | 04d2abb755d9 |
children | dc49655f57ae 7beb78bc1f8e |
comparison
equal
deleted
inserted
replaced
83406:8e25aa911e3e | 83407:37d0562504bf |
---|---|
1 ;;; cc-styles.el --- support for styles in CC Mode | 1 ;;; cc-styles.el --- support for styles in CC Mode |
2 | 2 |
3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, |
4 ;; Inc. | |
4 | 5 |
5 ;; Authors: 1998- Martin Stjernholm | 6 ;; Authors: 1998- Martin Stjernholm |
6 ;; 1992-1999 Barry A. Warsaw | 7 ;; 1992-1999 Barry A. Warsaw |
7 ;; 1987 Dave Detlefs and Stewart Clamen | 8 ;; 1987 Dave Detlefs and Stewart Clamen |
8 ;; 1985 Richard M. Stallman | 9 ;; 1985 Richard M. Stallman |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 ;; GNU General Public License for more details. | 25 ;; GNU General Public License for more details. |
25 | 26 |
26 ;; You should have received a copy of the GNU General Public License | 27 ;; You should have received a copy of the GNU General Public License |
27 ;; along with GNU Emacs; see the file COPYING. If not, write to | 28 ;; along with this program; see the file COPYING. If not, write to |
28 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 29 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
29 ;; Boston, MA 02110-1301, USA. | 30 ;; Boston, MA 02110-1301, USA. |
30 | 31 |
31 ;;; Commentary: | 32 ;;; Commentary: |
32 | 33 |
53 | 54 |
54 (defvar c-style-alist | 55 (defvar c-style-alist |
55 '(("gnu" | 56 '(("gnu" |
56 (c-basic-offset . 2) | 57 (c-basic-offset . 2) |
57 (c-comment-only-line-offset . (0 . 0)) | 58 (c-comment-only-line-offset . (0 . 0)) |
59 (c-hanging-braces-alist . ((substatement-open before after))) | |
58 (c-offsets-alist . ((statement-block-intro . +) | 60 (c-offsets-alist . ((statement-block-intro . +) |
59 (knr-argdecl-intro . 5) | 61 (knr-argdecl-intro . 5) |
60 (substatement-open . +) | 62 (substatement-open . +) |
61 (substatement-label . 0) | 63 (substatement-label . 0) |
62 (label . 0) | 64 (label . 0) |
63 (statement-case-open . +) | 65 (statement-case-open . +) |
64 (statement-cont . +) | 66 (statement-cont . +) |
65 (arglist-intro . c-lineup-arglist-intro-after-paren) | 67 (arglist-intro . c-lineup-arglist-intro-after-paren) |
66 (arglist-close . c-lineup-arglist) | 68 (arglist-close . c-lineup-arglist) |
67 (inline-open . 0) | 69 (inline-open . 0) |
68 (brace-list-open . +) | 70 (brace-list-open . +))) |
69 )) | |
70 (c-special-indent-hook . c-gnu-impose-minimum) | 71 (c-special-indent-hook . c-gnu-impose-minimum) |
71 (c-block-comment-prefix . "") | 72 (c-block-comment-prefix . "")) |
72 ) | 73 |
73 ("k&r" | 74 ("k&r" |
74 (c-basic-offset . 5) | 75 (c-basic-offset . 5) |
75 (c-comment-only-line-offset . 0) | 76 (c-comment-only-line-offset . 0) |
76 (c-offsets-alist . ((statement-block-intro . +) | 77 (c-offsets-alist . ((statement-block-intro . +) |
77 (knr-argdecl-intro . 0) | 78 (knr-argdecl-intro . 0) |
78 (substatement-open . 0) | 79 (substatement-open . 0) |
79 (substatement-label . 0) | 80 (substatement-label . 0) |
80 (label . 0) | 81 (label . 0) |
81 (statement-cont . +) | 82 (statement-cont . +)))) |
82 )) | 83 |
83 ) | |
84 ("bsd" | 84 ("bsd" |
85 (c-basic-offset . 8) | 85 (c-basic-offset . 8) |
86 (c-comment-only-line-offset . 0) | 86 (c-comment-only-line-offset . 0) |
87 (c-offsets-alist . ((statement-block-intro . +) | 87 (c-offsets-alist . ((statement-block-intro . +) |
88 (knr-argdecl-intro . +) | 88 (knr-argdecl-intro . +) |
89 (substatement-open . 0) | 89 (substatement-open . 0) |
90 (substatement-label . 0) | 90 (substatement-label . 0) |
91 (label . 0) | 91 (label . 0) |
92 (statement-cont . +) | 92 (statement-cont . +) |
93 (inline-open . 0) | 93 (inline-open . 0) |
94 (inexpr-class . 0) | 94 (inexpr-class . 0)))) |
95 )) | 95 |
96 ) | |
97 ("stroustrup" | 96 ("stroustrup" |
98 (c-basic-offset . 4) | 97 (c-basic-offset . 4) |
99 (c-comment-only-line-offset . 0) | 98 (c-comment-only-line-offset . 0) |
100 (c-offsets-alist . ((statement-block-intro . +) | 99 (c-offsets-alist . ((statement-block-intro . +) |
101 (substatement-open . 0) | 100 (substatement-open . 0) |
102 (substatement-label . 0) | 101 (substatement-label . 0) |
103 (label . 0) | 102 (label . 0) |
104 (statement-cont . +) | 103 (statement-cont . +)))) |
105 )) | 104 |
106 ) | |
107 ("whitesmith" | 105 ("whitesmith" |
108 (c-basic-offset . 4) | 106 (c-basic-offset . 4) |
109 (c-comment-only-line-offset . 0) | 107 (c-comment-only-line-offset . 0) |
110 (c-offsets-alist . ((knr-argdecl-intro . +) | 108 ;; It's obvious that the CC Mode way of choosing anchor positions |
111 (label . 0) | 109 ;; doesn't fit this style at all. :P |
112 (statement-cont . +) | 110 (c-offsets-alist . ((defun-open . +) |
111 (defun-close . c-lineup-whitesmith-in-block) | |
112 (defun-block-intro . (add c-lineup-whitesmith-in-block | |
113 c-indent-multi-line-block)) | |
114 (class-open . +) | |
115 (class-close . +) | |
116 (inline-open . +) | |
117 (inline-close . c-lineup-whitesmith-in-block) | |
118 (knr-argdecl-intro . +) | |
119 (block-open . 0) ; Get indentation from `statement' instead. | |
120 (block-close . c-lineup-whitesmith-in-block) | |
121 (brace-list-open . +) | |
122 (brace-list-close . c-lineup-whitesmith-in-block) | |
123 (brace-list-intro . (add c-lineup-whitesmith-in-block | |
124 c-indent-multi-line-block)) | |
125 (brace-list-entry . (add c-lineup-after-whitesmith-blocks | |
126 c-indent-multi-line-block)) | |
127 (brace-entry-open . (add c-lineup-after-whitesmith-blocks | |
128 c-indent-multi-line-block)) | |
129 (statement . (add c-lineup-after-whitesmith-blocks | |
130 c-indent-multi-line-block)) | |
131 (statement-block-intro . (add c-lineup-whitesmith-in-block | |
132 c-indent-multi-line-block)) | |
113 (substatement-open . +) | 133 (substatement-open . +) |
114 (substatement-label . +) | 134 (substatement-label . +) |
115 (block-open . +) | 135 (label . 0) |
116 (statement-block-intro . c-lineup-whitesmith-in-block) | 136 (arglist-intro . (add c-lineup-whitesmith-in-block |
117 (block-close . c-lineup-whitesmith-in-block) | 137 c-indent-multi-line-block)) |
118 (inline-open . +) | 138 (arglist-cont . (add c-lineup-after-whitesmith-blocks |
119 (defun-open . +) | 139 c-indent-multi-line-block)) |
120 (defun-block-intro . c-lineup-whitesmith-in-block) | 140 (arglist-cont-nonempty . (add c-lineup-whitesmith-in-block |
121 (defun-close . c-lineup-whitesmith-in-block) | 141 c-indent-multi-line-block)) |
122 (brace-list-open . +) | 142 (arglist-close . c-lineup-whitesmith-in-block) |
123 (brace-list-intro . c-lineup-whitesmith-in-block) | |
124 (brace-entry-open . c-indent-multi-line-block) | |
125 (brace-list-close . c-lineup-whitesmith-in-block) | |
126 (class-open . +) | |
127 (inclass . c-lineup-whitesmith-in-block) | 143 (inclass . c-lineup-whitesmith-in-block) |
128 (class-close . +) | |
129 (inexpr-class . 0) | |
130 (extern-lang-open . +) | 144 (extern-lang-open . +) |
145 (namespace-open . +) | |
146 (module-open . +) | |
147 (composition-open . +) | |
148 (extern-lang-close . +) | |
149 (namespace-close . +) | |
150 (module-close . +) | |
151 (composition-close . +) | |
131 (inextern-lang . c-lineup-whitesmith-in-block) | 152 (inextern-lang . c-lineup-whitesmith-in-block) |
132 (extern-lang-close . +) | |
133 (namespace-open . +) | |
134 (innamespace . c-lineup-whitesmith-in-block) | 153 (innamespace . c-lineup-whitesmith-in-block) |
135 (namespace-close . +) | |
136 (module-open . +) | |
137 (inmodule . c-lineup-whitesmith-in-block) | 154 (inmodule . c-lineup-whitesmith-in-block) |
138 (module-close . +) | |
139 (composition-open . +) | |
140 (incomposition . c-lineup-whitesmith-in-block) | 155 (incomposition . c-lineup-whitesmith-in-block) |
141 (composition-close . +) | 156 (inexpr-class . 0)))) |
142 )) | 157 |
143 ) | |
144 ("ellemtel" | 158 ("ellemtel" |
145 (c-basic-offset . 3) | 159 (c-basic-offset . 3) |
146 (c-comment-only-line-offset . 0) | 160 (c-comment-only-line-offset . 0) |
147 (c-hanging-braces-alist . ((substatement-open before after))) | 161 (c-hanging-braces-alist . ((substatement-open before after))) |
148 (c-offsets-alist . ((topmost-intro . 0) | 162 (c-offsets-alist . ((topmost-intro . 0) |
149 (substatement . +) | 163 (substatement . +) |
150 (substatement-open . 0) | 164 (substatement-open . 0) |
151 (case-label . +) | 165 (case-label . +) |
152 (access-label . -) | 166 (access-label . -) |
153 (inclass . ++) | 167 (inclass . ++) |
154 (inline-open . 0) | 168 (inline-open . 0)))) |
155 )) | 169 |
156 ) | |
157 ("linux" | 170 ("linux" |
158 (c-basic-offset . 8) | 171 (c-basic-offset . 8) |
159 (c-comment-only-line-offset . 0) | 172 (c-comment-only-line-offset . 0) |
160 (c-hanging-braces-alist . ((brace-list-open) | 173 (c-hanging-braces-alist . ((brace-list-open) |
161 (brace-entry-open) | 174 (brace-entry-open) |
165 (c-offsets-alist . ((statement-block-intro . +) | 178 (c-offsets-alist . ((statement-block-intro . +) |
166 (knr-argdecl-intro . 0) | 179 (knr-argdecl-intro . 0) |
167 (substatement-open . 0) | 180 (substatement-open . 0) |
168 (substatement-label . 0) | 181 (substatement-label . 0) |
169 (label . 0) | 182 (label . 0) |
170 (statement-cont . +) | 183 (statement-cont . +)))) |
171 )) | 184 |
172 ) | |
173 ("python" | 185 ("python" |
174 (indent-tabs-mode . t) | 186 (indent-tabs-mode . t) |
175 (fill-column . 78) | 187 (fill-column . 78) |
176 (c-basic-offset . 8) | 188 (c-basic-offset . 8) |
177 (c-offsets-alist . ((substatement-open . 0) | 189 (c-offsets-alist . ((substatement-open . 0) |
178 (inextern-lang . 0) | 190 (inextern-lang . 0) |
179 (arglist-intro . +) | 191 (arglist-intro . +) |
180 (knr-argdecl-intro . +) | 192 (knr-argdecl-intro . +))) |
181 )) | |
182 (c-hanging-braces-alist . ((brace-list-open) | 193 (c-hanging-braces-alist . ((brace-list-open) |
183 (brace-list-intro) | 194 (brace-list-intro) |
184 (brace-list-close) | 195 (brace-list-close) |
185 (brace-entry-open) | 196 (brace-entry-open) |
186 (substatement-open after) | 197 (substatement-open after) |
187 (block-close . c-snug-do-while) | 198 (block-close . c-snug-do-while))) |
188 )) | 199 (c-block-comment-prefix . "")) |
189 (c-block-comment-prefix . "") | 200 |
190 ) | |
191 ("java" | 201 ("java" |
192 (c-basic-offset . 4) | 202 (c-basic-offset . 4) |
193 (c-comment-only-line-offset . (0 . 0)) | 203 (c-comment-only-line-offset . (0 . 0)) |
194 ;; the following preserves Javadoc starter lines | 204 ;; the following preserves Javadoc starter lines |
195 (c-offsets-alist . ((inline-open . 0) | 205 (c-offsets-alist . ((inline-open . 0) |
203 (statement-cont . +) | 213 (statement-cont . +) |
204 (arglist-intro . c-lineup-arglist-intro-after-paren) | 214 (arglist-intro . c-lineup-arglist-intro-after-paren) |
205 (arglist-close . c-lineup-arglist) | 215 (arglist-close . c-lineup-arglist) |
206 (access-label . 0) | 216 (access-label . 0) |
207 (inher-cont . c-lineup-java-inher) | 217 (inher-cont . c-lineup-java-inher) |
208 (func-decl-cont . c-lineup-java-throws) | 218 (func-decl-cont . c-lineup-java-throws)))) |
209 )) | 219 |
210 ) | 220 ;; awk style exists primarily for auto-newline settings. Otherwise it's |
221 ;; pretty much like k&r. | |
222 ("awk" | |
223 (c-basic-offset . 4) | |
224 (c-comment-only-line-offset . 0) | |
225 (c-hanging-braces-alist . ((defun-open after) | |
226 (defun-close . c-snug-1line-defun-close) | |
227 (substatement-open after) | |
228 (block-close . c-snug-do-while))) | |
229 (c-hanging-semi&comma-criteria . nil) | |
230 (c-cleanup-list . nil) ; You might want one-liner-defun here. | |
231 (c-offsets-alist . ((statement-block-intro . +) | |
232 (substatement-open . 0) | |
233 (statement-cont . +)))) | |
234 | |
211 ) | 235 ) |
212 "Styles of indentation. | 236 "Styles of indentation. |
213 Elements of this alist are of the form: | 237 Elements of this alist are of the form: |
214 | 238 |
215 (STYLE-STRING [BASE-STYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) | 239 (STYLE-STRING [BASE-STYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) |
244 | 268 |
245 | 269 |
246 ;; Functions that manipulate styles | 270 ;; Functions that manipulate styles |
247 (defun c-set-style-1 (conscell dont-override) | 271 (defun c-set-style-1 (conscell dont-override) |
248 ;; Set the style for one variable | 272 ;; Set the style for one variable |
249 ;; | |
250 ;; This function does not do any hidden buffer changes. | |
251 (let ((attr (car conscell)) | 273 (let ((attr (car conscell)) |
252 (val (cdr conscell))) | 274 (val (cdr conscell))) |
253 (cond | 275 (cond |
254 ;; first special variable | 276 ;; first special variable |
255 ((eq attr 'c-offsets-alist) | 277 ((eq attr 'c-offsets-alist) |
289 (if (eq attr 'c-comment-prefix-regexp) | 311 (if (eq attr 'c-comment-prefix-regexp) |
290 (c-setup-paragraph-variables))))))) | 312 (c-setup-paragraph-variables))))))) |
291 | 313 |
292 (defun c-get-style-variables (style basestyles) | 314 (defun c-get-style-variables (style basestyles) |
293 ;; Return all variables in a style by resolving inheritances. | 315 ;; Return all variables in a style by resolving inheritances. |
294 ;; | |
295 ;; This function does not do any hidden buffer changes. | |
296 (if (not style) | 316 (if (not style) |
297 (copy-alist c-fallback-style) | 317 (copy-alist c-fallback-style) |
298 (let ((vars (cdr (or (assoc (downcase style) c-style-alist) | 318 (let ((vars (cdr (or (assoc (downcase style) c-style-alist) |
299 (assoc (upcase style) c-style-alist) | 319 (assoc (upcase style) c-style-alist) |
300 (assoc style c-style-alist) | 320 (assoc style c-style-alist) |
312 | 332 |
313 (defvar c-set-style-history nil) | 333 (defvar c-set-style-history nil) |
314 | 334 |
315 ;;;###autoload | 335 ;;;###autoload |
316 (defun c-set-style (stylename &optional dont-override) | 336 (defun c-set-style (stylename &optional dont-override) |
317 "Set CC Mode variables to use one of several different indentation styles. | 337 "Set the current buffer to use the style STYLENAME. |
318 STYLENAME is a string representing the desired style from the list of | 338 STYLENAME, a string, must be an existing CC Mode style - These are contained |
319 styles described in the variable `c-style-alist'. See that variable | 339 in the variable `c-style-alist'. |
320 for details of setting up styles. | 340 |
321 | 341 The variable `c-indentation-style' will get set to STYLENAME. |
322 The variable `c-indentation-style' always contains the buffer's current | 342 |
323 style name. | 343 \"Setting the style\" is done by setting CC Mode's \"style variables\" to the |
324 | 344 values indicated by the pertinent entry in `c-style-alist'. Other variables |
325 If the optional argument DONT-OVERRIDE is t, no style variables that | 345 might get set too. |
326 already have values will be overridden. I.e. in the case of | 346 |
327 `c-offsets-alist', syntactic symbols will only be added, and in the | 347 If DONT-OVERRIDE is neither nil nor t, style variables whose default values |
328 case of all other style variables, only those set to `set-from-style' | 348 have been set (more precisely, whose default values are not the symbol |
329 will be reassigned. | 349 `set-from-style') will not be changed. This avoids overriding global settings |
330 | 350 done in ~/.emacs. It is useful to call c-set-style from a mode hook in this |
331 If DONT-OVERRIDE is neither nil nor t, only those style variables that | 351 way. |
332 have default (i.e. non-buffer local) values will keep their settings | 352 |
333 while the rest will be overridden. This is useful to avoid overriding | 353 If DONT-OVERRIDE is t, style variables that already have values (i.e., whose |
334 global settings done in ~/.emacs when setting a style from a mode hook | 354 values are not the symbol `set-from-style') will not be overridden. CC Mode |
335 \(providing the style variables are buffer local, which is the | 355 calls c-set-style internally in this way whilst initializing a buffer; if |
336 default). | 356 cc-set-style is called like this from anywhere else, it will usually behave as |
337 | 357 a null operation." |
338 Obviously, setting DONT-OVERRIDE to t is useful mainly when the | |
339 initial style is chosen for a CC Mode buffer by a major mode. Since | |
340 that is done internally by CC Mode, it typically won't have any effect | |
341 when used elsewhere." | |
342 (interactive | 358 (interactive |
343 (list (let ((completion-ignore-case t) | 359 (list (let ((completion-ignore-case t) |
344 (prompt (format "Which %s indentation style? " | 360 (prompt (format "Which %s indentation style? " |
345 mode-name))) | 361 mode-name))) |
346 (condition-case nil | 362 (completing-read prompt c-style-alist nil t nil |
347 ;; The default argument is preferred over | 363 'c-set-style-history |
348 ;; initial-contents, but it only exists in Emacs >= 20 | 364 c-indentation-style)))) |
349 ;; and XEmacs >= 21. | 365 (or c-buffer-is-cc-mode |
350 (completing-read prompt c-style-alist nil t nil | 366 (error "Buffer %s is not a CC Mode buffer (c-set-style)" (buffer-name))) |
351 'c-set-style-history | |
352 c-indentation-style) | |
353 (wrong-number-of-arguments | |
354 ;; If the call above failed, we fall back to the old way | |
355 ;; of specifying the default value. | |
356 (completing-read prompt c-style-alist nil t | |
357 (cons c-indentation-style 0) | |
358 'c-set-style-history)))))) | |
359 (or (stringp stylename) | 367 (or (stringp stylename) |
360 (error "Argument to c-set-style was not a string")) | 368 (error "Argument to c-set-style was not a string")) |
361 (c-initialize-builtin-style) | 369 (c-initialize-builtin-style) |
362 (let ((vars (c-get-style-variables stylename nil))) | 370 (let ((vars (c-get-style-variables stylename nil))) |
363 (unless dont-override | 371 (unless dont-override |
404 (defvar c-read-offset-history nil) | 412 (defvar c-read-offset-history nil) |
405 | 413 |
406 (defun c-read-offset (langelem) | 414 (defun c-read-offset (langelem) |
407 ;; read new offset value for LANGELEM from minibuffer. return a | 415 ;; read new offset value for LANGELEM from minibuffer. return a |
408 ;; legal value only | 416 ;; legal value only |
409 ;; | |
410 ;; This function does not do any hidden buffer changes. | |
411 (let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist) | 417 (let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist) |
412 (assq langelem (get 'c-offsets-alist | 418 (assq langelem (get 'c-offsets-alist |
413 'c-stylevar-fallback))))) | 419 'c-stylevar-fallback))))) |
414 (symname (symbol-name langelem)) | 420 (symname (symbol-name langelem)) |
415 (defstr (format "(default %s): " oldoff)) | 421 (defstr (format "(default %s): " oldoff)) |
473 (setcdr entry offset) | 479 (setcdr entry offset) |
474 (if (assq symbol (get 'c-offsets-alist 'c-stylevar-fallback)) | 480 (if (assq symbol (get 'c-offsets-alist 'c-stylevar-fallback)) |
475 (setq c-offsets-alist (cons (cons symbol offset) | 481 (setq c-offsets-alist (cons (cons symbol offset) |
476 c-offsets-alist)) | 482 c-offsets-alist)) |
477 (c-benign-error "%s is not a valid syntactic symbol" symbol)))) | 483 (c-benign-error "%s is not a valid syntactic symbol" symbol)))) |
478 (c-benign-error "Invalid indentation setting for symbol %s: %s" | 484 (c-benign-error "Invalid indentation setting for symbol %s: %S" |
479 symbol offset)) | 485 symbol offset)) |
480 (c-keep-region-active)) | 486 (c-keep-region-active)) |
481 | 487 |
482 | 488 |
483 (defun c-setup-paragraph-variables () | 489 (defun c-setup-paragraph-variables () |
484 "Fix things up for paragraph recognition and filling inside comments by | 490 "Fix things up for paragraph recognition and filling inside comments and |
485 incorporating the value of `c-comment-prefix-regexp' in the relevant | 491 strings by incorporating the values of `c-comment-prefix-regexp', |
492 `sentence-end', `paragraph-start' and `paragraph-separate' in the relevant | |
486 variables." | 493 variables." |
487 ;; | |
488 ;; This function does not do any hidden buffer changes. | |
489 | 494 |
490 (interactive) | 495 (interactive) |
491 | 496 (or c-buffer-is-cc-mode |
497 (error "Buffer %s is not a CC Mode buffer (c-setup-paragraph-variables)" | |
498 (buffer-name))) | |
499 ;; Set up the values for use in comments. | |
492 (setq c-current-comment-prefix | 500 (setq c-current-comment-prefix |
493 (if (listp c-comment-prefix-regexp) | 501 (if (listp c-comment-prefix-regexp) |
494 (cdr-safe (or (assoc major-mode c-comment-prefix-regexp) | 502 (cdr-safe (or (assoc major-mode c-comment-prefix-regexp) |
495 (assoc 'other c-comment-prefix-regexp))) | 503 (assoc 'other c-comment-prefix-regexp))) |
496 c-comment-prefix-regexp)) | 504 c-comment-prefix-regexp)) |
497 | 505 |
498 (let ((comment-line-prefix | 506 (let ((comment-line-prefix |
499 (concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*"))) | 507 (concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*"))) |
500 | 508 |
501 (set (make-local-variable 'paragraph-start) | 509 (setq paragraph-start (concat comment-line-prefix |
502 (concat comment-line-prefix | 510 c-paragraph-start |
503 c-paragraph-start | 511 "\\|" |
504 "\\|" | 512 page-delimiter) |
505 page-delimiter)) | 513 paragraph-separate (concat comment-line-prefix |
506 (set (make-local-variable 'paragraph-separate) | 514 c-paragraph-separate |
507 (concat comment-line-prefix | 515 "\\|" |
508 c-paragraph-separate | 516 page-delimiter) |
509 "\\|" | 517 paragraph-ignore-fill-prefix t |
510 page-delimiter)) | 518 adaptive-fill-mode t |
511 (set (make-local-variable 'paragraph-ignore-fill-prefix) t) | 519 adaptive-fill-regexp |
512 (set (make-local-variable 'adaptive-fill-mode) t) | 520 (concat comment-line-prefix |
513 (set (make-local-variable 'adaptive-fill-regexp) | 521 (if (default-value 'adaptive-fill-regexp) |
514 (concat comment-line-prefix | 522 (concat "\\(" |
515 (if (default-value 'adaptive-fill-regexp) | 523 (default-value 'adaptive-fill-regexp) |
516 (concat "\\(" | 524 "\\)") |
517 (default-value 'adaptive-fill-regexp) | 525 ""))) |
518 "\\)") | |
519 ""))) | |
520 | 526 |
521 (when (boundp 'adaptive-fill-first-line-regexp) | 527 (when (boundp 'adaptive-fill-first-line-regexp) |
522 ;; XEmacs (20.x) adaptive fill mode doesn't have this. | 528 ;; XEmacs adaptive fill mode doesn't have this. |
523 (set (make-local-variable 'adaptive-fill-first-line-regexp) | 529 (make-local-variable 'adaptive-fill-first-line-regexp) |
524 (concat "\\`" comment-line-prefix | 530 (setq adaptive-fill-first-line-regexp |
525 ;; Maybe we should incorporate the old value here, | 531 (concat "\\`" comment-line-prefix |
526 ;; but then we have to do all sorts of kludges to | 532 ;; Maybe we should incorporate the old value here, |
527 ;; deal with the \` and \' it probably contains. | 533 ;; but then we have to do all sorts of kludges to |
528 "\\'"))))) | 534 ;; deal with the \` and \' it probably contains. |
535 "\\'")))) | |
536 | |
537 ;; Set up the values for use in strings. These are the default | |
538 ;; paragraph-start/separate values, enhanced to accept escaped EOLs as | |
539 ;; whitespace. Used in c-beginning/end-of-sentence-in-string in cc-cmds. | |
540 (setq c-string-par-start | |
541 ;;(concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$")) | |
542 "\f\\|[ \t]*\\\\?$") | |
543 (setq c-string-par-separate | |
544 ;;(concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$")) | |
545 "[ \t\f]*\\\\?$") | |
546 (setq c-sentence-end-with-esc-eol | |
547 (concat "\\(\\(" (c-default-value-sentence-end) "\\)" | |
548 ;; N.B.: "$" would be illegal when not enclosed like "\\($\\)". | |
549 "\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*" | |
550 "\\)"))) | |
529 | 551 |
530 | 552 |
531 ;; Helper for setting up Filladapt mode. It's not used by CC Mode itself. | 553 ;; Helper for setting up Filladapt mode. It's not used by CC Mode itself. |
532 | 554 |
533 (cc-bytecomp-defvar filladapt-token-table) | 555 (cc-bytecomp-defvar filladapt-token-table) |
540 `filladapt-token-table', `filladapt-token-match-table', and | 562 `filladapt-token-table', `filladapt-token-match-table', and |
541 `filladapt-token-conversion-table'. This is intended to be used on | 563 `filladapt-token-conversion-table'. This is intended to be used on |
542 `c-mode-common-hook' or similar." | 564 `c-mode-common-hook' or similar." |
543 ;; This function is intended to be used explicitly by the end user | 565 ;; This function is intended to be used explicitly by the end user |
544 ;; only. | 566 ;; only. |
545 ;; | |
546 ;; This function does not do any hidden buffer changes. | |
547 | 567 |
548 ;; The default configuration already handles C++ comments, but we | 568 ;; The default configuration already handles C++ comments, but we |
549 ;; need to add handling of C block comments. A new filladapt token | 569 ;; need to add handling of C block comments. A new filladapt token |
550 ;; `c-comment' is added for that. | 570 ;; `c-comment' is added for that. |
551 (let (p) | 571 (let (p) |
571 (defun c-initialize-builtin-style () | 591 (defun c-initialize-builtin-style () |
572 ;; Dynamically append the default value of most variables. This is | 592 ;; Dynamically append the default value of most variables. This is |
573 ;; crucial because future c-set-style calls will always reset the | 593 ;; crucial because future c-set-style calls will always reset the |
574 ;; variables first to the `cc-mode' style before instituting the new | 594 ;; variables first to the `cc-mode' style before instituting the new |
575 ;; style. Only do this once! | 595 ;; style. Only do this once! |
576 ;; | |
577 ;; This function does not do any hidden buffer changes. | |
578 (unless (get 'c-initialize-builtin-style 'is-run) | 596 (unless (get 'c-initialize-builtin-style 'is-run) |
579 (put 'c-initialize-builtin-style 'is-run t) | 597 (put 'c-initialize-builtin-style 'is-run t) |
580 ;;(c-initialize-cc-mode) | 598 ;;(c-initialize-cc-mode) |
581 (unless (assoc "user" c-style-alist) | 599 (unless (assoc "user" c-style-alist) |
582 (let ((vars c-style-variables) var val uservars) | 600 (let ((vars c-style-variables) var val uservars) |
599 | 617 |
600 (defun c-make-styles-buffer-local (&optional this-buf-only-p) | 618 (defun c-make-styles-buffer-local (&optional this-buf-only-p) |
601 "Make all CC Mode style variables buffer local. | 619 "Make all CC Mode style variables buffer local. |
602 If `this-buf-only-p' is non-nil, the style variables will be made | 620 If `this-buf-only-p' is non-nil, the style variables will be made |
603 buffer local only in the current buffer. Otherwise they'll be made | 621 buffer local only in the current buffer. Otherwise they'll be made |
604 permanently buffer local in any buffer that change their values. | 622 permanently buffer local in any buffer that changes their values. |
605 | 623 |
606 The buffer localness of the style variables are normally controlled | 624 The buffer localness of the style variables are normally controlled |
607 with the variable `c-style-variables-are-local-p', so there's seldom | 625 with the variable `c-style-variables-are-local-p', so there's seldom |
608 any reason to call this function directly." | 626 any reason to call this function directly." |
609 ;; | |
610 ;; This function does not do any hidden buffer changes. | |
611 | 627 |
612 ;; style variables | 628 ;; style variables |
613 (let ((func (if this-buf-only-p | 629 (let ((func (if this-buf-only-p |
614 'make-local-variable | 630 'make-local-variable |
615 'make-variable-buffer-local)) | 631 'make-variable-buffer-local)) |
617 (delq 'c-special-indent-hook varsyms) | 633 (delq 'c-special-indent-hook varsyms) |
618 (mapcar func varsyms) | 634 (mapcar func varsyms) |
619 ;; Hooks must be handled specially | 635 ;; Hooks must be handled specially |
620 (if this-buf-only-p | 636 (if this-buf-only-p |
621 (make-local-hook 'c-special-indent-hook) | 637 (make-local-hook 'c-special-indent-hook) |
622 (make-variable-buffer-local 'c-special-indent-hook) | 638 (with-no-warnings (make-variable-buffer-local 'c-special-indent-hook)) |
623 (setq c-style-variables-are-local-p t)) | 639 (setq c-style-variables-are-local-p t)) |
624 )) | 640 )) |
625 | 641 |
626 | 642 |
627 | 643 |
628 (cc-provide 'cc-styles) | 644 (cc-provide 'cc-styles) |
629 | 645 |
630 ;; arch-tag: c764f61a-96ba-484a-a68f-101c0e9d5d2c | 646 ;;; arch-tag: c764f61a-96ba-484a-a68f-101c0e9d5d2c |
631 ;;; cc-styles.el ends here | 647 ;;; cc-styles.el ends here |