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 10:44:10 +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="14384"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.11.3; emacs 30.0.50 Cc: help-gnu-emacs@gnu.org To: David Masterson Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 08 05:13:12 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 1pvrJH-0003VE-60 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 08 May 2023 05:13:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvrIT-0000oo-1M; Sun, 07 May 2023 23:12:21 -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 1pvrIR-0000oe-3N for help-gnu-emacs@gnu.org; Sun, 07 May 2023 23:12:19 -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 1pvrIP-0001zB-CO for help-gnu-emacs@gnu.org; Sun, 07 May 2023 23:12:18 -0400 Original-Received: from fw.net.yu.netyu.xyz ( [222.248.4.98]) by netyu.xyz (OpenSMTPD) with ESMTPSA id 65c613ed (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 8 May 2023 03:12:14 +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:143532 Archived-At: 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. > 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. [ 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. ] --8<---------------cut here---------------start------------->8--- (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)))) --8<---------------cut here---------------end--------------->8--- 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. 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. > My goal is to organwize my .emacs loading of 25+ packages to only load if > needed. That means (almost) all packages are deferred at startup and > will load itself and subpackages (minor modes, etc.) when I try to call > the package. This is what I hoped :after was for. > > Can someone advise on the proper use of ":after" and how to get > appropriate subpackages to also load when the main package is loaded. 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. 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. 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. -- Best, RY