Mercurial > emacs
changeset 45703:b022aba47c59
(c-set-style, c-set-style-1): Added another state for the
`dont-override' flag where it only keeps globally set variables.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Sat, 08 Jun 2002 23:37:37 +0000 |
parents | 411b3bf9d4db |
children | deb27e3d41fd |
files | lisp/progmodes/cc-styles.el |
diffstat | 1 files changed, 39 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/progmodes/cc-styles.el Sat Jun 08 22:52:46 2002 +0000 +++ b/lisp/progmodes/cc-styles.el Sat Jun 08 23:37:37 2002 +0000 @@ -247,31 +247,36 @@ (cond ;; first special variable ((eq attr 'c-offsets-alist) - (mapcar - (function - (lambda (langentry) - (let ((langelem (car langentry)) - (offset (cdr langentry))) - (unless (and dont-override - (assq langelem c-offsets-alist)) - (c-set-offset langelem offset)) - ))) - (if dont-override (reverse val) val))) + (let ((offsets (cond ((eq dont-override t) + c-offsets-alist) + (dont-override + (default-value 'c-offsets-alist))))) + (mapcar (lambda (langentry) + (let ((langelem (car langentry)) + (offset (cdr langentry))) + (unless (assq langelem offsets) + (c-set-offset langelem offset)))) + val))) ;; second special variable ((eq attr 'c-special-indent-hook) - (let ((add-func (if dont-override - (lambda (func) - (unless (memq func c-special-indent-hook) - (add-hook 'c-special-indent-hook func t))) - (lambda (func) - (add-hook 'c-special-indent-hook func))))) + ;; Maybe we should ignore dont-override here and always add new + ;; hooks? + (unless (cond ((eq dont-override t) + c-special-indent-hook) + (dont-override + (default-value 'c-special-indent-hook))) (if (listp val) - (mapcar add-func (if dont-override (reverse val) val)) - (funcall add-func val)))) + (mapcar (lambda (func) + (add-hook 'c-special-indent-hook func t t)) + val) + (add-hook 'c-special-indent-hook val t t)))) ;; all other variables (t (when (or (not dont-override) (not (memq attr c-style-variables)) - (eq (symbol-value attr) 'set-from-style)) + (eq (if (eq dont-override t) + (symbol-value attr) + (default-value attr)) + 'set-from-style)) (set attr val) ;; Must update a number of other variables if ;; c-comment-prefix-regexp is set. @@ -309,15 +314,23 @@ The variable `c-indentation-style' always contains the buffer's current style name. -If the optional argument DONT-OVERRIDE is non-nil, no style variables -that already have values will be overridden. I.e. in the case of +If the optional argument DONT-OVERRIDE is t, no style variables that +already have values will be overridden. I.e. in the case of `c-offsets-alist', syntactic symbols will only be added, and in the case of all other style variables, only those set to `set-from-style' will be reassigned. -Obviously, specifying DONT-OVERRIDE is useful mainly when the initial -style is chosen for a CC Mode buffer by a major mode. Since this is -done internally by CC Mode, there's hardly ever a reason to use it." +If DONT-OVERRIDE is neither nil nor t, only those style variables that +have default (i.e. non-buffer local) values will keep their settings +while the rest will be overridden. This is useful to avoid overriding +global settings done in ~/.emacs when setting a style from a mode hook +\(providing the style variables are buffer local, which is the +default). + +Obviously, setting DONT-OVERRIDE to t is useful mainly when the +initial style is chosen for a CC Mode buffer by a major mode. Since +that is done internally by CC Mode, it typically won't have any effect +when used elsewhere." (interactive (list (let ((completion-ignore-case t) (prompt (format "Which %s indentation style? " @@ -348,8 +361,8 @@ (mapcar (lambda (elem) (c-set-style-1 elem dont-override)) ;; Need to go through the variables backwards when we - ;; don't override. - (if dont-override (nreverse vars) vars))) + ;; don't override any settings. + (if (eq dont-override t) (nreverse vars) vars))) (setq c-indentation-style stylename) (c-keep-region-active))