0

I'd like a way to lazily activate certain ~/.emacs.d/elpa packages. I notice some of them have so many autoloads (which require other packages recursively from their *-autoloads.el), that you might as well just (require 'them).

Can I, for example, activate all except certain packages? I see you can set package-load-list to (all) or a list of names and versions, but I can't see anything like (all-but ,(alist)) in the docs.

  • 1
    FWIW, you might want to report that as a bug to the relevant package(s). – Stefan Sep 18 '16 at 16:09
1

Can I, for example, activate all except certain packages? I see you can set package-load-list to (all) or a list of names and versions, but I can't see anything like (all-but ,(alist)) in the docs.

You should be able to use ((a-slow-package . nil) (an-even-slower-package . nil) all).

As described in the docstring:

Each element in this list should be a list (NAME VERSION), or the
symbol ‘all’.  The symbol ‘all’ says to load the latest installed
versions of all packages not specified by other elements.

For an element (NAME VERSION), NAME is a package name (a symbol).
[...]
If VERSION is nil, the package is not loaded (it is "disabled").
  • Nice, I can now do (let ((package-load-list '((a-slow-package . nil) (an-even-slower-package . nil) all))) (package-initialize)) in my init.el, along with something like (use-package :if (package-installed-p 'a-slow-package) :init (defun my-start-slowness () (interactive) (package-activate 'a-slow-package) (a-slow-package-mode))) for requiring it when needed. – unhammer Sep 19 '16 at 10:34
1

This is difficult with package.el because package.el is not designed for modular package management. I suggest you use a different package manager, such as straight.el (which I wrote in order to solve the problems of package.el).

With straight.el, conditionally loading a package is trivial: just conditionally load it:

(when some-condition
  (straight-use-package 'my-slow-package))

This works because (unlike package.el), straight.el does exactly what you ask it to, and nothing more. Thus, preventing straight.el from installing and loading a package is as simple as not asking it to do so.

You can read verbose documentation about straight.el, including comparisons to other package managers, in the README.

Footnote for advanced straight.el users

If you use version lockfiles, then you want to be sure that the revisions of all your packages are recorded in your lockfile, even if they are not currently being loaded. This can be accomplished via

(if some-condition
    (straight-use-package 'my-slow-package)
  (straight-register-package 'my-slow-package))

although a more convenient syntax using use-package is planned in this issue.

0

This seems to do the trick:

(package-initialize 'no-activate)
(let* ((no-activate '(a-slow-package an-even-slower-package)))
    (mapc (lambda (s) (unless (member s no-activate)
                (package-activate s)))
          (mapcar #'car package-alist)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.