11042
|
1 ;;; ediff-diff.el --- diff-related utilities
|
14169
|
2
|
64762
|
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
|
68651
|
4 ;; 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
|
11042
|
5
|
42602
|
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
|
11042
|
7
|
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
14169
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
64091
|
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
23 ;; Boston, MA 02110-1301, USA.
|
14169
|
24
|
38422
|
25 ;;; Commentary:
|
|
26
|
14169
|
27 ;;; Code:
|
11042
|
28
|
18054
|
29
|
|
30 ;; compiler pacifier
|
|
31 (defvar ediff-default-variant)
|
42602
|
32 (defvar null-device)
|
64376
|
33 (defvar longlines-mode)
|
18054
|
34
|
|
35 (eval-when-compile
|
|
36 (let ((load-path (cons (expand-file-name ".") load-path)))
|
|
37 (or (featurep 'ediff-init)
|
|
38 (load "ediff-init.el" nil nil 'nosuffix))
|
|
39 (or (featurep 'ediff-util)
|
|
40 (load "ediff-util.el" nil nil 'nosuffix))
|
|
41 ))
|
|
42 ;; end pacifier
|
|
43
|
11042
|
44 (require 'ediff-init)
|
|
45
|
18054
|
46 (defgroup ediff-diff nil
|
64006
|
47 "Diff related utilities."
|
18054
|
48 :prefix "ediff-"
|
|
49 :group 'ediff)
|
14582
|
50
|
33842
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
51 ;; these two must be here to prevent ediff-test-utility from barking
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
52 (defcustom ediff-diff-program "diff"
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
53 "*Program to use for generating the differential of the two files."
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
54 :type 'string
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
55 :group 'ediff-diff)
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
56 (defcustom ediff-diff3-program "diff3"
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
57 "*Program to be used for three-way comparison.
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
58 Must produce output compatible with Unix's diff3 program."
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
59 :type 'string
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
60 :group 'ediff-diff)
|
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
61
|
36043
|
62
|
33842
f6a67d77484a
* ediff-diff.el: Moved variables around to have it compile under NT.
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
63 ;; The following functions must precede all defcustom-defined variables.
|
18054
|
64
|
29165
|
65 ;; The following functions needed for setting diff/diff3 options
|
|
66 ;; test if diff supports the --binary option
|
|
67 (defsubst ediff-test-utility (diff-util option &optional files)
|
53477
|
68 (eq 0 (apply 'call-process
|
|
69 (append (list diff-util nil nil nil option) files))))
|
29165
|
70
|
|
71 (defun ediff-diff-mandatory-option (diff-util)
|
|
72 (let ((file (if (boundp 'null-device) null-device "/dev/null")))
|
|
73 (cond ((not (memq system-type '(ms-dos windows-nt windows-95)))
|
|
74 "")
|
|
75 ((and (string= diff-util ediff-diff-program)
|
|
76 (ediff-test-utility
|
|
77 ediff-diff-program "--binary" (list file file)))
|
|
78 "--binary")
|
|
79 ((and (string= diff-util ediff-diff3-program)
|
|
80 (ediff-test-utility
|
|
81 ediff-diff3-program "--binary" (list file file file)))
|
|
82 "--binary")
|
|
83 (t ""))))
|
|
84
|
|
85 ;; make sure that mandatory options are added even if the user changes
|
|
86 ;; ediff-diff-options or ediff-diff3-options in the customization widget
|
|
87 (defun ediff-reset-diff-options (symb val)
|
42602
|
88 (let* ((diff-program
|
|
89 (if (eq symb 'ediff-diff-options)
|
29165
|
90 ediff-diff-program
|
|
91 ediff-diff3-program))
|
|
92 (mandatory-option (ediff-diff-mandatory-option diff-program))
|
|
93 (spacer (if (string-equal mandatory-option "") "" " ")))
|
42602
|
94 (set symb
|
29165
|
95 (if (string-match mandatory-option val)
|
|
96 val
|
|
97 (concat mandatory-option spacer val)))
|
|
98 ))
|
|
99
|
|
100
|
18054
|
101 (defcustom ediff-shell
|
11042
|
102 (cond ((eq system-type 'emx) "cmd") ; OS/2
|
15480
|
103 ((memq system-type '(ms-dos windows-nt windows-95))
|
|
104 shell-file-name) ; no standard name on MS-DOS
|
11042
|
105 ((memq system-type '(vax-vms axp-vms)) "*dcl*") ; VMS
|
|
106 (t "sh")) ; UNIX
|
42602
|
107 "*The shell used to run diff and patch.
|
|
108 If user's .profile or .cshrc files are set up correctly, any shell
|
|
109 will do. However, some people set $prompt or other things
|
|
110 incorrectly, which leads to undesirable output messages. These may
|
|
111 cause Ediff to fail. In such a case, set `ediff-shell' to a shell that
|
|
112 you are not using or, better, fix your shell's startup file."
|
18054
|
113 :type 'string
|
|
114 :group 'ediff-diff)
|
11042
|
115
|
20206
|
116 (defcustom ediff-cmp-program "cmp"
|
|
117 "*Utility to use to determine if two files are identical.
|
|
118 It must return code 0, if its arguments are identical files."
|
|
119 :type 'string
|
|
120 :group 'ediff-diff)
|
11042
|
121
|
26263
|
122 (defcustom ediff-cmp-options nil
|
41933
|
123 "*Options to pass to `ediff-cmp-program'.
|
|
124 If GNU diff is used as `ediff-cmp-program', then the most useful options
|
42602
|
125 are `-I REGEXP', to ignore changes whose lines match the REGEXP."
|
26263
|
126 :type '(repeat string)
|
|
127 :group 'ediff-diff)
|
|
128
|
29165
|
129 (defcustom ediff-diff-options ""
|
49588
|
130 "*Options to pass to `ediff-diff-program'.
|
68997
|
131 If Unix diff is used as `ediff-diff-program', then a useful option is
|
11042
|
132 `-w', to ignore space, and `-i', to ignore case of letters.
|
68997
|
133 Options `-c' and `-i' are not allowed. Case sensitivity can be toggled
|
|
134 interactively using [ediff-toggle-ignore-case]"
|
29165
|
135 :set 'ediff-reset-diff-options
|
18054
|
136 :type 'string
|
|
137 :group 'ediff-diff)
|
11042
|
138
|
68997
|
139 (ediff-defvar-local ediff-ignore-case nil
|
|
140 "*If t, skip over difference regions that differ only in letter case.
|
|
141 This variable can be set either in .emacs or toggled interactively.
|
|
142 Use `setq-default' if setting it in .emacs")
|
|
143
|
|
144 (defcustom ediff-ignore-case-option "-i"
|
|
145 "*Option that causes the diff program to ignore case of letters."
|
|
146 :type 'string
|
|
147 :group 'ediff-diff)
|
|
148
|
|
149 (defcustom ediff-ignore-case-option3 ""
|
|
150 "*Option that causes the diff3 program to ignore case of letters.
|
|
151 GNU diff3 doesn't have such an option."
|
|
152 :type 'string
|
|
153 :group 'ediff-diff)
|
|
154
|
|
155 ;; the actual options used in comparison
|
|
156 (ediff-defvar-local ediff-actual-diff-options "" "")
|
|
157
|
18054
|
158 (defcustom ediff-custom-diff-program ediff-diff-program
|
11042
|
159 "*Program to use for generating custom diff output for saving it in a file.
|
18054
|
160 This output is not used by Ediff internally."
|
|
161 :type 'string
|
|
162 :group 'ediff-diff)
|
|
163 (defcustom ediff-custom-diff-options "-c"
|
|
164 "*Options to pass to `ediff-custom-diff-program'."
|
|
165 :type 'string
|
|
166 :group 'ediff-diff)
|
11042
|
167
|
|
168 ;;; Support for diff3
|
|
169
|
38514
10482dd382e7
* viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
170 (defvar ediff-match-diff3-line "^====\\(.?\\)\C-m?$"
|
11042
|
171 "Pattern to match lines produced by diff3 that describe differences.")
|
42602
|
172 (defcustom ediff-diff3-options ""
|
18054
|
173 "*Options to pass to `ediff-diff3-program'."
|
29165
|
174 :set 'ediff-reset-diff-options
|
18054
|
175 :type 'string
|
|
176 :group 'ediff-diff)
|
68997
|
177
|
|
178 ;; the actual options used in comparison
|
|
179 (ediff-defvar-local ediff-actual-diff3-options "" "")
|
|
180
|
18054
|
181 (defcustom ediff-diff3-ok-lines-regexp
|
15480
|
182 "^\\([1-3]:\\|====\\| \\|.*Warning *:\\|.*No newline\\|.*missing newline\\|^\C-m$\\)"
|
11042
|
183 "*Regexp that matches normal output lines from `ediff-diff3-program'.
|
18054
|
184 Lines that do not match are assumed to be error messages."
|
|
185 :type 'regexp
|
|
186 :group 'ediff-diff)
|
11042
|
187
|
|
188 ;; keeps the status of the current diff in 3-way jobs.
|
|
189 ;; the status can be =diff(A), =diff(B), or =diff(A+B)
|
|
190 (ediff-defvar-local ediff-diff-status "" "")
|
|
191
|
49588
|
192
|
42602
|
193 ;;; Fine differences
|
11042
|
194
|
14582
|
195 (ediff-defvar-local ediff-auto-refine (if (ediff-has-face-support-p) 'on 'nix)
|
11042
|
196 "If `on', Ediff auto-highlights fine diffs for the current diff region.
|
|
197 If `off', auto-highlighting is not used. If `nix', no fine diffs are shown
|
|
198 at all, unless the user force-refines the region by hitting `*'.
|
|
199
|
|
200 This variable can be set either in .emacs or toggled interactively.
|
|
201 Use `setq-default' if setting it in .emacs")
|
|
202
|
|
203 (ediff-defvar-local ediff-ignore-similar-regions nil
|
|
204 "*If t, skip over difference regions that differ only in the white space and line breaks.
|
|
205 This variable can be set either in .emacs or toggled interactively.
|
|
206 Use `setq-default' if setting it in .emacs")
|
|
207
|
68997
|
208 (ediff-defvar-local ediff-auto-refine-limit 14000
|
15480
|
209 "*Auto-refine only the regions of this size \(in bytes\) or less.")
|
49588
|
210
|
11042
|
211 ;;; General
|
|
212
|
42602
|
213 (defvar ediff-diff-ok-lines-regexp
|
20343
|
214 (concat
|
|
215 "^\\("
|
|
216 "[0-9,]+[acd][0-9,]+\C-m?$"
|
|
217 "\\|[<>] "
|
|
218 "\\|---"
|
|
219 "\\|.*Warning *:"
|
|
220 "\\|.*No +newline"
|
|
221 "\\|.*missing +newline"
|
|
222 "\\|^\C-m?$"
|
|
223 "\\)")
|
11042
|
224 "Regexp that matches normal output lines from `ediff-diff-program'.
|
|
225 This is mostly lifted from Emerge, except that Ediff also considers
|
|
226 warnings and `Missing newline'-type messages to be normal output.
|
|
227 Lines that do not match are assumed to be error messages.")
|
|
228
|
20343
|
229 (defvar ediff-match-diff-line
|
|
230 (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
|
|
231 (concat "^" x "\\([acd]\\)" x "\C-m?$"))
|
11042
|
232 "Pattern to match lines produced by diff that describe differences.")
|
|
233
|
|
234 (ediff-defvar-local ediff-setup-diff-regions-function nil
|
|
235 "value is a function symbol depending on the kind of job is to be done.
|
|
236 For 2-way jobs and for ediff-merge, it should be `ediff-setup-diff-regions'.
|
|
237 For jobs requiring diff3, it should be `ediff-setup-diff-regions3'.
|
|
238
|
|
239 The function should take three mandatory arguments, file-A, file-B, and
|
|
240 file-C. It may ignore file C for diff2 jobs. It should also take
|
|
241 one optional arguments, diff-number to refine.")
|
|
242
|
49588
|
243
|
11042
|
244 ;;; Functions
|
|
245
|
|
246 ;; Generate the difference vector and overlays for the two files
|
|
247 ;; With optional arg REG-TO-REFINE, refine this region.
|
|
248 ;; File-C argument is not used here. It is there just because
|
|
249 ;; ediff-setup-diff-regions is called via a funcall to
|
|
250 ;; ediff-setup-diff-regions-function, which can also have the value
|
|
251 ;; ediff-setup-diff-regions3, which takes 4 arguments.
|
|
252 (defun ediff-setup-diff-regions (file-A file-B file-C)
|
68997
|
253 ;; looking for '-c', '-i', or a 'c', 'i' among clustered non-long options
|
69087
|
254 (if (string-match "^-[ci]\\| -[ci]\\|\\(^\\| \\)-[^- ]+[ci]"
|
|
255 ediff-diff-options)
|
68997
|
256 (error "Options `-c' and `-i' are not allowed in `ediff-diff-options'"))
|
49588
|
257
|
15480
|
258 ;; create, if it doesn't exist
|
11042
|
259 (or (ediff-buffer-live-p ediff-diff-buffer)
|
|
260 (setq ediff-diff-buffer
|
|
261 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
|
15480
|
262 (ediff-make-diff2-buffer ediff-diff-buffer file-A file-B)
|
11042
|
263 (ediff-prepare-error-list ediff-diff-ok-lines-regexp ediff-diff-buffer)
|
|
264 (ediff-convert-diffs-to-overlays
|
|
265 (ediff-extract-diffs
|
14582
|
266 ediff-diff-buffer ediff-word-mode ediff-narrow-bounds)))
|
15480
|
267
|
15482
|
268 ;; Run the diff program on FILE1 and FILE2 and put the output in DIFF-BUFFER
|
|
269 ;; Return the size of DIFF-BUFFER
|
36043
|
270 ;; The return code isn't used in the program at present.
|
15480
|
271 (defun ediff-make-diff2-buffer (diff-buffer file1 file2)
|
16248
|
272 (let ((file1-size (ediff-file-size file1))
|
|
273 (file2-size (ediff-file-size file2)))
|
|
274 (cond ((not (numberp file1-size))
|
|
275 (message "Can't find file: %s"
|
|
276 (ediff-abbreviate-file-name file1))
|
|
277 (sit-for 2)
|
|
278 ;; 1 is an error exit code
|
|
279 1)
|
|
280 ((not (numberp file2-size))
|
|
281 (message "Can't find file: %s"
|
|
282 (ediff-abbreviate-file-name file2))
|
|
283 (sit-for 2)
|
|
284 ;; 1 is an error exit code
|
|
285 1)
|
|
286 (t (message "Computing differences between %s and %s ..."
|
|
287 (file-name-nondirectory file1)
|
|
288 (file-name-nondirectory file2))
|
|
289 ;; this erases the diff buffer automatically
|
|
290 (ediff-exec-process ediff-diff-program
|
|
291 diff-buffer
|
|
292 'synchronize
|
68997
|
293 ediff-actual-diff-options file1 file2)
|
16248
|
294 (message "")
|
19047
|
295 (ediff-with-current-buffer diff-buffer
|
16248
|
296 (buffer-size))))))
|
49588
|
297
|
15480
|
298
|
49588
|
299
|
11042
|
300 ;; If file-A/B/C is nil, do 2-way comparison with the non-nil buffers
|
|
301 ;; This function works for diff3 and diff2 jobs
|
|
302 (defun ediff-setup-fine-diff-regions (file-A file-B file-C reg-num)
|
|
303 (or (ediff-buffer-live-p ediff-fine-diff-buffer)
|
|
304 (setq ediff-fine-diff-buffer
|
|
305 (get-buffer-create
|
|
306 (ediff-unique-buffer-name "*ediff-fine-diff" "*"))))
|
49588
|
307
|
15175
|
308 (let (diff3-job diff-program diff-options ok-regexp diff-list)
|
11042
|
309 (setq diff3-job ediff-3way-job
|
|
310 diff-program (if diff3-job ediff-diff3-program ediff-diff-program)
|
68997
|
311 diff-options (if diff3-job
|
|
312 ediff-actual-diff3-options
|
|
313 ediff-actual-diff-options)
|
11042
|
314 ok-regexp (if diff3-job
|
|
315 ediff-diff3-ok-lines-regexp
|
|
316 ediff-diff-ok-lines-regexp))
|
49588
|
317
|
13127
|
318 (ediff-message-if-verbose "Refining difference region %d ..." (1+ reg-num))
|
|
319 (ediff-exec-process diff-program ediff-fine-diff-buffer 'synchronize
|
15175
|
320 diff-options
|
13127
|
321 ;; The shuffle below is because we can compare 3-way
|
|
322 ;; or in several 2-way fashions, like fA fC, fA fB,
|
|
323 ;; or fB fC.
|
|
324 (if file-A file-A file-B)
|
|
325 (if file-B file-B file-A)
|
|
326 (if diff3-job
|
|
327 (if file-C file-C file-B))
|
|
328 ) ; exec process
|
49588
|
329
|
11042
|
330 (ediff-prepare-error-list ok-regexp ediff-fine-diff-buffer)
|
14582
|
331 (ediff-message-if-verbose
|
|
332 "")
|
13127
|
333 ;; "Refining difference region %d ... done" (1+ reg-num))
|
49588
|
334
|
11042
|
335 (setq diff-list
|
|
336 (if diff3-job
|
|
337 (ediff-extract-diffs3
|
|
338 ediff-fine-diff-buffer '3way-comparison 'word-mode)
|
|
339 (ediff-extract-diffs ediff-fine-diff-buffer 'word-mode)))
|
|
340 ;; fixup diff-list
|
|
341 (if diff3-job
|
|
342 (cond ((not file-A)
|
26263
|
343 (mapcar (lambda (elt)
|
|
344 (aset elt 0 nil)
|
|
345 (aset elt 1 nil))
|
11042
|
346 (cdr diff-list)))
|
|
347 ((not file-B)
|
26263
|
348 (mapcar (lambda (elt)
|
|
349 (aset elt 2 nil)
|
|
350 (aset elt 3 nil))
|
11042
|
351 (cdr diff-list)))
|
|
352 ((not file-C)
|
26263
|
353 (mapcar (lambda (elt)
|
|
354 (aset elt 4 nil)
|
|
355 (aset elt 5 nil))
|
11042
|
356 (cdr diff-list)))
|
|
357 ))
|
49588
|
358
|
11042
|
359 (ediff-convert-fine-diffs-to-overlays diff-list reg-num)
|
|
360 ))
|
49588
|
361
|
|
362
|
11042
|
363 (defun ediff-prepare-error-list (ok-regexp diff-buff)
|
13127
|
364 (or (ediff-buffer-live-p ediff-error-buffer)
|
|
365 (setq ediff-error-buffer
|
|
366 (get-buffer-create (ediff-unique-buffer-name
|
|
367 "*ediff-errors" "*"))))
|
19047
|
368 (ediff-with-current-buffer ediff-error-buffer
|
13127
|
369 (erase-buffer)
|
19047
|
370 (insert (ediff-with-current-buffer diff-buff (buffer-string)))
|
13127
|
371 (goto-char (point-min))
|
|
372 (delete-matching-lines ok-regexp)
|
|
373 (if (memq system-type '(vax-vms axp-vms))
|
|
374 (delete-matching-lines "^$")))
|
|
375 ;; If diff reports errors, show them then quit.
|
19047
|
376 (if (/= 0 (ediff-with-current-buffer ediff-error-buffer (buffer-size)))
|
13127
|
377 (let ((ctl-buf ediff-control-buffer)
|
|
378 (error-buf ediff-error-buffer))
|
|
379 (ediff-skip-unsuitable-frames)
|
|
380 (switch-to-buffer error-buf)
|
|
381 (ediff-kill-buffer-carefully ctl-buf)
|
42602
|
382 (error "Errors in diff output. Diff output is in %S" diff-buff))))
|
11042
|
383
|
|
384 ;; BOUNDS specifies visibility bounds to use.
|
|
385 ;; WORD-MODE tells whether we are in the word-mode or not.
|
|
386 ;; If WORD-MODE, also construct vector of diffs using word numbers.
|
|
387 ;; Else, use point values.
|
|
388 ;; This function handles diff-2 jobs including the case of
|
|
389 ;; merging buffers and files without ancestor.
|
|
390 (defun ediff-extract-diffs (diff-buffer word-mode &optional bounds)
|
|
391 (let ((A-buffer ediff-buffer-A)
|
|
392 (B-buffer ediff-buffer-B)
|
|
393 (C-buffer ediff-buffer-C)
|
|
394 (a-prev 1) ; this is needed to set the first diff line correctly
|
68997
|
395 (a-prev-pt nil)
|
11042
|
396 (b-prev 1)
|
68997
|
397 (b-prev-pt nil)
|
11042
|
398 (c-prev 1)
|
68997
|
399 (c-prev-pt nil)
|
11042
|
400 diff-list shift-A shift-B
|
|
401 )
|
68997
|
402
|
11042
|
403 ;; diff list contains word numbers, unless changed later
|
|
404 (setq diff-list (cons (if word-mode 'words 'points)
|
|
405 diff-list))
|
|
406 ;; we don't use visibility bounds for buffer C when merging
|
|
407 (if bounds
|
|
408 (setq shift-A
|
|
409 (ediff-overlay-start
|
|
410 (ediff-get-value-according-to-buffer-type 'A bounds))
|
42602
|
411 shift-B
|
11042
|
412 (ediff-overlay-start
|
|
413 (ediff-get-value-according-to-buffer-type 'B bounds))))
|
68997
|
414
|
11042
|
415 ;; reset point in buffers A/B/C
|
19047
|
416 (ediff-with-current-buffer A-buffer
|
11042
|
417 (goto-char (if shift-A shift-A (point-min))))
|
19047
|
418 (ediff-with-current-buffer B-buffer
|
11042
|
419 (goto-char (if shift-B shift-B (point-min))))
|
|
420 (if (ediff-buffer-live-p C-buffer)
|
19047
|
421 (ediff-with-current-buffer C-buffer
|
11042
|
422 (goto-char (point-min))))
|
49588
|
423
|
19047
|
424 (ediff-with-current-buffer diff-buffer
|
11042
|
425 (goto-char (point-min))
|
|
426 (while (re-search-forward ediff-match-diff-line nil t)
|
62402
|
427 (let* ((a-begin (string-to-number (buffer-substring (match-beginning 1)
|
|
428 (match-end 1))))
|
11042
|
429 (a-end (let ((b (match-beginning 3))
|
|
430 (e (match-end 3)))
|
|
431 (if b
|
62402
|
432 (string-to-number (buffer-substring b e))
|
11042
|
433 a-begin)))
|
|
434 (diff-type (buffer-substring (match-beginning 4) (match-end 4)))
|
62402
|
435 (b-begin (string-to-number (buffer-substring (match-beginning 5)
|
|
436 (match-end 5))))
|
11042
|
437 (b-end (let ((b (match-beginning 7))
|
|
438 (e (match-end 7)))
|
|
439 (if b
|
62402
|
440 (string-to-number (buffer-substring b e))
|
11042
|
441 b-begin)))
|
|
442 a-begin-pt a-end-pt b-begin-pt b-end-pt
|
|
443 c-begin c-end c-begin-pt c-end-pt)
|
|
444 ;; fix the beginning and end numbers, because diff is somewhat
|
|
445 ;; strange about how it numbers lines
|
|
446 (if (string-equal diff-type "a")
|
|
447 (setq b-end (1+ b-end)
|
|
448 a-begin (1+ a-begin)
|
|
449 a-end a-begin)
|
|
450 (if (string-equal diff-type "d")
|
|
451 (setq a-end (1+ a-end)
|
|
452 b-begin (1+ b-begin)
|
|
453 b-end b-begin)
|
|
454 ;; (string-equal diff-type "c")
|
|
455 (setq a-end (1+ a-end)
|
|
456 b-end (1+ b-end))))
|
49588
|
457
|
11042
|
458 (if (eq ediff-default-variant 'default-B)
|
|
459 (setq c-begin b-begin
|
|
460 c-end b-end)
|
|
461 (setq c-begin a-begin
|
|
462 c-end a-end))
|
49588
|
463
|
11042
|
464 ;; compute main diff vector
|
|
465 (if word-mode
|
|
466 ;; make diff-list contain word numbers
|
42602
|
467 (setq diff-list
|
11042
|
468 (nconc diff-list
|
|
469 (list
|
|
470 (if (ediff-buffer-live-p C-buffer)
|
|
471 (vector (- a-begin a-prev) (- a-end a-begin)
|
|
472 (- b-begin b-prev) (- b-end b-begin)
|
|
473 (- c-begin c-prev) (- c-end c-begin)
|
13127
|
474 nil nil ; dummy ancestor
|
|
475 nil ; state of diff
|
|
476 nil ; state of merge
|
|
477 nil ; state of ancestor
|
11042
|
478 )
|
|
479 (vector (- a-begin a-prev) (- a-end a-begin)
|
|
480 (- b-begin b-prev) (- b-end b-begin)
|
|
481 nil nil ; dummy buf C
|
13127
|
482 nil nil ; dummy ancestor
|
11042
|
483 nil ; state of diff
|
|
484 nil ; state of merge
|
13127
|
485 nil ; state of ancestor
|
11042
|
486 ))
|
|
487 ))
|
|
488 a-prev a-end
|
|
489 b-prev b-end
|
|
490 c-prev c-end)
|
|
491 ;; else convert lines to points
|
19047
|
492 (ediff-with-current-buffer A-buffer
|
64215
|
493 (let ((longlines-mode-val
|
|
494 (if (and (boundp 'longlines-mode) longlines-mode) 1 0)))
|
|
495 ;; we must disable and then restore longlines-mode
|
|
496 (if (eq longlines-mode-val 1)
|
|
497 (longlines-mode 0))
|
68997
|
498 (goto-char (or a-prev-pt shift-A (point-min)))
|
64215
|
499 (forward-line (- a-begin a-prev))
|
|
500 (setq a-begin-pt (point))
|
|
501 (forward-line (- a-end a-begin))
|
|
502 (setq a-end-pt (point)
|
68997
|
503 a-prev a-end
|
|
504 a-prev-pt a-end-pt)
|
64215
|
505 (if (eq longlines-mode-val 1)
|
|
506 (longlines-mode longlines-mode-val))
|
|
507 ))
|
19047
|
508 (ediff-with-current-buffer B-buffer
|
64215
|
509 (let ((longlines-mode-val
|
|
510 (if (and (boundp 'longlines-mode) longlines-mode) 1 0)))
|
|
511 (if (eq longlines-mode-val 1)
|
|
512 (longlines-mode 0))
|
68997
|
513 (goto-char (or b-prev-pt shift-B (point-min)))
|
64215
|
514 (forward-line (- b-begin b-prev))
|
|
515 (setq b-begin-pt (point))
|
|
516 (forward-line (- b-end b-begin))
|
|
517 (setq b-end-pt (point)
|
68997
|
518 b-prev b-end
|
|
519 b-prev-pt b-end-pt)
|
64215
|
520 (if (eq longlines-mode-val 1)
|
|
521 (longlines-mode longlines-mode-val))
|
|
522 ))
|
11042
|
523 (if (ediff-buffer-live-p C-buffer)
|
19047
|
524 (ediff-with-current-buffer C-buffer
|
64215
|
525 (let ((longlines-mode-val
|
|
526 (if (and (boundp 'longlines-mode) longlines-mode) 1 0)))
|
|
527 (if (eq longlines-mode-val 1)
|
|
528 (longlines-mode 0))
|
68997
|
529 (goto-char (or c-prev-pt (point-min)))
|
64215
|
530 (forward-line (- c-begin c-prev))
|
|
531 (setq c-begin-pt (point))
|
|
532 (forward-line (- c-end c-begin))
|
|
533 (setq c-end-pt (point)
|
68997
|
534 c-prev c-end
|
|
535 c-prev-pt c-end-pt)
|
64215
|
536 (if (eq longlines-mode-val 1)
|
|
537 (longlines-mode longlines-mode-val))
|
|
538 )))
|
42602
|
539 (setq diff-list
|
11042
|
540 (nconc
|
|
541 diff-list
|
|
542 (list
|
|
543 (if (ediff-buffer-live-p C-buffer)
|
|
544 (vector
|
|
545 a-begin-pt a-end-pt b-begin-pt b-end-pt
|
|
546 c-begin-pt c-end-pt
|
13127
|
547 nil nil ; dummy ancestor
|
11042
|
548 ;; state of diff
|
|
549 ;; shows which buff is different from the other two
|
|
550 (if (eq ediff-default-variant 'default-B) 'A 'B)
|
13127
|
551 ediff-default-variant ; state of merge
|
|
552 nil ; state of ancestor
|
11042
|
553 )
|
13127
|
554 (vector a-begin-pt a-end-pt
|
|
555 b-begin-pt b-end-pt
|
|
556 nil nil ; dummy buf C
|
|
557 nil nil ; dummy ancestor
|
|
558 nil nil ; dummy state of diff & merge
|
|
559 nil ; dummy state of ancestor
|
42602
|
560 )))
|
11042
|
561 )))
|
49588
|
562
|
19047
|
563 ))) ; end ediff-with-current-buffer
|
11042
|
564 diff-list
|
|
565 ))
|
49588
|
566
|
11042
|
567
|
13127
|
568 (defun ediff-convert-diffs-to-overlays (diff-list)
|
|
569 (ediff-set-diff-overlays-in-one-buffer 'A diff-list)
|
|
570 (ediff-set-diff-overlays-in-one-buffer 'B diff-list)
|
|
571 (if ediff-3way-job
|
|
572 (ediff-set-diff-overlays-in-one-buffer 'C diff-list))
|
|
573 (if ediff-merge-with-ancestor-job
|
|
574 (ediff-set-diff-overlays-in-one-buffer 'Ancestor diff-list))
|
|
575 ;; set up vector showing the status of merge regions
|
|
576 (if ediff-merge-job
|
|
577 (setq ediff-state-of-merge
|
|
578 (vconcat
|
26263
|
579 (mapcar (lambda (elt)
|
|
580 (let ((state-of-merge (aref elt 9))
|
|
581 (state-of-ancestor (aref elt 10)))
|
|
582 (vector
|
|
583 ;; state of merge: prefers/default-A/B or combined
|
|
584 (if state-of-merge (format "%S" state-of-merge))
|
|
585 ;; whether the ancestor region is empty
|
|
586 state-of-ancestor)))
|
13127
|
587 ;; the first elt designates type of list
|
|
588 (cdr diff-list))
|
|
589 )))
|
|
590 (message "Processing difference regions ... done"))
|
|
591
|
49588
|
592
|
11042
|
593 (defun ediff-set-diff-overlays-in-one-buffer (buf-type diff-list)
|
|
594 (let* ((current-diff -1)
|
|
595 (buff (ediff-get-buffer buf-type))
|
60151
|
596 (ctl-buf ediff-control-buffer)
|
11042
|
597 ;; ediff-extract-diffs puts the type of diff-list as the first elt
|
|
598 ;; of this list. The type is either 'points or 'words
|
|
599 (diff-list-type (car diff-list))
|
|
600 (shift (ediff-overlay-start
|
|
601 (ediff-get-value-according-to-buffer-type
|
|
602 buf-type ediff-narrow-bounds)))
|
|
603 (limit (ediff-overlay-end
|
42602
|
604 (ediff-get-value-according-to-buffer-type
|
11042
|
605 buf-type ediff-narrow-bounds)))
|
|
606 diff-overlay-list list-element total-diffs
|
13127
|
607 begin end pt-saved overlay state-of-diff)
|
11042
|
608
|
|
609 (setq diff-list (cdr diff-list)) ; discard diff list type
|
|
610 (setq total-diffs (length diff-list))
|
49588
|
611
|
11042
|
612 ;; shift, if necessary
|
19047
|
613 (ediff-with-current-buffer buff (setq pt-saved shift))
|
49588
|
614
|
11042
|
615 (while diff-list
|
|
616 (setq current-diff (1+ current-diff)
|
|
617 list-element (car diff-list)
|
|
618 begin (aref list-element (cond ((eq buf-type 'A) 0)
|
|
619 ((eq buf-type 'B) 2)
|
13127
|
620 ((eq buf-type 'C) 4)
|
|
621 (t 6))) ; Ancestor
|
11042
|
622 end (aref list-element (cond ((eq buf-type 'A) 1)
|
|
623 ((eq buf-type 'B) 3)
|
13127
|
624 ((eq buf-type 'C) 5)
|
|
625 (t 7))) ; Ancestor
|
|
626 state-of-diff (aref list-element 8)
|
|
627 )
|
49588
|
628
|
11042
|
629 (cond ((and (not (eq buf-type state-of-diff))
|
13127
|
630 (not (eq buf-type 'Ancestor))
|
11042
|
631 (memq state-of-diff '(A B C)))
|
|
632 (setq state-of-diff
|
|
633 (car (delq buf-type (delq state-of-diff (list 'A 'B 'C)))))
|
|
634 (setq state-of-diff (format "=diff(%S)" state-of-diff))
|
|
635 )
|
13127
|
636 (t (setq state-of-diff nil)))
|
49588
|
637
|
11042
|
638 ;; Put overlays at appropriate places in buffer
|
|
639 ;; convert word numbers to points, if necessary
|
|
640 (if (eq diff-list-type 'words)
|
|
641 (progn
|
19047
|
642 (ediff-with-current-buffer buff (goto-char pt-saved))
|
60151
|
643 (ediff-with-current-buffer ctl-buf
|
|
644 (setq begin (ediff-goto-word (1+ begin) buff)
|
|
645 end (ediff-goto-word end buff 'end)))
|
11042
|
646 (if (> end limit) (setq end limit))
|
|
647 (if (> begin end) (setq begin end))
|
19047
|
648 (setq pt-saved (ediff-with-current-buffer buff (point)))))
|
11042
|
649 (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
|
49588
|
650
|
11042
|
651 (ediff-overlay-put overlay 'priority ediff-shadow-overlay-priority)
|
|
652 (ediff-overlay-put overlay 'ediff-diff-num current-diff)
|
14582
|
653 (if (and (ediff-has-face-support-p)
|
13127
|
654 ediff-use-faces ediff-highlight-all-diffs)
|
|
655 (ediff-set-overlay-face
|
|
656 overlay (ediff-background-face buf-type current-diff)))
|
11042
|
657
|
|
658 (if (= 0 (mod current-diff 10))
|
|
659 (message "Buffer %S: Processing difference region %d of %d"
|
|
660 buf-type current-diff total-diffs))
|
26263
|
661 ;; Record all overlays for this difference.
|
|
662 ;; The 2-d elt, nil, is a place holder for the fine diff vector.
|
|
663 ;; The 3-d elt, nil, is a place holder for no-fine-diffs flag.
|
|
664 ;; The 4-th elt says which diff region is different from the other two
|
|
665 ;; (3-way jobs only).
|
11042
|
666 (setq diff-overlay-list
|
|
667 (nconc
|
|
668 diff-overlay-list
|
13127
|
669 (list (vector overlay nil nil state-of-diff)))
|
11042
|
670 diff-list
|
|
671 (cdr diff-list))
|
|
672 ) ; while
|
49588
|
673
|
19047
|
674 (set (ediff-get-symbol-from-alist buf-type ediff-difference-vector-alist)
|
13127
|
675 (vconcat diff-overlay-list))
|
11042
|
676 ))
|
13127
|
677
|
11042
|
678 ;; `n' is the diff region to work on. Default is ediff-current-difference.
|
|
679 ;; if `flag' is 'noforce then make fine-diffs only if this region's fine
|
|
680 ;; diffs have not been computed before.
|
|
681 ;; if `flag' is 'skip then don't compute fine diffs for this region.
|
42602
|
682 (defun ediff-make-fine-diffs (&optional n flag)
|
11042
|
683 (or n (setq n ediff-current-difference))
|
49588
|
684
|
11042
|
685 (if (< ediff-number-of-differences 1)
|
15480
|
686 (error ediff-NO-DIFFERENCES))
|
49588
|
687
|
11042
|
688 (if ediff-word-mode
|
|
689 (setq flag 'skip
|
|
690 ediff-auto-refine 'nix))
|
49588
|
691
|
11042
|
692 (or (< n 0)
|
|
693 (>= n ediff-number-of-differences)
|
|
694 ;; n is within the range
|
|
695 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
|
|
696 (file-A ediff-temp-file-A)
|
|
697 (file-B ediff-temp-file-B)
|
|
698 (file-C ediff-temp-file-C)
|
|
699 (empty-A (ediff-empty-diff-region-p n 'A))
|
|
700 (empty-B (ediff-empty-diff-region-p n 'B))
|
|
701 (empty-C (ediff-empty-diff-region-p n 'C))
|
|
702 (whitespace-A (ediff-whitespace-diff-region-p n 'A))
|
|
703 (whitespace-B (ediff-whitespace-diff-region-p n 'B))
|
|
704 (whitespace-C (ediff-whitespace-diff-region-p n 'C))
|
|
705 cumulative-fine-diff-length)
|
49588
|
706
|
18054
|
707 (cond ;; If one of the regions is empty (or 2 in 3way comparison)
|
13127
|
708 ;; then don't refine.
|
|
709 ;; If the region happens to be entirely whitespace or empty then
|
|
710 ;; mark as such.
|
11042
|
711 ((> (length (delq nil (list empty-A empty-B empty-C))) 1)
|
|
712 (if (and (ediff-looks-like-combined-merge n)
|
|
713 ediff-merge-job)
|
|
714 (ediff-set-fine-overlays-in-one-buffer 'C nil n))
|
13127
|
715 (if ediff-3way-comparison-job
|
|
716 (ediff-message-if-verbose
|
|
717 "Region %d is empty in all buffers but %S"
|
42602
|
718 (1+ n)
|
13127
|
719 (cond ((not empty-A) 'A)
|
|
720 ((not empty-B) 'B)
|
|
721 ((not empty-C) 'C)))
|
|
722 (ediff-message-if-verbose
|
|
723 "Region %d in buffer %S is empty"
|
42602
|
724 (1+ n)
|
13127
|
725 (cond (empty-A 'A)
|
|
726 (empty-B 'B)
|
|
727 (empty-C 'C)))
|
|
728 )
|
15480
|
729 ;; if all regions happen to be whitespace
|
13127
|
730 (if (and whitespace-A whitespace-B whitespace-C)
|
15480
|
731 ;; mark as space only
|
11042
|
732 (ediff-mark-diff-as-space-only n t)
|
15480
|
733 ;; if some regions are white and others don't, then mark as
|
|
734 ;; non-white-space-only
|
11042
|
735 (ediff-mark-diff-as-space-only n nil)))
|
18054
|
736
|
|
737 ;; don't compute fine diffs if diff vector exists
|
|
738 ((and (eq flag 'noforce) (ediff-get-fine-diff-vector n 'A))
|
|
739 (if (ediff-no-fine-diffs-p n)
|
|
740 (message
|
|
741 "Only white-space differences in region %d %s"
|
|
742 (1+ n)
|
|
743 (cond ((eq (ediff-no-fine-diffs-p n) 'A)
|
|
744 "in buffers B & C")
|
|
745 ((eq (ediff-no-fine-diffs-p n) 'B)
|
|
746 "in buffers A & C")
|
|
747 ((eq (ediff-no-fine-diffs-p n) 'C)
|
|
748 "in buffers A & B")
|
|
749 (t "")))))
|
11042
|
750 ;; don't compute fine diffs for this region
|
|
751 ((eq flag 'skip)
|
|
752 (or (ediff-get-fine-diff-vector n 'A)
|
|
753 (memq ediff-auto-refine '(off nix))
|
13127
|
754 (ediff-message-if-verbose
|
26263
|
755 "Region %d exceeds the auto-refinement limit. Type `%s' to refine"
|
11042
|
756 (1+ n)
|
13127
|
757 (substitute-command-keys
|
|
758 "\\[ediff-make-or-kill-fine-diffs]")
|
11042
|
759 )))
|
|
760 (t
|
|
761 ;; recompute fine diffs
|
|
762 (ediff-wordify
|
|
763 (ediff-get-diff-posn 'A 'beg n)
|
|
764 (ediff-get-diff-posn 'A 'end n)
|
|
765 ediff-buffer-A
|
|
766 tmp-buffer
|
|
767 ediff-control-buffer)
|
13127
|
768 (setq file-A
|
|
769 (ediff-make-temp-file tmp-buffer "fineDiffA" file-A))
|
49588
|
770
|
11042
|
771 (ediff-wordify
|
|
772 (ediff-get-diff-posn 'B 'beg n)
|
|
773 (ediff-get-diff-posn 'B 'end n)
|
|
774 ediff-buffer-B
|
|
775 tmp-buffer
|
|
776 ediff-control-buffer)
|
13127
|
777 (setq file-B
|
|
778 (ediff-make-temp-file tmp-buffer "fineDiffB" file-B))
|
49588
|
779
|
11042
|
780 (if ediff-3way-job
|
|
781 (progn
|
|
782 (ediff-wordify
|
|
783 (ediff-get-diff-posn 'C 'beg n)
|
|
784 (ediff-get-diff-posn 'C 'end n)
|
|
785 ediff-buffer-C
|
|
786 tmp-buffer
|
|
787 ediff-control-buffer)
|
13127
|
788 (setq file-C
|
|
789 (ediff-make-temp-file
|
|
790 tmp-buffer "fineDiffC" file-C))))
|
49588
|
791
|
11042
|
792 ;; save temp file names.
|
|
793 (setq ediff-temp-file-A file-A
|
|
794 ediff-temp-file-B file-B
|
|
795 ediff-temp-file-C file-C)
|
49588
|
796
|
11042
|
797 ;; set the new vector of fine diffs, if none exists
|
|
798 (cond ((and ediff-3way-job whitespace-A)
|
|
799 (ediff-setup-fine-diff-regions nil file-B file-C n))
|
|
800 ((and ediff-3way-job whitespace-B)
|
|
801 (ediff-setup-fine-diff-regions file-A nil file-C n))
|
|
802 ((and ediff-3way-job
|
15480
|
803 ;; In merge-jobs, whitespace-C is t, since
|
|
804 ;; ediff-empty-diff-region-p returns t in this case
|
|
805 whitespace-C)
|
11042
|
806 (ediff-setup-fine-diff-regions file-A file-B nil n))
|
|
807 (t
|
|
808 (ediff-setup-fine-diff-regions file-A file-B file-C n)))
|
49588
|
809
|
11042
|
810 (setq cumulative-fine-diff-length
|
|
811 (+ (length (ediff-get-fine-diff-vector n 'A))
|
15480
|
812 (length (ediff-get-fine-diff-vector n 'B))
|
|
813 ;; in merge jobs, the merge buffer is never refined
|
|
814 (if (and file-C (not ediff-merge-job))
|
|
815 (length (ediff-get-fine-diff-vector n 'C))
|
|
816 0)))
|
49588
|
817
|
11042
|
818 (cond ((or
|
|
819 ;; all regions are white space
|
|
820 (and whitespace-A whitespace-B whitespace-C)
|
|
821 ;; none is white space and no fine diffs detected
|
|
822 (and (not whitespace-A)
|
|
823 (not whitespace-B)
|
|
824 (not (and ediff-3way-job whitespace-C))
|
|
825 (eq cumulative-fine-diff-length 0)))
|
|
826 (ediff-mark-diff-as-space-only n t)
|
13127
|
827 (ediff-message-if-verbose
|
11042
|
828 "Only white-space differences in region %d" (1+ n)))
|
|
829 ((eq cumulative-fine-diff-length 0)
|
13127
|
830 (ediff-message-if-verbose
|
11042
|
831 "Only white-space differences in region %d %s"
|
|
832 (1+ n)
|
18054
|
833 (cond (whitespace-A (ediff-mark-diff-as-space-only n 'A)
|
|
834 "in buffers B & C")
|
|
835 (whitespace-B (ediff-mark-diff-as-space-only n 'B)
|
|
836 "in buffers A & C")
|
|
837 (whitespace-C (ediff-mark-diff-as-space-only n 'C)
|
|
838 "in buffers A & B"))))
|
42602
|
839 (t
|
11042
|
840 (ediff-mark-diff-as-space-only n nil)))
|
|
841 )
|
|
842 ) ; end cond
|
|
843 (ediff-set-fine-diff-properties n)
|
|
844 )))
|
49588
|
845
|
11042
|
846 ;; Interface to ediff-make-fine-diffs. Checks for auto-refine limit, etc.
|
|
847 (defun ediff-install-fine-diff-if-necessary (n)
|
44028
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
848 (cond ((and (eq ediff-auto-refine 'on)
|
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
849 ediff-use-faces
|
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
850 (not (eq ediff-highlighting-style 'off))
|
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
851 (not (eq ediff-highlighting-style 'ascii)))
|
11042
|
852 (if (and
|
|
853 (> ediff-auto-refine-limit
|
|
854 (- (ediff-get-diff-posn 'A 'end n)
|
|
855 (ediff-get-diff-posn 'A 'beg n)))
|
|
856 (> ediff-auto-refine-limit
|
|
857 (- (ediff-get-diff-posn 'B 'end n)
|
|
858 (ediff-get-diff-posn 'B 'beg n))))
|
|
859 (ediff-make-fine-diffs n 'noforce)
|
|
860 (ediff-make-fine-diffs n 'skip)))
|
49588
|
861
|
11042
|
862 ;; highlight iff fine diffs already exist
|
|
863 ((eq ediff-auto-refine 'off)
|
|
864 (ediff-make-fine-diffs n 'skip))))
|
49588
|
865
|
|
866
|
11042
|
867 ;; if fine diff vector is not set for diff N, then do nothing
|
|
868 (defun ediff-set-fine-diff-properties (n &optional default)
|
14582
|
869 (or (not (ediff-has-face-support-p))
|
11042
|
870 (< n 0)
|
|
871 (>= n ediff-number-of-differences)
|
14582
|
872 ;; when faces are supported, set faces and priorities of fine overlays
|
11042
|
873 (progn
|
|
874 (ediff-set-fine-diff-properties-in-one-buffer 'A n default)
|
|
875 (ediff-set-fine-diff-properties-in-one-buffer 'B n default)
|
|
876 (if ediff-3way-job
|
|
877 (ediff-set-fine-diff-properties-in-one-buffer 'C n default)))))
|
49588
|
878
|
11042
|
879 (defun ediff-set-fine-diff-properties-in-one-buffer (buf-type
|
|
880 n &optional default)
|
|
881 (let ((fine-diff-vector (ediff-get-fine-diff-vector n buf-type))
|
42602
|
882 (face (if default
|
11042
|
883 'default
|
|
884 (face-name
|
19047
|
885 (ediff-get-symbol-from-alist
|
|
886 buf-type ediff-fine-diff-face-alist))))
|
11042
|
887 (priority (if default
|
|
888 0
|
|
889 (1+ (or (ediff-overlay-get
|
|
890 (symbol-value
|
19047
|
891 (ediff-get-symbol-from-alist
|
|
892 buf-type
|
|
893 ediff-current-diff-overlay-alist))
|
11042
|
894 'priority)
|
|
895 0)))))
|
26263
|
896 (mapcar (lambda (overl)
|
|
897 (ediff-set-overlay-face overl face)
|
|
898 (ediff-overlay-put overl 'priority priority))
|
|
899 fine-diff-vector)))
|
49588
|
900
|
26585
|
901 ;; Set overlays over the regions that denote delimiters
|
11042
|
902 (defun ediff-set-fine-overlays-for-combined-merge (diff-list reg-num)
|
26585
|
903 (let (overlay overlay-list)
|
|
904 (while diff-list
|
|
905 (condition-case nil
|
|
906 (setq overlay
|
|
907 (ediff-make-bullet-proof-overlay
|
|
908 (nth 0 diff-list) (nth 1 diff-list) ediff-buffer-C))
|
|
909 (error ""))
|
|
910 (setq overlay-list (cons overlay overlay-list))
|
|
911 (if (> (length diff-list) 1)
|
|
912 (setq diff-list (cdr (cdr diff-list)))
|
|
913 (error "ediff-set-fine-overlays-for-combined-merge: corrupt list of
|
|
914 delimiter regions"))
|
|
915 )
|
|
916 (setq overlay-list (reverse overlay-list))
|
|
917 (ediff-set-fine-diff-vector
|
|
918 reg-num 'C (apply 'vector overlay-list))
|
11042
|
919 ))
|
49588
|
920
|
|
921
|
11042
|
922 ;; Convert diff list to overlays for a given DIFF-REGION
|
|
923 ;; in buffer of type BUF-TYPE
|
|
924 (defun ediff-set-fine-overlays-in-one-buffer (buf-type diff-list region-num)
|
|
925 (let* ((current-diff -1)
|
|
926 (reg-start (ediff-get-diff-posn buf-type 'beg region-num))
|
|
927 (buff (ediff-get-buffer buf-type))
|
60151
|
928 (ctl-buf ediff-control-buffer)
|
11042
|
929 combined-merge-diff-list
|
|
930 diff-overlay-list list-element
|
|
931 begin end overlay)
|
|
932
|
|
933 (ediff-clear-fine-differences-in-one-buffer region-num buf-type)
|
|
934 (setq diff-list (cdr diff-list)) ; discard list type (words or points)
|
19047
|
935 (ediff-with-current-buffer buff (goto-char reg-start))
|
49588
|
936
|
11042
|
937 ;; if it is a combined merge then set overlays in buff C specially
|
|
938 (if (and ediff-merge-job (eq buf-type 'C)
|
|
939 (setq combined-merge-diff-list
|
|
940 (ediff-looks-like-combined-merge region-num)))
|
|
941 (ediff-set-fine-overlays-for-combined-merge
|
|
942 combined-merge-diff-list region-num)
|
|
943 ;; regular fine diff
|
|
944 (while diff-list
|
|
945 (setq current-diff (1+ current-diff)
|
|
946 list-element (car diff-list)
|
|
947 begin (aref list-element (cond ((eq buf-type 'A) 0)
|
|
948 ((eq buf-type 'B) 2)
|
|
949 (t 4))) ; buf C
|
|
950 end (aref list-element (cond ((eq buf-type 'A) 1)
|
|
951 ((eq buf-type 'B) 3)
|
|
952 (t 5)))) ; buf C
|
|
953 (if (not (or begin end))
|
|
954 () ; skip this diff
|
|
955 ;; Put overlays at appropriate places in buffers
|
|
956 ;; convert lines to points, if necessary
|
60151
|
957 (ediff-with-current-buffer ctl-buf
|
|
958 (setq begin (ediff-goto-word (1+ begin) buff)
|
|
959 end (ediff-goto-word end buff 'end)))
|
11042
|
960 (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
|
|
961 ;; record all overlays for this difference region
|
|
962 (setq diff-overlay-list (nconc diff-overlay-list (list overlay))))
|
49588
|
963
|
11042
|
964 (setq diff-list (cdr diff-list))
|
|
965 ) ; while
|
|
966 ;; convert the list of difference information into a vector
|
|
967 ;; for fast access
|
42602
|
968 (ediff-set-fine-diff-vector
|
13127
|
969 region-num buf-type (vconcat diff-overlay-list))
|
11042
|
970 )))
|
|
971
|
|
972
|
42602
|
973 (defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num)
|
|
974 (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num)
|
|
975 (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num)
|
|
976 (if ediff-3way-job
|
|
977 (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num)
|
|
978 ))
|
|
979
|
|
980
|
11042
|
981 ;; Stolen from emerge.el
|
|
982 (defun ediff-get-diff3-group (file)
|
|
983 ;; This save-excursion allows ediff-get-diff3-group to be called for the
|
|
984 ;; various groups of lines (1, 2, 3) in any order, and for the lines to
|
|
985 ;; appear in any order. The reason this is necessary is that Gnu diff3
|
|
986 ;; can produce the groups in the order 1, 2, 3 or 1, 3, 2.
|
|
987 (save-excursion
|
|
988 (re-search-forward
|
38514
10482dd382e7
* viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
989 (concat "^" file ":\\([0-9]+\\)\\(,\\([0-9]+\\)\\)?\\([ac]\\)\C-m?$"))
|
11042
|
990 (beginning-of-line 2)
|
|
991 ;; treatment depends on whether it is an "a" group or a "c" group
|
|
992 (if (string-equal (buffer-substring (match-beginning 4) (match-end 4)) "c")
|
|
993 ;; it is a "c" group
|
|
994 (if (match-beginning 2)
|
|
995 ;; it has two numbers
|
62402
|
996 (list (string-to-number
|
11042
|
997 (buffer-substring (match-beginning 1) (match-end 1)))
|
62402
|
998 (1+ (string-to-number
|
11042
|
999 (buffer-substring (match-beginning 3) (match-end 3)))))
|
|
1000 ;; it has one number
|
62402
|
1001 (let ((x (string-to-number
|
11042
|
1002 (buffer-substring (match-beginning 1) (match-end 1)))))
|
|
1003 (list x (1+ x))))
|
|
1004 ;; it is an "a" group
|
62402
|
1005 (let ((x (1+ (string-to-number
|
11042
|
1006 (buffer-substring (match-beginning 1) (match-end 1))))))
|
|
1007 (list x x)))))
|
|
1008
|
|
1009
|
|
1010 ;; If WORD-MODE, construct vector of diffs using word numbers.
|
|
1011 ;; Else, use point values.
|
|
1012 ;; WORD-MODE also tells if we are in the word-mode or not.
|
|
1013 ;; If THREE-WAY-COMP, then it is a 3-way comparison. Else, it is merging
|
13127
|
1014 ;; with ancestor, in which case buffer-C contents is identical to buffer-A/B,
|
|
1015 ;; contents (unless buffer-A is narrowed) depending on ediff-default-variant's
|
|
1016 ;; value.
|
11042
|
1017 ;; BOUNDS specifies visibility bounds to use.
|
|
1018 (defun ediff-extract-diffs3 (diff-buffer word-mode three-way-comp
|
|
1019 &optional bounds)
|
|
1020 (let ((A-buffer ediff-buffer-A)
|
|
1021 (B-buffer ediff-buffer-B)
|
|
1022 (C-buffer ediff-buffer-C)
|
13127
|
1023 (anc-buffer ediff-ancestor-buffer)
|
11042
|
1024 (a-prev 1) ; needed to set the first diff line correctly
|
68997
|
1025 (a-prev-pt nil)
|
11042
|
1026 (b-prev 1)
|
68997
|
1027 (b-prev-pt nil)
|
11042
|
1028 (c-prev 1)
|
68997
|
1029 (c-prev-pt nil)
|
13127
|
1030 (anc-prev 1)
|
11042
|
1031 diff-list shift-A shift-B shift-C
|
|
1032 )
|
49588
|
1033
|
11042
|
1034 ;; diff list contains word numbers or points, depending on word-mode
|
|
1035 (setq diff-list (cons (if word-mode 'words 'points)
|
|
1036 diff-list))
|
|
1037 (if bounds
|
|
1038 (setq shift-A
|
|
1039 (ediff-overlay-start
|
|
1040 (ediff-get-value-according-to-buffer-type 'A bounds))
|
42602
|
1041 shift-B
|
11042
|
1042 (ediff-overlay-start
|
|
1043 (ediff-get-value-according-to-buffer-type 'B bounds))
|
42602
|
1044 shift-C
|
11042
|
1045 (if three-way-comp
|
|
1046 (ediff-overlay-start
|
|
1047 (ediff-get-value-according-to-buffer-type 'C bounds)))))
|
49588
|
1048
|
11042
|
1049 ;; reset point in buffers A, B, C
|
19047
|
1050 (ediff-with-current-buffer A-buffer
|
11042
|
1051 (goto-char (if shift-A shift-A (point-min))))
|
19047
|
1052 (ediff-with-current-buffer B-buffer
|
11042
|
1053 (goto-char (if shift-B shift-B (point-min))))
|
13127
|
1054 (if three-way-comp
|
19047
|
1055 (ediff-with-current-buffer C-buffer
|
13127
|
1056 (goto-char (if shift-C shift-C (point-min)))))
|
|
1057 (if (ediff-buffer-live-p anc-buffer)
|
19047
|
1058 (ediff-with-current-buffer anc-buffer
|
13127
|
1059 (goto-char (point-min))))
|
49588
|
1060
|
19047
|
1061 (ediff-with-current-buffer diff-buffer
|
11042
|
1062 (goto-char (point-min))
|
|
1063 (while (re-search-forward ediff-match-diff3-line nil t)
|
|
1064 ;; leave point after matched line
|
|
1065 (beginning-of-line 2)
|
|
1066 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1))))
|
15480
|
1067 ;; if the files A and B are the same and not 3way-comparison,
|
11042
|
1068 ;; ignore the difference
|
|
1069 (if (or three-way-comp (not (string-equal agreement "3")))
|
|
1070 (let* ((a-begin (car (ediff-get-diff3-group "1")))
|
|
1071 (a-end (nth 1 (ediff-get-diff3-group "1")))
|
|
1072 (b-begin (car (ediff-get-diff3-group "2")))
|
|
1073 (b-end (nth 1 (ediff-get-diff3-group "2")))
|
13127
|
1074 (c-or-anc-begin (car (ediff-get-diff3-group "3")))
|
|
1075 (c-or-anc-end (nth 1 (ediff-get-diff3-group "3")))
|
11042
|
1076 (state-of-merge
|
|
1077 (cond ((string-equal agreement "1") 'prefer-A)
|
|
1078 ((string-equal agreement "2") 'prefer-B)
|
|
1079 (t ediff-default-variant)))
|
|
1080 (state-of-diff-merge
|
|
1081 (if (memq state-of-merge '(default-A prefer-A)) 'B 'A))
|
|
1082 (state-of-diff-comparison
|
|
1083 (cond ((string-equal agreement "1") 'A)
|
|
1084 ((string-equal agreement "2") 'B)
|
|
1085 ((string-equal agreement "3") 'C)))
|
13127
|
1086 state-of-ancestor
|
11042
|
1087 c-begin c-end
|
|
1088 a-begin-pt a-end-pt
|
13127
|
1089 b-begin-pt b-end-pt
|
|
1090 c-begin-pt c-end-pt
|
|
1091 anc-begin-pt anc-end-pt)
|
49588
|
1092
|
13127
|
1093 (setq state-of-ancestor
|
|
1094 (= c-or-anc-begin c-or-anc-end))
|
|
1095
|
|
1096 (cond (three-way-comp
|
|
1097 (setq c-begin c-or-anc-begin
|
|
1098 c-end c-or-anc-end))
|
|
1099 ((eq ediff-default-variant 'default-B)
|
|
1100 (setq c-begin b-begin
|
|
1101 c-end b-end))
|
|
1102 (t
|
|
1103 (setq c-begin a-begin
|
|
1104 c-end a-end)))
|
49588
|
1105
|
11042
|
1106 ;; compute main diff vector
|
|
1107 (if word-mode
|
|
1108 ;; make diff-list contain word numbers
|
42602
|
1109 (setq diff-list
|
11042
|
1110 (nconc diff-list
|
|
1111 (list (vector
|
|
1112 (- a-begin a-prev) (- a-end a-begin)
|
|
1113 (- b-begin b-prev) (- b-end b-begin)
|
|
1114 (- c-begin c-prev) (- c-end c-begin)
|
13127
|
1115 nil nil ; dummy ancestor
|
|
1116 nil ; state of diff
|
|
1117 nil ; state of merge
|
|
1118 nil ; state of ancestor
|
|
1119 )))
|
11042
|
1120 a-prev a-end
|
|
1121 b-prev b-end
|
|
1122 c-prev c-end)
|
|
1123 ;; else convert lines to points
|
19047
|
1124 (ediff-with-current-buffer A-buffer
|
64215
|
1125 (let ((longlines-mode-val
|
|
1126 (if (and (boundp 'longlines-mode) longlines-mode) 1 0)))
|
|
1127 ;; we must disable and then restore longlines-mode
|
|
1128 (if (eq longlines-mode-val 1)
|
|
1129 (longlines-mode 0))
|
68997
|
1130 (goto-char (or a-prev-pt shift-A (point-min)))
|
64215
|
1131 (forward-line (- a-begin a-prev))
|
|
1132 (setq a-begin-pt (point))
|
|
1133 (forward-line (- a-end a-begin))
|
|
1134 (setq a-end-pt (point)
|
68997
|
1135 a-prev a-end
|
|
1136 a-prev-pt a-end-pt)
|
64215
|
1137 (if (eq longlines-mode-val 1)
|
|
1138 (longlines-mode longlines-mode-val))
|
|
1139 ))
|
19047
|
1140 (ediff-with-current-buffer B-buffer
|
64215
|
1141 (let ((longlines-mode-val
|
|
1142 (if (and (boundp 'longlines-mode) longlines-mode) 1 0)))
|
|
1143 (if (eq longlines-mode-val 1)
|
|
1144 (longlines-mode 0))
|
68997
|
1145 (goto-char (or b-prev-pt shift-B (point-min)))
|
64215
|
1146 (forward-line (- b-begin b-prev))
|
|
1147 (setq b-begin-pt (point))
|
|
1148 (forward-line (- b-end b-begin))
|
|
1149 (setq b-end-pt (point)
|
68997
|
1150 b-prev b-end
|
|
1151 b-prev-pt b-end-pt)
|
64215
|
1152 (if (eq longlines-mode-val 1)
|
|
1153 (longlines-mode longlines-mode-val))
|
|
1154 ))
|
19047
|
1155 (ediff-with-current-buffer C-buffer
|
64215
|
1156 (let ((longlines-mode-val
|
|
1157 (if (and (boundp 'longlines-mode) longlines-mode) 1 0)))
|
|
1158 (if (eq longlines-mode-val 1)
|
|
1159 (longlines-mode 0))
|
68997
|
1160 (goto-char (or c-prev-pt shift-C (point-min)))
|
64215
|
1161 (forward-line (- c-begin c-prev))
|
|
1162 (setq c-begin-pt (point))
|
|
1163 (forward-line (- c-end c-begin))
|
|
1164 (setq c-end-pt (point)
|
68997
|
1165 c-prev c-end
|
|
1166 c-prev-pt c-end-pt)
|
64215
|
1167 (if (eq longlines-mode-val 1)
|
|
1168 (longlines-mode longlines-mode-val))
|
|
1169 ))
|
13127
|
1170 (if (ediff-buffer-live-p anc-buffer)
|
19047
|
1171 (ediff-with-current-buffer anc-buffer
|
64215
|
1172 (let ((longlines-mode-val
|
|
1173 (if (and (boundp 'longlines-mode) longlines-mode) 1 0)))
|
|
1174 (if (eq longlines-mode-val 1)
|
|
1175 (longlines-mode 0))
|
|
1176 (forward-line (- c-or-anc-begin anc-prev))
|
|
1177 (setq anc-begin-pt (point))
|
|
1178 (forward-line (- c-or-anc-end c-or-anc-begin))
|
|
1179 (setq anc-end-pt (point)
|
|
1180 anc-prev c-or-anc-end)
|
|
1181 (if (eq longlines-mode-val 1)
|
|
1182 (longlines-mode longlines-mode-val))
|
|
1183 )))
|
42602
|
1184 (setq diff-list
|
11042
|
1185 (nconc
|
|
1186 diff-list
|
|
1187 ;; if comparing with ancestor, then there also is a
|
|
1188 ;; state-of-difference marker
|
|
1189 (if three-way-comp
|
|
1190 (list (vector
|
|
1191 a-begin-pt a-end-pt
|
|
1192 b-begin-pt b-end-pt
|
|
1193 c-begin-pt c-end-pt
|
13127
|
1194 nil nil ; ancestor begin/end
|
11042
|
1195 state-of-diff-comparison
|
13127
|
1196 nil ; state of merge
|
|
1197 nil ; state of ancestor
|
11042
|
1198 ))
|
|
1199 (list (vector a-begin-pt a-end-pt
|
|
1200 b-begin-pt b-end-pt
|
|
1201 c-begin-pt c-end-pt
|
13127
|
1202 anc-begin-pt anc-end-pt
|
11042
|
1203 state-of-diff-merge
|
|
1204 state-of-merge
|
13127
|
1205 state-of-ancestor
|
11042
|
1206 )))
|
|
1207 )))
|
|
1208 ))
|
49588
|
1209
|
19047
|
1210 ))) ; end ediff-with-current-buffer
|
11042
|
1211 diff-list
|
|
1212 ))
|
49588
|
1213
|
11042
|
1214 ;; Generate the difference vector and overlays for three files
|
|
1215 ;; File-C is either the third file to compare (in case of 3-way comparison)
|
|
1216 ;; or it is the ancestor file.
|
|
1217 (defun ediff-setup-diff-regions3 (file-A file-B file-C)
|
68997
|
1218 ;; looking for '-i' or a 'i' among clustered non-long options
|
69087
|
1219 (if (string-match "^-i\\| -i\\|\\(^\\| \\)-[^- ]+i" ediff-diff-options)
|
68997
|
1220 (error "Option `-i' is not allowed in `ediff-diff3-options'"))
|
|
1221
|
11042
|
1222 (or (ediff-buffer-live-p ediff-diff-buffer)
|
|
1223 (setq ediff-diff-buffer
|
|
1224 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
|
49588
|
1225
|
13127
|
1226 (message "Computing differences ...")
|
|
1227 (ediff-exec-process ediff-diff3-program ediff-diff-buffer 'synchronize
|
68997
|
1228 ediff-actual-diff3-options file-A file-B file-C)
|
49588
|
1229
|
11042
|
1230 (ediff-prepare-error-list ediff-diff3-ok-lines-regexp ediff-diff-buffer)
|
13127
|
1231 ;;(message "Computing differences ... done")
|
11042
|
1232 (ediff-convert-diffs-to-overlays
|
|
1233 (ediff-extract-diffs3
|
|
1234 ediff-diff-buffer
|
|
1235 ediff-word-mode ediff-3way-comparison-job ediff-narrow-bounds)
|
|
1236 ))
|
49588
|
1237
|
11042
|
1238
|
14582
|
1239 ;; Execute PROGRAM asynchronously, unless OS/2, Windows-*, or DOS, or unless
|
19047
|
1240 ;; SYNCH is non-nil. BUFFER must be a buffer object, and must be alive. The
|
|
1241 ;; OPTIONS arg is a list of options to pass to PROGRAM. It may be a blank
|
|
1242 ;; string. All elements in FILES must be strings. We also delete nil from
|
|
1243 ;; args.
|
|
1244 (defun ediff-exec-process (program buffer synch options &rest files)
|
|
1245 (let ((data (match-data))
|
36043
|
1246 (coding-system-for-read ediff-coding-system-for-read)
|
19047
|
1247 args)
|
|
1248 (setq args (append (split-string options) files))
|
|
1249 (setq args (delete "" (delq nil args))) ; delete nil and "" from arguments
|
29206
|
1250 ;; the --binary option, if present, should be used only for buffer jobs
|
29412
|
1251 ;; or for refining the differences
|
29206
|
1252 (or (string-match "buffer" (symbol-name ediff-job-name))
|
29412
|
1253 (eq buffer ediff-fine-diff-buffer)
|
29206
|
1254 (setq args (delete "--binary" args)))
|
11042
|
1255 (unwind-protect
|
|
1256 (let ((directory default-directory)
|
|
1257 proc)
|
|
1258 (save-excursion
|
|
1259 (set-buffer buffer)
|
|
1260 (erase-buffer)
|
|
1261 (setq default-directory directory)
|
14582
|
1262 (if (or (memq system-type '(emx ms-dos windows-nt windows-95))
|
|
1263 synch)
|
|
1264 ;; In OS/2 (emx) do it synchronously, since OS/2 doesn't let us
|
13127
|
1265 ;; delete files used by other processes. Thus, in ediff-buffers
|
|
1266 ;; and similar functions, we can't delete temp files because
|
14582
|
1267 ;; they might be used by the asynch process that computes
|
13127
|
1268 ;; custom diffs. So, we have to wait till custom diff
|
|
1269 ;; subprocess is done.
|
14582
|
1270 ;; Similarly for Windows-*
|
|
1271 ;; In DOS, must synchronize because DOS doesn't have
|
|
1272 ;; asynchronous processes.
|
13127
|
1273 (apply 'call-process program nil buffer nil args)
|
|
1274 ;; On other systems, do it asynchronously.
|
|
1275 (setq proc (get-buffer-process buffer))
|
|
1276 (if proc (kill-process proc))
|
|
1277 (setq proc
|
|
1278 (apply 'start-process "Custom Diff" buffer program args))
|
|
1279 (setq mode-line-process '(":%s"))
|
|
1280 (set-process-sentinel proc 'ediff-process-sentinel)
|
|
1281 (set-process-filter proc 'ediff-process-filter)
|
|
1282 )))
|
21940
|
1283 (store-match-data data))))
|
49588
|
1284
|
24875
|
1285 ;; This is shell-command-filter from simple.el in Emacs.
|
11042
|
1286 ;; Copied here because XEmacs doesn't have it.
|
13127
|
1287 (defun ediff-process-filter (proc string)
|
11042
|
1288 ;; Do save-excursion by hand so that we can leave point numerically unchanged
|
|
1289 ;; despite an insertion immediately after it.
|
|
1290 (let* ((obuf (current-buffer))
|
|
1291 (buffer (process-buffer proc))
|
|
1292 opoint
|
|
1293 (window (get-buffer-window buffer))
|
|
1294 (pos (window-start window)))
|
|
1295 (unwind-protect
|
|
1296 (progn
|
|
1297 (set-buffer buffer)
|
|
1298 (or (= (point) (point-max))
|
|
1299 (setq opoint (point)))
|
|
1300 (goto-char (point-max))
|
|
1301 (insert-before-markers string))
|
|
1302 ;; insert-before-markers moved this marker: set it back.
|
|
1303 (set-window-start window pos)
|
|
1304 ;; Finish our save-excursion.
|
|
1305 (if opoint
|
|
1306 (goto-char opoint))
|
|
1307 (set-buffer obuf))))
|
49588
|
1308
|
11042
|
1309 ;; like shell-command-sentinel but doesn't print an exit status message
|
|
1310 ;; we do this because diff always exits with status 1, if diffs are found
|
|
1311 ;; so shell-command-sentinel displays a confusing message to the user
|
13127
|
1312 (defun ediff-process-sentinel (process signal)
|
11042
|
1313 (if (and (memq (process-status process) '(exit signal))
|
|
1314 (buffer-name (process-buffer process)))
|
|
1315 (progn
|
|
1316 (save-excursion
|
|
1317 (set-buffer (process-buffer process))
|
|
1318 (setq mode-line-process nil))
|
|
1319 (delete-process process))))
|
49588
|
1320
|
11042
|
1321
|
42602
|
1322 ;;; Word functions used to refine the current diff
|
11042
|
1323
|
|
1324 (defvar ediff-forward-word-function 'ediff-forward-word
|
|
1325 "*Function to call to move to the next word.
|
|
1326 Used for splitting difference regions into individual words.")
|
44028
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
1327 (make-variable-buffer-local 'ediff-forward-word-function)
|
11042
|
1328
|
|
1329 (defvar ediff-whitespace " \n\t\f"
|
|
1330 "*Characters constituting white space.
|
|
1331 These characters are ignored when differing regions are split into words.")
|
44028
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
1332 (make-variable-buffer-local 'ediff-whitespace)
|
11042
|
1333
|
42602
|
1334 (defvar ediff-word-1
|
|
1335 (ediff-cond-compile-for-xemacs-or-emacs "a-zA-Z---_" "-[:word:]_")
|
11042
|
1336 "*Characters that constitute words of type 1.
|
|
1337 More precisely, [ediff-word-1] is a regexp that matches type 1 words.
|
42602
|
1338 See `ediff-forward-word' for more details.")
|
44028
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
1339 (make-variable-buffer-local 'ediff-word-1)
|
11042
|
1340
|
|
1341 (defvar ediff-word-2 "0-9.,"
|
|
1342 "*Characters that constitute words of type 2.
|
|
1343 More precisely, [ediff-word-2] is a regexp that matches type 2 words.
|
|
1344 See `ediff-forward-word' for more details.")
|
44028
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
1345 (make-variable-buffer-local 'ediff-word-2)
|
11042
|
1346
|
|
1347 (defvar ediff-word-3 "`'?!:;\"{}[]()"
|
|
1348 "*Characters that constitute words of type 3.
|
|
1349 More precisely, [ediff-word-3] is a regexp that matches type 3 words.
|
|
1350 See `ediff-forward-word' for more details.")
|
44028
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
1351 (make-variable-buffer-local 'ediff-word-3)
|
11042
|
1352
|
|
1353 (defvar ediff-word-4
|
|
1354 (concat "^" ediff-word-1 ediff-word-2 ediff-word-3 ediff-whitespace)
|
|
1355 "*Characters that constitute words of type 4.
|
|
1356 More precisely, [ediff-word-4] is a regexp that matches type 4 words.
|
42602
|
1357 See `ediff-forward-word' for more details.")
|
44028
182881d68883
* ediff-diff.el (ediff-install-fine-diff-if-necessary): take
Michael Kifer <kifer@cs.stonybrook.edu>
diff
changeset
|
1358 (make-variable-buffer-local 'ediff-word-4)
|
11042
|
1359
|
|
1360 ;; Split region along word boundaries. Each word will be on its own line.
|
|
1361 ;; Output to buffer out-buffer.
|
|
1362 (defun ediff-forward-word ()
|
|
1363 "Move point one word forward.
|
|
1364 There are four types of words, each of which consists entirely of
|
|
1365 characters in `ediff-word-1', `ediff-word-2', `ediff-word-3', or
|
29165
|
1366 `ediff-word-4'. Words are recognized by passing these one after another as
|
|
1367 arguments to `skip-chars-forward'."
|
|
1368 (or (> (+ (skip-chars-forward ediff-word-1)
|
|
1369 (skip-syntax-forward "w"))
|
|
1370 0)
|
11042
|
1371 (> (skip-chars-forward ediff-word-2) 0)
|
|
1372 (> (skip-chars-forward ediff-word-3) 0)
|
|
1373 (> (skip-chars-forward ediff-word-4) 0)
|
|
1374 ))
|
|
1375
|
30089
|
1376
|
11042
|
1377 (defun ediff-wordify (beg end in-buffer out-buffer &optional control-buf)
|
42602
|
1378 (let ((forward-word-function
|
|
1379 ;; eval in control buf to let user create local versions for
|
|
1380 ;; different invocations
|
|
1381 (if control-buf
|
|
1382 (ediff-with-current-buffer control-buf
|
|
1383 ediff-forward-word-function)
|
|
1384 ediff-forward-word-function))
|
|
1385 inbuf-syntax-tbl sv-point diff-string)
|
11042
|
1386 (save-excursion
|
|
1387 (set-buffer in-buffer)
|
36857
|
1388 (setq inbuf-syntax-tbl
|
|
1389 (if control-buf
|
|
1390 (ediff-with-current-buffer control-buf
|
|
1391 ediff-syntax-table)
|
|
1392 (syntax-table)))
|
|
1393 (setq diff-string (buffer-substring-no-properties beg end))
|
11042
|
1394
|
|
1395 (set-buffer out-buffer)
|
46159
|
1396 ;; Make sure that temp buff syntax table is the same as the original buf
|
30089
|
1397 ;; syntax tbl, because we use ediff-forward-word in both and
|
|
1398 ;; ediff-forward-word depends on the syntax classes of characters.
|
|
1399 (set-syntax-table inbuf-syntax-tbl)
|
11042
|
1400 (erase-buffer)
|
36857
|
1401 (insert diff-string)
|
11042
|
1402 (goto-char (point-min))
|
|
1403 (skip-chars-forward ediff-whitespace)
|
|
1404 (delete-region (point-min) (point))
|
49588
|
1405
|
11042
|
1406 (while (not (eobp))
|
42602
|
1407 (funcall forward-word-function)
|
11042
|
1408 (setq sv-point (point))
|
|
1409 (skip-chars-forward ediff-whitespace)
|
|
1410 (delete-region sv-point (point))
|
|
1411 (insert "\n")))))
|
49588
|
1412
|
42602
|
1413 ;; copy string specified as BEG END from IN-BUF to OUT-BUF
|
11042
|
1414 (defun ediff-copy-to-buffer (beg end in-buffer out-buffer)
|
42602
|
1415 (with-current-buffer out-buffer
|
|
1416 (erase-buffer)
|
|
1417 (insert-buffer-substring in-buffer beg end)
|
|
1418 (goto-char (point-min))))
|
11042
|
1419
|
|
1420
|
|
1421 ;; goto word #n starting at current position in buffer `buf'
|
36857
|
1422 ;; For ediff, a word is determined by ediff-forward-word-function
|
11042
|
1423 ;; If `flag' is non-nil, goto the end of the n-th word.
|
|
1424 (defun ediff-goto-word (n buf &optional flag)
|
|
1425 ;; remember val ediff-forward-word-function has in ctl buf
|
36857
|
1426 (let ((fwd-word-fun ediff-forward-word-function)
|
|
1427 (syntax-tbl ediff-syntax-table))
|
19047
|
1428 (ediff-with-current-buffer buf
|
11042
|
1429 (skip-chars-forward ediff-whitespace)
|
42602
|
1430 (ediff-with-syntax-table syntax-tbl
|
|
1431 (while (> n 1)
|
|
1432 (funcall fwd-word-fun)
|
|
1433 (skip-chars-forward ediff-whitespace)
|
60151
|
1434 (setq n (1- n)))
|
|
1435 (if (and flag (> n 0))
|
|
1436 (funcall fwd-word-fun)))
|
11042
|
1437 (point))))
|
|
1438
|
20206
|
1439 (defun ediff-same-file-contents (f1 f2)
|
60151
|
1440 "Return t if files F1 and F2 have identical contents."
|
|
1441 (if (and (not (file-directory-p f1))
|
|
1442 (not (file-directory-p f2)))
|
|
1443 (let ((res
|
|
1444 (apply 'call-process ediff-cmp-program nil nil nil
|
|
1445 (append ediff-cmp-options (list f1 f2)))))
|
|
1446 (and (numberp res) (eq res 0))))
|
|
1447 )
|
|
1448
|
|
1449
|
|
1450 (defun ediff-same-contents (d1 d2 &optional filter-re)
|
|
1451 "Returns t iff D1 and D2 have the same content.
|
|
1452 D1 and D2 can either be both directories or both regular files.
|
|
1453 Symlinks and the likes are not handled.
|
|
1454 If FILTER-RE is non-nil, recursive checking in directories
|
|
1455 affects only files whose names match the expression."
|
|
1456 ;; Normalize empty filter RE to nil.
|
62963
|
1457 (unless (> (length filter-re) 0) (setq filter-re nil))
|
60151
|
1458 ;; Indicate progress
|
|
1459 (message "Comparing '%s' and '%s' modulo '%s'" d1 d2 filter-re)
|
|
1460 (cond
|
|
1461 ;; D1 & D2 directories => recurse
|
|
1462 ((and (file-directory-p d1)
|
|
1463 (file-directory-p d2))
|
|
1464 (if (null ediff-recurse-to-subdirectories)
|
|
1465 (if (y-or-n-p "Compare subdirectories recursively? ")
|
|
1466 (setq ediff-recurse-to-subdirectories 'yes)
|
|
1467 (setq ediff-recurse-to-subdirectories 'no)))
|
|
1468 (if (eq ediff-recurse-to-subdirectories 'yes)
|
|
1469 (let* ((all-entries-1 (directory-files d1 t filter-re))
|
|
1470 (all-entries-2 (directory-files d2 t filter-re))
|
62963
|
1471 (entries-1 (ediff-delete-all-matches "^\\.\\.?$" all-entries-1))
|
|
1472 (entries-2 (ediff-delete-all-matches "^\\.\\.?$" all-entries-2))
|
60151
|
1473 )
|
62963
|
1474
|
|
1475 (ediff-same-file-contents-lists entries-1 entries-2 filter-re)
|
60151
|
1476 ))
|
|
1477 ) ; end of the directories case
|
|
1478 ;; D1 & D2 are both files => compare directly
|
|
1479 ((and (file-regular-p d1)
|
|
1480 (file-regular-p d2))
|
|
1481 (ediff-same-file-contents d1 d2))
|
|
1482 ;; Otherwise => false: unequal contents
|
|
1483 )
|
|
1484 )
|
20206
|
1485
|
62963
|
1486 ;; If lists have the same length and names of files are pairwise equal
|
|
1487 ;; (removing the directories) then compare contents pairwise.
|
|
1488 ;; True if all contents are the same; false otherwise
|
|
1489 (defun ediff-same-file-contents-lists (entries-1 entries-2 filter-re)
|
|
1490 ;; First, check only the names (works quickly and ensures a
|
|
1491 ;; precondition for subsequent code)
|
|
1492 (if (and (= (length entries-1) (length entries-2))
|
|
1493 (equal (mapcar 'file-name-nondirectory entries-1)
|
|
1494 (mapcar 'file-name-nondirectory entries-2)))
|
|
1495 ;; With name equality established, compare the entries
|
|
1496 ;; through recursion.
|
|
1497 (let ((continue t))
|
|
1498 (while (and entries-1 continue)
|
|
1499 (if (ediff-same-contents
|
|
1500 (car entries-1) (car entries-2) filter-re)
|
|
1501 (setq entries-1 (cdr entries-1)
|
|
1502 entries-2 (cdr entries-2))
|
|
1503 (setq continue nil))
|
|
1504 )
|
|
1505 ;; if reached the end then lists are equal
|
|
1506 (null entries-1))
|
|
1507 )
|
|
1508 )
|
|
1509
|
|
1510
|
|
1511 ;; ARG1 is a regexp, ARG2 is a list of full-filenames
|
|
1512 ;; Delete all entries that match the regexp
|
|
1513 (defun ediff-delete-all-matches (regex file-list-list)
|
|
1514 (let (result elt)
|
|
1515 (while file-list-list
|
|
1516 (setq elt (car file-list-list))
|
|
1517 (or (string-match regex (file-name-nondirectory elt))
|
|
1518 (setq result (cons elt result)))
|
|
1519 (setq file-list-list (cdr file-list-list)))
|
|
1520 (reverse result)))
|
|
1521
|
68997
|
1522 ;; Ignore case handling - some ideas from drew.adams@@oracle.com
|
|
1523 (defun ediff-toggle-ignore-case ()
|
|
1524 (interactive)
|
|
1525 (ediff-barf-if-not-control-buffer)
|
|
1526 (setq ediff-ignore-case (not ediff-ignore-case))
|
|
1527 (cond (ediff-ignore-case
|
|
1528 (setq ediff-actual-diff-options
|
|
1529 (concat ediff-diff-options " " ediff-ignore-case-option)
|
|
1530 ediff-actual-diff3-options
|
|
1531 (concat ediff-diff3-options " " ediff-ignore-case-option3))
|
|
1532 (message "Ignoring regions that differ only in case"))
|
|
1533 (t
|
|
1534 (setq ediff-actual-diff-options ediff-diff-options
|
|
1535 ediff-actual-diff3-options ediff-diff3-options)
|
|
1536 (message "Ignoring case differences turned OFF")))
|
|
1537 (cond (ediff-merge-job
|
|
1538 (message "Ignoring letter case is too dangerous in merge jobs"))
|
|
1539 ((and ediff-diff3-job (string= ediff-ignore-case-option3 ""))
|
|
1540 (message "Ignoring letter case is not supported by this diff3 program"))
|
|
1541 ((and (not ediff-3way-job) (string= ediff-ignore-case-option ""))
|
|
1542 (message "Ignoring letter case is not supported by this diff program"))
|
|
1543 (t
|
|
1544 (sit-for 1)
|
|
1545 (ediff-update-diffs)))
|
|
1546 )
|
|
1547
|
|
1548
|
|
1549 (provide 'ediff-diff)
|
|
1550
|
11042
|
1551
|
15480
|
1552 ;;; Local Variables:
|
|
1553 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
|
19047
|
1554 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
|
|
1555 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
|
15480
|
1556 ;;; End:
|
|
1557
|
52401
|
1558 ;;; arch-tag: a86d448e-58d7-4572-a1d9-fdedfa22f648
|
38422
|
1559 ;;; ediff-diff.el ends here
|