aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/custom.el
diff options
context:
space:
mode:
authorStefan Monnier2013-08-02 17:16:33 -0400
committerStefan Monnier2013-08-02 17:16:33 -0400
commita104f656c8217b027866d32e8d7bf024a671e3cc (patch)
treeb62ddfb915099ba3398b2f0b1f9ddc0ed6203102 /lisp/custom.el
parent185e3b5a2f3dc2b5163eb1fe97499c6af1edaa9c (diff)
downloademacs-a104f656c8217b027866d32e8d7bf024a671e3cc.tar.gz
emacs-a104f656c8217b027866d32e8d7bf024a671e3cc.zip
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.el85
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.")
49 49
50;;; The `defcustom' Macro. 50;;; The `defcustom' Macro.
51 51
52(defun custom-initialize-default (symbol value) 52(defun custom-initialize-default (symbol exp)
53 "Initialize SYMBOL with VALUE. 53 "Initialize SYMBOL with EXP.
54This will do nothing if symbol already has a default binding. 54This will do nothing if symbol already has a default binding.
55Otherwise, if symbol has a `saved-value' property, it will evaluate 55Otherwise, if symbol has a `saved-value' property, it will evaluate
56the car of that and use it as the default binding for symbol. 56the car of that and use it as the default binding for symbol.
57Otherwise, VALUE will be evaluated and used as the default binding for 57Otherwise, EXP will be evaluated and used as the default binding for
58symbol." 58symbol."
59 (eval `(defvar ,symbol ,(if (get symbol 'saved-value) 59 (eval `(defvar ,symbol ,(let ((sv (get symbol 'saved-value)))
60 (car (get symbol 'saved-value)) 60 (if sv (car sv) exp)))))
61 value))))
62 61
63(defun custom-initialize-set (symbol value) 62(defun custom-initialize-set (symbol exp)
64 "Initialize SYMBOL based on VALUE. 63 "Initialize SYMBOL based on EXP.
65If the symbol doesn't have a default binding already, 64If the symbol doesn't have a default binding already,
66then set it using its `:set' function (or `set-default' if it has none). 65then set it using its `:set' function (or `set-default' if it has none).
67The value is either the value in the symbol's `saved-value' property, 66The value is either the value in the symbol's `saved-value' property,
68if any, or VALUE." 67if any, or the value of EXP."
69 (unless (default-boundp symbol) 68 (condition-case nil
70 (funcall (or (get symbol 'custom-set) 'set-default) 69 (default-toplevel-value symbol)
71 symbol 70 (error
72 (eval (if (get symbol 'saved-value) 71 (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value)
73 (car (get symbol 'saved-value)) 72 symbol
74 value))))) 73 (eval (let ((sv (get symbol 'saved-value)))
75 74 (if sv (car sv) exp)))))))
76(defun custom-initialize-reset (symbol value) 75
77 "Initialize SYMBOL based on VALUE. 76(defun custom-initialize-reset (symbol exp)
77 "Initialize SYMBOL based on EXP.
78Set the symbol, using its `:set' function (or `set-default' if it has none). 78Set the symbol, using its `:set' function (or `set-default' if it has none).
79The value is either the symbol's current value 79The value is either the symbol's current value
80 (as obtained using the `:get' function), if any, 80 (as obtained using the `:get' function), if any,
81or the value in the symbol's `saved-value' property if any, 81or the value in the symbol's `saved-value' property if any,
82or (last of all) VALUE." 82or (last of all) the value of EXP."
83 (funcall (or (get symbol 'custom-set) 'set-default) 83 (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value)
84 symbol 84 symbol
85 (cond ((default-boundp symbol) 85 (condition-case nil
86 (funcall (or (get symbol 'custom-get) 'default-value) 86 (let ((def (default-toplevel-value symbol))
87 symbol)) 87 (getter (get symbol 'custom-get)))
88 ((get symbol 'saved-value) 88 (if getter (funcall getter symbol) def))
89 (eval (car (get symbol 'saved-value)))) 89 (error
90 (t 90 (eval (let ((sv (get symbol 'saved-value)))
91 (eval value))))) 91 (if sv (car sv) exp)))))))
92 92
93(defun custom-initialize-changed (symbol value) 93(defun custom-initialize-changed (symbol exp)
94 "Initialize SYMBOL with VALUE. 94 "Initialize SYMBOL with EXP.
95Like `custom-initialize-reset', but only use the `:set' function if 95Like `custom-initialize-reset', but only use the `:set' function if
96not using the standard setting. 96not using the standard setting.
97For the standard setting, use `set-default'." 97For the standard setting, use `set-default'."
98 (cond ((default-boundp symbol) 98 (condition-case nil
99 (funcall (or (get symbol 'custom-set) 'set-default) 99 (let ((def (default-toplevel-value symbol)))
100 symbol 100 (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value)
101 (funcall (or (get symbol 'custom-get) 'default-value) 101 symbol
102 symbol))) 102 (let ((getter (get symbol 'custom-get)))
103 ((get symbol 'saved-value) 103 (if getter (funcall getter symbol) def))))
104 (funcall (or (get symbol 'custom-set) 'set-default) 104 (error
105 symbol 105 (cond
106 (eval (car (get symbol 'saved-value))))) 106 ((get symbol 'saved-value)
107 (t 107 (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value)
108 (set-default symbol (eval value))))) 108 symbol
109 (eval (car (get symbol 'saved-value)))))
110 (t
111 (set-default symbol (eval exp)))))))
109 112
110(defvar custom-delayed-init-variables nil 113(defvar custom-delayed-init-variables nil
111 "List of variables whose initialization is pending.") 114 "List of variables whose initialization is pending.")