1

I would like to have whitespace-newline-mode enabled every time visual-line-mode is enabled, and disabled correspondingly.

The documentation on "visual-line-mode-hook" says "Hook run after entering or leaving `visual-line-mode'."

I put this in my .emacs :

(add-hook 'visual-line-mode-hook #'whitespace-newline-mode)

When I go into visual-line-mode, I can see the newlines as desired. However, when I go out of visual-line-mode, the newlines are still there, and I have to manually run whitespace-newline-mode to disable it.

Is the visual-line-mode-hook documentation just wrong, or am I missing something fundamental about add-hook here?

(As an aside: how do I configure the color of the newline characters that are displayed when I run whitespace-newline-mode?)

1
  • Welcome to emacs.SE! Please consider moving the second question in a separate post. Commented Sep 1, 2019 at 15:53

1 Answer 1

1

The doc string of whitespace-newline-mode (C-h f whitespace-newline-mode) 'includes:

(whitespace-newline-mode &optional ARG)

Toggle newline visualization (Whitespace Newline mode). With a prefix argument ARG, enable Whitespace Newline mode if ARG is positive, and disable it otherwise.

If called from Lisp, also enables the mode if ARG is omitted or nil, and toggles it if ARG is ‘toggle’.

As you see, the behavior when executed from lisp code is not the same as when executed interactively. So, assuming whitespace-newline-mode is disabled by default, you could use:

(add-hook 'visual-line-mode-hook (lambda () (whitespace-newline-mode 'toggle))) 
1
  • d'oh! It didn't occur to me to check the docstring on whitespace-newline-mode. That should have been the obvious thing to do. Thanks for the tip! Commented Sep 2, 2019 at 16:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.