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?)

  • Welcome to emacs.SE! Please consider moving the second question in a separate post. – JeanPierre Sep 1 at 15:53
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)))
  • 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! – Prospero Sep 2 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.