aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Stjernholm2002-06-08 23:38:42 +0000
committerMartin Stjernholm2002-06-08 23:38:42 +0000
commit6635cf6e499d8f72ce0436e2912374a28ddba3bd (patch)
tree458806b8c7738064952b71bfc4cc1ce0c25b647e
parent256ab4cf12e1e6517699f29c6bb9e7794dd25a3c (diff)
downloademacs-6635cf6e499d8f72ce0436e2912374a28ddba3bd.tar.gz
emacs-6635cf6e499d8f72ce0436e2912374a28ddba3bd.zip
(c-set-style, c-set-style-1): Added another state for the
`dont-override' flag where it only keeps globally set variables.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/cc-styles.el65
2 files changed, 45 insertions, 26 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bf71a2315a3..a4db10b8920 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12002-06-09 Martin Stjernholm <bug-cc-mode@gnu.org>
2
3 * progmodes/cc-style.el (c-set-style, c-set-style-1): Added
4 another state for the `dont-override' flag where it only keeps
5 globally set variables.
6
12002-06-08 Colin Walters <walters@gnu.org> 72002-06-08 Colin Walters <walters@gnu.org>
2 8
3 * descr-text.el (describe-text-properties): Sort the output by the 9 * descr-text.el (describe-text-properties): Sort the output by the
diff --git a/lisp/progmodes/cc-styles.el b/lisp/progmodes/cc-styles.el
index 524a5373152..8cf7b35b96b 100644
--- a/lisp/progmodes/cc-styles.el
+++ b/lisp/progmodes/cc-styles.el
@@ -247,31 +247,36 @@ the existing style.")
247 (cond 247 (cond
248 ;; first special variable 248 ;; first special variable
249 ((eq attr 'c-offsets-alist) 249 ((eq attr 'c-offsets-alist)
250 (mapcar 250 (let ((offsets (cond ((eq dont-override t)
251 (function 251 c-offsets-alist)
252 (lambda (langentry) 252 (dont-override
253 (let ((langelem (car langentry)) 253 (default-value 'c-offsets-alist)))))
254 (offset (cdr langentry))) 254 (mapcar (lambda (langentry)
255 (unless (and dont-override 255 (let ((langelem (car langentry))
256 (assq langelem c-offsets-alist)) 256 (offset (cdr langentry)))
257 (c-set-offset langelem offset)) 257 (unless (assq langelem offsets)
258 ))) 258 (c-set-offset langelem offset))))
259 (if dont-override (reverse val) val))) 259 val)))
260 ;; second special variable 260 ;; second special variable
261 ((eq attr 'c-special-indent-hook) 261 ((eq attr 'c-special-indent-hook)
262 (let ((add-func (if dont-override 262 ;; Maybe we should ignore dont-override here and always add new
263 (lambda (func) 263 ;; hooks?
264 (unless (memq func c-special-indent-hook) 264 (unless (cond ((eq dont-override t)
265 (add-hook 'c-special-indent-hook func t))) 265 c-special-indent-hook)
266 (lambda (func) 266 (dont-override
267 (add-hook 'c-special-indent-hook func))))) 267 (default-value 'c-special-indent-hook)))
268 (if (listp val) 268 (if (listp val)
269 (mapcar add-func (if dont-override (reverse val) val)) 269 (mapcar (lambda (func)
270 (funcall add-func val)))) 270 (add-hook 'c-special-indent-hook func t t))
271 val)
272 (add-hook 'c-special-indent-hook val t t))))
271 ;; all other variables 273 ;; all other variables
272 (t (when (or (not dont-override) 274 (t (when (or (not dont-override)
273 (not (memq attr c-style-variables)) 275 (not (memq attr c-style-variables))
274 (eq (symbol-value attr) 'set-from-style)) 276 (eq (if (eq dont-override t)
277 (symbol-value attr)
278 (default-value attr))
279 'set-from-style))
275 (set attr val) 280 (set attr val)
276 ;; Must update a number of other variables if 281 ;; Must update a number of other variables if
277 ;; c-comment-prefix-regexp is set. 282 ;; c-comment-prefix-regexp is set.
@@ -309,15 +314,23 @@ for details of setting up styles.
309The variable `c-indentation-style' always contains the buffer's current 314The variable `c-indentation-style' always contains the buffer's current
310style name. 315style name.
311 316
312If the optional argument DONT-OVERRIDE is non-nil, no style variables 317If the optional argument DONT-OVERRIDE is t, no style variables that
313that already have values will be overridden. I.e. in the case of 318already have values will be overridden. I.e. in the case of
314`c-offsets-alist', syntactic symbols will only be added, and in the 319`c-offsets-alist', syntactic symbols will only be added, and in the
315case of all other style variables, only those set to `set-from-style' 320case of all other style variables, only those set to `set-from-style'
316will be reassigned. 321will be reassigned.
317 322
318Obviously, specifying DONT-OVERRIDE is useful mainly when the initial 323If DONT-OVERRIDE is neither nil nor t, only those style variables that
319style is chosen for a CC Mode buffer by a major mode. Since this is 324have default (i.e. non-buffer local) values will keep their settings
320done internally by CC Mode, there's hardly ever a reason to use it." 325while the rest will be overridden. This is useful to avoid overriding
326global settings done in ~/.emacs when setting a style from a mode hook
327\(providing the style variables are buffer local, which is the
328default).
329
330Obviously, setting DONT-OVERRIDE to t is useful mainly when the
331initial style is chosen for a CC Mode buffer by a major mode. Since
332that is done internally by CC Mode, it typically won't have any effect
333when used elsewhere."
321 (interactive 334 (interactive
322 (list (let ((completion-ignore-case t) 335 (list (let ((completion-ignore-case t)
323 (prompt (format "Which %s indentation style? " 336 (prompt (format "Which %s indentation style? "
@@ -348,8 +361,8 @@ done internally by CC Mode, there's hardly ever a reason to use it."
348 (mapcar (lambda (elem) 361 (mapcar (lambda (elem)
349 (c-set-style-1 elem dont-override)) 362 (c-set-style-1 elem dont-override))
350 ;; Need to go through the variables backwards when we 363 ;; Need to go through the variables backwards when we
351 ;; don't override. 364 ;; don't override any settings.
352 (if dont-override (nreverse vars) vars))) 365 (if (eq dont-override t) (nreverse vars) vars)))
353 (setq c-indentation-style stylename) 366 (setq c-indentation-style stylename)
354 (c-keep-region-active)) 367 (c-keep-region-active))
355 368