I want to customize the behavior of global-whitespace-mode on a per-major-mode basis, and also define some interactive commands that change what's being highlighted on a per-buffer basis. global-whitespace-mode does something rather more complicated than just turning on whitespace-mode in every buffer, I don't particularly understand why, but anyway it's getting in the way of me writing those interactive commands. Specifically, this function works as a mode hook but not as an interactive command:

(defun turn-off-highlight-long-lines ()
  "Turn off highlighting of long lines via global-whitespace-mode."
  (let* ((already-active-p (local-variable-p 'whitespace-active-style))
          (delq 'lines (copy-sequence (if already-active-p
    (if already-active-p
        (progn (setq whitespace-active-style desired-style)
      (setq-local whitespace-style desired-style))))

But this seems to be exactly what (global-)whitespace-toggle-options does, except buffer-locally, so I'm stumped.

(I'm not using (global-)whitespace-toggle-options because I want the effect to be buffer-local.)

  • M-x whitespace-toggle-options is buffer-local for me; what was making you think it wasn't? I often do M-x whitespace-toggle-options L to turn off long line visualization in a specific buffer. Commented Dec 29, 2020 at 16:48
  • It's possible that I misunderstood the code and/or tested it wrong, but it sure seems like M-x whitespace-toggle-options globally changes the options for local whitespace-mode, and therefore both has no effect because I'm only using global-whitespace-mode, and wouldn't do what I want anyway.
    – zwol
    Commented Dec 29, 2020 at 17:21
  • Ah, I'm sure it's my fault: turns out I don't use global-whitespace-mode. Personally I enable whitespace-mode early in my config, then in certain mode hooks (like in go-mode-hook), I do a (whitespace-toggle-options '(lines-tail). That doesn't answer your question but hopefully it helps give some ideas! Commented Dec 29, 2020 at 17:34


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.