[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Customizable modes and package.el
From: |
Artur Malabarba |
Subject: |
Re: Customizable modes and package.el |
Date: |
Sun, 29 Mar 2015 15:48:35 +0100 |
Initial draft
The only thing I'm totally sure on is the `now' parameter. I think
it's not a problem, because it's meant to indicate "set the value
wihout waiting for the defcustom" and not "set the value immediately",
but I don't know its real use-case, so it's hard to say for sure.
diff --git a/lisp/custom.el b/lisp/custom.el
index e5fe0eb..d07f0c0 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -933,6 +933,37 @@ handle SYMBOL properly.
COMMENT is a comment string about SYMBOL."
(apply 'custom-theme-set-variables 'user args))
+(defun custom--load-entry (entry &optional requests)
+ "Load custom ENTRY, after requiring all features in REQUESTS.
+Signal a meaningful error if any of the features are absent."
+ ;; Now set the variable.
+ (let* ((now (nth 2 entry))
+ (comment (nth 4 entry))
+ (symbol (indirect-variable (nth 0 entry)))
+ (value (nth 1 entry))
+ set)
+ (dolist (f requests)
+ (unless (require f nil t)
+ (error "Cannot find load file `%s', required by `%s' inside your `%s'"
+ f symbol 'custom-set-variables)))
+ (setq set (or (get symbol 'custom-set) 'custom-set-default))
+ (put symbol 'saved-value (list value))
+ (put symbol 'saved-variable-comment comment)
+ ;; Allow for errors in the case where the setter has
+ ;; changed between versions, say, but let the user know.
+ (condition-case data
+ (cond (now
+ ;; Rogue variable, set it now.
+ (put symbol 'force-value t)
+ (funcall set symbol (eval value)))
+ ((default-boundp symbol)
+ ;; Something already set this, overwrite it.
+ (funcall set symbol (eval value))))
+ (error
+ (message "Error setting %s: %s" symbol data)))
+ (and (or now (default-boundp symbol))
+ (put symbol 'variable-comment comment))))
+
(defun custom-theme-set-variables (theme &rest args)
"Initialize variables for theme THEME according to settings in ARGS.
Each of the arguments in ARGS should be a list of this form:
@@ -972,31 +1003,16 @@ COMMENT is a comment string about SYMBOL."
(value (nth 1 entry)))
(custom-push-theme 'theme-value symbol theme 'set value)
(unless custom--inhibit-theme-enable
- ;; Now set the variable.
- (let* ((now (nth 2 entry))
- (requests (nth 3 entry))
- (comment (nth 4 entry))
- set)
- (when requests
- (put symbol 'custom-requests requests)
- (mapc 'require requests))
- (setq set (or (get symbol 'custom-set) 'custom-set-default))
- (put symbol 'saved-value (list value))
- (put symbol 'saved-variable-comment comment)
- ;; Allow for errors in the case where the setter has
- ;; changed between versions, say, but let the user know.
- (condition-case data
- (cond (now
- ;; Rogue variable, set it now.
- (put symbol 'force-value t)
- (funcall set symbol (eval value)))
- ((default-boundp symbol)
- ;; Something already set this, overwrite it.
- (funcall set symbol (eval value))))
- (error
- (message "Error setting %s: %s" symbol data)))
- (and (or now (default-boundp symbol))
- (put symbol 'variable-comment comment)))))))
+ (let* ((requests (nth 3 entry)))
+ (when requests
+ (put symbol 'custom-requests requests))
+ ;; If a symbol has requirements, we don't even try to load
+ ;; them now, because we might accidentally load an old
+ ;; built-in instead of a newer installed version.
+ (if requests
+ (add-hook 'after-init-hook
+ (apply-partially #'custom--load-entry entry requests))
+ (custom--load-entry entry)))))))
(defvar custom--sort-vars-table)
(defvar custom--sort-vars-result)
- Customizable modes and package.el, Sebastian Wiesner, 2015/03/28
- Re: Customizable modes and package.el, Philipp Stephani, 2015/03/28
- Re: Customizable modes and package.el, Stefan Monnier, 2015/03/28
- Re: Customizable modes and package.el, Sebastian Wiesner, 2015/03/28
- Re: Customizable modes and package.el, Artur Malabarba, 2015/03/28
- Re: Customizable modes and package.el, Stefan Monnier, 2015/03/28
- Re: Customizable modes and package.el,
Artur Malabarba <=
- Re: Customizable modes and package.el, Stefan Monnier, 2015/03/29
- Re: Customizable modes and package.el, Artur Malabarba, 2015/03/30
- Re: Customizable modes and package.el, Stefan Monnier, 2015/03/30
- Re: Customizable modes and package.el, Artur Malabarba, 2015/03/30
- Re: Customizable modes and package.el, Robert Pluim, 2015/03/30
- Re: Customizable modes and package.el, Artur Malabarba, 2015/03/30
- RE: Customizable modes and package.el, Drew Adams, 2015/03/30
- Re: Customizable modes and package.el, Stefan Monnier, 2015/03/30
- Re: Customizable modes and package.el, Achim Gratz, 2015/03/30
- Re: Customizable modes and package.el, Artur Malabarba, 2015/03/30