joostkremers / writeroom-mode

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

hide line number with a hook #59

Closed chmol closed 4 years ago

chmol commented 4 years ago

Hello,

I'm enjoying this packages but I have the following issues: line number are displayed when the mode is started which is expected as I have the following in my init.el

(global-display-line-numbers-mode 1)
(setq display-line-numbers-type 'visual)

But I fail hiding them when I add a specific hook

(add-hook 'writeroom-mode-hook (lambda () (display-line-numbers-mode nil) ))

or

(add-hook 'writeroom-mode-hook (lambda () (setq-local display-line-numbers nil)))

Am I missing something?

Thanks,

joostkremers commented 4 years ago

Disabling a minor mode in Elisp is done by passing e.g., -1 to the function. If you pass nil, the mode is actually enabled, not disabled.

That's counter-intuitive, but the reason is that it allows for activating a minor mode just by adding its function name to a mode hook.

(add-hook 'prog-mode-hook 'display-line-numbers-mode)

This calls the function display-line-numbers-mode without any argument, but internally there is no distinction between calling a function with no arguments and calling it with the argument nil.

So basically, your first invocation is actually the same as the line above...

If you do:

(add-hook 'writeroom-mode-hook (lambda () (display-line-numbers-mode -1)))

it should work.

Why setting the variable display-line-numbers directly doesn't work, I don't know.

chmol commented 4 years ago

Thank you so much for taking the time to explain the logic behind it. Its working and my writing environment is perfect !

joostkremers commented 4 years ago

Glad it's working!