diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2013-08-02 17:16:33 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2013-08-02 17:16:33 -0400 |
commit | a104f656c8217b027866d32e8d7bf024a671e3cc (patch) | |
tree | b62ddfb915099ba3398b2f0b1f9ddc0ed6203102 /lisp/custom.el | |
parent | 185e3b5a2f3dc2b5163eb1fe97499c6af1edaa9c (diff) | |
download | emacs-a104f656c8217b027866d32e8d7bf024a671e3cc.tar.gz |
Make defvar affect the default binding outside of any let.
* src/eval.c (default_toplevel_binding): New function.
(Fdefvar): Use it.
(unbind_to, backtrace_eval_unrewind): Do a bit of CSE simplification.
(Fdefault_toplevel_value, Fset_default_toplevel_value): New subrs.
(syms_of_eval): Export them.
* src/data.c (Fdefault_value): Micro cleanup.
* src/term.c (init_tty): Use "false".
* lisp/custom.el (custom-initialize-default, custom-initialize-set)
(custom-initialize-reset, custom-initialize-changed): Affect the
toplevel-default-value (bug#6275, bug#14586).
* lisp/emacs-lisp/advice.el (ad-compile-function): Undo previous workaround
for bug#6275.
* test/automated/core-elisp-tests.el: New file.
Diffstat (limited to 'lisp/custom.el')
-rw-r--r-- | lisp/custom.el | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/lisp/custom.el b/lisp/custom.el index f2d58084e9e..3db34e4d1fb 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -49,63 +49,66 @@ Users should not set it.") ;;; The `defcustom' Macro. -(defun custom-initialize-default (symbol value) - "Initialize SYMBOL with VALUE. +(defun custom-initialize-default (symbol exp) + "Initialize SYMBOL with EXP. This will do nothing if symbol already has a default binding. Otherwise, if symbol has a `saved-value' property, it will evaluate the car of that and use it as the default binding for symbol. -Otherwise, VALUE will be evaluated and used as the default binding for +Otherwise, EXP will be evaluated and used as the default binding for symbol." - (eval `(defvar ,symbol ,(if (get symbol 'saved-value) - (car (get symbol 'saved-value)) - value)))) + (eval `(defvar ,symbol ,(let ((sv (get symbol 'saved-value))) + (if sv (car sv) exp))))) -(defun custom-initialize-set (symbol value) - "Initialize SYMBOL based on VALUE. +(defun custom-initialize-set (symbol exp) + "Initialize SYMBOL based on EXP. If the symbol doesn't have a default binding already, then set it using its `:set' function (or `set-default' if it has none). The value is either the value in the symbol's `saved-value' property, -if any, or VALUE." - (unless (default-boundp symbol) - (funcall (or (get symbol 'custom-set) 'set-default) - symbol - (eval (if (get symbol 'saved-value) - (car (get symbol 'saved-value)) - value))))) - -(defun custom-initialize-reset (symbol value) - "Initialize SYMBOL based on VALUE. +if any, or the value of EXP." + (condition-case nil + (default-toplevel-value symbol) + (error + (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value) + symbol + (eval (let ((sv (get symbol 'saved-value))) + (if sv (car sv) exp))))))) + +(defun custom-initialize-reset (symbol exp) + "Initialize SYMBOL based on EXP. Set the symbol, using its `:set' function (or `set-default' if it has none). The value is either the symbol's current value (as obtained using the `:get' function), if any, or the value in the symbol's `saved-value' property if any, -or (last of all) VALUE." - (funcall (or (get symbol 'custom-set) 'set-default) +or (last of all) the value of EXP." + (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value) symbol - (cond ((default-boundp symbol) - (funcall (or (get symbol 'custom-get) 'default-value) - symbol)) - ((get symbol 'saved-value) - (eval (car (get symbol 'saved-value)))) - (t - (eval value))))) - -(defun custom-initialize-changed (symbol value) - "Initialize SYMBOL with VALUE. + (condition-case nil + (let ((def (default-toplevel-value symbol)) + (getter (get symbol 'custom-get))) + (if getter (funcall getter symbol) def)) + (error + (eval (let ((sv (get symbol 'saved-value))) + (if sv (car sv) exp))))))) + +(defun custom-initialize-changed (symbol exp) + "Initialize SYMBOL with EXP. Like `custom-initialize-reset', but only use the `:set' function if not using the standard setting. For the standard setting, use `set-default'." - (cond ((default-boundp symbol) - (funcall (or (get symbol 'custom-set) 'set-default) - symbol - (funcall (or (get symbol 'custom-get) 'default-value) - symbol))) - ((get symbol 'saved-value) - (funcall (or (get symbol 'custom-set) 'set-default) - symbol - (eval (car (get symbol 'saved-value))))) - (t - (set-default symbol (eval value))))) + (condition-case nil + (let ((def (default-toplevel-value symbol))) + (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value) + symbol + (let ((getter (get symbol 'custom-get))) + (if getter (funcall getter symbol) def)))) + (error + (cond + ((get symbol 'saved-value) + (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value) + symbol + (eval (car (get symbol 'saved-value))))) + (t + (set-default symbol (eval exp))))))) (defvar custom-delayed-init-variables nil "List of variables whose initialization is pending.") |