* Changing whitespace-mode style in mode hook?
@ 2021-03-10 13:23 Peter Hardy
2021-03-10 22:04 ` Peter Hardy
0 siblings, 1 reply; 2+ messages in thread
From: Peter Hardy @ 2021-03-10 13:23 UTC (permalink / raw)
To: help-gnu-emacs
Hey folks. I'm having trouble understanding how to modify
whitespace-mode styles for specific modes.
First, in my init.el I'm turning on global whitespace mode like this:
(global-whitespace-mode t)
(setq whitespace-style (quote (face trailing tabs lines-tail newline empty indentation space-after-tab space-before-tab))))
But for some modes I don't want long lines to be highlighted - usually
because I'm using visual-line-mode instead. So I wrote a quick function
to toggle off the lines-tail option, and added it to a mode hook:
(defun my/disable-long-line-mark ()
(whitespace-toggle-options 'lines-tail))
(add-hook 'org-mode-hook 'my/disable-long-line-mark)
I've checked the value of `org-mode-hook` with describe-variable, and I
know that my function is being run when I visit an org file. But the
lines-tail option is still active (confirmed by running
whitespace-toggle-options interactively and checking what's enabled).
I've also checked with just evaluating (my/disable-long-line-mark) in a
buffer, and it behaves how I would expect; lines-tail is toggled off,
local whitespace-mode is turned on, and marks on long lines in the
buffer disappear.
I guess I'm misusing whitespace-toggle-options or something here. Or
there's a better way to achieve what I'm trying to do. But I'm currently
at a loss. Any advice would be appreciated!
Thanks,
--
Pete
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Changing whitespace-mode style in mode hook?
2021-03-10 13:23 Changing whitespace-mode style in mode hook? Peter Hardy
@ 2021-03-10 22:04 ` Peter Hardy
0 siblings, 0 replies; 2+ messages in thread
From: Peter Hardy @ 2021-03-10 22:04 UTC (permalink / raw)
To: help-gnu-emacs
Peter Hardy writes:
> First, in my init.el I'm turning on global whitespace mode like this:
>
> (global-whitespace-mode t)
> (setq whitespace-style (quote (face trailing tabs lines-tail newline empty indentation space-after-tab space-before-tab))))
>
> But for some modes I don't want long lines to be highlighted - usually
> because I'm using visual-line-mode instead. So I wrote a quick function
> to toggle off the lines-tail option, and added it to a mode hook:
>
> (defun my/disable-long-line-mark ()
> (whitespace-toggle-options 'lines-tail))
>
> (add-hook 'org-mode-hook 'my/disable-long-line-mark)
I later realised that it's probably because turning on local
whitespace-mode with `whitespace-toggle-options` was getting clobbered
by having global-whitespace-mode active in the buffer as well. So I've
set whitespace-global-modes to ignore org-mode:
(setq whitespace-global-modes '(not org-mode))
And now I'm getting the behaviour I was expecting. I'm still not sure if
this is the best way to modify whitespace settings per-mode, but it's a
start.
Thanks,
--
Pete
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-10 22:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-10 13:23 Changing whitespace-mode style in mode hook? Peter Hardy
2021-03-10 22:04 ` Peter Hardy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).