From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.devel Subject: Re: Customizable modes and package.el Date: Sun, 29 Mar 2015 15:48:35 +0100 Message-ID: References: Reply-To: bruce.connor.am@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1427640538 28107 80.91.229.3 (29 Mar 2015 14:48:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 29 Mar 2015 14:48:58 +0000 (UTC) Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 29 16:48:53 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YcEWA-00006C-EE for ged-emacs-devel@m.gmane.org; Sun, 29 Mar 2015 16:48:50 +0200 Original-Received: from localhost ([::1]:57281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcEW9-0005Gy-Iu for ged-emacs-devel@m.gmane.org; Sun, 29 Mar 2015 10:48:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcEVx-0005Fw-DE for emacs-devel@gnu.org; Sun, 29 Mar 2015 10:48:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YcEVw-0005EM-ET for emacs-devel@gnu.org; Sun, 29 Mar 2015 10:48:37 -0400 Original-Received: from mail-lb0-x22e.google.com ([2a00:1450:4010:c04::22e]:35448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcEVw-0005EA-31 for emacs-devel@gnu.org; Sun, 29 Mar 2015 10:48:36 -0400 Original-Received: by lbdc10 with SMTP id c10so37448704lbd.2 for ; Sun, 29 Mar 2015 07:48:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=pAeEz/gOxdwvPBqPlw4ZlNfKzjDT9QR42NtGHQbogA4=; b=iwh4RmYxajzb1ww2fnAVYCVkV0zhbY7bSeA7kM+pl5kwwHsGfG3WBm3V8HPxyJN5eS Jtu/hkTCPgZGK86zb1KUxSwO4AcYb8UV/OcTCZLWrAG3feHGxuAq4zAaWKy/rDYFi9LN Wl3kPp9R9mQLyk1eL8+RoYCUV7snhuR9ru63fnlks3+OXe5EGZMvnCMhqAJI6wOFBnM7 MPocOTkwj502EXWa14BZm9OwLohjH6ORlai4wlajhMeynIICCva7Od1maSvHaYa6Q44q HvM0XERH03y4dXH9vWShrLaRCuLxchUJqZ/x8kBUr6Fi4VkqGXJA2KAxYILQw7xeWZmZ rOzw== X-Received: by 10.112.98.201 with SMTP id ek9mr25300219lbb.68.1427640515228; Sun, 29 Mar 2015 07:48:35 -0700 (PDT) Original-Received: by 10.112.207.225 with HTTP; Sun, 29 Mar 2015 07:48:35 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: 5EQsAwt4gMo455x7w32IyUDtKcU X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:184518 Archived-At: 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)