unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: martin rudalics <rudalics@gmx.at>
Cc: 19170@debbugs.gnu.org
Subject: bug#19170: 25.0.50; enhancement request: `compare-windows' use across frames
Date: Fri, 28 Nov 2014 23:15:38 +0200	[thread overview]
Message-ID: <8761dzxc05.fsf@mail.linkov.net> (raw)
In-Reply-To: <54782455.3020206@gmx.at> (martin rudalics's message of "Fri, 28 Nov 2014 08:29:25 +0100")

> You mean when the window referenced by `last-selected-window' is
> deleted?  The one returned by (get-mru-window t t t) I presume.  In any
> case `window-use-time' allows to order all windows by the time when they
> were selected.

Thank you, Martin.  This is exactly what we need.

diff --git a/lisp/vc/compare-w.el b/lisp/vc/compare-w.el
index 25d4cf7..8e5cf11 100644
--- a/lisp/vc/compare-w.el
+++ b/lisp/vc/compare-w.el
@@ -140,9 +140,37 @@ out all highlighting later with the command `compare-windows-dehighlight'."
 (defvar compare-windows-overlays2 nil)
 (defvar compare-windows-sync-point nil)
 
+(defcustom compare-windows-get-window-function 'compare-windows-get-recent-window
+  "Function that provides the window to compare with."
+  :type '(choice
+	  (function-item :tag "Most recently used window"
+			 compare-windows-get-recent-window)
+	  (function-item :tag "Next window"
+			 compare-windows-get-next-window)
+	  (function :tag "Your function"))
+  :group 'compare-windows
+  :version "25.0")
+
+(defun compare-windows-get-recent-window ()
+  (let ((w2 (get-mru-window 'visible t t)))
+    (if (eq w2 (selected-window))
+	(error "No other window"))
+    w2))
+
+(defun compare-windows-get-next-window ()
+  (let ((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"))
+    w2))
+
 ;;;###autoload
 (defun compare-windows (ignore-whitespace)
-  "Compare text in current window with text in next window.
+  "Compare text in current window with text in another window.
+The option `compare-windows-get-window-function' defines how
+to get another window.
+
 Compares the text starting at point in each window,
 moving over text in each one as far as they match.
 
@@ -179,11 +207,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 (funcall compare-windows-get-window-function))
     (setq p2 (window-point w2)
 	  b2 (window-buffer w2))
     (setq opoint2 p2)
@@ -255,12 +279,15 @@ on third call it again advances points to the next difference and so on."
             (recenter (car compare-windows-recenter))
             (with-selected-window w2 (recenter (cadr compare-windows-recenter))))
           ;; If points are still not synchronized, then ding
-          (when (and (= p1 opoint1) (= p2 opoint2))
-            ;; Display error message when current points in two windows
-            ;; are unmatched and next matching points can't be found.
-            (compare-windows-dehighlight)
-            (ding)
-            (message "No more matching points"))))))
+          (if (and (= p1 opoint1) (= p2 opoint2))
+	      (progn
+		;; Display error message when current points in two windows
+		;; are unmatched and next matching points can't be found.
+		(compare-windows-dehighlight)
+		(ding)
+		(message "No more matching points with %s" b2))
+	    (message "Match with %s" b2)))
+      (message "Difference with %s" b2))))
 
 ;; Move forward over whatever might be called whitespace.
 ;; compare-windows-whitespace is a regexp that matches whitespace.
@@ -303,7 +330,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 (funcall compare-windows-get-window-function))
              (b2 (window-buffer w2))
              (point-max2 (with-current-buffer b2 (point-max)))
              (op2 (window-point w2))





  parent reply	other threads:[~2014-11-28 21:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-24 19:24 bug#19170: 25.0.50; enhancement request: `compare-windows' use across frames Drew Adams
2014-11-24 22:19 ` Juri Linkov
2014-11-24 22:34   ` Drew Adams
2014-11-25  0:13     ` Drew Adams
2014-11-25  0:37     ` Juri Linkov
2014-11-25  4:09       ` Drew Adams
2014-11-25 21:39         ` Juri Linkov
2014-11-25 22:00           ` Drew Adams
2014-11-25 22:56             ` Juri Linkov
2014-11-25 23:40               ` Drew Adams
2014-11-27  0:57                 ` Juri Linkov
2014-11-27  3:18                   ` Drew Adams
2014-11-28  0:54                     ` Juri Linkov
2014-11-28  7:29                       ` martin rudalics
2014-11-28 15:31                         ` Drew Adams
2014-11-28 21:15                         ` Juri Linkov [this message]
2014-11-28 22:20                           ` Drew Adams
2014-11-29  0:50                             ` Juri Linkov
2014-11-29  1:53                               ` Drew Adams
2014-12-05  0:51                                 ` Juri Linkov
2014-11-28 15:25                       ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8761dzxc05.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=19170@debbugs.gnu.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).