bbatsov/prelude

Adjust whitespace-style in different modes

williamgrimes opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
The default prelude-whitespace and prelude-clean-whitespace-on-save is very convenient. The whitespace-style is set in core/prelude-editor.el as follows:

;; whitespace-mode config 
(require 'whitespace) 
(setq whitespace-line-column 80) ;; limit line length 
(setq whitespace-style '(face tabs empty trailing lines-tail)) 

Generally this is extremely helpful!

However, for some files (modes) e.g. .md, .html, .org I don't want to highlight lines longer than 80 chars. I am fine with having long lines and I want to keep all the whitespace behavior except not highlighting the lines-tail. What is the most tidy way to achieve this?

Describe the solution you'd like
What I would like is to define certain modes in which the style is changed so as to disable lines-tail i.e. org-mode, gfm-mode and web-mode. The should be configurable whilst keeping all other whitespace default features.

Describe alternatives you've considered
I've tried the following in my personal.el, disabling prelude-whitespace and creating two functions depending on the desired behavior and loading these with a hook.

 (setq prelude-whitespace nil)

 (defun whitespace-programming-mode ()
   "Visualize long lines 80+ for programming modes."
   (add-hook 'before-save-hook 'prelude-cleanup-maybe nil t)
   (whitespace-mode +1)
   (make-local-variable 'whitespace-style)
   (setq whitespace-style '(face tabs empty trailing lines-tail)))

 (defun whitespace-writing-mode ()
   "Don't visualize long lines 80+ for programming modes."
   ;(setq whitespace-style (delete 'lines-tail whitespace-style))
   (add-hook 'before-save-hook 'prelude-cleanup-maybe nil t)
   (whitespace-mode +1)
   (make-local-variable 'whitespace-style)
   (setq whitespace-style '(face tabs empty trailing)))

  (add-hook 'org-mode-hook 'whitespace-writing-mode)
  (add-hook 'web-mode-hook 'whitespace-writing-mode)

  (add-hook 'python-mode-hook 'whitespace-programming-mode)

This almost works. It is fine for python-mode and org-mode, except for some reason not the web-mode-hook still highlights the lines-tail for some reason.

In addition this approach is not optimal since for each mode it has to be activated for programming or writing. I would rather have prelude-whitespace enabled for all text-modes and then define some exceptions to those e.g. org-mode where lines-tail style is not enabled.

Additional context

https://stackoverflow.com/a/41499252

(add-hook 'gfm-mode-hook (lambda () (whitespace-toggle-options 'lines-tail)))
(add-hook 'web-mode-hook (lambda () (whitespace-toggle-options 'lines-tail)))

Ah this is what I wanted, I was not aware of whitespace-toggle-options so I just set it for those modes.