unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
@ 2019-07-15 22:23 Michael Heerdegen
  2019-07-17  8:39 ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2019-07-15 22:23 UTC (permalink / raw)
  To: 36680


Hi,

recipe from emacs -Q, after getting a source of undo-tree:

Copy to scratch and evaluate

(setq display-buffer-reuse-frames t)
(require 'undo-tree)
(undo-tree-mode)

Make some further edits to scratch for testing.  Then

C-x 5 2
C-x u
[up]...

Any time you switch the current node in the visualizer, the first frame
is raised for a very short time, then lowered again.  This is quite
annoying, it makes C-x u quite useless when you have a window in another
frame displaying the current buffer because it distracts me from seeing
what changes in the buffer, I'm unable to see it.  Setting
display-buffer-reuse-frames -> nil fixes this.

The visualizer calls

  (switch-to-buffer-other-window undo-tree-visualizer-buffer-name)

which doesn't seem to behave well in this situation.

TIA,

Michael.


In GNU Emacs 27.0.50 (build 9, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
 of 2019-07-15 built on drachen
Repository revision: fb725fc0fa320e94daf8e4aa1a3320ba60142449
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux bullseye/sid






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

* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
  2019-07-15 22:23 bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t Michael Heerdegen
@ 2019-07-17  8:39 ` martin rudalics
  2019-07-18  2:38   ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2019-07-17  8:39 UTC (permalink / raw)
  To: Michael Heerdegen, 36680

 > (setq display-buffer-reuse-frames t)
 > (require 'undo-tree)
 > (undo-tree-mode)
 >
 > Make some further edits to scratch for testing.  Then
 >
 > C-x 5 2
 > C-x u
 > [up]...
 >
 > Any time you switch the current node in the visualizer, the first frame
 > is raised for a very short time, then lowered again.  This is quite
 > annoying, it makes C-x u quite useless when you have a window in another
 > frame displaying the current buffer because it distracts me from seeing
 > what changes in the buffer, I'm unable to see it.  Setting
 > display-buffer-reuse-frames -> nil fixes this.
 >
 > The visualizer calls
 >
 >    (switch-to-buffer-other-window undo-tree-visualizer-buffer-name)
 >
 > which doesn't seem to behave well in this situation.

I don't know why 'undo-tree' apparently insists on switching to its
buffer here but if you put it on another frame you have to live with
the fact that that frame will be raised.  I think you should make a
special rule for 'display-buffer' to not display the undo tree on a
separate frame.  Note also that 'display-buffer-reuse-frames' is an
obsolete variable.

martin





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

* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
  2019-07-17  8:39 ` martin rudalics
@ 2019-07-18  2:38   ` Michael Heerdegen
  2019-07-18  3:01     ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2019-07-18  2:38 UTC (permalink / raw)
  To: martin rudalics; +Cc: 36680

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

martin rudalics <rudalics@gmx.at> writes:

> I don't know why 'undo-tree' apparently insists on switching to its
> buffer here but if you put it on another frame you have to live with
> the fact that that frame will be raised.

I think you didn't understand what I tried to describe.  I attach a
video demonstration (hope that works).

I don't put the visualizer to another frame, that's not the case and not
the problem.

It's the visualizer that looks if the buffer is displayed not only in
the current frame, but also in another frame, and raises this other
frame when there is one.

> I think you should make a special rule for 'display-buffer' to not
> display the undo tree on a separate frame.

As said, this is not the problem.

> Note also that 'display-buffer-reuse-frames' is an obsolete variable.

I think also other settings could lead to this effect.


Thanks,

Michael.


[-- Attachment #2: Emacs Bug#36680.webm --]
[-- Type: video/webm, Size: 225340 bytes --]

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

* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
  2019-07-18  2:38   ` Michael Heerdegen
@ 2019-07-18  3:01     ` Michael Heerdegen
  2019-07-18  7:49       ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2019-07-18  3:01 UTC (permalink / raw)
  To: martin rudalics; +Cc: 36680

Michael Heerdegen <michael_heerdegen@web.de> writes:

> As said, this is not the problem.

BTW, the call tree looks like

undo-tree-visualize > switch-to-buffer-other-window
                    > pop-to-buffer with t ACTION
                    > display-buffer with t ACTION
                    > display-buffer-reuse-window

and the last blindly uses the first window in

  (get-buffer-window-list buffer 'nomini frames)

which can be a window of a different frame even if there is a suitable
window in the selected frame.  That's not good IMHO.

Michael.





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

* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
  2019-07-18  3:01     ` Michael Heerdegen
@ 2019-07-18  7:49       ` martin rudalics
  2019-07-18 21:13         ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2019-07-18  7:49 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 36680

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

 >> As said, this is not the problem.

You probably should have used an 'inhibit-switch-frame' ALIST entry
then.

 > BTW, the call tree looks like
 >
 > undo-tree-visualize > switch-to-buffer-other-window
 >                      > pop-to-buffer with t ACTION
 >                      > display-buffer with t ACTION
 >                      > display-buffer-reuse-window
 >
 > and the last blindly uses the first window in
 >
 >    (get-buffer-window-list buffer 'nomini frames)
 >
 > which can be a window of a different frame even if there is a suitable
 > window in the selected frame.  That's not good IMHO.

OK.  Then please, try the attached patch.  Note that when there's no
suitable window on the selected frame you will still get the annoying
behavior.

Thanks, martin

[-- Attachment #2: display-buffer-reuse-window.diff --]
[-- Type: text/plain, Size: 3453 bytes --]

diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index b5ca053e46..1035739e2b 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -2536,7 +2536,8 @@ Buffer Display Action Functions
 
 @defun display-buffer-reuse-window buffer alist
 This function tries to display @var{buffer} by finding a window that
-is already displaying it.
+is already displaying it.  Windows on the selected frame are preferred
+to windows on other frames.
 
 If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
 the selected window is not eligible for reuse.  The set of frames to
diff --git a/lisp/window.el b/lisp/window.el
index 726d022dfe..8cb9670ae4 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7332,25 +7332,26 @@ display-buffer--maybe-same-window
 
 (defun display-buffer-reuse-window (buffer alist)
   "Return a window that is already displaying BUFFER.
-Return nil if no usable window is found.
+Preferably use a window on the selected frame if such a window
+exists.  Return nil if no usable window is found.
 
-If ALIST has a non-nil `inhibit-same-window' entry, the selected
+If ALIST has a non-nil 'inhibit-same-window' entry, the selected
 window is not eligible for reuse.
 
-If ALIST contains a `reusable-frames' entry, its value determines
+If ALIST contains a 'reusable-frames' entry, its value determines
 which frames to search for a reusable window:
   nil -- the selected frame (actually the last non-minibuffer frame)
   A frame   -- just that frame
-  `visible' -- all visible frames
+  'visible' -- all visible frames
   0   -- all frames on the current terminal
   t   -- all frames.
 
-If ALIST contains no `reusable-frames' entry, search just the
+If ALIST contains no 'reusable-frames' entry, search just the
 selected frame if `display-buffer-reuse-frames' and
 `pop-up-frames' are both nil; search all frames on the current
 terminal if either of those variables is non-nil.
 
-If ALIST has a non-nil `inhibit-switch-frame' entry, then in the
+If ALIST has a non-nil 'inhibit-switch-frame' entry, then in the
 event that a window on another frame is chosen, avoid raising
 that frame."
   (let* ((alist-entry (assq 'reusable-frames alist))
@@ -7364,9 +7365,21 @@ display-buffer-reuse-window
 	 (window (if (and (eq buffer (window-buffer))
 			  (not (cdr (assq 'inhibit-same-window alist))))
 		     (selected-window)
-		   (car (delq (selected-window)
-			      (get-buffer-window-list buffer 'nomini
-						      frames))))))
+                   ;; Preferably use a window on the selected frame,
+                   ;; if such a window exists (Bug#36680).
+                   (let* ((windows (delq (selected-window)
+                                         (get-buffer-window-list
+                                          buffer 'nomini frames)))
+                          (first (car windows))
+                          (this-frame (selected-frame)))
+                     (cond
+                      ((eq (window-frame first) this-frame)
+                       first)
+                      ((catch 'found
+                         (dolist (next (cdr windows))
+                           (when (eq (window-frame next) this-frame)
+                             (throw 'found next)))))
+                      (t first))))))
     (when (window-live-p window)
       (prog1 (window--display-buffer buffer window 'reuse alist)
 	(unless (cdr (assq 'inhibit-switch-frame alist))


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

* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
  2019-07-18  7:49       ` martin rudalics
@ 2019-07-18 21:13         ` Michael Heerdegen
  2019-07-19  8:16           ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2019-07-18 21:13 UTC (permalink / raw)
  To: martin rudalics; +Cc: 36680

martin rudalics <rudalics@gmx.at> writes:

> You probably should have used an 'inhibit-switch-frame' ALIST entry
> then.

Where would you suggest to do that, as a user, without changing code?
Potentially any arbitrary buffer can be affected.

> OK.  Then please, try the attached patch.

Yes, good, that's what I want - thanks.  I hope no existing code relies
on the old behavior.  But I think it's an improvement, also in other
situations.

> Note that when there's no suitable window on the selected frame you
> will still get the annoying behavior.

In this case it's not trivial what could be done better.  Let's say that
this is not part of my report.


Thanks,

Michael.





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

* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
  2019-07-18 21:13         ` Michael Heerdegen
@ 2019-07-19  8:16           ` martin rudalics
  2019-07-19 21:49             ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2019-07-19  8:16 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 36680

 >> You probably should have used an 'inhibit-switch-frame' ALIST entry
 >> then.
 >
 > Where would you suggest to do that, as a user, without changing code?
 > Potentially any arbitrary buffer can be affected.

It's not trivial, unfortunately.  As a user, one has to identify the
calling undo-tree function.

 >> OK.  Then please, try the attached patch.
 >
 > Yes, good, that's what I want - thanks.

I pushed the change now.

 > I hope no existing code relies
 > on the old behavior.  But I think it's an improvement, also in other
 > situations.

Strictly speaking, the change should be in 'get-buffer-window-list' to
possibly pick a window before the selected one on the selected frame.
But I can't really change the semantics of that.

 >> Note that when there's no suitable window on the selected frame you
 >> will still get the annoying behavior.
 >
 > In this case it's not trivial what could be done better.  Let's say that
 > this is not part of my report.

OK.  If you see no further problems, please close this bug.

Thanks, martin





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

* bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t
  2019-07-19  8:16           ` martin rudalics
@ 2019-07-19 21:49             ` Michael Heerdegen
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2019-07-19 21:49 UTC (permalink / raw)
  To: martin rudalics; +Cc: 36680-done

martin rudalics <rudalics@gmx.at> writes:

> OK.  If you see no further problems, please close this bug.

I'm happy.  Thanks for working on this.

Michael.





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

end of thread, other threads:[~2019-07-19 21:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-15 22:23 bug#36680: 27.0.50; undo-tree visualizer flickering with display-buffer-reuse-frames -> t Michael Heerdegen
2019-07-17  8:39 ` martin rudalics
2019-07-18  2:38   ` Michael Heerdegen
2019-07-18  3:01     ` Michael Heerdegen
2019-07-18  7:49       ` martin rudalics
2019-07-18 21:13         ` Michael Heerdegen
2019-07-19  8:16           ` martin rudalics
2019-07-19 21:49             ` Michael Heerdegen

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