joostkremers / writeroom-mode

Writeroom-mode: distraction-free writing for Emacs.
BSD 3-Clause "New" or "Revised" License
607 stars 28 forks source link

writeroom-mode-disable-hook does nothing #63

Closed juacq97 closed 4 years ago

juacq97 commented 4 years ago

Hi! I want to change the font to a proportional one instead of the mono font I normally use when I run writeroom-mode, so I tried this:

      (use-package writeroom-mode
    :ensure t
    :bind ("<f6>" . writeroom-mode))

    (add-hook 'writeroom-mode-hook
          #'(lambda ()
        (variable-pitch-mode 1)))

    (add-hook 'writeroom-mode-disable-hook
         #'(lambda ()
           (variable-pitch-mode -1)))

When I enable writeroom-mode the font change as expected, but when I disable it, the font remains, I need to manually disable varible-pitch-font. I tried to disable the line numbers too, but the same happens, the numbers dissapers when writeroom-mode is enabled, but don't return when writeroom-mode is disabled. I'm doing something wrong with the writeroom-mode-disable-hook? Thanks!!

joostkremers commented 4 years ago

Hm, issue #62 seems to be about the exact same problem. It could be that writeroom-mode-disable-hook is called in the wrong context, but I'll need a bit more time to look into this than I have right now. I'll try to get back to this in a few days.

joostkremers commented 4 years ago

Hi, my apologies it took so long, but I think I've now been able to fix this issue. The problem turns out to be that minor mode hooks are also run when a minor mode is disabled. So activating variable-pitch-mode in writeroom-mode-hook has the effect that variable-pitch is activated again right after it was deactivated in writeroom-mode-disable-hook.

I've added a hook writeroom-mode-enable-hook which only gets run when writeroom-mode is enabled, so you could use that instead of writeroom-mode-hook. But I also added a user option writeroom-local-effects, which can be used instead:

(add-hook 'writeroom-local-effects 'variable-pitch-mode)

Functions in this "abnormal" hook are called with the argument 1 when writeroom-mode is enabled and with -1 when it is disabled, so you can just drop some minor mode on it and it will be handled correctly.

Thanks for reporting this bug and please let me know if you still run into problems.