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?

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)))
  • Thanks @Jesse I've tried but still stays in 80 =( – ZzAntáres 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 0: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!. – ZzAntáres Jun 29 '16 at 0:22

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.