annotate lisp/compare-w.el @ 75347:e3694f1cb928

Add 2007 to copyright years.
author Glenn Morris <rgm@gnu.org>
date Sun, 21 Jan 2007 03:53:13 +0000
parents ddcbd2c1b70d
children 7d51f6ae5d8a 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38412
253f761ad37b Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents: 24948
diff changeset
1 ;;; compare-w.el --- compare text between windows for Emacs
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
2
74439
ddcbd2c1b70d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72432
diff changeset
3 ;; Copyright (C) 1986, 1989, 1993, 1997, 2001, 2002, 2003, 2004,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74439
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
5
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
6 ;; Maintainer: FSF
45078
829beb9a6a4b Follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 44202
diff changeset
7 ;; Keywords: convenience files
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; any later version.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 10031
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63220
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63220
diff changeset
24 ;; Boston, MA 02110-1301, USA.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2011
diff changeset
26 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2011
diff changeset
27
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2011
diff changeset
28 ;; This package provides one entry point, compare-windows. It compares
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2011
diff changeset
29 ;; text starting from point in two adjacent windows, advancing point
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2011
diff changeset
30 ;; until it finds a difference. Option variables permit you to ignore
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2011
diff changeset
31 ;; whitespace differences, or case differences, or both.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2011
diff changeset
32
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
33 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
34
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
35 (defgroup compare-w nil
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
36 "Compare text between windows."
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
37 :prefix "compare-"
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
38 :group 'tools)
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
39
46405
2bde7081136b (compare-windows-whitespace): Always allow newline
Richard M. Stallman <rms@gnu.org>
parents: 45078
diff changeset
40 (defcustom compare-windows-whitespace "\\(\\s-\\|\n\\)+"
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
41 "*Regexp or function that defines whitespace sequences for `compare-windows'.
46405
2bde7081136b (compare-windows-whitespace): Always allow newline
Richard M. Stallman <rms@gnu.org>
parents: 45078
diff changeset
42 That command optionally ignores changes in whitespace.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
46405
2bde7081136b (compare-windows-whitespace): Always allow newline
Richard M. Stallman <rms@gnu.org>
parents: 45078
diff changeset
44 The value of `compare-windows-whitespace' is normally a regexp, but it
2bde7081136b (compare-windows-whitespace): Always allow newline
Richard M. Stallman <rms@gnu.org>
parents: 45078
diff changeset
45 can also be a function. The function's job is to categorize any
2bde7081136b (compare-windows-whitespace): Always allow newline
Richard M. Stallman <rms@gnu.org>
parents: 45078
diff changeset
46 whitespace around (including before) point; it should also advance
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
47 past any whitespace. The function is called in each window, with
46405
2bde7081136b (compare-windows-whitespace): Always allow newline
Richard M. Stallman <rms@gnu.org>
parents: 45078
diff changeset
48 point at the current scanning point. It gets one argument, the point
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
49 where \\[compare-windows] was originally called; it should not look at
46405
2bde7081136b (compare-windows-whitespace): Always allow newline
Richard M. Stallman <rms@gnu.org>
parents: 45078
diff changeset
50 any text before that point.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
52 If the function returns the same value for both windows, then the
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
53 whitespace is considered to match, and is skipped."
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
54 :type '(choice regexp function)
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
55 :group 'compare-w)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
57 (defcustom compare-ignore-whitespace nil
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
58 "*Non-nil means `compare-windows' ignores whitespace."
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
59 :type 'boolean
64492
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
60 :group 'compare-w
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
61 :version "22.1")
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
62
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
63 (defcustom compare-ignore-case nil
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
64 "*Non-nil means `compare-windows' ignores case differences."
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
65 :type 'boolean
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 17542
diff changeset
66 :group 'compare-w)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
68 (defcustom compare-windows-sync 'compare-windows-sync-default-function
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
69 "*Function or regexp that is used to synchronize points in two
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
70 windows if before calling `compare-windows' points are located
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
71 on mismatched positions.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
72
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
73 The value of `compare-windows-sync' can be a function. The
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
74 function's job is to advance points in both windows to the next
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
75 matching text. If the value of `compare-windows-sync' is a
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
76 regexp, then points in both windows are advanced to the next
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
77 occurrence of this regexp.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
78
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
79 The current default value is the general function
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
80 `compare-windows-sync-default-function' that is able to
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
81 synchronize points by using quadratic algorithm to find the first
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
82 matching 32-character string in two windows.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
83
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
84 The other useful values of this variable could be such functions
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
85 as `forward-word', `forward-sentence', `forward-paragraph', or a
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
86 regexp containing some field separator or a newline, depending on
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
87 the nature of the difference units separator. The variable can
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
88 be made buffer-local.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
89
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
90 If the value of this variable is `nil', then function `ding' is
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
91 called to beep or flash the screen when points are mismatched."
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
92 :type '(choice regexp function)
64492
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
93 :group 'compare-w
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
94 :version "22.1")
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
95
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
96 (defcustom compare-windows-sync-string-size 32
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
97 "*Size of string from one window that is searched in second window.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
98
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
99 Small number makes difference regions more fine-grained, but it
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
100 may fail by finding the wrong match. The bigger number makes
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
101 difference regions more coarse-grained.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
102
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
103 The default value 32 is good for the most cases."
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
104 :type 'integer
64492
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
105 :group 'compare-w
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
106 :version "22.1")
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
107
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
108 (defcustom compare-windows-recenter nil
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
109 "*List of two values, each of which is used as argument of
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
110 function `recenter' called in each of two windows to place
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
111 matching points side-by-side.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
112
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
113 The value `(-1 0)' is useful if windows are split vertically,
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
114 and the value `((4) (4))' for horizontally split windows."
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
115 :type '(list sexp sexp)
64492
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
116 :group 'compare-w
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
117 :version "22.1")
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
118
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
119 (defcustom compare-windows-highlight t
69127
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
120 "*Non-nil means compare-windows highlights the differences.
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
121 The value t removes highlighting immediately after invoking a command
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
122 other than `compare-windows'.
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
123 The value `persistent' leaves all highlighted differences. You can clear
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
124 out all highlighting later with the command `compare-windows-dehighlight'."
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
125 :type '(choice (const :tag "No highlighting" nil)
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
126 (const :tag "Persistent highlighting" persistent)
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
127 (other :tag "Highlight until next command" t))
64492
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
128 :group 'compare-w
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
129 :version "22.1")
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
130
63220
b14224937156 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-384
Miles Bader <miles@gnu.org>
parents: 58601
diff changeset
131 (defface compare-windows
64492
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
132 '((t :inherit lazy-highlight))
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
133 "Face for highlighting of compare-windows difference regions."
64492
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
134 :group 'compare-w
3fee42bf372b (compare-ignore-whitespace, compare-windows-sync)
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
135 :version "22.1")
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
136
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
137 (defvar compare-windows-overlay1 nil)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
138 (defvar compare-windows-overlay2 nil)
69127
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
139 (defvar compare-windows-overlays1 nil)
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
140 (defvar compare-windows-overlays2 nil)
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
141 (defvar compare-windows-sync-point nil)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
142
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 ;;;###autoload
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (defun compare-windows (ignore-whitespace)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 "Compare text in current window with text in next window.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 Compares the text starting at point in each window,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 moving over text in each one as far as they match.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148
10031
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
149 This command pushes the mark in each window
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
150 at the prior location of point in that window.
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
151 If both windows display the same buffer,
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
152 the mark is pushed twice in that buffer:
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
153 first in the other window, then in the selected window.
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
154
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
155 A prefix arg means reverse the value of variable
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
156 `compare-ignore-whitespace'. If `compare-ignore-whitespace' is
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
157 nil, then a prefix arg means ignore changes in whitespace. If
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
158 `compare-ignore-whitespace' is non-nil, then a prefix arg means
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
159 don't ignore changes in whitespace. The variable
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
160 `compare-windows-whitespace' controls how whitespace is skipped.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
161 If `compare-ignore-case' is non-nil, changes in case are also
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
162 ignored.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
163
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
164 If `compare-windows-sync' is non-nil, then successive calls of
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
165 this command work in interlaced mode:
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
166 on first call it advances points to the next difference,
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
167 on second call it synchronizes points by skipping the difference,
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
168 on third call it again advances points to the next difference and so on."
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 (interactive "P")
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
170 (if compare-ignore-whitespace
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
171 (setq ignore-whitespace (not ignore-whitespace)))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (let* (p1 p2 maxp1 maxp2 b1 b2 w2
16986
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
173 (progress 1)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (opoint1 (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 opoint2
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
176 skip-func-1
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
177 skip-func-2
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
178 (sync-func (if (stringp compare-windows-sync)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
179 'compare-windows-sync-regexp
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
180 compare-windows-sync)))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (setq p1 (point) b1 (current-buffer))
24948
970c0b904d35 (compare-windows): Try to find the next window in
Andreas Schwab <schwab@suse.de>
parents: 21088
diff changeset
182 (setq w2 (next-window (selected-window)))
970c0b904d35 (compare-windows): Try to find the next window in
Andreas Schwab <schwab@suse.de>
parents: 21088
diff changeset
183 (if (eq w2 (selected-window))
970c0b904d35 (compare-windows): Try to find the next window in
Andreas Schwab <schwab@suse.de>
parents: 21088
diff changeset
184 (setq w2 (next-window (selected-window) nil 'visible)))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (if (eq w2 (selected-window))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (error "No other window"))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (setq p2 (window-point w2)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 b2 (window-buffer w2))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (setq opoint2 p2)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (setq maxp1 (point-max))
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
191
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
192 (setq skip-func-1 (if ignore-whitespace
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
193 (if (stringp compare-windows-whitespace)
72432
ceec9309d859 (compare-windows): lambda's take an arg and pass
Richard M. Stallman <rms@gnu.org>
parents: 72408
diff changeset
194 (lambda (pos)
ceec9309d859 (compare-windows): lambda's take an arg and pass
Richard M. Stallman <rms@gnu.org>
parents: 72408
diff changeset
195 (compare-windows-skip-whitespace pos)
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
196 t)
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
197 compare-windows-whitespace)))
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
198
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
199 (with-current-buffer b2
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
200 (setq skip-func-2 (if ignore-whitespace
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
201 (if (stringp compare-windows-whitespace)
72432
ceec9309d859 (compare-windows): lambda's take an arg and pass
Richard M. Stallman <rms@gnu.org>
parents: 72408
diff changeset
202 (lambda (pos)
ceec9309d859 (compare-windows): lambda's take an arg and pass
Richard M. Stallman <rms@gnu.org>
parents: 72408
diff changeset
203 (compare-windows-skip-whitespace pos)
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
204 t)
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
205 compare-windows-whitespace)))
10031
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
206 (push-mark p2 t)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (setq maxp2 (point-max)))
10031
324e027f01bc (compare-windows): Push mark in both buffers at start.
Richard M. Stallman <rms@gnu.org>
parents: 7701
diff changeset
208 (push-mark)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
16986
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
210 (while (> progress 0)
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
211 ;; If both windows have whitespace next to point,
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 ;; optionally skip over it.
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
213 (and skip-func-1
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (let (p1a p2a w1 w2 result1 result2)
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
216 (setq result1 (funcall skip-func-1 opoint1))
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
217 (setq p1a (point))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (set-buffer b2)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (goto-char p2)
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
220 (setq result2 (funcall skip-func-2 opoint2))
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
221 (setq p2a (point))
72408
7b77bbd3e40c (compare-windows): Factor compare-ignore-whitespace into ignore-whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 69127
diff changeset
222 (if (and result1 result2 (eq result1 result2))
7701
ec15948b9458 (compare-windows): Make leading whitespace equivalent
Richard M. Stallman <rms@gnu.org>
parents: 5005
diff changeset
223 (setq p1 p1a
ec15948b9458 (compare-windows): Make leading whitespace equivalent
Richard M. Stallman <rms@gnu.org>
parents: 5005
diff changeset
224 p2 p2a)))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225
16986
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
226 (let ((size (min (- maxp1 p1) (- maxp2 p2)))
2011
eea183a35396 (compare-windows): Use compare-buffer-substrings.
Richard M. Stallman <rms@gnu.org>
parents: 845
diff changeset
227 (case-fold-search compare-ignore-case))
16986
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
228 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
229 b1 p1 (+ size p1)))
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
230 (setq progress (if (zerop progress) size (1- (abs progress))))
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
231 (setq p1 (+ p1 progress) p2 (+ p2 progress)))
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
232 ;; Advance point now rather than later, in case we're interrupted.
dc0cd1c70c87 (compare-windows): Make more efficient use of
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
233 (goto-char p1)
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
234 (set-window-point w2 p2)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
235 (when compare-windows-recenter
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
236 (recenter (car compare-windows-recenter))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
237 (with-selected-window w2 (recenter (cadr compare-windows-recenter)))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (if (= (point) opoint1)
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
240 (if (not sync-func)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
241 (ding)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
242 ;; If points are not advanced (i.e. already on mismatch position),
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
243 ;; then synchronize points between both windows
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
244 (save-excursion
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
245 (setq compare-windows-sync-point nil)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
246 (funcall sync-func)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
247 (setq p1 (point))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
248 (set-buffer b2)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
249 (goto-char p2)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
250 (funcall sync-func)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
251 (setq p2 (point)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
252 (goto-char p1)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
253 (set-window-point w2 p2)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
254 (when compare-windows-recenter
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
255 (recenter (car compare-windows-recenter))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
256 (with-selected-window w2 (recenter (cadr compare-windows-recenter))))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
257 ;; If points are still not synchronized, then ding
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
258 (when (and (= p1 opoint1) (= p2 opoint2))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
259 ;; Display error message when current points in two windows
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
260 ;; are unmatched and next matching points can't be found.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
261 (compare-windows-dehighlight)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
262 (ding)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
263 (message "No more matching points"))))))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 257
diff changeset
264
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
265 ;; Move forward over whatever might be called whitespace.
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
266 ;; compare-windows-whitespace is a regexp that matches whitespace.
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
267 ;; Match it at various starting points before the original point
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
268 ;; and find the latest point at which a match ends.
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
269 ;; Don't try starting points before START, though.
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
270 ;; Value is non-nil if whitespace is found.
4925
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
271 ;; If there is whitespace before point, but none after,
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
272 ;; then return t, but don't advance point.
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
273 (defun compare-windows-skip-whitespace (start)
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
274 (let ((end (point))
4925
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
275 (beg (point))
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
276 (opoint (point)))
5005
c762abae3964 (compare-windows-skip-whitespace): Swap the two
Richard M. Stallman <rms@gnu.org>
parents: 4925
diff changeset
277 (while (or (and (looking-at compare-windows-whitespace)
4925
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
278 (<= end (match-end 0))
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
279 ;; This match goes past END, so advance END.
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
280 (progn (setq end (match-end 0))
5005
c762abae3964 (compare-windows-skip-whitespace): Swap the two
Richard M. Stallman <rms@gnu.org>
parents: 4925
diff changeset
281 (> (point) start)))
c762abae3964 (compare-windows-skip-whitespace): Swap the two
Richard M. Stallman <rms@gnu.org>
parents: 4925
diff changeset
282 (and (/= (point) start)
c762abae3964 (compare-windows-skip-whitespace): Swap the two
Richard M. Stallman <rms@gnu.org>
parents: 4925
diff changeset
283 ;; Consider at least the char before point,
c762abae3964 (compare-windows-skip-whitespace): Swap the two
Richard M. Stallman <rms@gnu.org>
parents: 4925
diff changeset
284 ;; unless it is also before START.
c762abae3964 (compare-windows-skip-whitespace): Swap the two
Richard M. Stallman <rms@gnu.org>
parents: 4925
diff changeset
285 (= (point) opoint)))
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
286 ;; keep going back until whitespace
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
287 ;; doesn't extend to or past end
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
288 (forward-char -1))
4925
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
289 (setq beg (point))
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
290 (goto-char end)
4925
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
291 (or (/= beg opoint)
76fb8b35df3f (compare-windows-skip-whitespace): Return t
Richard M. Stallman <rms@gnu.org>
parents: 4072
diff changeset
292 (/= end opoint))))
4072
d38c94145afe (compare-windows-skip-whitespace): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
293
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
294 ;; Move forward to the next synchronization regexp.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
295 (defun compare-windows-sync-regexp ()
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
296 (if (stringp compare-windows-sync)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
297 (re-search-forward compare-windows-sync nil t)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
298
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
299 ;; Function works in two passes: one call on each window.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
300 ;; On the first call both matching points are computed,
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
301 ;; and one of them is stored in compare-windows-sync-point
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
302 ;; to be used when this function is called on second window.
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
303 (defun compare-windows-sync-default-function ()
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
304 (if (not compare-windows-sync-point)
58601
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
305 (let* ((w1 (selected-window))
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
306 (w2 (next-window w1))
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
307 (b2 (window-buffer w2))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
308 (point-max2 (with-current-buffer b2 (point-max)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
309 (op2 (window-point w2))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
310 (op1 (point))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
311 (region-size compare-windows-sync-string-size)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
312 (string-size compare-windows-sync-string-size)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
313 in-bounds-p s1 p2 p12s p12)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
314 (while (and
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
315 ;; until matching points are found
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
316 (not p12s)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
317 ;; until size exceeds the maximum points of both buffers
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
318 ;; (bounds below take care to not overdo in each of them)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
319 (or (setq in-bounds-p (< region-size (max (- (point-max) op1)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
320 (- point-max2 op2))))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
321 ;; until string size becomes smaller than 4
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
322 (> string-size 4)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
323 (if in-bounds-p
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
324 ;; make the next search in the double-sized region;
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
325 ;; on first iteration it is 2*compare-windows-sync-string-size,
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
326 ;; on last iterations it exceeds both buffers maximum points
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
327 (setq region-size (* region-size 2))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
328 ;; if region size exceeds the maximum points of both buffers,
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
329 ;; then start to halve the string size until 4;
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
330 ;; this helps to find differences near the end of buffers
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
331 (setq string-size (/ string-size 2)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
332 (let ((p1 op1)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
333 (bound1 (- (min (+ op1 region-size) (point-max)) string-size))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
334 (bound2 (min (+ op2 region-size) point-max2)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
335 (while (< p1 bound1)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
336 (setq s1 (buffer-substring-no-properties p1 (+ p1 string-size)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
337 (setq p2 (with-current-buffer b2
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
338 (goto-char op2)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
339 (let ((case-fold-search compare-ignore-case))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
340 (search-forward s1 bound2 t))))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
341 (when p2
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
342 (setq p2 (- p2 string-size))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
343 (setq p12s (cons (list (+ p1 p2) p1 p2) p12s)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
344 (setq p1 (1+ p1)))))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
345 (when p12s
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
346 ;; use closest matching points (i.e. points with minimal sum)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
347 (setq p12 (cdr (assq (apply 'min (mapcar 'car p12s)) p12s)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
348 (goto-char (car p12))
58601
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
349 (compare-windows-highlight op1 (car p12) (current-buffer) w1
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
350 op2 (cadr p12) b2 w2))
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
351 (setq compare-windows-sync-point (or (cadr p12) t)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
352 ;; else set point in the second window to the pre-calculated value
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
353 (if (numberp compare-windows-sync-point)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
354 (goto-char compare-windows-sync-point))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
355 (setq compare-windows-sync-point nil)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
356
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
357 ;; Highlight differences
58601
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
358 (defun compare-windows-highlight (beg1 end1 b1 w1 beg2 end2 b2 w2)
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
359 (when compare-windows-highlight
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
360 (if compare-windows-overlay1
58601
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
361 (move-overlay compare-windows-overlay1 beg1 end1 b1)
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
362 (setq compare-windows-overlay1 (make-overlay beg1 end1 b1))
63220
b14224937156 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-384
Miles Bader <miles@gnu.org>
parents: 58601
diff changeset
363 (overlay-put compare-windows-overlay1 'face 'compare-windows)
67428
9e33a6897729 (compare-windows-highlight): Change overlay priority from 1 to 1000.
Juri Linkov <juri@jurta.org>
parents: 64993
diff changeset
364 (overlay-put compare-windows-overlay1 'priority 1000))
58601
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
365 (overlay-put compare-windows-overlay1 'window w1)
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
366 (if compare-windows-overlay2
58601
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
367 (move-overlay compare-windows-overlay2 beg2 end2 b2)
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
368 (setq compare-windows-overlay2 (make-overlay beg2 end2 b2))
63220
b14224937156 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-384
Miles Bader <miles@gnu.org>
parents: 58601
diff changeset
369 (overlay-put compare-windows-overlay2 'face 'compare-windows)
67428
9e33a6897729 (compare-windows-highlight): Change overlay priority from 1 to 1000.
Juri Linkov <juri@jurta.org>
parents: 64993
diff changeset
370 (overlay-put compare-windows-overlay2 'priority 1000))
58601
4663989dd34a (compare-windows-highlight): Attach each overlay
Juri Linkov <juri@jurta.org>
parents: 55703
diff changeset
371 (overlay-put compare-windows-overlay2 'window w2)
69127
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
372 (if (not (eq compare-windows-highlight 'persistent))
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
373 ;; Remove highlighting before next command is executed
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
374 (add-hook 'pre-command-hook 'compare-windows-dehighlight)
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
375 (when compare-windows-overlay1
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
376 (push (copy-overlay compare-windows-overlay1) compare-windows-overlays1)
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
377 (delete-overlay compare-windows-overlay1))
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
378 (when compare-windows-overlay2
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
379 (push (copy-overlay compare-windows-overlay2) compare-windows-overlays2)
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
380 (delete-overlay compare-windows-overlay2)))))
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
381
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
382 (defun compare-windows-dehighlight ()
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
383 "Remove highlighting created by `compare-windows-highlight'."
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
384 (interactive)
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
385 (remove-hook 'pre-command-hook 'compare-windows-dehighlight)
69127
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
386 (mapc 'delete-overlay compare-windows-overlays1)
a7ce66a8df73 (compare-windows-highlight): Add new value
Juri Linkov <juri@jurta.org>
parents: 68651
diff changeset
387 (mapc 'delete-overlay compare-windows-overlays2)
52893
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
388 (and compare-windows-overlay1 (delete-overlay compare-windows-overlay1))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
389 (and compare-windows-overlay2 (delete-overlay compare-windows-overlay2)))
a8714ce78ab1 (compare-windows-whitespace): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
390
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 257
diff changeset
391 (provide 'compare-w)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 257
diff changeset
392
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 46405
diff changeset
393 ;;; arch-tag: 4177aab1-48e6-4a98-b7a1-000ee285de46
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
394 ;;; compare-w.el ends here