2

I'm trying to have whitespace-line-column set to 80 in prog-mode and 100 in web-mode, etc. However when using hooks seems to get ignored, as is always set to 80.

(require 'whitespace)
(setq whitespace-style '(face trailing tab-mark lines-tail))

(add-hook 'prog-mode-hook '(lambda ()
                             (interactive)
                             (whitespace-mode t)
                             (setq whitespace-line-column 80)))

(add-hook 'web-mode-hook '(lambda ()
                            (interactive)
                            (whitespace-mode t)
                            (setq whitespace-line-column 100)))

What is the correct way to achieve this?

Scott Weldon
  • 2,695
  • 1
  • 17
  • 31
zzantares
  • 217
  • 1
  • 9

1 Answers1

2

You probably have to restart whitespace mode for the changes to take effect. Try the following:

(add-hook 'prog-mode-hook '(lambda ()
                            (interactive)
                            (whitespace-mode 0)
                            (setq whitespace-line-column 80)
                            (whitespace-mode 1)))

(add-hook 'web-mode-hook '(lambda ()
                           (interactive)
                           (whitespace-mode 0)
                           (setq whitespace-line-column 100)
                           (whitespace-mode 1)))
Scott Weldon
  • 2,695
  • 1
  • 17
  • 31
Jesse
  • 1,984
  • 11
  • 19
  • Thanks @Jesse I've tried but still stays in 80 =( – zzantares Jun 28 '16 at 23:51
  • @ZzAntáres that's strange, it worked for me. Please make sure you emptied your hooks before evaluating the code I posted – Jesse Jun 29 '16 at 00:14
  • oh yes! thank you, I didn't copy your code I was using `(whitespace-mode nil)` for disabling and I now see that you need the `0` otherwise isn't disabled, but yes using your code works! Thanks!. – zzantares Jun 29 '16 at 00:22
  • I think you can use `(setq-local whitespace-line-column 100)` to avoid affecting the value of the variable in other buffers. – gsgx Sep 28 '20 at 07:44