From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Customizable modes and package.el Date: Sun, 29 Mar 2015 20:41:50 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1427676130 13524 80.91.229.3 (30 Mar 2015 00:42:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 30 Mar 2015 00:42:10 +0000 (UTC) Cc: emacs-devel To: Artur Malabarba Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 30 02:42:02 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 1YcNmD-00009p-7t for ged-emacs-devel@m.gmane.org; Mon, 30 Mar 2015 02:42:01 +0200 Original-Received: from localhost ([::1]:58763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcNmC-0000JS-Bx for ged-emacs-devel@m.gmane.org; Sun, 29 Mar 2015 20:42:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcNm9-0000JM-8N for emacs-devel@gnu.org; Sun, 29 Mar 2015 20:41:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YcNm3-0008Sp-C0 for emacs-devel@gnu.org; Sun, 29 Mar 2015 20:41:57 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:19825) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YcNm3-0008Sl-75 for emacs-devel@gnu.org; Sun, 29 Mar 2015 20:41:51 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnEFAGvvdVRBbthL/2dsb2JhbAA3gVOfQYIugQiBdQEBBAFWIwULCw4mEhQYDSSIE6IRjGSDTQODcASoOw X-IPAS-Result: AnEFAGvvdVRBbthL/2dsb2JhbAA3gVOfQYIugQiBdQEBBAFWIwULCw4mEhQYDSSIE6IRjGSDTQODcASoOw X-IronPort-AV: E=Sophos;i="5.01,1,1400040000"; d="scan'208";a="114908213" Original-Received: from 65-110-216-75.cpe.pppoe.ca (HELO pastel.home) ([65.110.216.75]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Mar 2015 20:41:51 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 490AEDB0; Sun, 29 Mar 2015 20:41:50 -0400 (EDT) In-Reply-To: (Artur Malabarba's message of "Sun, 29 Mar 2015 15:48:35 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:184528 Archived-At: > 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. Hmm... I thought the idea was to add "(package-initialize)" to the ~/.emacs Stefan > 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)