From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ruijie Yu via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: use-package :after ?? Date: Mon, 08 May 2023 12:25:44 +0800 Message-ID: References: Reply-To: Ruijie Yu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12192"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.11.3; emacs 30.0.50 Cc: Ruijie Yu via Users list for the GNU Emacs text editor To: David Masterson Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 08 06:30:27 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pvsW2-00031p-JR for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 08 May 2023 06:30:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsVD-0005vR-MV; Mon, 08 May 2023 00:29:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pvsVC-0005uy-Fd for help-gnu-emacs@gnu.org; Mon, 08 May 2023 00:29:34 -0400 Original-Received: from netyu.xyz ([152.44.41.246] helo=mail.netyu.xyz) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pvsVA-00056N-KU for help-gnu-emacs@gnu.org; Mon, 08 May 2023 00:29:34 -0400 Original-Received: from fw.net.yu.netyu.xyz ( [222.248.4.98]) by netyu.xyz (OpenSMTPD) with ESMTPSA id b86c59e2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 8 May 2023 04:29:30 +0000 (UTC) In-reply-to: Received-SPF: pass client-ip=152.44.41.246; envelope-from=ruijie@netyu.xyz; helo=mail.netyu.xyz X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143535 Archived-At: David Masterson writes: > Thanks for the followup. > > Ruijie Yu via Users list for the GNU Emacs text editor > writes: > >> David Masterson writes: >> >>> 1. If any of the listed packages are not loaded currently, then the >>> current package will not be loaded. Period. >>> 2. #1 + "magic" will be done to ensure that, once the listed packages >>> are loaded, the current package will be (auto?) loaded. >>> >>> If #1 is correct, I do not know how the current package will ever be >>> loaded if ":after" fails. If #2 is correct, I do not know what the >>> "magic" could be to safely do this. >> >> TL;DR: #2, see below. > > I tried to write it to be skimmable. ;) > >>> For instance: >>> >>> (use-package org-ac :after org) >>> (use-package org) >> >> This is what I get when I `macroexpand' the first `use-package' call >> with `use-package-always-defer' set to nil. > > Which I assumed is the default and goal (defer all packages until you > need them). > >> [ If `u-p-a-defer' is set to t when I `macroexpand', the >> `eval-after-load' call reduces to nil on expand-time because this >> package is not installed, nor does `package.el' know how to install it >> because I only have gnu and nongnu elpa configured. ] > > Understood > >> (progn >> (defvar use-package--warning3 >> #'(lambda >> (keyword err) >> (let >> ((msg >> (format "%s/%s: %s" 'org-ac keyword >> (error-message-string err)))) >> (display-warning 'use-package msg :error)))) >> (condition-case-unless-debug err >> (eval-after-load 'org >> '(if >> (not >> (require 'org-ac nil t)) >> (display-warning 'use-package >> (format "Cannot load %s" 'org-ac) >> :error))) >> (error >> (funcall use-package--warning3 :catch err)))) > > Hmm. > >> So, this might help you understand what is happening under the hood. >> Essentially, it will try to load org-ac, only after *all packages* >> listed in the :after section, showing a warning if loading org-ac fails. > > I presume the 'if' gets more complicated and more 'eval-after-load' > calls are done if :after lists more than one item, correct? Yes, see this snippet: What I ran: --8<---------------cut here---------------start------------->8--- (let ((use-package-always-defer nil) (use-package-always-ensure nil)) (macroexpand-1 '(use-package foo :after (bar baz)))) --8<---------------cut here---------------end--------------->8--- What I got: --8<---------------cut here---------------start------------->8--- (progn (defvar use-package--warning9 #'(lambda (keyword err) (let ((msg (format "%s/%s: %s" 'foo keyword (error-message-string err)))) (display-warning 'use-package msg :error)))) (condition-case-unless-debug err (eval-after-load 'baz '(eval-after-load 'bar '(if (not (require 'foo nil t)) (display-warning 'use-package (format "Cannot load %s" 'foo) :error)))) (error (funcall use-package--warning9 :catch err)))) --8<---------------cut here---------------end--------------->8--- This also answers your question of "how to macroexpand". There are also the two functions `macroexpand' and `macroexpand-all' which you can try to use as well. >> Keep in mind, according to the macroexpand result, that this also means >> that if you load the subpackage `org-ac' manually (via a hook, autoload, >> etc), it is not going to try to load `org' at all. I feel that this is >> kind of strange, but maybe it has its reasons. > > Hmm. > >> It seems that you opted to go with setting `u-p-a-defer' to t. And >> since you didn't mention :ensure at all, I assume you set `u-p-a-ensure' >> to t as well. > > I'm looking at 'ensure'. I currently use 'auto-update' package. > >> In this case, order doesn't _really_ matter, you just need to >> `(use-package sub-pkg :after main-pkg :config your-other-configs)' on >> all your subpackages. > > I thought I had. I even had 'org' before 'org-ac' (but after > 'auto-complete') in .emacs, but things weren't working right until I > hand loaded 'org-ac'. I'll have to test this some more. > > How did you do the macroexpand to debug this? I haven't seen that > technique. Looks interesting. > >> Note, since you use `org' as an example, that you should probably >> `(use-package org)' first thing in your init.el, because otherwise >> something else is probably going to load builtin `org', and the Elpa >> `org' will complain afterwards about mismatched versions. > > Yes, I ran into that. I wound up removing the builtin manually. I > believe org has been trying to fix this. > > Thanks -- Best, RY