Mercurial > emacs
annotate lisp/compare-w.el @ 2262:29579cd51981
Added unlock and relock.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 19 Mar 1993 07:49:20 +0000 |
parents | eea183a35396 |
children | 10e417efb12a |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; compare-w.el --- compare text between windows for Emacs. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1986, 1989 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Maintainer: FSF |
257 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; 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
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
257 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
23 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
24 |
257 | 25 (defvar compare-windows-whitespace " \t\n" |
26 "*String of characters considered whitespace for \\[compare-windows]. | |
27 Changes in whitespace are optionally ignored. | |
28 | |
29 The value of `compare-windows-whitespace' may instead be a function; this | |
30 function is called in each buffer, with point at the current scanning point. | |
31 The function's job is to categorize any whitespace around (including before) | |
32 point; it should also advance past any whitespace. | |
33 | |
34 The function is passed one argument, the point where `compare-windows' | |
35 was originally called; it should not consider any text before that point. | |
36 If the function returns the same value for both buffers, then the | |
37 whitespace is considered to match, and is skipped.") | |
38 | |
39 (defvar compare-ignore-case nil | |
40 "*Non-nil means \\[compare-windows] ignores case differences.") | |
41 | |
42 ;;;###autoload | |
43 (defun compare-windows (ignore-whitespace) | |
44 "Compare text in current window with text in next window. | |
45 Compares the text starting at point in each window, | |
46 moving over text in each one as far as they match. | |
47 | |
48 A prefix arg means ignore changes in whitespace. | |
49 The variable `compare-windows-whitespace' controls how whitespace is skipped. | |
50 If `compare-ignore-case' is non-nil, changes in case are also ignored." | |
51 (interactive "P") | |
52 (let* (p1 p2 maxp1 maxp2 b1 b2 w2 | |
53 success size | |
54 (opoint1 (point)) | |
55 opoint2 | |
56 (skip-whitespace (if ignore-whitespace | |
57 compare-windows-whitespace)) | |
58 (skip-whitespace-regexp (concat "[" skip-whitespace "]+"))) | |
59 (setq p1 (point) b1 (current-buffer)) | |
60 (setq w2 (next-window (selected-window))) | |
61 (if (eq w2 (selected-window)) | |
62 (error "No other window")) | |
63 (setq p2 (window-point w2) | |
64 b2 (window-buffer w2)) | |
65 (setq opoint2 p2) | |
66 (setq maxp1 (point-max)) | |
67 (save-excursion | |
68 (set-buffer b2) | |
69 (setq maxp2 (point-max))) | |
70 | |
71 (setq success t) | |
72 (while success | |
73 (setq success nil) | |
74 ;; if interrupted, show how far we've gotten | |
75 (goto-char p1) | |
76 (set-window-point w2 p2) | |
77 | |
78 ;; If both buffers have whitespace next to point, | |
79 ;; optionally skip over it. | |
80 | |
81 (and skip-whitespace | |
82 (save-excursion | |
83 (let (p1a p2a w1 w2 result1 result2) | |
84 (if (stringp skip-whitespace) | |
85 (progn | |
86 (if (not (eobp)) | |
87 (skip-chars-backward skip-whitespace opoint1)) | |
88 (and (looking-at skip-whitespace-regexp) | |
89 (setq p1a (match-end 0) result1 t))) | |
90 (setq result1 (funcall skip-whitespace opoint1)) | |
91 (setq p1a (point))) | |
92 (set-buffer b2) | |
93 (goto-char p2) | |
94 (if (stringp skip-whitespace) | |
95 (progn | |
96 (if (not (eobp)) | |
97 (skip-chars-backward skip-whitespace opoint2)) | |
98 (and (looking-at skip-whitespace-regexp) | |
99 (setq p2a (match-end 0) result2 t))) | |
100 (setq result2 (funcall skip-whitespace opoint2)) | |
101 (setq p2a (point))) | |
102 (and result1 result2 (eq result1 result2) | |
103 (setq p1 p1a | |
104 p2 p2a))))) | |
105 | |
106 ;; Try advancing comparing 1000 chars at a time. | |
107 ;; When that fails, go 500 chars at a time, and so on. | |
108 (let ((size 1000) | |
2011
eea183a35396
(compare-windows): Use compare-buffer-substrings.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
109 success-1 |
eea183a35396
(compare-windows): Use compare-buffer-substrings.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
110 (case-fold-search compare-ignore-case)) |
257 | 111 (while (> size 0) |
112 (setq success-1 t) | |
2011
eea183a35396
(compare-windows): Use compare-buffer-substrings.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
113 ;; Try comparing SIZE chars at a time, repeatedly, till that fails. |
257 | 114 (while success-1 |
115 (setq size (min size (- maxp1 p1) (- maxp2 p2))) | |
116 (setq success-1 | |
117 (and (> size 0) | |
2011
eea183a35396
(compare-windows): Use compare-buffer-substrings.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
118 (= 0 (compare-buffer-substrings b2 p2 (+ size p2) |
eea183a35396
(compare-windows): Use compare-buffer-substrings.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
119 b1 p1 (+ size p1))))) |
257 | 120 (if success-1 |
121 (setq p1 (+ p1 size) p2 (+ p2 size) | |
122 success t))) | |
2011
eea183a35396
(compare-windows): Use compare-buffer-substrings.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
123 ;; If SIZE chars don't match, try fewer. |
257 | 124 (setq size (/ size 2))))) |
125 | |
126 (goto-char p1) | |
127 (set-window-point w2 p2) | |
128 (if (= (point) opoint1) | |
129 (ding)))) | |
584 | 130 |
131 (provide 'compare-w) | |
132 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
133 ;;; compare-w.el ends here |