Illusory stillness

mumble mumble techblog

Whitespace-mode

Why does whitespace-mode fuck up longlines mode when it’s supposed to be disabled?

I’d like to edit markdown files with longlines-mode (word wrapping). Clearly when longlines-mode is enabled, I don’t want to highlight 80+ char lines, as I do when editing code. However, I still want the other whitespace-mode features (highlight trailing spaces, tabs, etc)

I have, in my markdown-mode modehook:

1
2
3
  (when whitespace-mode
    (whitespace-mode 'disable)
    (setq-local whitespace-style (remove 'lines-tail whitespace-style)))

It doesn’t work. Lines longer than 80char still get highlighted.

But indeed ‘lines-tail does not appear in whitespace-style. However, too late: this came after whitespace-mode had initialized, and so it’s already set up.

Moving to a lighlighted char and doing (face-at-point) reveals whitespace-line.

Disabling font-lock-mode disables all highlighting.

font-lock-fontify-buffer doesn’t do it.

font-lock-keywords-alist does not contain anything pertaining to whitespace-mode.

Hmmm. maybe I can locally redefine the face.

font-lock-keywords is not buffer local. It contains this:

1
2
("^\\([^ \n]\\{4\\}\\|[^ \n]\\{0,3\\}    \\)\\{20\\}\\(.+\\)$"
(2 whitespace-line t))

If I remove lines-tail f rom whitespace-style before loading the buffer… the offending highlighting does not take place.

So I need to to the remove before enabling whitespace mode? and make it buffer-local?

So, I made sure that the modification to whitespace-style occurred before whitespace-mode was enabled. That did the trick, I think.

So, here:

1
2
3
4
5
6
7
8
9
10
11
(add-hook 'markdown-mode-hook 'pbm-markdown-fonts)

(defun pbm-markdown-fonts ()
  ;Use variable pitch fonts, and wrap long lines.
  (variable-pitch-mode t)
  (if whitespace-mode
      (error "markdown mode needs configured before whitespace mode is enabled"))
  (setq-local whitespace-style (remove 'lines-tail whitespace-style))
  (visual-line-mode)
  (set-visual-wrap-column 75)
  (font-lock-fontify-buffer))