* with-eval-after-load with sh-mode
@ 2021-07-02 5:59 lisa-asket
2021-07-02 6:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 8:42 ` Arthur Miller
0 siblings, 2 replies; 19+ messages in thread
From: lisa-asket @ 2021-07-02 5:59 UTC (permalink / raw)
To: help-gnu-emacs
How can I use `with-eval-after-load` with sh-mode?
Basically I want to defer call to sh-mode-map until sh-mode is loaded
(with-eval-after-load 'sh
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 5:59 with-eval-after-load with sh-mode lisa-asket
@ 2021-07-02 6:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 7:32 ` lisa-asket
2021-07-02 8:21 ` lisa-asket
2021-07-02 8:42 ` Arthur Miller
1 sibling, 2 replies; 19+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-02 6:58 UTC (permalink / raw)
To: help-gnu-emacs
lisa-asket wrote:
> Basically I want to defer call to sh-mode-map until sh-mode
> is loaded
First try
(require 'sh-script)
Then set the keys in `sh-mode-map' (which is a variable BTW) ...
If that doesn't work keep the first line but turn the second
line to into a function (just enclose it in a `defun'), then
do
(defun sh-mode-hook-f ()
;; call your key setting function here
)
(add-hook 'sh-mode-hook #'sh-mode-hook-f)
I don't know why some modes need the more elaborate and in
theory less efficient hook solution (less efficient since it
gets called every time), do they themselves reset the their
keymaps after they have been `require'd? This has puzzled me
for several years... I guess one could just compare the source
for two in this sense opposing modes!
You shouldn't be afraid of sensible use of hooks tho, they
aren't the ones to slow down the interactive feel, having TONS
of buffers open is the chief culprit, rather...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 19+ messages in thread
* with-eval-after-load with sh-mode
2021-07-02 6:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-02 7:32 ` lisa-asket
2021-07-02 13:14 ` Arthur Miller
2021-07-02 8:21 ` lisa-asket
1 sibling, 1 reply; 19+ messages in thread
From: lisa-asket @ 2021-07-02 7:32 UTC (permalink / raw)
To: moasenwood, help-gnu-emacs
>From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
>To: help-gnu-emacs@gnu.org
>Subject: Re: with-eval-after-load with sh-mode
>Date: 02/07/2021 08:58:36 Europe/Paris
>lisa-asket wrote:
>> Basically I want to defer call to sh-mode-map until sh-mode
>> is loaded
>First try
>(require 'sh-script)
>Then set the keys in `sh-mode-map' (which is a variable BTW) ...
>If that doesn't work keep the first line but turn the second
>line to into a function (just enclose it in a `defun'), then
>do
>(defun sh-mode-hook-f ()
>;; call your key setting function here
>)
>(add-hook 'sh-mode-hook #'sh-mode-hook-f)
So I don't use `with-eval-after-load`? Just do `add-hook`?
>I don't know why some modes need the more elaborate and in
>theory less efficient hook solution (less efficient since it
>gets called every time), do they themselves reset the their
>keymaps after they have been `require'd? This has puzzled me
>for several years... I guess one could just compare the source
>for two in this sense opposing modes!
>You shouldn't be afraid of sensible use of hooks tho, they
>aren't the ones to slow down the interactive feel, having TONS
>of buffers open is the chief culprit, rather...
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 7:32 ` lisa-asket
@ 2021-07-02 13:14 ` Arthur Miller
2021-07-02 15:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 19+ messages in thread
From: Arthur Miller @ 2021-07-02 13:14 UTC (permalink / raw)
To: lisa-asket; +Cc: help-gnu-emacs, moasenwood
lisa-asket@perso.be writes:
>>From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
>>To: help-gnu-emacs@gnu.org
>>Subject: Re: with-eval-after-load with sh-mode
>>Date: 02/07/2021 08:58:36 Europe/Paris
>
>>lisa-asket wrote:
>
>>> Basically I want to defer call to sh-mode-map until sh-mode
>>> is loaded
>
>>First try
>
>>(require 'sh-script)
You don't need to require sh-script.el. sh-mode is autolaoded function
so Emacs will load sh-script when sh-mode is invoked automatically.
>>Then set the keys in `sh-mode-map' (which is a variable BTW) ...
>
>>If that doesn't work keep the first line but turn the second
>>line to into a function (just enclose it in a `defun'), then
>>do
>
>>(defun sh-mode-hook-f ()
>>;; call your key setting function here
>>)
>>(add-hook 'sh-mode-hook #'sh-mode-hook-f)
>
>
>
> So I don't use `with-eval-after-load`? Just do `add-hook`?
It depends if you want your code to run only once, when sh-script.el is
loaded or do you want it to run each every time the mode is loaded,
which will happen every time you open or create a shell file.
If you wish to modify key shortcuts, with-eval-after-load is probably
better place.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 13:14 ` Arthur Miller
@ 2021-07-02 15:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 16:57 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-02 20:59 ` Arthur Miller
0 siblings, 2 replies; 19+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-02 15:45 UTC (permalink / raw)
To: help-gnu-emacs
Arthur Miller wrote:
> You don't need to require sh-script.el. sh-mode is
> autolaoded function so Emacs will load sh-script when
> sh-mode is invoked automatically.
You sometimes need to `require' it anyway, e.g. try setting
the face `sh-escaped-newline' to something.
The byte-compiler seems to be OK with it (it doesn't say
anything) but when the file that does it is loaded it says
that's an invalid face and everything comes to a halt.
BTW it seems you don't need the hook solution for this
particular mode, just require and set the faces, when the mode
is loaded the faces are OK what I can see.
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 15:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-02 16:57 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-02 17:02 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 18:30 ` lisa-asket
2021-07-02 20:59 ` Arthur Miller
1 sibling, 2 replies; 19+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-07-02 16:57 UTC (permalink / raw)
To: help-gnu-emacs
> You sometimes need to `require' it anyway, e.g. try setting
> the face `sh-escaped-newline' to something.
Definitely not needed: I set all my faces with `custom-set-faces` in my
init file and it works regardless if the faces are already defined
or not.
Stefan
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 15:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 16:57 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-07-02 20:59 ` Arthur Miller
2021-07-02 23:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 19+ messages in thread
From: Arthur Miller @ 2021-07-02 20:59 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> Arthur Miller wrote:
>
>> You don't need to require sh-script.el. sh-mode is
>> autolaoded function so Emacs will load sh-script when
>> sh-mode is invoked automatically.
>
> You sometimes need to `require' it anyway, e.g. try setting
> the face `sh-escaped-newline' to something.
>
> The byte-compiler seems to be OK with it (it doesn't say
> anything) but when the file that does it is loaded it says
> that's an invalid face and everything comes to a halt.
>
> BTW it seems you don't need the hook solution for this
> particular mode, just require and set the faces, when the mode
> is loaded the faces are OK what I can see.
Of course you can require, but why require it in your init file when you
can postpone that loading (lazy load it) until you actually use sh-mode?
Set that face in either with-eval-after-load or mode hook so you don't
need to require that file before it is actually needed.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 20:59 ` Arthur Miller
@ 2021-07-02 23:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-03 1:01 ` Arthur Miller
0 siblings, 1 reply; 19+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-02 23:08 UTC (permalink / raw)
To: help-gnu-emacs
Arthur Miller wrote:
> Set that face in either with-eval-after-load or mode hook so
> you don't need to require that file before it is
> actually needed.
Oh, or else what? What are YOU going to do about it?
Meanwhile I'm just gonna require and set faces and require...
https://dataswamp.org/~incal/figures/emacs/art-miller.png
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 23:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-03 1:01 ` Arthur Miller
2021-07-03 1:17 ` lisa-asket
0 siblings, 1 reply; 19+ messages in thread
From: Arthur Miller @ 2021-07-03 1:01 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> Arthur Miller wrote:
>
>> Set that face in either with-eval-after-load or mode hook so
>> you don't need to require that file before it is
>> actually needed.
>
> Oh, or else what?
Or else what what?
> What are YOU going to do about it?
?
I guess get a cold beer since I don't like pop-corn and wait for your
answer? :D
> Meanwhile I'm just gonna require and set faces and require...
>
> https://dataswamp.org/~incal/figures/emacs/art-miller.png
You run your Emacs whichever way you like, your life is your problem
dude.
I reflected over your (bad) advice to someone who obviously doesn't
understand how mechanism work. Op does not need to require that file
just to set shortcuts for sh-mode.
^ permalink raw reply [flat|nested] 19+ messages in thread
* with-eval-after-load with sh-mode
2021-07-03 1:01 ` Arthur Miller
@ 2021-07-03 1:17 ` lisa-asket
0 siblings, 0 replies; 19+ messages in thread
From: lisa-asket @ 2021-07-03 1:17 UTC (permalink / raw)
To: Arthur Miller, help-gnu-emacs
From: Arthur Miller <arthur.miller@live.com>
To: help-gnu-emacs@gnu.org
Subject: Re: with-eval-after-load with sh-mode
Date: 03/07/2021 03:01:24 Europe/Paris
Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> Arthur Miller wrote:
>
>> Set that face in either with-eval-after-load or mode hook so
>> you don't need to require that file before it is
>> actually needed.
>
> Oh, or else what?
Or else what what?
> What are YOU going to do about it?
?
I guess get a cold beer since I don't like pop-corn and wait for your
answer? :D
> Meanwhile I'm just gonna require and set faces and require...
>
> https://dataswamp.org/~incal/figures/emacs/art-miller.png
You run your Emacs whichever way you like, your life is your problem
dude.
I reflected over your (bad) advice to someone who obviously doesn't
understand how mechanism work. Op does not need to require that file
just to set shortcuts for sh-mode.
I removed the require and things still worked.
^ permalink raw reply [flat|nested] 19+ messages in thread
* with-eval-after-load with sh-mode
2021-07-02 6:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 7:32 ` lisa-asket
@ 2021-07-02 8:21 ` lisa-asket
1 sibling, 0 replies; 19+ messages in thread
From: lisa-asket @ 2021-07-02 8:21 UTC (permalink / raw)
To: moasenwood, help-gnu-emacs
>From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
>To: help-gnu-emacs@gnu.org
>Subject: Re: with-eval-after-load with sh-mode
>Date: 02/07/2021 08:58:36 Europe/Paris
>lisa-asket wrote:
>> Basically I want to defer call to sh-mode-map until sh-mode
>> is loaded
>First try
>(require 'sh-script)
Seems I needed to use (require 'sh-script)
>Then set the keys in `sh-mode-map' (which is a variable BTW) ...
>If that doesn't work keep the first line but turn the second
>line to into a function (just enclose it in a `defun'), then
>do
>(defun sh-mode-hook-f ()
>;; call your key setting function here
>)
>(add-hook 'sh-mode-hook #'sh-mode-hook-f)
>I don't know why some modes need the more elaborate and in
>theory less efficient hook solution (less efficient since it
>gets called every time), do they themselves reset the their
>keymaps after they have been `require'd? This has puzzled me
>for several years... I guess one could just compare the source
>for two in this sense opposing modes!
>You shouldn't be afraid of sensible use of hooks tho, they
>aren't the ones to slow down the interactive feel, having TONS
>of buffers open is the chief culprit, rather...
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 5:59 with-eval-after-load with sh-mode lisa-asket
2021-07-02 6:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-02 8:42 ` Arthur Miller
2021-07-02 8:49 ` lisa-asket
1 sibling, 1 reply; 19+ messages in thread
From: Arthur Miller @ 2021-07-02 8:42 UTC (permalink / raw)
To: lisa-asket; +Cc: help-gnu-emacs
lisa-asket@perso.be writes:
> How can I use `with-eval-after-load` with sh-mode?
>
>
>
> Basically I want to defer call to sh-mode-map until sh-mode is loaded
>
>
>
> (with-eval-after-load 'sh
Try this:
(with-eval-after-load 'sh-script
(message "My cool one-time config follows here ..."))
sh-mode is defined in lisp/progmodes/sh-script.el.
^ permalink raw reply [flat|nested] 19+ messages in thread
* with-eval-after-load with sh-mode
2021-07-02 8:42 ` Arthur Miller
@ 2021-07-02 8:49 ` lisa-asket
2021-07-02 8:56 ` Arthur Miller
0 siblings, 1 reply; 19+ messages in thread
From: lisa-asket @ 2021-07-02 8:49 UTC (permalink / raw)
To: Arthur Miller; +Cc: help-gnu-emacs
>From: Arthur Miller <arthur.miller@live.com>
>To: lisa-asket@perso.be
>Subject: Re: with-eval-after-load with sh-mode
>Date: 02/07/2021 10:42:38 Europe/Paris
>Cc: help-gnu-emacs@gnu.org
>lisa-asket@perso.be writes:
>> How can I use `with-eval-after-load` with sh-mode?
>>
>> Basically I want to defer call to sh-mode-map until sh-mode is loaded
>>
>> (with-eval-after-load 'sh
>Try this:
>(with-eval-after-load 'sh-script
>(message "My cool one-time config follows here ..."))
>sh-mode is defined in lisp/progmodes/sh-script.el.
What is the difference between
(with-eval-after-load 'sh-script
(myfun))
and
(add-hook 'sh-mode-hook #'myfun)
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 8:49 ` lisa-asket
@ 2021-07-02 8:56 ` Arthur Miller
2021-07-02 10:35 ` lisa-asket
0 siblings, 1 reply; 19+ messages in thread
From: Arthur Miller @ 2021-07-02 8:56 UTC (permalink / raw)
To: lisa-asket; +Cc: help-gnu-emacs
lisa-asket@perso.be writes:
>>From: Arthur Miller <arthur.miller@live.com>
>>To: lisa-asket@perso.be
>>Subject: Re: with-eval-after-load with sh-mode
>>Date: 02/07/2021 10:42:38 Europe/Paris
>>Cc: help-gnu-emacs@gnu.org
>
>>lisa-asket@perso.be writes:
>
>>> How can I use `with-eval-after-load` with sh-mode?
>>>
>>> Basically I want to defer call to sh-mode-map until sh-mode is loaded
>>>
>>> (with-eval-after-load 'sh
>
>>Try this:
>
>>(with-eval-after-load 'sh-script
>>(message "My cool one-time config follows here ..."))
>
>>sh-mode is defined in lisp/progmodes/sh-script.el.
>
> What is the difference between
>
> (with-eval-after-load 'sh-script
> (myfun))
>
> and
>
> (add-hook 'sh-mode-hook #'myfun)
Obviously sh-mode-hook gets executed every time you load sh-mode, i.e,
when you open a shell file.
eval after load will kick in when feature is loaded, i.e. when you read
in (load or require) sh-script.el, so it least in theory it should get
executed only once, unless you unload feature 'sh-script for some reason.
^ permalink raw reply [flat|nested] 19+ messages in thread
* with-eval-after-load with sh-mode
2021-07-02 8:56 ` Arthur Miller
@ 2021-07-02 10:35 ` lisa-asket
2021-07-02 13:08 ` Arthur Miller
0 siblings, 1 reply; 19+ messages in thread
From: lisa-asket @ 2021-07-02 10:35 UTC (permalink / raw)
To: Arthur Miller; +Cc: help-gnu-emacs
>From: Arthur Miller <arthur.miller@live.com>
>To: lisa-asket@perso.be
>Subject: Re: with-eval-after-load with sh-mode
>Date: 02/07/2021 10:56:14 Europe/Paris
>Cc: help-gnu-emacs@gnu.org
>lisa-asket@perso.be writes:
>>From: Arthur Miller <arthur.miller@live.com>
>>To: lisa-asket@perso.be
>>Subject: Re: with-eval-after-load with sh-mode
>>Date: 02/07/2021 10:42:38 Europe/Paris
>>Cc: help-gnu-emacs@gnu.org
>
>>lisa-asket@perso.be writes:
>
>>> How can I use `with-eval-after-load` with sh-mode?
>>>
>>> Basically I want to defer call to sh-mode-map until sh-mode is loaded
>>>
>>> (with-eval-after-load 'sh
>
>>Try this:
>
>>(with-eval-after-load 'sh-script
>>(message "My cool one-time config follows here ..."))
>
>>sh-mode is defined in lisp/progmodes/sh-script.el.
>
> What is the difference between
>
> (with-eval-after-load 'sh-script
> (myfun))
>
> and
>
> (add-hook 'sh-mode-hook #'myfun)
>Obviously sh-mode-hook gets executed every time you load sh-mode, i.e,
>when you open a shell file.
>eval after load will kick in when feature is loaded, i.e. when you read
>in (load or require) sh-script.el, so it least in theory it should get
>executed only once, unless you unload feature 'sh-script for some reason.
This leads to another consideraion. There are certainly advantages about using
`with-eval-after-load`. But, then, what are the circumstances for using `add-hook`?
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: with-eval-after-load with sh-mode
2021-07-02 10:35 ` lisa-asket
@ 2021-07-02 13:08 ` Arthur Miller
0 siblings, 0 replies; 19+ messages in thread
From: Arthur Miller @ 2021-07-02 13:08 UTC (permalink / raw)
To: lisa-asket; +Cc: help-gnu-emacs
lisa-asket@perso.be writes:
>>From: Arthur Miller <arthur.miller@live.com>
>>To: lisa-asket@perso.be
>>Subject: Re: with-eval-after-load with sh-mode
>>Date: 02/07/2021 10:56:14 Europe/Paris
>>Cc: help-gnu-emacs@gnu.org
>
>>lisa-asket@perso.be writes:
>
>>>From: Arthur Miller <arthur.miller@live.com>
>>>To: lisa-asket@perso.be
>>>Subject: Re: with-eval-after-load with sh-mode
>>>Date: 02/07/2021 10:42:38 Europe/Paris
>>>Cc: help-gnu-emacs@gnu.org
>>
>>>lisa-asket@perso.be writes:
>>
>>>> How can I use `with-eval-after-load` with sh-mode?
>>>>
>>>> Basically I want to defer call to sh-mode-map until sh-mode is loaded
>>>>
>>>> (with-eval-after-load 'sh
>>
>>>Try this:
>>
>>>(with-eval-after-load 'sh-script
>>>(message "My cool one-time config follows here ..."))
>>
>>>sh-mode is defined in lisp/progmodes/sh-script.el.
>>
>> What is the difference between
>>
>> (with-eval-after-load 'sh-script
>> (myfun))
>>
>> and
>>
>> (add-hook 'sh-mode-hook #'myfun)
>
>>Obviously sh-mode-hook gets executed every time you load sh-mode, i.e,
>>when you open a shell file.
>
>>eval after load will kick in when feature is loaded, i.e. when you read
>>in (load or require) sh-script.el, so it least in theory it should get
>>executed only once, unless you unload feature 'sh-script for some reason.
>
> This leads to another consideraion. There are certainly advantages about using
> `with-eval-after-load`. But, then, what are the circumstances for using `add-hook`?
As said above: the circustance is when you wish a piece of code to run
every time a mode is loaded.
You should probably read the fine manual:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html
https://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks-for-Loading.html
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2021-07-03 1:17 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-02 5:59 with-eval-after-load with sh-mode lisa-asket
2021-07-02 6:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 7:32 ` lisa-asket
2021-07-02 13:14 ` Arthur Miller
2021-07-02 15:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 16:57 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-02 17:02 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-02 17:15 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-02 18:30 ` lisa-asket
2021-07-02 20:59 ` Arthur Miller
2021-07-02 23:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-03 1:01 ` Arthur Miller
2021-07-03 1:17 ` lisa-asket
2021-07-02 8:21 ` lisa-asket
2021-07-02 8:42 ` Arthur Miller
2021-07-02 8:49 ` lisa-asket
2021-07-02 8:56 ` Arthur Miller
2021-07-02 10:35 ` lisa-asket
2021-07-02 13:08 ` Arthur Miller
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.