unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* [Question] use-package's :init or :config for enabling modes
@ 2024-05-19 17:38 Rodrigo Morales
  2024-05-19 18:11 ` tomas
  2024-05-19 19:15 ` Ergus
  0 siblings, 2 replies; 9+ messages in thread
From: Rodrigo Morales @ 2024-05-19 17:38 UTC (permalink / raw)
  To: help-gnu-emacs


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)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-19 17:38 [Question] use-package's :init or :config for enabling modes Rodrigo Morales
@ 2024-05-19 18:11 ` tomas
  2024-05-20  3:56   ` Rodrigo Morales
  2024-05-19 19:15 ` Ergus
  1 sibling, 1 reply; 9+ messages in thread
From: tomas @ 2024-05-19 18:11 UTC (permalink / raw)
  To: Rodrigo Morales; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

On Sun, May 19, 2024 at 12:38:02PM -0500, 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.

The doc says :init is run before the package is loaded, and :config
after. So the right thing would seem to be :config.

Why :init works for you is anybody's guess -- perhaps vertico is
autoloaded?

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-19 17:38 [Question] use-package's :init or :config for enabling modes Rodrigo Morales
  2024-05-19 18:11 ` tomas
@ 2024-05-19 19:15 ` Ergus
  2024-05-20  4:03   ` Rodrigo Morales
  2024-05-20  5:37   ` tomas
  1 sibling, 2 replies; 9+ messages in thread
From: Ergus @ 2024-05-19 19:15 UTC (permalink / raw)
  To: Rodrigo Morales; +Cc: help-gnu-emacs

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)
>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-19 18:11 ` tomas
@ 2024-05-20  3:56   ` Rodrigo Morales
  2024-05-20  5:34     ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: Rodrigo Morales @ 2024-05-20  3:56 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

<tomas@tuxteam.de> writes:

> Why :init works for you is anybody's guess -- perhaps vertico is
> autoloaded?

Yes, vertico-mode is autoloaded. So, if I get right, all modes that are
autolaoded by a package can be enabled in :init. However, I should
enable modes defined by packages in :config. Am I right?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-19 19:15 ` Ergus
@ 2024-05-20  4:03   ` Rodrigo Morales
  2024-05-20  5:37   ` tomas
  1 sibling, 0 replies; 9+ messages in thread
From: Rodrigo Morales @ 2024-05-20  4:03 UTC (permalink / raw)
  To: Ergus; +Cc: help-gnu-emacs

Ergus <spacibba@aol.com> writes:

> 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

Running (message ...) inside :init and :config made it easier to
understand when they are run. Thanks for the idea. It is more clear now.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-20  3:56   ` Rodrigo Morales
@ 2024-05-20  5:34     ` tomas
  0 siblings, 0 replies; 9+ messages in thread
From: tomas @ 2024-05-20  5:34 UTC (permalink / raw)
  To: Rodrigo Morales; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

On Sun, May 19, 2024 at 10:56:15PM -0500, Rodrigo Morales wrote:
> <tomas@tuxteam.de> writes:
> 
> > Why :init works for you is anybody's guess -- perhaps vertico is
> > autoloaded?
> 
> Yes, vertico-mode is autoloaded. So, if I get right, all modes that are
> autolaoded by a package can be enabled in :init. However, I should
> enable modes defined by packages in :config. Am I right?

It seems so, yes. When the mode is autoloaded, you only have to invoke
it -- then the magic happens (if it hasn't happened before).

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-19 19:15 ` Ergus
  2024-05-20  4:03   ` Rodrigo Morales
@ 2024-05-20  5:37   ` tomas
  2024-05-22 21:15     ` Ergus
  1 sibling, 1 reply; 9+ messages in thread
From: tomas @ 2024-05-20  5:37 UTC (permalink / raw)
  To: Ergus; +Cc: Rodrigo Morales, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 681 bytes --]

On Sun, May 19, 2024 at 09:15:07PM +0200, Ergus wrote:
> 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).

If I understand correctly, :init happens (possibly) before the package
is loaded. So assuming it's already there seems risky.

Unless "just invoking" the mode (as OP did in the :init) manages to
load the package, because, e.g. it is autoloaded). Then all is well,
but the explicit load doesn't do anything, because the package was
(auto-) loaded in the :init already.

But I may be wrong :-)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-20  5:37   ` tomas
@ 2024-05-22 21:15     ` Ergus
  2024-05-23  4:32       ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: Ergus @ 2024-05-22 21:15 UTC (permalink / raw)
  To: tomas; +Cc: Rodrigo Morales, help-gnu-emacs



On May 20, 2024 7:37:42 AM GMT+02:00, tomas@tuxteam.de wrote:
>On Sun, May 19, 2024 at 09:15:07PM +0200, Ergus wrote:
>> 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).
>
>If I understand correctly, :init happens (possibly) before the package
>is loaded. So assuming it's already there seems risky.
>
Exactly. 

>Unless "just invoking" the mode (as OP did in the :init) manages to
>load the package, because, e.g. it is autoloaded). Then all is well,
>but the explicit load doesn't do anything, because the package was
>(auto-) loaded in the :init already.
>
>But I may be wrong :-)
>
The package may be autoloaded unless there is a defer indication (command, keymap, defer).

The :init may take place at any moment, but usually it is before loading the package. There is also a :preface keyword which happens even earlier, for example to set things like the load-path or define functions that will be used in the init.


>Cheers

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Question] use-package's :init or :config for enabling modes
  2024-05-22 21:15     ` Ergus
@ 2024-05-23  4:32       ` tomas
  0 siblings, 0 replies; 9+ messages in thread
From: tomas @ 2024-05-23  4:32 UTC (permalink / raw)
  To: Ergus; +Cc: Rodrigo Morales, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]

On Wed, May 22, 2024 at 11:15:31PM +0200, Ergus wrote:
> 
> 
> On May 20, 2024 7:37:42 AM GMT+02:00, tomas@tuxteam.de wrote:

[...]

> >If I understand correctly, :init happens (possibly) before the package
> >is loaded. So assuming it's already there seems risky.
> >
> Exactly. 

[...]

> The package may be autoloaded unless there is a defer indication (command, keymap, defer).
> 
> The :init may take place at any moment, but usually it is before loading the package. There is also a :preface keyword which happens even earlier, for example to set things like the load-path or define functions that will be used in the init.

Thanks for the clarifications :-)

-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-05-23  4:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-19 17:38 [Question] use-package's :init or :config for enabling modes Rodrigo Morales
2024-05-19 18:11 ` tomas
2024-05-20  3:56   ` Rodrigo Morales
2024-05-20  5:34     ` tomas
2024-05-19 19:15 ` Ergus
2024-05-20  4:03   ` Rodrigo Morales
2024-05-20  5:37   ` tomas
2024-05-22 21:15     ` Ergus
2024-05-23  4:32       ` tomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).