unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* global-whitespace-mode should show whitespace when switching to new buffer
@ 2018-03-30 21:51 Jefferson Carpenter
  2018-03-30 21:57 ` Jefferson Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jefferson Carpenter @ 2018-03-30 21:51 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1584 bytes --]

This is probably the worst patch you've ever seen - not sure whether the 
"advice" I added is the optimal one to add, it just seems to solve the 
problem for me.  Adding unused "&rest args" to a function so that it can 
be used as advice is probably incorrect as well.

Problem was, with global-whitespace-mode enabled, when I switched to a 
new buffer (say C-x b asdf <RET>), whitespace was not visible.  The 
`whitespacesturn-on-if-enabled' function is already added to 
after-change-major-mode-hook, but apparently that isn't triggered when a 
new buffer is created in fundamental-mode.  If I turn 
global-whitespace-mode off and back on again, or if I type "M-x 
fundamental-mode", then whitespace is visible.

The fix I came up with in my init file was to add the code:

     (defun whitespace-turn-on-if-enabled-2 (&rest args)
       (whitespace-turn-on-if-enabled))
     (advice-add 'switch-to-buffer :after 'whitespace-turn-on-if-enabled-2)

But I figured I would create a patch and let you guys look at it and 
decide what should be done.  I have attached it.  It works for me, but 
might not fix a wider root cause, and is almost certainly not the 
optimal elisp code in any case.


Jefferson Carpenter

P.S. Even with the above fix (either init file or whitespace.el patch), 
when I switch to a new buffer, whitespace is shown but in the wrong 
color.  It remains the wrong color if I turn global-whitespace-mode off 
and on again, but uses the "whitespace-space" face, etc. as it should, 
when I run "M-x fundamental-mode" (the buffer already being in 
fundamental-mode).

