Turn off Emacs Whitespace-mode "Long Line" Visualization
Asked Answered
P

3

14

I personally keep all lines under 80 characters, but I also work on projects in teams where other programmers don't care about line length.

I love using whitespace-mode, but the long line visualization is really annoying when I'm working on projects where I shouldn't interfere with the long lines. It seems like it should be easy to turn off the long line visualization---I hit m-x global-whitespace-toggle-options l, and then can hit m-x global-whitespace-toggel-options ? to confirm that the "long-line visualization" is turned off. But long lines are still highlighted. I kill buffers and reload them, and highlighting is still there. I'm definitely using global, not local, whitespace-mode.

Why can't I turn off the long line visualization?

Prosector answered 29/7, 2011 at 23:40 Comment(1)
Without wanting to sound like Roy from "The I.T. Crowd", have you tried turning white-space-mode off and on again in your buffer after toggling the global options?Revanchism
R
11

The last time I customized whitespace-mode, I noticed that my changes to the settings didn't have any effect in buffers that already existed; try recreating the buffer, or leaving and reentering whitespace-mode. In case you don't already know, you can use M-x customize-group whitespace to turn off that particular option entirely, rather than doing it manually.

Edit: Specifically you want to customize the whitespace-style variable. This lets you turn on and off individual styles. In this case you should turn off the ones labelled "(Face) Lines" and "(Face) Lines, only overlong part". The former changes the face of the whole line when it is overly long, while the latter only changes the face of the part that extends past the threshold.

(Other options in this group define the faces that whitespace-mode will use to highlight the styles you've turned on, the regexes it uses to identify certain situations, etc, but usually you only care about whitespace-style).

Ripuarian answered 30/7, 2011 at 4:28 Comment(3)
Note that you can turn off the long-line "validation" by customizing the "Whitespace style" setting, and removing line-tail or similar.Exo
This doesn't really answer the question though, I mean, what do we change in M-x customize group? I have changed the "Whitespace Line Face" (i.e. turned it off and saved) several times and nothing changes.Poul
I've edited my answer to be more specific, but note that my answer was more to the question of why changing the setting didn't update the buffer. You generally have to close and reopen the buffer before these settings are applied. On the other hand, editing a face (as opposed to updating the style variable) should update everything using that face immediately; perhaps you were editing the wrong face?Ripuarian
R
5

Set whitespace-line-column to a higher value (default is 80), so the highlighting of long lines doesn't kick in:

(setq whitespace-line-column 250)

Rousing answered 23/11, 2011 at 21:48 Comment(2)
why use a hack when you can just toggle it off?Neotropical
@EugeneBeresovsky Because this is the only answer that actually works.Poul
C
2

I'm assuming that you already have whitespace-mode activated somewhere in your init.el or similar. If so, you can adapt duma's comment above, and either

  • Edit the elisp that sets whitespace-style to remove lines-tail. E.g., Emacs Prelude sets

    (setq whitespace-style '(face tabs empty trailing lines-tail))

    Simply change that to

    (setq whitespace-style '(face tabs empty trailing))

  • If you don't want to directly edit that elisp, but rather override it later with your own code, do something like

    (setq whitespace-style (delete 'lines-tail whitespace-style))

    Unfortunately, if running Prelude with auto-loaded buffers (using something like Emacs Desktop), the initial setting will take precedence: for each buffer on which you want to see whitespace-style displayed as directed, you must [1]

    1. kill the buffer
    2. re-open the buffer

[1]: Note to OP: if there's another way to reload a buffer, please edit or comment this answer. I was hoping to find something like M-x reload-buffer but am not seeing anything like that with C-h a buffer.

Cenis answered 6/1, 2017 at 5:4 Comment(2)
I think this answer is the most useful if you want to use this stuff with hooks for major modes, for example when you want to deactivate it for text editing, but then enable it again for some programming languages.Pistoia
For the [1] PS note: M-x revert-buffer is what you want, save your changes first C-x C-s, otherwise they are lostAutacoid

© 2022 - 2024 — McMap. All rights reserved.