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