[-- Attachment #2: 0001-Turn-on-global-whitespace-mode-when-switching-buffer.patch --]
[-- Type: text/plain, Size: 1614 bytes --]

From 88890a45c5d29f584f21475e7a9ce4f95c3bdaaa Mon Sep 17 00:00:00 2001
From: Jefferson Carpenter <jeffersoncarpenter2@gmail.com>
Date: Fri, 30 Mar 2018 03:37:24 -0500
Subject: [PATCH] Turn on global-whitespace-mode when switching buffers

---
 lisp/whitespace.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index c2827d3d51..af96ad46ab 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -998,6 +998,7 @@ global-whitespace-mode
     (save-current-buffer
       (add-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
       (add-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
+      (advice-add 'switch-to-buffer :after 'whitespace-turn-on-if-enabled)
       (dolist (buffer (buffer-list))	; adjust all local mode
 	(set-buffer buffer)
 	(unless whitespace-mode
@@ -1006,6 +1007,7 @@ global-whitespace-mode
     (save-current-buffer
       (remove-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
       (remove-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
+      (advice-remove 'switch-to-buffer 'whitespace-turn-on-if-enabled)
       (dolist (buffer (buffer-list))	; adjust all local mode
 	(set-buffer buffer)
 	(unless whitespace-mode
@@ -1033,7 +1035,7 @@ whitespace-enable-predicate
 if the current buffer should obey `global-whitespace-mode'.
 This variable is normally modified via `add-function'.")
 
-(defun whitespace-turn-on-if-enabled ()
+(defun whitespace-turn-on-if-enabled (&rest args)
   (when (funcall whitespace-enable-predicate)
     (whitespace-turn-on)))
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: global-whitespace-mode should show whitespace when switching to new buffer
  2018-03-30 21:51 global-whitespace-mode should show whitespace when switching to new buffer Jefferson Carpenter
@ 2018-03-30 21:57 ` Jefferson Carpenter
  2018-03-31  4:06 ` Stefan Monnier
  2018-03-31  8:14 ` Eli Zaretskii
  2 siblings, 0 replies; 5+ messages in thread
From: Jefferson Carpenter @ 2018-03-30 21:57 UTC (permalink / raw)
  To: emacs-devel

Sorry, this is pretty minor, all things considered.  (I have a much more 
interesting project that I would also like some feedback on, but this is 
something I happened to crash into while I was formatting my question 
for that project.)

On 3/30/2018 9:51 PM, Jefferson Carpenter wrote:
> This is probably the worst patch you've ever seen - not sure whether the 
> "advice" I added is the optimal one to add, it just seems to solve the 
> problem for me.  Adding unused "&rest args" to a function so that it can 
> be used as advice is probably incorrect as well.
> 
> Problem was, with global-whitespace-mode enabled, when I switched to a 
> new buffer (say C-x b asdf <RET>), whitespace was not visible.  The 
> `whitespacesturn-on-if-enabled' function is already added to 
> after-change-major-mode-hook, but apparently that isn't triggered when a 
> new buffer is created in fundamental-mode.  If I turn 
> global-whitespace-mode off and back on again, or if I type "M-x 
> fundamental-mode", then whitespace is visible.
> 
> The fix I came up with in my init file was to add the code:
> 
>      (defun whitespace-turn-on-if-enabled-2 (&rest args)
>        (whitespace-turn-on-if-enabled))
>      (advice-add 'switch-to-buffer :after 'whitespace-turn-on-if-enabled-2)
> 
> But I figured I would create a patch and let you guys look at it and 
> decide what should be done.  I have attached it.  It works for me, but 
> might not fix a wider root cause, and is almost certainly not the 
> optimal elisp code in any case.
> 
> 
> Jefferson Carpenter
> 
> P.S. Even with the above fix (either init file or whitespace.el patch), 
> when I switch to a new buffer, whitespace is shown but in the wrong 
> color.  It remains the wrong color if I turn global-whitespace-mode off 
> and on again, but uses the "whitespace-space" face, etc. as it should, 
> when I run "M-x fundamental-mode" (the buffer already being in 
> fundamental-mode).



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: global-whitespace-mode should show whitespace when switching to new buffer
  2018-03-30 21:51 global-whitespace-mode should show whitespace when switching to new buffer Jefferson Carpenter
  2018-03-30 21:57 ` Jefferson Carpenter
@ 2018-03-31  4:06 ` Stefan Monnier
  2018-03-31  8:14 ` Eli Zaretskii
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2018-03-31  4:06 UTC (permalink / raw)
  To: emacs-devel

> Problem was, with global-whitespace-mode enabled, when I switched to a new
> buffer (say C-x b asdf <RET>), whitespace was not visible.
> The `whitespacesturn-on-if-enabled' function is already added to
> after-change-major-mode-hook, but apparently that isn't triggered when a new
> buffer is created in fundamental-mode.  If I turn global-whitespace-mode off
> and back on again, or if I type "M-x 
> fundamental-mode", then whitespace is visible.

Looks like a bug.  When C-x b switches to a new buffer, it should run
the major mode function of the default major mode (typically
fundamental-mode).


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: global-whitespace-mode should show whitespace when switching to new buffer
  2018-03-30 21:51 global-whitespace-mode should show whitespace when switching to new buffer Jefferson Carpenter
  2018-03-30 21:57 ` Jefferson Carpenter
  2018-03-31  4:06 ` Stefan Monnier
@ 2018-03-31  8:14 ` Eli Zaretskii
  2018-03-31 20:43   ` Jefferson Carpenter
  2 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2018-03-31  8:14 UTC (permalink / raw)
  To: Jefferson Carpenter; +Cc: emacs-devel

> From: Jefferson Carpenter <jeffersoncarpenter2@gmail.com>
> Date: Fri, 30 Mar 2018 21:51:43 +0000
> 
> Problem was, with global-whitespace-mode enabled, when I switched to a 
> new buffer (say C-x b asdf <RET>), whitespace was not visible.

I can reproduce this in Emacs 25.2, but not in the latest pretest of
26.1.  In which version of Emacs did you see this?  If you see this in
Emacs 25.x, then the problem appears to have been solved already.

Thanks.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: global-whitespace-mode should show whitespace when switching to new buffer
  2018-03-31  8:14 ` Eli Zaretskii
@ 2018-03-31 20:43   ` Jefferson Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Jefferson Carpenter @ 2018-03-31 20:43 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

On 3/31/2018 8:14 AM, Eli Zaretskii wrote:
>> From: Jefferson Carpenter <jeffersoncarpenter2@gmail.com>
>> Date: Fri, 30 Mar 2018 21:51:43 +0000
>>
>> Problem was, with global-whitespace-mode enabled, when I switched to a
>> new buffer (say C-x b asdf <RET>), whitespace was not visible.
> 
> I can reproduce this in Emacs 25.2, but not in the latest pretest of
> 26.1.  In which version of Emacs did you see this?  If you see this in
> Emacs 25.x, then the problem appears to have been solved already.
> 
> Thanks.
> 

Yes, it is fixed in the latest version (M-x version says 27.0.50). 
Sorry, I will test against the latest version on master branch next time 
before posting to the mailing list.

Jefferson Carpenter

P.S. Whitespace is shown in the correct colors now too.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-31 20:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-30 21:51 global-whitespace-mode should show whitespace when switching to new buffer Jefferson Carpenter
2018-03-30 21:57 ` Jefferson Carpenter
2018-03-31  4:06 ` Stefan Monnier
2018-03-31  8:14 ` Eli Zaretskii
2018-03-31 20:43   ` Jefferson Carpenter

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).