7

I use use-package to defer package loading.
This is useful in emacs standalone mode.
I additional run emacs in daemon mode (emacs --daemon), then this behavior is not desired.

Is there a way to load all, in my init files defined, packages? In a way like this:

(if (daemonp) (foo-for-all-till-now-known-definitions-load-package)) 

Notes:
My init file is distributed over multiple files and directories.

I do not want to keep an extra list of packages which I have defined using use-package.
Me doing this, is not wanted:

(if (daemonp) (require 'org) (require 'paredit) ... ) 

Edit: it seems, that it is not clear what should be achieved by this. So here it is more clearly:

  1. Packages should be loaded on demand only , when I am using emacs (without daemon or server mode). This is already working by using keywords :defer, :commands and :bind
    and
  2. In server mode all packages should be loaded right at start of emacs --daemon, so that there is no waiting time later. This I hope to achieve by triggering a function, which triggers all packages (the ones defined using use-package) to be loaded.

3 Answers 3

8

Take a look at the customization options available for use-package. I think you can set use-package-always-demand based on how Emacs was started to get the behavior you want.

For example at the start of your init file (before any use-package forms) you could do something like:

(setq use-package-always-demand (daemonp)) 
1
  • not the solution I expected, but this is working! After just a little bit tweaking of all my use-package package definitions. :) Commented Jun 26, 2017 at 22:19
2

You can either add :ensure t to each package you want to load from ELPA, or add (setq use-package-always-ensure t) to the beginning of your emacs config file and add :ensure nil to those few packages that you do not want from ELPA.

Packages are downloaded or upgraded at load time. When you want to install a new package, you should write the use-package sexp for it and eval it with C-x C-e to install and configure it at the same time.

Read mode instructions from https://github.com/jwiegley/use-package#for-packageel-users

3
  • 1
    My question is not about downloading and installing, but about loading at runtime. A feature activated by :defer t or :commands or :bind does this -> defered loading of a package. Commented Jun 26, 2017 at 14:23
  • I do not see any reason why packages should not be deferred in daemon mode. I start my emacs and it defers most packages and enters daemon mode. I can start working with it sooner and at any point I can use emacsclient to open files into it from command line. Commented Jun 26, 2017 at 15:09
  • 1
    Emacs server (daemon) is started with operating system only once per day, I don't care how long this takes, but I do not want have long load time when using some functionality of a package, so it can/should load every package on startup. Emacs in standalone (no daemon) is used to quickly view a file which is out of context to the opened files on the daemon, so load-time matters a lot. The :defer t is for standalone mode, but server should have everything ready after start. Commented Jun 26, 2017 at 16:59
0

I have not tested this, but according to the README there is a :demand feature that could do what you want:

You can override package deferral with the :demand keyword. Thus, even if you use :bind, using :demand will force loading to occur immediately and not establish an autoload for the bound key.

2
  • Then all packages are always loaded at start. This behavior is not wanted. I edited the Question to make it more clear. Commented Jun 26, 2017 at 19:23
  • no they are not. it is a per package attribute. Commented Nov 16, 2020 at 19:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.