Commit 059290d6 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(custom-reevaluate-setting): Simple function to handle variables

that are defined before their default value can really be computed.
(custom-theme-set-variables): Remove unused var `immediate'.
parent 55d0f066
;;; custom.el --- tools for declaring and initializing options ;;; custom.el --- tools for declaring and initializing options
;; ;;
;; Copyright (C) 1996, 1997, 1999, 2001, 2002, 2004 ;; Copyright (C) 1996, 1997, 1999, 2001, 2002, 2004, 2005
;; Free Software Foundation, Inc. ;; Free Software Foundation, Inc.
;; ;;
;; Author: Per Abrahamsen <abraham@dina.kvl.dk> ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
...@@ -726,6 +726,15 @@ handle SYMBOL properly. ...@@ -726,6 +726,15 @@ handle SYMBOL properly.
COMMENT is a comment string about SYMBOL." COMMENT is a comment string about SYMBOL."
(apply 'custom-theme-set-variables 'user args)) (apply 'custom-theme-set-variables 'user args))
(defun custom-reevaluate-setting (symbol)
"Reset the value of SYMBOL by re-evaluating its saved or default value.
This is useful for variables that are defined before their default value
can really be computed. E.g. dumped variables whose default depends on
run-time information."
(funcall (or (get symbol 'custom-set) 'set-default)
symbol
(eval (car (or (get symbol 'saved-value) (get symbol 'standard-value))))))
(defun custom-theme-set-variables (theme &rest args) (defun custom-theme-set-variables (theme &rest args)
"Initialize variables for theme THEME according to settings in ARGS. "Initialize variables for theme THEME according to settings in ARGS.
Each of the arguments in ARGS should be a list of this form: Each of the arguments in ARGS should be a list of this form:
...@@ -753,44 +762,43 @@ SYMBOL's property `force-value' is set to the symbol `immediate'. ...@@ -753,44 +762,43 @@ SYMBOL's property `force-value' is set to the symbol `immediate'.
EXP itself is saved unevaluated as SYMBOL property `saved-value' and EXP itself is saved unevaluated as SYMBOL property `saved-value' and
in SYMBOL's list property `theme-value' \(using `custom-push-theme')." in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
(custom-check-theme theme) (custom-check-theme theme)
(let ((immediate (get theme 'theme-immediate))) (setq args
(setq args (sort args
(sort args (lambda (a1 a2)
(lambda (a1 a2) (let* ((sym1 (car a1))
(let* ((sym1 (car a1)) (sym2 (car a2))
(sym2 (car a2)) (1-then-2 (memq sym1 (get sym2 'custom-dependencies)))
(1-then-2 (memq sym1 (get sym2 'custom-dependencies))) (2-then-1 (memq sym2 (get sym1 'custom-dependencies))))
(2-then-1 (memq sym2 (get sym1 'custom-dependencies)))) (cond ((and 1-then-2 2-then-1)
(cond ((and 1-then-2 2-then-1) (error "Circular custom dependency between `%s' and `%s'"
(error "Circular custom dependency between `%s' and `%s'" sym1 sym2))
sym1 sym2)) (2-then-1 nil)
(2-then-1 nil) ;; Put symbols with :require last. The macro
;; Put symbols with :require last. The macro ;; define-minor-mode generates a defcustom
;; define-minor-mode generates a defcustom ;; with a :require and a :set, where the
;; with a :require and a :set, where the ;; setter function calls the mode function.
;; setter function calls the mode function. ;; Putting symbols with :require last ensures
;; Putting symbols with :require last ensures ;; that the mode function will see other
;; that the mode function will see other ;; customized values rather than default
;; customized values rather than default ;; values.
;; values. (t (nth 3 a2)))))))
(t (nth 3 a2))))))) (while args
(while args (let ((entry (car args)))
(let ((entry (car args))) (if (listp entry)
(if (listp entry) (let* ((symbol (indirect-variable (nth 0 entry)))
(let* ((symbol (indirect-variable (nth 0 entry))) (value (nth 1 entry))
(value (nth 1 entry)) (now (nth 2 entry))
(now (nth 2 entry)) (requests (nth 3 entry))
(requests (nth 3 entry)) (comment (nth 4 entry))
(comment (nth 4 entry)) set)
set) (when requests
(when requests (put symbol 'custom-requests requests)
(put symbol 'custom-requests requests) (mapc 'require requests))
(mapc 'require requests)) (setq set (or (get symbol 'custom-set) 'custom-set-default))
(setq set (or (get symbol 'custom-set) 'custom-set-default)) (put symbol 'saved-value (list value))
(put symbol 'saved-value (list value)) (put symbol 'saved-variable-comment comment)
(put symbol 'saved-variable-comment comment) (custom-push-theme 'theme-value symbol theme 'set value)
(custom-push-theme 'theme-value symbol theme 'set value) ;; Allow for errors in the case where the setter has
;; Allow for errors in the case where the setter has
;; changed between versions, say, but let the user know. ;; changed between versions, say, but let the user know.
(condition-case data (condition-case data
(cond (now (cond (now
...@@ -802,18 +810,18 @@ in SYMBOL's list property `theme-value' \(using `custom-push-theme')." ...@@ -802,18 +810,18 @@ in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
(funcall set symbol (eval value)))) (funcall set symbol (eval value))))
(error (error
(message "Error setting %s: %s" symbol data))) (message "Error setting %s: %s" symbol data)))
(setq args (cdr args)) (setq args (cdr args))
(and (or now (default-boundp symbol)) (and (or now (default-boundp symbol))
(put symbol 'variable-comment comment))) (put symbol 'variable-comment comment)))
;; Old format, a plist of SYMBOL VALUE pairs. ;; Old format, a plist of SYMBOL VALUE pairs.
(message "Warning: old format `custom-set-variables'") (message "Warning: old format `custom-set-variables'")
(ding) (ding)
(sit-for 2) (sit-for 2)
(let ((symbol (indirect-variable (nth 0 args))) (let ((symbol (indirect-variable (nth 0 args)))
(value (nth 1 args))) (value (nth 1 args)))
(put symbol 'saved-value (list value)) (put symbol 'saved-value (list value))
(custom-push-theme 'theme-value symbol theme 'set value)) (custom-push-theme 'theme-value symbol theme 'set value))
(setq args (cdr (cdr args)))))))) (setq args (cdr (cdr args)))))))
(defun custom-set-default (variable value) (defun custom-set-default (variable value)
"Default :set function for a customizable variable. "Default :set function for a customizable variable.
...@@ -1091,5 +1099,5 @@ This means reset VARIABLE to its value in TO-THEME." ...@@ -1091,5 +1099,5 @@ This means reset VARIABLE to its value in TO-THEME."
(provide 'custom) (provide 'custom)
;;; arch-tag: 041b6116-aabe-4f9a-902d-74092bc3dab2 ;; arch-tag: 041b6116-aabe-4f9a-902d-74092bc3dab2
;;; custom.el ends here ;;; custom.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment