I want to force whitespace-mode highlight line after 99 character in rust-mode (cuz this length recommended by guidelines). For other modes i want to leave this variable with default value(80). How can i do this?
3 Answers
As erikstokes correctly points out, the variable that controls this behaviour is whitespace-line-column
. If you unconditionally set this variable in your user-init-file
, however, it will affect all modes.
The standard mechanism that Emacs provides for mode-specific customisations is hooks. So, to modify the variable in question for rust-mode
only, you can write something like the following:
(add-hook 'rust-mode-hook
(lambda ()
(setq-local whitespace-line-column 99)))
or, in Emacs versions prior to 24.3:
(add-hook 'rust-mode-hook
(lambda ()
(set (make-local-variable 'whitespace-line-column) 99)))

- 12,383
- 43
- 69
Rather than whitespace-mode, try column-enforce-mode
which can be installed from Emacs MELPA. See https://github.com/jordonbiondo/column-enforce-mode for more details.

- 737
- 3
- 8
-
1Why is that better than using whitespace-mode? – Qudit Mar 27 '18 at 18:00
The variable you want is whitespace-line-column
:
Specify column beyond which the line is highlighted.
It must be an integer or nil. If nil, the ‘fill-column’ variable value is used.
Used when ‘whitespace-style’ includes ‘lines’ or ‘lines-tail’.
Add (setq whitespace-line-column 99)
to your .emacs
.

- 12,927
- 2
- 36
- 56