* minor-mode hook not run
@ 2018-03-20 18:39 Andreas Röhler
2018-03-20 20:31 ` John Shahid
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andreas Röhler @ 2018-03-20 18:39 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi,
writing a minor-mode, whose hook should do some setup
(define-minor-mode foo
"Do something" nil " FOO"}
:keymap foo-map
(cond
((eq major-mode 'abc)
(add-hook 'foo-mode-hook 'foo-load-abc nil t)
;; (funcall 'foo-load-abc)
)
...
Unfortunately, while the function ‘foo-load-abc-mode’ is present in the
hook, it is not called.
While uncommenting the funcall shown would set up the vars.
Any idea, while this as a hook has no effect?
Thanks,
Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: minor-mode hook not run
2018-03-20 18:39 minor-mode hook not run Andreas Röhler
@ 2018-03-20 20:31 ` John Shahid
2018-03-20 20:31 ` Stefan Monnier
[not found] ` <mailman.10975.1521577943.27995.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 7+ messages in thread
From: John Shahid @ 2018-03-20 20:31 UTC (permalink / raw)
To: Andreas Röhler; +Cc: Help Gnu Emacs mailing list
i think the hook will be called `foo-hook' not `foo-mode-hook'
Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
> Hi,
>
> writing a minor-mode, whose hook should do some setup
>
> (define-minor-mode foo
> "Do something" nil " FOO"}
> :keymap foo-map
> (cond
> ((eq major-mode 'abc)
> (add-hook 'foo-mode-hook 'foo-load-abc nil t)
> ;; (funcall 'foo-load-abc)
> )
> ...
>
> Unfortunately, while the function ‘foo-load-abc-mode’ is present in the hook,
> it is not called.
>
> While uncommenting the funcall shown would set up the vars.
>
> Any idea, while this as a hook has no effect?
>
> Thanks,
>
> Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: minor-mode hook not run
2018-03-20 18:39 minor-mode hook not run Andreas Röhler
2018-03-20 20:31 ` John Shahid
@ 2018-03-20 20:31 ` Stefan Monnier
2018-03-21 11:57 ` Andreas Röhler
[not found] ` <mailman.10975.1521577943.27995.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2018-03-20 20:31 UTC (permalink / raw)
To: help-gnu-emacs
> (define-minor-mode foo
^^^
This should likely be `foo-mode`.
> "Do something" nil " FOO"}
Is the above } intended?
> :keymap foo-map
[ I strongly recommend not to use :keymap argument and just name your
minor mode map `<MINORMODE>-map`. ]
> (cond
> ((eq major-mode 'abc)
It's usually better to test (derived-mode-p 'abc).
> (add-hook 'foo-mode-hook 'foo-load-abc nil t)
Adding elements to one's own hook here definitely deserve a "bug ugly
hack" comment explaining why you'd want to do it that way.
In any case, the minor mode `foo` will run `foo-hook` but not
`foo-mode-hook` (which would be run by the `foo-mode` minor mode).
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: minor-mode hook not run
[not found] ` <mailman.10975.1521577943.27995.help-gnu-emacs@gnu.org>
@ 2018-03-20 21:17 ` Emanuel Berg
0 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg @ 2018-03-20 21:17 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier wrote:
> Adding elements to one's own hook here
> definitely deserve a "bug ugly hack" comment
> explaining why you'd want to do it that way.
>
> In any case, the minor mode `foo` will run
> `foo-hook` but not `foo-mode-hook` (which
> would be run by the `foo-mode` minor mode).
Callings things foo isn't encouraged BTW.
It finds its way into "production code" soon
enough. If it is just a joke intended for
personal computer exploration, instead make
something up: make it replace the char at point
by the next char in the English alphabet, and
call it "abc-mode", or whatever, just not foo,
bar, foobar, main, or anything like that.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: minor-mode hook not run
2018-03-20 20:31 ` Stefan Monnier
@ 2018-03-21 11:57 ` Andreas Röhler
2018-03-22 13:52 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Röhler @ 2018-03-21 11:57 UTC (permalink / raw)
To: help-gnu-emacs
On 20.03.2018 21:31, Stefan Monnier wrote:
>> (define-minor-mode foo
> ^^^
> This should likely be `foo-mode`.
>
>> "Do something" nil " FOO"}
>
> Is the above } intended?
No, it's a typo, sorry.
>
>> :keymap foo-map
>
> [ I strongly recommend not to use :keymap argument and just name your
> minor mode map `<MINORMODE>-map`. ]
>
>> (cond
>> ((eq major-mode 'abc)
>
> It's usually better to test (derived-mode-p 'abc).
Okay, done.
>
>> (add-hook 'foo-mode-hook 'foo-load-abc nil t)
>
> Adding elements to one's own hook here definitely deserve a "bug ugly
> hack" comment explaining why you'd want to do it that way.
Hmm, not sure if I understand that part.
Purpose is a generic key for related commands:
For example to start a REPL, haskell-mode calls
‘haskell-interactive-switch’, python.el calls ‘run-python’,
python-mode.el ‘py-shell’ etc.
Instead of remembering different keys and change them maybe at several
locations, a unified command ‘gk-repl’ is provided, whose key-binding
should DTRT in all modes.
For the audacious:
https://github.com/andreas-roehler/general-key
>
> In any case, the minor mode `foo` will run `foo-hook` but not
> `foo-mode-hook` (which would be run by the `foo-mode` minor mode).
>
That solved it, thanks all,
Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: minor-mode hook not run
2018-03-21 11:57 ` Andreas Röhler
@ 2018-03-22 13:52 ` Stefan Monnier
2018-03-23 12:46 ` Andreas Röhler
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2018-03-22 13:52 UTC (permalink / raw)
To: help-gnu-emacs
>>> (add-hook 'foo-mode-hook 'foo-load-abc nil t)
>> Adding elements to one's own hook here definitely deserve a "bug ugly
>> hack" comment explaining why you'd want to do it that way.
> Hmm, not sure if I understand that part.
I'm saying that adding to <FOO>-mode-hook from within the body of
<FOO>-mode is weird.
Instead of
(define-minor-mode foo-mode
...
(add-hook 'foo-mode-hook #'blabla nil t)
...)
why not do the more natural:
(define-minor-mode foo-mode
...
(blabla)
...)
The "big ugly hack" comment should explain why the `add-hook` version
is needed.
> Purpose is a generic key for related commands:
> For example to start a REPL, haskell-mode calls
> ‘haskell-interactive-switch’, python.el calls ‘run-python’,
> python-mode.el ‘py-shell’ etc.
>
> Instead of remembering different keys and change them maybe at several
> locations, a unified command ‘gk-repl’ is provided, whose key-binding
> should DTRT in all modes.
I don't see how this explains why you need to go through foo-mode-hook
rather than calling the function directly.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: minor-mode hook not run
2018-03-22 13:52 ` Stefan Monnier
@ 2018-03-23 12:46 ` Andreas Röhler
0 siblings, 0 replies; 7+ messages in thread
From: Andreas Röhler @ 2018-03-23 12:46 UTC (permalink / raw)
To: help-gnu-emacs
On 22.03.2018 14:52, Stefan Monnier wrote:
>>>> (add-hook 'foo-mode-hook 'foo-load-abc nil t)
>>> Adding elements to one's own hook here definitely deserve a "bug ugly
>>> hack" comment explaining why you'd want to do it that way.
>> Hmm, not sure if I understand that part.
>
> I'm saying that adding to <FOO>-mode-hook from within the body of
> <FOO>-mode is weird.
>
> Instead of
>
> (define-minor-mode foo-mode
> ...
> (add-hook 'foo-mode-hook #'blabla nil t)
> ...)
>
> why not do the more natural:
>
> (define-minor-mode foo-mode
> ...
> (blabla)
> ...)
>
> The "big ugly hack" comment should explain why the `add-hook` version
> is needed.
>
>> Purpose is a generic key for related commands:
>> For example to start a REPL, haskell-mode calls
>> ‘haskell-interactive-switch’, python.el calls ‘run-python’,
>> python-mode.el ‘py-shell’ etc.
>>
>> Instead of remembering different keys and change them maybe at several
>> locations, a unified command ‘gk-repl’ is provided, whose key-binding
>> should DTRT in all modes.
>
> I don't see how this explains why you need to go through foo-mode-hook
> rather than calling the function directly.
>
Okay, got it, thanks,
Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-03-23 12:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-20 18:39 minor-mode hook not run Andreas Röhler
2018-03-20 20:31 ` John Shahid
2018-03-20 20:31 ` Stefan Monnier
2018-03-21 11:57 ` Andreas Röhler
2018-03-22 13:52 ` Stefan Monnier
2018-03-23 12:46 ` Andreas Röhler
[not found] ` <mailman.10975.1521577943.27995.help-gnu-emacs@gnu.org>
2018-03-20 21:17 ` Emanuel Berg
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).