jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.39k stars 259 forks source link

Cannot add hooks to elpher-mode-hook #890

Closed Munksgaard closed 3 years ago

Munksgaard commented 3 years ago

Elpher is my favorite way of browsing gemini- and gopherspace. It feels natural and intuitive to use. However, it shows lots of trailing whitespace, for some reason. In my .emacs I have globally enabled show-trailing-whitespace. That makes many gopher and gemini pages render with ugly red boxes all over. I therefore wanted to disable show-trailing-whitespace in elpher buffers, and put the following in my .emacs:

(use-package elpher
  :ensure t
  :config
  (add-hook 'elper-mode-hook
            (lambda ()
              (setq show-trailing-whitespace nil))))

But it doesn't seem to work? When I inspect elpher-mode-hook afterwards, it's still nil, as if the hook never ran. What gives?

rprimus commented 3 years ago

Sat Dec 12 08:22:28 GMT 2020

HI @Munksgaard ,

From the elpher source code, elpher does not have any hooks.

This could be discovered by trying to search for the variable elpher-mode-hook using describe-variable: M-x describe-variable.

As elpher-mode is derived from special-mode you could instead add the lambda to special-mode-hook.

Alternatively, (setq-local show-trailing-whitespace nil) in :config should work.

Munksgaard commented 3 years ago

Hi @rprimus

That's odd, when I C-h v elpher-mode-hook I get the following:

elpher-mode-hook is a variable defined in ‘elpher.el’.
Its value is nil

  This variable may be risky if used as a file-local variable.

Documentation:
Hook run after entering elpher mode.
No problems result if this variable is not bound.
‘add-hook’ automatically binds it.  (This is true for all hook variables.)

Where does that hook come from, then? I'm confused...

Munksgaard commented 3 years ago

Alternatively, (setq-local show-trailing-whitespace nil) in :config should work.

This also doesn't seem to work for some reason. Could there be something else wrong with my setup?

rprimus commented 3 years ago

Sat Dec 12 10:29:01 GMT 2020

Where does that hook come from, then?

My bad. elpher-mode-hook gets created when elpher-mode is defined (by call to macro define-derived-mode). After setting up elpher in a vanilla emacs session (emacs -Q), I am seeing show-trailing-whitespace as a buffer local variable.

Please try the following:

  1. In current setup, when in elpher-mode, M-x describe-mode.
    • Does whitespace-mode show as an active mode?
    • Toggle whitespace-mode - do the red areas disappear?
  2. Change the lambda to:
    (lambda ()
    (whitespace-mode -1))
  3. Save file and restart emacs, enable elpher-mode and: (a) See if the 'red' is still showing

This also doesn't seem to work for some reason. Could there be something else wrong with my setup?

(b) If it is,  there may be another mode that is re-enabling `whitespace-mode` and/or resetting
      the value of `show-trailing-whitespace`.
Munksgaard commented 3 years ago

This was all my silly mistake. See if you can spot the typo in my configuration code.

Thanks @rprimus for helping out!