Subject: bug#26892: 25.2; whitespace-mode does not turn off correctly

From: Eli Zaretskii <[email-masked]>
Date: Fri, 12 May 2017 09:19:52 +0300

> From: Nick Helm <[email-masked]>
> Date: Fri, 12 May 2017 11:34:33 +1200
> 
> Emacs -Q
> C-u 20 SPC RET RET RET RET   ; type some random whitespace
> M-x global-whitespace-mode
> M-x whitespace-mode
> M-x whitespace-mode
> 
> The last command should toggle local whitespace-mode off, but note that the
> whitespace display characters are not properly removed from the current
> buffer.
> 
> I had a look at whitespace.el and I think the problem lies in
> `whitespace-display-char-on'. Among other things, this function stores the
> buffer display table and replaces it with a temporary display table to show
> whitespace chars. The original is restored when the mode is turned off.
> 
> However, with global-whitespace-mode active, there is already a temporary
> display table in place, which whitespace-mode incorrectly picks up and stores,
> clobbering the original display table in the process. When whitespace-mode is
> turned off, it restores the temporary display table set by
> global-whitespace-mode, which leads to the problem.
> 
> Here's a little patch to check if global-whitespace-mode is active before
> storing the display table. I've tried this for a few days with no obvious
> problems.

Did you try running whitespace-tests with this change, and if so, did
they pass?

If the tests pass, would you mind to please add a new test for this
bug?

Thanks.