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

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