* add-hook without need for intermediate functions
@ 2023-06-09 15:48 uzibalqa
2023-06-09 16:56 ` [External] : " Drew Adams
2023-06-10 8:20 ` Platon Pronko
0 siblings, 2 replies; 10+ messages in thread
From: uzibalqa @ 2023-06-09 15:48 UTC (permalink / raw)
To: uzibalqa via Users list for the GNU Emacs text editor
I have seen that since Emacs 24.1 one does not need the intermediate 'turn-on-foo-mode'
style functions when using hooks.
Does this apply to all modes, including minor modes ?
And thusly one can write
(add-hook 'emacs-lisp-mode-hook #'foo-minor-mode)
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : add-hook without need for intermediate functions
2023-06-09 15:48 add-hook without need for intermediate functions uzibalqa
@ 2023-06-09 16:56 ` Drew Adams
2023-06-09 17:05 ` uzibalqa
2023-06-10 8:20 ` Platon Pronko
1 sibling, 1 reply; 10+ messages in thread
From: Drew Adams @ 2023-06-09 16:56 UTC (permalink / raw)
To: uzibalqa, uzibalqa via Users list for the GNU Emacs text editor
> I have seen that since Emacs 24.1 one does not need the intermediate
> 'turn-on-foo-mode' style functions when using hooks.
>
> Does this apply to all modes, including minor modes ?
> And thusly one can write
> (add-hook 'emacs-lisp-mode-hook #'foo-minor-mode)
See `define-globalized-minor-mode'.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Minor-Modes.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : add-hook without need for intermediate functions
2023-06-09 16:56 ` [External] : " Drew Adams
@ 2023-06-09 17:05 ` uzibalqa
2023-06-09 17:15 ` Drew Adams
0 siblings, 1 reply; 10+ messages in thread
From: uzibalqa @ 2023-06-09 17:05 UTC (permalink / raw)
To: Drew Adams; +Cc: uzibalqa via Users list for the GNU Emacs text editor
------- Original Message -------
On Saturday, June 10th, 2023 at 4:56 AM, Drew Adams <drew.adams@oracle.com> wrote:
> > I have seen that since Emacs 24.1 one does not need the intermediate
> > 'turn-on-foo-mode' style functions when using hooks.
> >
> > Does this apply to all modes, including minor modes ?
> > And thusly one can write
> > (add-hook 'emacs-lisp-mode-hook #'foo-minor-mode)
>
>
> See `define-globalized-minor-mode'.
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Minor-Modes.html
I do not follow how to extract the information in your link to answer my question.
My focus is only about a simple minor mode rather than a globalised one.
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : add-hook without need for intermediate functions
2023-06-09 17:05 ` uzibalqa
@ 2023-06-09 17:15 ` Drew Adams
2023-06-09 17:30 ` uzibalqa
2023-06-09 20:07 ` Emanuel Berg
0 siblings, 2 replies; 10+ messages in thread
From: Drew Adams @ 2023-06-09 17:15 UTC (permalink / raw)
To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor
> I do not follow how to extract the information in your link to answer my
> question.
> My focus is only about a simple minor mode rather than a globalised one.
Reread what you asked:
Does not needing a `turn-on-foo-mode' function
apply to all modes, including minor modes?
The doc I cited tells you that that not-needing
doesn't apply to globalized minor modes.
That's the only occurrence of "turn-on" in the
Elisp manual.
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : add-hook without need for intermediate functions
2023-06-09 17:15 ` Drew Adams
@ 2023-06-09 17:30 ` uzibalqa
2023-06-09 20:07 ` Emanuel Berg
1 sibling, 0 replies; 10+ messages in thread
From: uzibalqa @ 2023-06-09 17:30 UTC (permalink / raw)
To: Drew Adams; +Cc: uzibalqa via Users list for the GNU Emacs text editor
------- Original Message -------
On Saturday, June 10th, 2023 at 5:15 AM, Drew Adams <drew.adams@oracle.com> wrote:
> > I do not follow how to extract the information in your link to answer my
> > question.
> > My focus is only about a simple minor mode rather than a globalised one.
>
>
> Reread what you asked:
>
> Does not needing a `turn-on-foo-mode' function
> apply to all modes, including minor modes?
>
> The doc I cited tells you that that not-needing
> doesn't apply to globalized minor modes.
>
> That's the only occurrence of "turn-on" in the
> Elisp manual.
I mean this
(add-hook 'emacs-lisp-mode-hook #'foo-minor-mode)
versus this
(defun turn-on-foo ()
"Enable foo"
(foo-minor-mode 1)
)
(add-hook 'emacs-lisp-mode-hook #'turn-on-foo)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [External] : add-hook without need for intermediate functions
2023-06-09 17:15 ` Drew Adams
2023-06-09 17:30 ` uzibalqa
@ 2023-06-09 20:07 ` Emanuel Berg
2023-06-10 21:05 ` Drew Adams
1 sibling, 1 reply; 10+ messages in thread
From: Emanuel Berg @ 2023-06-09 20:07 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams wrote:
> The doc I cited tells you that that not-needing doesn't
> apply to globalized minor modes.
What's a globalized minor mode?
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: add-hook without need for intermediate functions
2023-06-09 15:48 add-hook without need for intermediate functions uzibalqa
2023-06-09 16:56 ` [External] : " Drew Adams
@ 2023-06-10 8:20 ` Platon Pronko
2023-06-10 15:21 ` uzibalqa
1 sibling, 1 reply; 10+ messages in thread
From: Platon Pronko @ 2023-06-10 8:20 UTC (permalink / raw)
To: uzibalqa, uzibalqa via Users list for the GNU Emacs text editor
On 2023-06-09 23:48, uzibalqa wrote:
>
> I have seen that since Emacs 24.1 one does not need the intermediate 'turn-on-foo-mode'
> style functions when using hooks.
>
> Does this apply to all modes, including minor modes ?
>
> And thusly one can write
>
> (add-hook 'emacs-lisp-mode-hook #'foo-minor-mode)
>
>
>
foo-minor-mode is just a function, so it is called when hook executes. Any other modes that are turned on via a single function call will also "work".
However note that this won't work for your use-case (from previous thread) - hook is called both when mode is turned on, and when it is turned off. So in your code snippet foo-minor-mode will be turned on when emacs-lisp-mode is turned off, which is probably not something you would want.
--
Best regards,
Platon Pronko
PGP 2A62D77A7A2CB94E
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: add-hook without need for intermediate functions
2023-06-10 8:20 ` Platon Pronko
@ 2023-06-10 15:21 ` uzibalqa
2023-06-11 1:37 ` Platon Pronko
0 siblings, 1 reply; 10+ messages in thread
From: uzibalqa @ 2023-06-10 15:21 UTC (permalink / raw)
To: Platon Pronko; +Cc: uzibalqa via Users list for the GNU Emacs text editor
------- Original Message -------
On Saturday, June 10th, 2023 at 8:20 PM, Platon Pronko <platon7pronko@gmail.com> wrote:
> On 2023-06-09 23:48, uzibalqa wrote:
>
> > I have seen that since Emacs 24.1 one does not need the intermediate 'turn-on-foo-mode'
> > style functions when using hooks.
> >
> > Does this apply to all modes, including minor modes ?
> >
> > And thusly one can write
> >
> > (add-hook 'emacs-lisp-mode-hook #'foo-minor-mode)
>
>
> foo-minor-mode is just a function, so it is called when hook executes. Any other modes that are turned on via a single function call will also "work".
>
> However note that this won't work for your use-case (from previous thread) - hook is called both when mode is turned on, and when it is turned off. So in your code snippet foo-minor-mode will be turned on when emacs-lisp-mode is turned off, which is probably not something you would want. - Platon Pronko
What would one do then, remove the hook at some point. Would you show me an example on how to handle the situation
properly.
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [External] : add-hook without need for intermediate functions
2023-06-09 20:07 ` Emanuel Berg
@ 2023-06-10 21:05 ` Drew Adams
0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2023-06-10 21:05 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs@gnu.org
> > The doc I cited tells you that that not-needing
> > [a TURN-ON function] doesn't apply to globalized
> > minor modes.
>
> What's a globalized minor mode?
Ask Emacs:
C-h i m Elisp RET
i globali TAB RET
____
You can define a global minor mode directly
(from scratch), with macro `define-minor-mode'
and keyword arg `:global t'.
You can define a global minor mode indirectly,
based on a buffer-local minor mode, with macro
`define-globalized-minor-mode'. For this you
need to provide a TURN-ON function.
____
Turn on, tune in, drop out - globally or buffer
locally.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: add-hook without need for intermediate functions
2023-06-10 15:21 ` uzibalqa
@ 2023-06-11 1:37 ` Platon Pronko
0 siblings, 0 replies; 10+ messages in thread
From: Platon Pronko @ 2023-06-11 1:37 UTC (permalink / raw)
To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor
>> However note that this won't work for your use-case (from previous thread) - hook is called both when mode is turned on, and when it is turned off. So in your code snippet foo-minor-mode will be turned on when emacs-lisp-mode is turned off, which is probably not something you would want. - Platon Pronko
>
> What would one do then, remove the hook at some point. Would you show me an example on how to handle the situation
> properly.
>
Here's an example I've sent in one of previous emails:
(defun tematika--toggle-outline-mode ()
(if tematika-minor-mode
(outline-minor-mode)
(outline-minor-mode -1)))
(add-hook 'tematika-minor-mode-hook 'tematika--toggle-outline-mode)
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-06-11 1:37 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-09 15:48 add-hook without need for intermediate functions uzibalqa
2023-06-09 16:56 ` [External] : " Drew Adams
2023-06-09 17:05 ` uzibalqa
2023-06-09 17:15 ` Drew Adams
2023-06-09 17:30 ` uzibalqa
2023-06-09 20:07 ` Emanuel Berg
2023-06-10 21:05 ` Drew Adams
2023-06-10 8:20 ` Platon Pronko
2023-06-10 15:21 ` uzibalqa
2023-06-11 1:37 ` Platon Pronko
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).