247 |
(cond |
(cond |
248 |
;; first special variable |
;; first special variable |
249 |
((eq attr 'c-offsets-alist) |
((eq attr 'c-offsets-alist) |
250 |
(mapcar |
(let ((offsets (cond ((eq dont-override t) |
251 |
(function |
c-offsets-alist) |
252 |
(lambda (langentry) |
(dont-override |
253 |
(let ((langelem (car langentry)) |
(default-value 'c-offsets-alist))))) |
254 |
(offset (cdr langentry))) |
(mapcar (lambda (langentry) |
255 |
(unless (and dont-override |
(let ((langelem (car langentry)) |
256 |
(assq langelem c-offsets-alist)) |
(offset (cdr langentry))) |
257 |
(c-set-offset langelem offset)) |
(unless (assq langelem offsets) |
258 |
))) |
(c-set-offset langelem offset)))) |
259 |
(if dont-override (reverse val) val))) |
val))) |
260 |
;; second special variable |
;; second special variable |
261 |
((eq attr 'c-special-indent-hook) |
((eq attr 'c-special-indent-hook) |
262 |
(let ((add-func (if dont-override |
;; Maybe we should ignore dont-override here and always add new |
263 |
(lambda (func) |
;; hooks? |
264 |
(unless (memq func c-special-indent-hook) |
(unless (cond ((eq dont-override t) |
265 |
(add-hook 'c-special-indent-hook func t))) |
c-special-indent-hook) |
266 |
(lambda (func) |
(dont-override |
267 |
(add-hook 'c-special-indent-hook func))))) |
(default-value 'c-special-indent-hook))) |
268 |
(if (listp val) |
(if (listp val) |
269 |
(mapcar add-func (if dont-override (reverse val) val)) |
(mapcar (lambda (func) |
270 |
(funcall add-func val)))) |
(add-hook 'c-special-indent-hook func t t)) |
271 |
|
val) |
272 |
|
(add-hook 'c-special-indent-hook val t t)))) |
273 |
;; all other variables |
;; all other variables |
274 |
(t (when (or (not dont-override) |
(t (when (or (not dont-override) |
275 |
(not (memq attr c-style-variables)) |
(not (memq attr c-style-variables)) |
276 |
(eq (symbol-value attr) 'set-from-style)) |
(eq (if (eq dont-override t) |
277 |
|
(symbol-value attr) |
278 |
|
(default-value attr)) |
279 |
|
'set-from-style)) |
280 |
(set attr val) |
(set attr val) |
281 |
;; Must update a number of other variables if |
;; Must update a number of other variables if |
282 |
;; c-comment-prefix-regexp is set. |
;; c-comment-prefix-regexp is set. |
314 |
The variable `c-indentation-style' always contains the buffer's current |
The variable `c-indentation-style' always contains the buffer's current |
315 |
style name. |
style name. |
316 |
|
|
317 |
If the optional argument DONT-OVERRIDE is non-nil, no style variables |
If the optional argument DONT-OVERRIDE is t, no style variables that |
318 |
that already have values will be overridden. I.e. in the case of |
already have values will be overridden. I.e. in the case of |
319 |
`c-offsets-alist', syntactic symbols will only be added, and in the |
`c-offsets-alist', syntactic symbols will only be added, and in the |
320 |
case of all other style variables, only those set to `set-from-style' |
case of all other style variables, only those set to `set-from-style' |
321 |
will be reassigned. |
will be reassigned. |
322 |
|
|
323 |
Obviously, specifying DONT-OVERRIDE is useful mainly when the initial |
If DONT-OVERRIDE is neither nil nor t, only those style variables that |
324 |
style is chosen for a CC Mode buffer by a major mode. Since this is |
have default (i.e. non-buffer local) values will keep their settings |
325 |
done internally by CC Mode, there's hardly ever a reason to use it." |
while the rest will be overridden. This is useful to avoid overriding |
326 |
|
global settings done in ~/.emacs when setting a style from a mode hook |
327 |
|
\(providing the style variables are buffer local, which is the |
328 |
|
default). |
329 |
|
|
330 |
|
Obviously, setting DONT-OVERRIDE to t is useful mainly when the |
331 |
|
initial style is chosen for a CC Mode buffer by a major mode. Since |
332 |
|
that is done internally by CC Mode, it typically won't have any effect |
333 |
|
when used elsewhere." |
334 |
(interactive |
(interactive |
335 |
(list (let ((completion-ignore-case t) |
(list (let ((completion-ignore-case t) |
336 |
(prompt (format "Which %s indentation style? " |
(prompt (format "Which %s indentation style? " |
361 |
(mapcar (lambda (elem) |
(mapcar (lambda (elem) |
362 |
(c-set-style-1 elem dont-override)) |
(c-set-style-1 elem dont-override)) |
363 |
;; Need to go through the variables backwards when we |
;; Need to go through the variables backwards when we |
364 |
;; don't override. |
;; don't override any settings. |
365 |
(if dont-override (nreverse vars) vars))) |
(if (eq dont-override t) (nreverse vars) vars))) |
366 |
(setq c-indentation-style stylename) |
(setq c-indentation-style stylename) |
367 |
(c-keep-region-active)) |
(c-keep-region-active)) |
368 |
|
|