help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: use-package :after ??


From: Ruijie Yu
Subject: Re: use-package :after ??
Date: Mon, 08 May 2023 10:44:10 +0800
User-agent: mu4e 1.11.3; emacs 30.0.50

David Masterson <dsmasterson@gmail.com> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]