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