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

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

Re: [Question] use-package's :init or :config for enabling modes


From: Ergus
Subject: Re: [Question] use-package's :init or :config for enabling modes
Date: Sun, 19 May 2024 21:15:07 +0200

Hi:

I am not specialist here, but they exist because the :init is ALWAYS
executed while loading the init.el, but the :config is executed AFTER
loading the package (using eval-after-load).

In your example the package is loaded immediately-unconditionally
because there is not defer, so, you don't see any difference; but if
some package is loaded lazily you will see the difference.

When we defer the load (either with the :defer, :command or :keys) the
package is lazily loaded using the autoload mecanisms.

#+BEGIN_SRC elisp
(use-package vertico :defer t
  :init
  (message "Call 1") ;; this will execute always
  :config
  (message "Call 2") ;; this will execute after M-x vertico-mode
  (vertico-mode 1))
#+END_SRC

Hope this helps,
Ergus

On Sun, May 19, 2024 at 12:38:02PM GMT, Rodrigo Morales wrote:

I emptied =~/.config/emacs/init.el= file and I inserted the following sexp and 
launched Emacs. =vertico-mode= was enabled.

#+BEGIN_SRC elisp
(use-package vertico

 :config (vertico-mode))
#+END_SRC

I emptied =~/.config/emacs/init.el= again and I inserted the following sexp and 
launched Emacs. =vertico-mode= was enabled.

#+BEGIN_SRC elisp
(use-package vertico

 :init (vertico-mode))
#+END_SRC

As shown above, whether we use =:init= or =:config= both can be used for 
enabling a mode. So my question is: What's the difference between using 
=:config= and =:init= for enabling a mode that is defined by a package.

* System information

GNU Emacs 29.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo 
version 1.18.0)



reply via email to

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