emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 96e6fd3: Compare with the most recently used window


From: Juri Linkov
Subject: [Emacs-diffs] master 96e6fd3: Compare with the most recently used window by default.
Date: Fri, 05 Dec 2014 00:50:48 +0000

branch: master
commit 96e6fd3c155b1851e0acd477789535a45b8d3187
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    Compare with the most recently used window by default.
    
    * lisp/vc/compare-w.el (compare-windows-get-window-function):
    New defcustom.
    (compare-windows-get-recent-window)
    (compare-windows-get-next-window): New functions.
    (compare-windows, compare-windows-sync-default-function):
    Use `compare-windows-get-window-function' instead of `next-window'.
    (compare-windows): Add diff/match messages with region boundaries.
    Fixes: debbugs:19170
---
 etc/NEWS             |    4 +++
 lisp/ChangeLog       |   11 +++++++++
 lisp/vc/compare-w.el |   61 ++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ae92fa9..9d204cf 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -329,6 +329,10 @@ and comments.
 the color range from `vc-annotate-color-map' is applied to the
 background or to the foreground.
 
+*** compare-windows now compares text with the most recently used window
+instead of the next window.  The new option 
`compare-windows-get-window-function'
+allows to customize this.
+
 ** Calculator: decimal display mode uses "," groups, so it's more
 fitting for use in money calculations; factorial works with
 non-integer inputs.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 19a3020..26572c3 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
+2014-12-05  Juri Linkov  <address@hidden>
+
+       Compare with the most recent window by default.
+       * vc/compare-w.el (compare-windows-get-window-function): New defcustom.
+       (compare-windows-get-recent-window)
+       (compare-windows-get-next-window): New functions.
+       (compare-windows, compare-windows-sync-default-function):
+       Use `compare-windows-get-window-function' instead of `next-window'.
+       (compare-windows): Add diff/match messages with region boundaries.
+       (Bug#19170)
+
 2014-12-04  Stefan Monnier  <address@hidden>
 
        * subr.el (filter): Remove.  Use `cl-remove-if-not' or `seq-filter'.
diff --git a/lisp/vc/compare-w.el b/lisp/vc/compare-w.el
index 25d4cf7..3b8293c 100644
--- a/lisp/vc/compare-w.el
+++ b/lisp/vc/compare-w.el
@@ -140,9 +140,43 @@ 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 ()
+  "Return the most recently used window.
+First try to get the most recently used window on a visible frame,
+then try to get a window on an iconified frame, and finally
+consider all existing frames."
+  (or (get-mru-window 'visible t t)
+      (get-mru-window 0 t t)
+      (get-mru-window t t t)))
+
+(defun compare-windows-get-next-window ()
+  "Return the window next in the cyclic ordering of windows.
+In the selected frame contains only one window, consider windows
+on all visible frames."
+  (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 +213,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)
@@ -212,7 +242,7 @@ on third call it again advances points to the next 
difference and so on."
       ;; optionally skip over it.
       (and skip-func-1
           (save-excursion
-            (let (p1a p2a w1 w2 result1 result2)
+            (let (p1a p2a result1 result2)
               (setq result1 (funcall skip-func-1 opoint1))
               (setq p1a (point))
               (set-buffer b2)
@@ -255,12 +285,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 matches with %s" b2))
+           (message "Diff -%s,%s +%s,%s with %s" opoint2 p2 opoint1 p1 b2)))
+      (message "Match -%s,%s +%s,%s with %s" opoint2 p2 opoint1 p1 b2))))
 
 ;; Move forward over whatever might be called whitespace.
 ;; compare-windows-whitespace is a regexp that matches whitespace.
@@ -303,7 +336,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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]