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

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

Re: minor-mode hook not run


From: Andreas Röhler
Subject: Re: minor-mode hook not run
Date: Fri, 23 Mar 2018 13:46:46 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

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




reply via email to

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