Subject: bug#19170: 25.0.50; enhancement request: `compare-windows' use across frames

From: Juri Linkov <[email-masked]>
Date: Wed, 26 Nov 2014 00:56:30 +0200

> And yes, we need only record the previously selected window,
> not a whole access history (at least for this command).

Below is the smallest patch that implements this feature.
It refactors the next-window choosing logic into a separate
function that you can redefine using define-advice if you want
to define own logic.  By default, it provides a special command
`compare-windows-set-next-window' that you can bind to an own key
and use to define the next window that `compare-windows' will use,
then move back to the original window and execute `compare-windows'
normally (with or without its current argument to ignore whitespace).

diff --git a/lisp/vc/compare-w.el b/lisp/vc/compare-w.el
index 25d4cf7..a8a0a17 100644
--- a/lisp/vc/compare-w.el
+++ b/lisp/vc/compare-w.el
@@ -140,6 +140,22 @@ out all highlighting later with the command `compare-windows-dehighlight'."
 (defvar compare-windows-overlays2 nil)
 (defvar compare-windows-sync-point nil)
 
+(defvar compare-windows-next-window nil)
+
+(defun compare-windows-set-next-window ()
+  (interactive)
+  (setq compare-windows-next-window (selected-window)))
+
+(defun compare-windows-get-next-window ()
+  (let ((w2 (if (window-live-p compare-windows-next-window)
+		compare-windows-next-window
+	      (next-window))))
+    (if (eq w2 (selected-window))
+	(setq w2 (next-window (selected-window) nil 'visible)))
+    (if (eq w2 (selected-window))
+	(error "No other window"))
+    w2))
+
 ;;;###autoload
 (defun compare-windows (ignore-whitespace)
   "Compare text in current window with text in next window.
@@ -179,11 +195,7 @@ on third call it again advances points to the next difference and so on."
                            'compare-windows-sync-regexp
                          compare-windows-sync)))
     (setq p1 (point) b1 (current-buffer))
-    (setq w2 (next-window))
-    (if (eq w2 (selected-window))
-	(setq w2 (next-window (selected-window) nil 'visible)))
-    (if (eq w2 (selected-window))
-	(error "No other window"))
+    (setq w2 (compare-windows-get-next-window))
     (setq p2 (window-point w2)
 	  b2 (window-buffer w2))
     (setq opoint2 p2)
@@ -303,7 +315,7 @@ on third call it again advances points to the next difference and so on."
 (defun compare-windows-sync-default-function ()
   (if (not compare-windows-sync-point)
       (let* ((w1 (selected-window))
-             (w2 (next-window w1))
+             (w2 (compare-windows-get-next-window))
              (b2 (window-buffer w2))
              (point-max2 (with-current-buffer b2 (point-max)))
              (op2 (window-point w2))