]> code.delx.au - gnu-emacs/blob - lisp/ediff-diff.el
Say "standard settings" instead of "factory settings".
[gnu-emacs] / lisp / ediff-diff.el
1 ;;; ediff-diff.el --- diff-related utilities
2
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
4
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Code:
25
26 (require 'ediff-init)
27
28
29 (defvar ediff-shell
30 (cond ((eq system-type 'emx) "cmd") ; OS/2
31 ((memq system-type '(ms-dos windows-nt windows-95))
32 shell-file-name) ; no standard name on MS-DOS
33 ((memq system-type '(vax-vms axp-vms)) "*dcl*") ; VMS
34 (t "sh")) ; UNIX
35 "*The shell used to run diff and patch. If user's .profile or
36 .cshrc files are set up correctly, any shell will do. However, some people
37 set $prompt or other things incorrectly, which leads to undesirable output
38 messages. These may cause Ediff to fail. In such a case, set ediff-shell
39 to a shell that you are not using or, better, fix your shell's startup file.")
40
41
42 (defvar ediff-diff-program "diff"
43 "*Program to use for generating the differential of the two files.")
44 (defvar ediff-diff-options ""
45 "*Options to pass to `ediff-diff-program'.
46 If diff\(1\) is used as `ediff-diff-program', then the most useful options are
47 `-w', to ignore space, and `-i', to ignore case of letters.
48 At present, the option `-c' is ignored, since Ediff doesn't understand this
49 type of output.")
50
51 (defvar ediff-custom-diff-program ediff-diff-program
52 "*Program to use for generating custom diff output for saving it in a file.
53 This output is not used by Ediff internally.")
54 (defvar ediff-custom-diff-options "-c"
55 "*Options to pass to `ediff-custom-diff-program'.")
56
57 ;;; Support for diff3
58
59 (defvar ediff-match-diff3-line "^====\\(.?\\)$"
60 "Pattern to match lines produced by diff3 that describe differences.")
61 (defvar ediff-diff3-program "diff3"
62 "*Program to be used for three-way comparison.
63 Must produce output compatible with Unix's diff3 program.")
64 (defvar ediff-diff3-options ""
65 "*Options to pass to `ediff-diff3-program'.")
66 (defvar ediff-diff3-ok-lines-regexp
67 "^\\([1-3]:\\|====\\| \\|.*Warning *:\\|.*No newline\\|.*missing newline\\|^\C-m$\\)"
68 "*Regexp that matches normal output lines from `ediff-diff3-program'.
69 Lines that do not match are assumed to be error messages.")
70
71 ;; keeps the status of the current diff in 3-way jobs.
72 ;; the status can be =diff(A), =diff(B), or =diff(A+B)
73 (ediff-defvar-local ediff-diff-status "" "")
74
75
76 ;;; Fine differences
77
78 (ediff-defvar-local ediff-auto-refine (if (ediff-has-face-support-p) 'on 'nix)
79 "If `on', Ediff auto-highlights fine diffs for the current diff region.
80 If `off', auto-highlighting is not used. If `nix', no fine diffs are shown
81 at all, unless the user force-refines the region by hitting `*'.
82
83 This variable can be set either in .emacs or toggled interactively.
84 Use `setq-default' if setting it in .emacs")
85
86 (ediff-defvar-local ediff-ignore-similar-regions nil
87 "*If t, skip over difference regions that differ only in the white space and line breaks.
88 This variable can be set either in .emacs or toggled interactively.
89 Use `setq-default' if setting it in .emacs")
90
91 (ediff-defvar-local ediff-auto-refine-limit 1400
92 "*Auto-refine only the regions of this size \(in bytes\) or less.")
93
94 ;;; General
95
96 (defvar ediff-diff-ok-lines-regexp
97 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\|.*Warning *:\\|.*No +newline\\|.*missing +newline\\|^\C-m$\\)"
98 "Regexp that matches normal output lines from `ediff-diff-program'.
99 This is mostly lifted from Emerge, except that Ediff also considers
100 warnings and `Missing newline'-type messages to be normal output.
101 Lines that do not match are assumed to be error messages.")
102
103 (defvar ediff-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
104 (concat "^" x "\\([acd]\\)" x "$"))
105 "Pattern to match lines produced by diff that describe differences.")
106
107 (ediff-defvar-local ediff-setup-diff-regions-function nil
108 "value is a function symbol depending on the kind of job is to be done.
109 For 2-way jobs and for ediff-merge, it should be `ediff-setup-diff-regions'.
110 For jobs requiring diff3, it should be `ediff-setup-diff-regions3'.
111
112 The function should take three mandatory arguments, file-A, file-B, and
113 file-C. It may ignore file C for diff2 jobs. It should also take
114 one optional arguments, diff-number to refine.")
115
116
117 ;;; Functions
118
119 ;; Generate the difference vector and overlays for the two files
120 ;; With optional arg REG-TO-REFINE, refine this region.
121 ;; File-C argument is not used here. It is there just because
122 ;; ediff-setup-diff-regions is called via a funcall to
123 ;; ediff-setup-diff-regions-function, which can also have the value
124 ;; ediff-setup-diff-regions3, which takes 4 arguments.
125 (defun ediff-setup-diff-regions (file-A file-B file-C)
126 ;;; ;; Force all minibuffers to display ediff's messages.
127 ;;; ;; When xemacs implements minibufferless frames, this won't be necessary
128 ;;; (if ediff-xemacs-p (setq synchronize-minibuffers t))
129
130 ;; create, if it doesn't exist
131 (or (ediff-buffer-live-p ediff-diff-buffer)
132 (setq ediff-diff-buffer
133 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
134 (ediff-make-diff2-buffer ediff-diff-buffer file-A file-B)
135 (ediff-prepare-error-list ediff-diff-ok-lines-regexp ediff-diff-buffer)
136 (ediff-convert-diffs-to-overlays
137 (ediff-extract-diffs
138 ediff-diff-buffer ediff-word-mode ediff-narrow-bounds)))
139
140 ;; Run the diff program on FILE1 and FILE2 and put the output in DIFF-BUFFER
141 ;; Return the size of DIFF-BUFFER
142 (defun ediff-make-diff2-buffer (diff-buffer file1 file2)
143 (let ((file1-size (ediff-file-size file1))
144 (file2-size (ediff-file-size file2)))
145 (cond ((not (numberp file1-size))
146 (message "Can't find file: %s"
147 (ediff-abbreviate-file-name file1))
148 (sit-for 2)
149 ;; 1 is an error exit code
150 1)
151 ((not (numberp file2-size))
152 (message "Can't find file: %s"
153 (ediff-abbreviate-file-name file2))
154 (sit-for 2)
155 ;; 1 is an error exit code
156 1)
157 ((< file1-size 0)
158 (message "Can't diff remote files: %s"
159 (ediff-abbreviate-file-name file1))
160 (sit-for 2)
161 ;; 1 is an error exit code
162 1)
163 ((< file2-size 0)
164 (message "Can't diff remote file: %s"
165 (ediff-abbreviate-file-name file2))
166 (sit-for 2)
167 (message "")
168 ;; 1 is an error exit code
169 1)
170 (t (message "Computing differences between %s and %s ..."
171 (file-name-nondirectory file1)
172 (file-name-nondirectory file2))
173 ;; this erases the diff buffer automatically
174 (ediff-exec-process ediff-diff-program
175 diff-buffer
176 'synchronize
177 ediff-diff-options file1 file2)
178 ;;(message "Computing differences ... done")
179 (message "")
180 (ediff-eval-in-buffer diff-buffer
181 (buffer-size))))))
182
183
184
185 ;; If file-A/B/C is nil, do 2-way comparison with the non-nil buffers
186 ;; This function works for diff3 and diff2 jobs
187 (defun ediff-setup-fine-diff-regions (file-A file-B file-C reg-num)
188 (or (ediff-buffer-live-p ediff-fine-diff-buffer)
189 (setq ediff-fine-diff-buffer
190 (get-buffer-create
191 (ediff-unique-buffer-name "*ediff-fine-diff" "*"))))
192
193 (let (diff3-job diff-program diff-options ok-regexp diff-list)
194 (setq diff3-job ediff-3way-job
195 diff-program (if diff3-job ediff-diff3-program ediff-diff-program)
196 diff-options (if diff3-job ediff-diff3-options ediff-diff-options)
197 ok-regexp (if diff3-job
198 ediff-diff3-ok-lines-regexp
199 ediff-diff-ok-lines-regexp))
200
201 (ediff-message-if-verbose "Refining difference region %d ..." (1+ reg-num))
202 (ediff-exec-process diff-program ediff-fine-diff-buffer 'synchronize
203 diff-options
204 ;; The shuffle below is because we can compare 3-way
205 ;; or in several 2-way fashions, like fA fC, fA fB,
206 ;; or fB fC.
207 (if file-A file-A file-B)
208 (if file-B file-B file-A)
209 (if diff3-job
210 (if file-C file-C file-B))
211 ) ; exec process
212
213 (ediff-prepare-error-list ok-regexp ediff-fine-diff-buffer)
214 (ediff-message-if-verbose
215 "")
216 ;; "Refining difference region %d ... done" (1+ reg-num))
217
218 (setq diff-list
219 (if diff3-job
220 (ediff-extract-diffs3
221 ediff-fine-diff-buffer '3way-comparison 'word-mode)
222 (ediff-extract-diffs ediff-fine-diff-buffer 'word-mode)))
223 ;; fixup diff-list
224 (if diff3-job
225 (cond ((not file-A)
226 (mapcar (function (lambda (elt)
227 (aset elt 0 nil)
228 (aset elt 1 nil)))
229 (cdr diff-list)))
230 ((not file-B)
231 (mapcar (function (lambda (elt)
232 (aset elt 2 nil)
233 (aset elt 3 nil)))
234 (cdr diff-list)))
235 ((not file-C)
236 (mapcar (function (lambda (elt)
237 (aset elt 4 nil)
238 (aset elt 5 nil)))
239 (cdr diff-list)))
240 ))
241
242 (ediff-convert-fine-diffs-to-overlays diff-list reg-num)
243 ))
244
245
246 (defun ediff-prepare-error-list (ok-regexp diff-buff)
247 (or (ediff-buffer-live-p ediff-error-buffer)
248 (setq ediff-error-buffer
249 (get-buffer-create (ediff-unique-buffer-name
250 "*ediff-errors" "*"))))
251 (ediff-eval-in-buffer ediff-error-buffer
252 (erase-buffer)
253 (insert (ediff-eval-in-buffer diff-buff (buffer-string)))
254 (goto-char (point-min))
255 (delete-matching-lines ok-regexp)
256 (if (memq system-type '(vax-vms axp-vms))
257 (delete-matching-lines "^$")))
258 ;; If diff reports errors, show them then quit.
259 (if (/= 0 (ediff-eval-in-buffer ediff-error-buffer (buffer-size)))
260 (let ((ctl-buf ediff-control-buffer)
261 (error-buf ediff-error-buffer))
262 (ediff-skip-unsuitable-frames)
263 (switch-to-buffer error-buf)
264 (ediff-kill-buffer-carefully ctl-buf)
265 (error "Errors in diff output. Diff output is in %S" diff-buff))))
266
267 ;; BOUNDS specifies visibility bounds to use.
268 ;; WORD-MODE tells whether we are in the word-mode or not.
269 ;; If WORD-MODE, also construct vector of diffs using word numbers.
270 ;; Else, use point values.
271 ;; This function handles diff-2 jobs including the case of
272 ;; merging buffers and files without ancestor.
273 (defun ediff-extract-diffs (diff-buffer word-mode &optional bounds)
274 (let ((A-buffer ediff-buffer-A)
275 (B-buffer ediff-buffer-B)
276 (C-buffer ediff-buffer-C)
277 (a-prev 1) ; this is needed to set the first diff line correctly
278 (b-prev 1)
279 (c-prev 1)
280 diff-list shift-A shift-B
281 )
282
283 ;; diff list contains word numbers, unless changed later
284 (setq diff-list (cons (if word-mode 'words 'points)
285 diff-list))
286 ;; we don't use visibility bounds for buffer C when merging
287 (if bounds
288 (setq shift-A
289 (ediff-overlay-start
290 (ediff-get-value-according-to-buffer-type 'A bounds))
291 shift-B
292 (ediff-overlay-start
293 (ediff-get-value-according-to-buffer-type 'B bounds))))
294
295 ;; reset point in buffers A/B/C
296 (ediff-eval-in-buffer A-buffer
297 (goto-char (if shift-A shift-A (point-min))))
298 (ediff-eval-in-buffer B-buffer
299 (goto-char (if shift-B shift-B (point-min))))
300 (if (ediff-buffer-live-p C-buffer)
301 (ediff-eval-in-buffer C-buffer
302 (goto-char (point-min))))
303
304 (ediff-eval-in-buffer diff-buffer
305 (goto-char (point-min))
306 (while (re-search-forward ediff-match-diff-line nil t)
307 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1)
308 (match-end 1))))
309 (a-end (let ((b (match-beginning 3))
310 (e (match-end 3)))
311 (if b
312 (string-to-int (buffer-substring b e))
313 a-begin)))
314 (diff-type (buffer-substring (match-beginning 4) (match-end 4)))
315 (b-begin (string-to-int (buffer-substring (match-beginning 5)
316 (match-end 5))))
317 (b-end (let ((b (match-beginning 7))
318 (e (match-end 7)))
319 (if b
320 (string-to-int (buffer-substring b e))
321 b-begin)))
322 a-begin-pt a-end-pt b-begin-pt b-end-pt
323 c-begin c-end c-begin-pt c-end-pt)
324 ;; fix the beginning and end numbers, because diff is somewhat
325 ;; strange about how it numbers lines
326 (if (string-equal diff-type "a")
327 (setq b-end (1+ b-end)
328 a-begin (1+ a-begin)
329 a-end a-begin)
330 (if (string-equal diff-type "d")
331 (setq a-end (1+ a-end)
332 b-begin (1+ b-begin)
333 b-end b-begin)
334 ;; (string-equal diff-type "c")
335 (setq a-end (1+ a-end)
336 b-end (1+ b-end))))
337
338 (if (eq ediff-default-variant 'default-B)
339 (setq c-begin b-begin
340 c-end b-end)
341 (setq c-begin a-begin
342 c-end a-end))
343
344 ;; compute main diff vector
345 (if word-mode
346 ;; make diff-list contain word numbers
347 (setq diff-list
348 (nconc diff-list
349 (list
350 (if (ediff-buffer-live-p C-buffer)
351 (vector (- a-begin a-prev) (- a-end a-begin)
352 (- b-begin b-prev) (- b-end b-begin)
353 (- c-begin c-prev) (- c-end c-begin)
354 nil nil ; dummy ancestor
355 nil ; state of diff
356 nil ; state of merge
357 nil ; state of ancestor
358 )
359 (vector (- a-begin a-prev) (- a-end a-begin)
360 (- b-begin b-prev) (- b-end b-begin)
361 nil nil ; dummy buf C
362 nil nil ; dummy ancestor
363 nil ; state of diff
364 nil ; state of merge
365 nil ; state of ancestor
366 ))
367 ))
368 a-prev a-end
369 b-prev b-end
370 c-prev c-end)
371 ;; else convert lines to points
372 (ediff-eval-in-buffer A-buffer
373 (forward-line (- a-begin a-prev))
374 (setq a-begin-pt (point))
375 (forward-line (- a-end a-begin))
376 (setq a-end-pt (point)
377 a-prev a-end))
378 (ediff-eval-in-buffer B-buffer
379 (forward-line (- b-begin b-prev))
380 (setq b-begin-pt (point))
381 (forward-line (- b-end b-begin))
382 (setq b-end-pt (point)
383 b-prev b-end))
384 (if (ediff-buffer-live-p C-buffer)
385 (ediff-eval-in-buffer C-buffer
386 (forward-line (- c-begin c-prev))
387 (setq c-begin-pt (point))
388 (forward-line (- c-end c-begin))
389 (setq c-end-pt (point)
390 c-prev c-end)))
391 (setq diff-list
392 (nconc
393 diff-list
394 (list
395 (if (ediff-buffer-live-p C-buffer)
396 (vector
397 a-begin-pt a-end-pt b-begin-pt b-end-pt
398 c-begin-pt c-end-pt
399 nil nil ; dummy ancestor
400 ;; state of diff
401 ;; shows which buff is different from the other two
402 (if (eq ediff-default-variant 'default-B) 'A 'B)
403 ediff-default-variant ; state of merge
404 nil ; state of ancestor
405 )
406 (vector a-begin-pt a-end-pt
407 b-begin-pt b-end-pt
408 nil nil ; dummy buf C
409 nil nil ; dummy ancestor
410 nil nil ; dummy state of diff & merge
411 nil ; dummy state of ancestor
412 )))
413 )))
414
415 ))) ; end ediff-eval-in-buffer
416 diff-list
417 ))
418
419
420 (defun ediff-convert-diffs-to-overlays (diff-list)
421 (ediff-set-diff-overlays-in-one-buffer 'A diff-list)
422 (ediff-set-diff-overlays-in-one-buffer 'B diff-list)
423 (if ediff-3way-job
424 (ediff-set-diff-overlays-in-one-buffer 'C diff-list))
425 (if ediff-merge-with-ancestor-job
426 (ediff-set-diff-overlays-in-one-buffer 'Ancestor diff-list))
427 ;; set up vector showing the status of merge regions
428 (if ediff-merge-job
429 (setq ediff-state-of-merge
430 (vconcat
431 (mapcar (function
432 (lambda (elt)
433 (let ((state-of-merge (aref elt 9))
434 (state-of-ancestor (aref elt 10)))
435 (vector
436 (if state-of-merge (format "%S" state-of-merge))
437 state-of-ancestor))))
438 ;; the first elt designates type of list
439 (cdr diff-list))
440 )))
441 (message "Processing difference regions ... done"))
442
443
444 (defun ediff-set-diff-overlays-in-one-buffer (buf-type diff-list)
445 (let* ((current-diff -1)
446 (buff (ediff-get-buffer buf-type))
447 ;; ediff-extract-diffs puts the type of diff-list as the first elt
448 ;; of this list. The type is either 'points or 'words
449 (diff-list-type (car diff-list))
450 (shift (ediff-overlay-start
451 (ediff-get-value-according-to-buffer-type
452 buf-type ediff-narrow-bounds)))
453 (limit (ediff-overlay-end
454 (ediff-get-value-according-to-buffer-type
455 buf-type ediff-narrow-bounds)))
456 diff-overlay-list list-element total-diffs
457 begin end pt-saved overlay state-of-diff)
458
459 (setq diff-list (cdr diff-list)) ; discard diff list type
460 (setq total-diffs (length diff-list))
461
462 ;; shift, if necessary
463 (ediff-eval-in-buffer buff (setq pt-saved shift))
464
465 (while diff-list
466 (setq current-diff (1+ current-diff)
467 list-element (car diff-list)
468 begin (aref list-element (cond ((eq buf-type 'A) 0)
469 ((eq buf-type 'B) 2)
470 ((eq buf-type 'C) 4)
471 (t 6))) ; Ancestor
472 end (aref list-element (cond ((eq buf-type 'A) 1)
473 ((eq buf-type 'B) 3)
474 ((eq buf-type 'C) 5)
475 (t 7))) ; Ancestor
476 state-of-diff (aref list-element 8)
477 )
478
479 (cond ((and (not (eq buf-type state-of-diff))
480 (not (eq buf-type 'Ancestor))
481 (memq state-of-diff '(A B C)))
482 (setq state-of-diff
483 (car (delq buf-type (delq state-of-diff (list 'A 'B 'C)))))
484 (setq state-of-diff (format "=diff(%S)" state-of-diff))
485 )
486 (t (setq state-of-diff nil)))
487
488 ;; Put overlays at appropriate places in buffer
489 ;; convert word numbers to points, if necessary
490 (if (eq diff-list-type 'words)
491 (progn
492 (ediff-eval-in-buffer buff (goto-char pt-saved))
493 (setq begin (ediff-goto-word (1+ begin) buff)
494 end (ediff-goto-word end buff 'end))
495 (if (> end limit) (setq end limit))
496 (if (> begin end) (setq begin end))
497 (setq pt-saved (ediff-eval-in-buffer buff (point)))))
498 (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
499
500 (ediff-overlay-put overlay 'priority ediff-shadow-overlay-priority)
501 (ediff-overlay-put overlay 'ediff-diff-num current-diff)
502 (if (and (ediff-has-face-support-p)
503 ediff-use-faces ediff-highlight-all-diffs)
504 (ediff-set-overlay-face
505 overlay (ediff-background-face buf-type current-diff)))
506
507 (if (= 0 (mod current-diff 10))
508 (message "Buffer %S: Processing difference region %d of %d"
509 buf-type current-diff total-diffs))
510 ;; record all overlays for this difference
511 ;; the second elt, nil, is a place holder for the fine diff vector.
512 ;; the third elt, nil, is a place holder for no-fine-diffs flag.
513 (setq diff-overlay-list
514 (nconc
515 diff-overlay-list
516 (list (vector overlay nil nil state-of-diff)))
517 diff-list
518 (cdr diff-list))
519 ) ; while
520
521 (set (intern (format "ediff-difference-vector-%S" buf-type))
522 (vconcat diff-overlay-list))
523 ))
524
525 ;; `n' is the diff region to work on. Default is ediff-current-difference.
526 ;; if `flag' is 'noforce then make fine-diffs only if this region's fine
527 ;; diffs have not been computed before.
528 ;; if `flag' is 'skip then don't compute fine diffs for this region.
529 (defun ediff-make-fine-diffs (&optional n flag)
530 (or n (setq n ediff-current-difference))
531
532 (if (< ediff-number-of-differences 1)
533 (error ediff-NO-DIFFERENCES))
534
535 (if ediff-word-mode
536 (setq flag 'skip
537 ediff-auto-refine 'nix))
538
539 (or (< n 0)
540 (>= n ediff-number-of-differences)
541 ;; n is within the range
542 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
543 (file-A ediff-temp-file-A)
544 (file-B ediff-temp-file-B)
545 (file-C ediff-temp-file-C)
546 (empty-A (ediff-empty-diff-region-p n 'A))
547 (empty-B (ediff-empty-diff-region-p n 'B))
548 (empty-C (ediff-empty-diff-region-p n 'C))
549 (whitespace-A (ediff-whitespace-diff-region-p n 'A))
550 (whitespace-B (ediff-whitespace-diff-region-p n 'B))
551 (whitespace-C (ediff-whitespace-diff-region-p n 'C))
552 cumulative-fine-diff-length)
553
554 (cond ((and (eq flag 'noforce) (ediff-get-fine-diff-vector n 'A))
555 ;; don't compute fine diffs if diff vector exists
556 (if (ediff-no-fine-diffs-p n)
557 ;;(ediff-message-if-verbose
558 (message
559 "Only white-space differences in region %d" (1+ n))))
560 ;; If one of the regions is empty (or 2 in 3way comparison)
561 ;; then don't refine.
562 ;; If the region happens to be entirely whitespace or empty then
563 ;; mark as such.
564 ((> (length (delq nil (list empty-A empty-B empty-C))) 1)
565 (if (and (ediff-looks-like-combined-merge n)
566 ediff-merge-job)
567 (ediff-set-fine-overlays-in-one-buffer 'C nil n))
568 (if ediff-3way-comparison-job
569 (ediff-message-if-verbose
570 "Region %d is empty in all buffers but %S"
571 (1+ n)
572 (cond ((not empty-A) 'A)
573 ((not empty-B) 'B)
574 ((not empty-C) 'C)))
575 (ediff-message-if-verbose
576 "Region %d in buffer %S is empty"
577 (1+ n)
578 (cond (empty-A 'A)
579 (empty-B 'B)
580 (empty-C 'C)))
581 )
582 ;; if all regions happen to be whitespace
583 (if (and whitespace-A whitespace-B whitespace-C)
584 ;; mark as space only
585 (ediff-mark-diff-as-space-only n t)
586 ;; if some regions are white and others don't, then mark as
587 ;; non-white-space-only
588 (ediff-mark-diff-as-space-only n nil)))
589 ;; don't compute fine diffs for this region
590 ((eq flag 'skip)
591 (or (ediff-get-fine-diff-vector n 'A)
592 (memq ediff-auto-refine '(off nix))
593 (ediff-message-if-verbose
594 "Region %d exceeds auto-refine limit. Type `%s' to refine"
595 (1+ n)
596 (substitute-command-keys
597 "\\[ediff-make-or-kill-fine-diffs]")
598 )))
599 (t
600 ;; recompute fine diffs
601 (ediff-wordify
602 (ediff-get-diff-posn 'A 'beg n)
603 (ediff-get-diff-posn 'A 'end n)
604 ediff-buffer-A
605 tmp-buffer
606 ediff-control-buffer)
607 (setq file-A
608 (ediff-make-temp-file tmp-buffer "fineDiffA" file-A))
609
610 (ediff-wordify
611 (ediff-get-diff-posn 'B 'beg n)
612 (ediff-get-diff-posn 'B 'end n)
613 ediff-buffer-B
614 tmp-buffer
615 ediff-control-buffer)
616 (setq file-B
617 (ediff-make-temp-file tmp-buffer "fineDiffB" file-B))
618
619 (if ediff-3way-job
620 (progn
621 (ediff-wordify
622 (ediff-get-diff-posn 'C 'beg n)
623 (ediff-get-diff-posn 'C 'end n)
624 ediff-buffer-C
625 tmp-buffer
626 ediff-control-buffer)
627 (setq file-C
628 (ediff-make-temp-file
629 tmp-buffer "fineDiffC" file-C))))
630
631 ;; save temp file names.
632 (setq ediff-temp-file-A file-A
633 ediff-temp-file-B file-B
634 ediff-temp-file-C file-C)
635
636 ;; set the new vector of fine diffs, if none exists
637 (cond ((and ediff-3way-job whitespace-A)
638 (ediff-setup-fine-diff-regions nil file-B file-C n))
639 ((and ediff-3way-job whitespace-B)
640 (ediff-setup-fine-diff-regions file-A nil file-C n))
641 ((and ediff-3way-job
642 ;; In merge-jobs, whitespace-C is t, since
643 ;; ediff-empty-diff-region-p returns t in this case
644 whitespace-C)
645 (ediff-setup-fine-diff-regions file-A file-B nil n))
646 (t
647 (ediff-setup-fine-diff-regions file-A file-B file-C n)))
648
649 (setq cumulative-fine-diff-length
650 (+ (length (ediff-get-fine-diff-vector n 'A))
651 (length (ediff-get-fine-diff-vector n 'B))
652 ;; in merge jobs, the merge buffer is never refined
653 (if (and file-C (not ediff-merge-job))
654 (length (ediff-get-fine-diff-vector n 'C))
655 0)))
656
657 (cond ((or
658 ;; all regions are white space
659 (and whitespace-A whitespace-B whitespace-C)
660 ;; none is white space and no fine diffs detected
661 (and (not whitespace-A)
662 (not whitespace-B)
663 (not (and ediff-3way-job whitespace-C))
664 (eq cumulative-fine-diff-length 0)))
665 (ediff-mark-diff-as-space-only n t)
666 (ediff-message-if-verbose
667 "Only white-space differences in region %d" (1+ n)))
668 ((eq cumulative-fine-diff-length 0)
669 (ediff-mark-diff-as-space-only n t)
670 (ediff-message-if-verbose
671 "Only white-space differences in region %d %s"
672 (1+ n)
673 (cond (whitespace-A "in buffers B & C")
674 (whitespace-B "in buffers A & C")
675 (whitespace-C "in buffers A & B"))))
676 (t
677 (ediff-mark-diff-as-space-only n nil)))
678 )
679 ) ; end cond
680 (ediff-set-fine-diff-properties n)
681 )))
682
683 ;; Interface to ediff-make-fine-diffs. Checks for auto-refine limit, etc.
684 (defun ediff-install-fine-diff-if-necessary (n)
685 (cond ((eq ediff-auto-refine 'on)
686 (if (and
687 (> ediff-auto-refine-limit
688 (- (ediff-get-diff-posn 'A 'end n)
689 (ediff-get-diff-posn 'A 'beg n)))
690 (> ediff-auto-refine-limit
691 (- (ediff-get-diff-posn 'B 'end n)
692 (ediff-get-diff-posn 'B 'beg n))))
693 (ediff-make-fine-diffs n 'noforce)
694 (ediff-make-fine-diffs n 'skip)))
695
696 ;; highlight iff fine diffs already exist
697 ((eq ediff-auto-refine 'off)
698 (ediff-make-fine-diffs n 'skip))))
699
700
701 ;; if fine diff vector is not set for diff N, then do nothing
702 (defun ediff-set-fine-diff-properties (n &optional default)
703 (or (not (ediff-has-face-support-p))
704 (< n 0)
705 (>= n ediff-number-of-differences)
706 ;; when faces are supported, set faces and priorities of fine overlays
707 (progn
708 (ediff-set-fine-diff-properties-in-one-buffer 'A n default)
709 (ediff-set-fine-diff-properties-in-one-buffer 'B n default)
710 (if ediff-3way-job
711 (ediff-set-fine-diff-properties-in-one-buffer 'C n default)))))
712
713 (defun ediff-set-fine-diff-properties-in-one-buffer (buf-type
714 n &optional default)
715 (let ((fine-diff-vector (ediff-get-fine-diff-vector n buf-type))
716 (face (if default
717 'default
718 (face-name
719 (intern (format "ediff-fine-diff-face-%S" buf-type)))))
720 (priority (if default
721 0
722 (1+ (or (ediff-overlay-get
723 (symbol-value
724 (intern
725 (format
726 "ediff-current-diff-overlay-%S" buf-type)))
727 'priority)
728 0)))))
729 (mapcar
730 (function (lambda (overl)
731 (ediff-set-overlay-face overl face)
732 (ediff-overlay-put overl 'priority priority)))
733 fine-diff-vector)))
734
735 ;; This assumes buffer C and that the region looks like a combination of
736 ;; regions in buffer A and C.
737 (defun ediff-set-fine-overlays-for-combined-merge (diff-list reg-num)
738 (let (overlay1 overlay2 overlay3)
739 (setq overlay1 (ediff-make-bullet-proof-overlay (nth 0 diff-list)
740 (nth 1 diff-list)
741 ediff-buffer-C)
742 overlay2 (ediff-make-bullet-proof-overlay (nth 2 diff-list)
743 (nth 3 diff-list)
744 ediff-buffer-C)
745 overlay3 (ediff-make-bullet-proof-overlay (nth 4 diff-list)
746 (nth 5 diff-list)
747 ediff-buffer-C))
748 (ediff-set-fine-diff-vector reg-num 'C (vector overlay1 overlay2 overlay3))
749 ))
750
751
752 ;; Convert diff list to overlays for a given DIFF-REGION
753 ;; in buffer of type BUF-TYPE
754 (defun ediff-set-fine-overlays-in-one-buffer (buf-type diff-list region-num)
755 (let* ((current-diff -1)
756 (reg-start (ediff-get-diff-posn buf-type 'beg region-num))
757 (buff (ediff-get-buffer buf-type))
758 combined-merge-diff-list
759 diff-overlay-list list-element
760 begin end overlay)
761
762 (ediff-clear-fine-differences-in-one-buffer region-num buf-type)
763 (setq diff-list (cdr diff-list)) ; discard list type (words or points)
764 (ediff-eval-in-buffer buff (goto-char reg-start))
765
766 ;; if it is a combined merge then set overlays in buff C specially
767 (if (and ediff-merge-job (eq buf-type 'C)
768 (setq combined-merge-diff-list
769 (ediff-looks-like-combined-merge region-num)))
770 (ediff-set-fine-overlays-for-combined-merge
771 combined-merge-diff-list region-num)
772 ;; regular fine diff
773 (while diff-list
774 (setq current-diff (1+ current-diff)
775 list-element (car diff-list)
776 begin (aref list-element (cond ((eq buf-type 'A) 0)
777 ((eq buf-type 'B) 2)
778 (t 4))) ; buf C
779 end (aref list-element (cond ((eq buf-type 'A) 1)
780 ((eq buf-type 'B) 3)
781 (t 5)))) ; buf C
782 (if (not (or begin end))
783 () ; skip this diff
784 ;; Put overlays at appropriate places in buffers
785 ;; convert lines to points, if necessary
786 (setq begin (ediff-goto-word (1+ begin) buff)
787 end (ediff-goto-word end buff 'end))
788 (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
789 ;; record all overlays for this difference region
790 (setq diff-overlay-list (nconc diff-overlay-list (list overlay))))
791
792 (setq diff-list (cdr diff-list))
793 ) ; while
794 ;; convert the list of difference information into a vector
795 ;; for fast access
796 (ediff-set-fine-diff-vector
797 region-num buf-type (vconcat diff-overlay-list))
798 )))
799
800
801 ;; Stolen from emerge.el
802 (defun ediff-get-diff3-group (file)
803 ;; This save-excursion allows ediff-get-diff3-group to be called for the
804 ;; various groups of lines (1, 2, 3) in any order, and for the lines to
805 ;; appear in any order. The reason this is necessary is that Gnu diff3
806 ;; can produce the groups in the order 1, 2, 3 or 1, 3, 2.
807 (save-excursion
808 (re-search-forward
809 (concat "^" file ":\\([0-9]+\\)\\(,\\([0-9]+\\)\\)?\\([ac]\\)$"))
810 (beginning-of-line 2)
811 ;; treatment depends on whether it is an "a" group or a "c" group
812 (if (string-equal (buffer-substring (match-beginning 4) (match-end 4)) "c")
813 ;; it is a "c" group
814 (if (match-beginning 2)
815 ;; it has two numbers
816 (list (string-to-int
817 (buffer-substring (match-beginning 1) (match-end 1)))
818 (1+ (string-to-int
819 (buffer-substring (match-beginning 3) (match-end 3)))))
820 ;; it has one number
821 (let ((x (string-to-int
822 (buffer-substring (match-beginning 1) (match-end 1)))))
823 (list x (1+ x))))
824 ;; it is an "a" group
825 (let ((x (1+ (string-to-int
826 (buffer-substring (match-beginning 1) (match-end 1))))))
827 (list x x)))))
828
829
830 ;; If WORD-MODE, construct vector of diffs using word numbers.
831 ;; Else, use point values.
832 ;; WORD-MODE also tells if we are in the word-mode or not.
833 ;; If THREE-WAY-COMP, then it is a 3-way comparison. Else, it is merging
834 ;; with ancestor, in which case buffer-C contents is identical to buffer-A/B,
835 ;; contents (unless buffer-A is narrowed) depending on ediff-default-variant's
836 ;; value.
837 ;; BOUNDS specifies visibility bounds to use.
838 (defun ediff-extract-diffs3 (diff-buffer word-mode three-way-comp
839 &optional bounds)
840 (let ((A-buffer ediff-buffer-A)
841 (B-buffer ediff-buffer-B)
842 (C-buffer ediff-buffer-C)
843 (anc-buffer ediff-ancestor-buffer)
844 (a-prev 1) ; needed to set the first diff line correctly
845 (b-prev 1)
846 (c-prev 1)
847 (anc-prev 1)
848 diff-list shift-A shift-B shift-C
849 )
850
851 ;; diff list contains word numbers or points, depending on word-mode
852 (setq diff-list (cons (if word-mode 'words 'points)
853 diff-list))
854 (if bounds
855 (setq shift-A
856 (ediff-overlay-start
857 (ediff-get-value-according-to-buffer-type 'A bounds))
858 shift-B
859 (ediff-overlay-start
860 (ediff-get-value-according-to-buffer-type 'B bounds))
861 shift-C
862 (if three-way-comp
863 (ediff-overlay-start
864 (ediff-get-value-according-to-buffer-type 'C bounds)))))
865
866 ;; reset point in buffers A, B, C
867 (ediff-eval-in-buffer A-buffer
868 (goto-char (if shift-A shift-A (point-min))))
869 (ediff-eval-in-buffer B-buffer
870 (goto-char (if shift-B shift-B (point-min))))
871 (if three-way-comp
872 (ediff-eval-in-buffer C-buffer
873 (goto-char (if shift-C shift-C (point-min)))))
874 (if (ediff-buffer-live-p anc-buffer)
875 (ediff-eval-in-buffer anc-buffer
876 (goto-char (point-min))))
877
878 (ediff-eval-in-buffer diff-buffer
879 (goto-char (point-min))
880 (while (re-search-forward ediff-match-diff3-line nil t)
881 ;; leave point after matched line
882 (beginning-of-line 2)
883 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1))))
884 ;; if the files A and B are the same and not 3way-comparison,
885 ;; ignore the difference
886 (if (or three-way-comp (not (string-equal agreement "3")))
887 (let* ((a-begin (car (ediff-get-diff3-group "1")))
888 (a-end (nth 1 (ediff-get-diff3-group "1")))
889 (b-begin (car (ediff-get-diff3-group "2")))
890 (b-end (nth 1 (ediff-get-diff3-group "2")))
891 (c-or-anc-begin (car (ediff-get-diff3-group "3")))
892 (c-or-anc-end (nth 1 (ediff-get-diff3-group "3")))
893 (state-of-merge
894 (cond ((string-equal agreement "1") 'prefer-A)
895 ((string-equal agreement "2") 'prefer-B)
896 (t ediff-default-variant)))
897 (state-of-diff-merge
898 (if (memq state-of-merge '(default-A prefer-A)) 'B 'A))
899 (state-of-diff-comparison
900 (cond ((string-equal agreement "1") 'A)
901 ((string-equal agreement "2") 'B)
902 ((string-equal agreement "3") 'C)))
903 state-of-ancestor
904 c-begin c-end
905 a-begin-pt a-end-pt
906 b-begin-pt b-end-pt
907 c-begin-pt c-end-pt
908 anc-begin-pt anc-end-pt)
909
910 (setq state-of-ancestor
911 (= c-or-anc-begin c-or-anc-end))
912
913 (cond (three-way-comp
914 (setq c-begin c-or-anc-begin
915 c-end c-or-anc-end))
916 ((eq ediff-default-variant 'default-B)
917 (setq c-begin b-begin
918 c-end b-end))
919 (t
920 (setq c-begin a-begin
921 c-end a-end)))
922
923 ;; compute main diff vector
924 (if word-mode
925 ;; make diff-list contain word numbers
926 (setq diff-list
927 (nconc diff-list
928 (list (vector
929 (- a-begin a-prev) (- a-end a-begin)
930 (- b-begin b-prev) (- b-end b-begin)
931 (- c-begin c-prev) (- c-end c-begin)
932 nil nil ; dummy ancestor
933 nil ; state of diff
934 nil ; state of merge
935 nil ; state of ancestor
936 )))
937 a-prev a-end
938 b-prev b-end
939 c-prev c-end)
940 ;; else convert lines to points
941 (ediff-eval-in-buffer A-buffer
942 (forward-line (- a-begin a-prev))
943 (setq a-begin-pt (point))
944 (forward-line (- a-end a-begin))
945 (setq a-end-pt (point)
946 a-prev a-end))
947 (ediff-eval-in-buffer B-buffer
948 (forward-line (- b-begin b-prev))
949 (setq b-begin-pt (point))
950 (forward-line (- b-end b-begin))
951 (setq b-end-pt (point)
952 b-prev b-end))
953 (ediff-eval-in-buffer C-buffer
954 (forward-line (- c-begin c-prev))
955 (setq c-begin-pt (point))
956 (forward-line (- c-end c-begin))
957 (setq c-end-pt (point)
958 c-prev c-end))
959 (if (ediff-buffer-live-p anc-buffer)
960 (ediff-eval-in-buffer anc-buffer
961 (forward-line (- c-or-anc-begin anc-prev))
962 (setq anc-begin-pt (point))
963 (forward-line (- c-or-anc-end c-or-anc-begin))
964 (setq anc-end-pt (point)
965 anc-prev c-or-anc-end)))
966 (setq diff-list
967 (nconc
968 diff-list
969 ;; if comparing with ancestor, then there also is a
970 ;; state-of-difference marker
971 (if three-way-comp
972 (list (vector
973 a-begin-pt a-end-pt
974 b-begin-pt b-end-pt
975 c-begin-pt c-end-pt
976 nil nil ; ancestor begin/end
977 state-of-diff-comparison
978 nil ; state of merge
979 nil ; state of ancestor
980 ))
981 (list (vector a-begin-pt a-end-pt
982 b-begin-pt b-end-pt
983 c-begin-pt c-end-pt
984 anc-begin-pt anc-end-pt
985 state-of-diff-merge
986 state-of-merge
987 state-of-ancestor
988 )))
989 )))
990 ))
991
992 ))) ; end ediff-eval-in-buffer
993 diff-list
994 ))
995
996 ;; Generate the difference vector and overlays for three files
997 ;; File-C is either the third file to compare (in case of 3-way comparison)
998 ;; or it is the ancestor file.
999 (defun ediff-setup-diff-regions3 (file-A file-B file-C)
1000
1001 ;;; ;; force all minibuffers to display ediff's messages.
1002 ;;; ;; when xemacs implements minibufferless frames, this won't be necessary
1003 ;;; (if ediff-xemacs-p (setq synchronize-minibuffers t))
1004
1005 (or (ediff-buffer-live-p ediff-diff-buffer)
1006 (setq ediff-diff-buffer
1007 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
1008
1009 (message "Computing differences ...")
1010 (ediff-exec-process ediff-diff3-program ediff-diff-buffer 'synchronize
1011 ediff-diff3-options file-A file-B file-C)
1012
1013 (ediff-prepare-error-list ediff-diff3-ok-lines-regexp ediff-diff-buffer)
1014 ;;(message "Computing differences ... done")
1015 (ediff-convert-diffs-to-overlays
1016 (ediff-extract-diffs3
1017 ediff-diff-buffer
1018 ediff-word-mode ediff-3way-comparison-job ediff-narrow-bounds)
1019 ))
1020
1021
1022 ;; Execute PROGRAM asynchronously, unless OS/2, Windows-*, or DOS, or unless
1023 ;; SYNCH is non-nil. BUFFER must be a buffer object, and must be alive. All
1024 ;; arguments in ARGS must be strings. The first arg may be a blank string, in
1025 ;; which case we delete it from ARGS list. We also delete nil from args.
1026 (defun ediff-exec-process (program buffer synch &rest args)
1027 (let ((data (match-data)))
1028 (if (string-match "^[ \t]*$" (car args)) ; delete blank string
1029 (setq args (cdr args)))
1030 (setq args (delq nil args)) ; delete nil from arguments
1031 (setq args (ediff-split-string (mapconcat 'identity args " ")))
1032 (unwind-protect
1033 (let ((directory default-directory)
1034 proc)
1035 (save-excursion
1036 (set-buffer buffer)
1037 (erase-buffer)
1038 (setq default-directory directory)
1039 (if (or (memq system-type '(emx ms-dos windows-nt windows-95))
1040 synch)
1041 ;; In OS/2 (emx) do it synchronously, since OS/2 doesn't let us
1042 ;; delete files used by other processes. Thus, in ediff-buffers
1043 ;; and similar functions, we can't delete temp files because
1044 ;; they might be used by the asynch process that computes
1045 ;; custom diffs. So, we have to wait till custom diff
1046 ;; subprocess is done.
1047 ;; Similarly for Windows-*
1048 ;; In DOS, must synchronize because DOS doesn't have
1049 ;; asynchronous processes.
1050 (apply 'call-process program nil buffer nil args)
1051 ;; On other systems, do it asynchronously.
1052 (setq proc (get-buffer-process buffer))
1053 (if proc (kill-process proc))
1054 (setq proc
1055 (apply 'start-process "Custom Diff" buffer program args))
1056 (setq mode-line-process '(":%s"))
1057 (set-process-sentinel proc 'ediff-process-sentinel)
1058 (set-process-filter proc 'ediff-process-filter)
1059 )))
1060 (store-match-data data))))
1061
1062 ;; This is shell-command-filter from simple.el in FSF Emacs.
1063 ;; Copied here because XEmacs doesn't have it.
1064 (defun ediff-process-filter (proc string)
1065 ;; Do save-excursion by hand so that we can leave point numerically unchanged
1066 ;; despite an insertion immediately after it.
1067 (let* ((obuf (current-buffer))
1068 (buffer (process-buffer proc))
1069 opoint
1070 (window (get-buffer-window buffer))
1071 (pos (window-start window)))
1072 (unwind-protect
1073 (progn
1074 (set-buffer buffer)
1075 (or (= (point) (point-max))
1076 (setq opoint (point)))
1077 (goto-char (point-max))
1078 (insert-before-markers string))
1079 ;; insert-before-markers moved this marker: set it back.
1080 (set-window-start window pos)
1081 ;; Finish our save-excursion.
1082 (if opoint
1083 (goto-char opoint))
1084 (set-buffer obuf))))
1085
1086 ;; like shell-command-sentinel but doesn't print an exit status message
1087 ;; we do this because diff always exits with status 1, if diffs are found
1088 ;; so shell-command-sentinel displays a confusing message to the user
1089 (defun ediff-process-sentinel (process signal)
1090 (if (and (memq (process-status process) '(exit signal))
1091 (buffer-name (process-buffer process)))
1092 (progn
1093 (save-excursion
1094 (set-buffer (process-buffer process))
1095 (setq mode-line-process nil))
1096 (delete-process process))))
1097
1098
1099 ;;; Word functions used to refine the current diff
1100
1101 (defvar ediff-forward-word-function 'ediff-forward-word
1102 "*Function to call to move to the next word.
1103 Used for splitting difference regions into individual words.")
1104
1105 (defvar ediff-whitespace " \n\t\f"
1106 "*Characters constituting white space.
1107 These characters are ignored when differing regions are split into words.")
1108
1109 ;;(defvar ediff-word-1 "a-zA-Z---_`'.?!:"
1110 (defvar ediff-word-1 "a-zA-Z---_"
1111 "*Characters that constitute words of type 1.
1112 More precisely, [ediff-word-1] is a regexp that matches type 1 words.
1113 See `ediff-forward-word' for more details.")
1114
1115 (defvar ediff-word-2 "0-9.,"
1116 "*Characters that constitute words of type 2.
1117 More precisely, [ediff-word-2] is a regexp that matches type 2 words.
1118 See `ediff-forward-word' for more details.")
1119
1120 (defvar ediff-word-3 "`'?!:;\"{}[]()"
1121 "*Characters that constitute words of type 3.
1122 More precisely, [ediff-word-3] is a regexp that matches type 3 words.
1123 See `ediff-forward-word' for more details.")
1124
1125 (defvar ediff-word-4
1126 (concat "^" ediff-word-1 ediff-word-2 ediff-word-3 ediff-whitespace)
1127 "*Characters that constitute words of type 4.
1128 More precisely, [ediff-word-4] is a regexp that matches type 4 words.
1129 See `ediff-forward-word' for more details.")
1130
1131 ;; Split region along word boundaries. Each word will be on its own line.
1132 ;; Output to buffer out-buffer.
1133 (defun ediff-forward-word ()
1134 "Move point one word forward.
1135 There are four types of words, each of which consists entirely of
1136 characters in `ediff-word-1', `ediff-word-2', `ediff-word-3', or
1137 `ediff-word-4'. Words are recognized by passing these in turn as the
1138 argument to `skip-chars-forward'."
1139 (or (> (skip-chars-forward ediff-word-1) 0)
1140 (> (skip-chars-forward ediff-word-2) 0)
1141 (> (skip-chars-forward ediff-word-3) 0)
1142 (> (skip-chars-forward ediff-word-4) 0)
1143 ))
1144
1145 (defun ediff-wordify (beg end in-buffer out-buffer &optional control-buf)
1146 (let (sv-point string)
1147 (save-excursion
1148 (set-buffer in-buffer)
1149 (setq string (buffer-substring beg end))
1150
1151 (set-buffer out-buffer)
1152 (erase-buffer)
1153 (insert string)
1154 (goto-char (point-min))
1155 (skip-chars-forward ediff-whitespace)
1156 (delete-region (point-min) (point))
1157
1158 (while (not (eobp))
1159 ;; eval incontrol buf to let user create local versions for
1160 ;; different invocations
1161 (if control-buf
1162 (funcall
1163 (ediff-eval-in-buffer control-buf ediff-forward-word-function))
1164 (funcall ediff-forward-word-function))
1165 (setq sv-point (point))
1166 (skip-chars-forward ediff-whitespace)
1167 (delete-region sv-point (point))
1168 (insert "\n")))))
1169
1170 ;; copy string from BEG END from IN-BUF to OUT-BUF
1171 (defun ediff-copy-to-buffer (beg end in-buffer out-buffer)
1172 (let (string)
1173 (save-excursion
1174 (set-buffer in-buffer)
1175 (setq string (buffer-substring beg end))
1176
1177 (set-buffer out-buffer)
1178 (erase-buffer)
1179 (insert string)
1180 (goto-char (point-min)))))
1181
1182
1183 ;; goto word #n starting at current position in buffer `buf'
1184 ;; For ediff, a word is either a string of a-z,A-Z, incl `-' and `_';
1185 ;; or a string of other non-blanks. A blank is a \n\t\f
1186 ;; If `flag' is non-nil, goto the end of the n-th word.
1187 (defun ediff-goto-word (n buf &optional flag)
1188 ;; remember val ediff-forward-word-function has in ctl buf
1189 (let ((fwd-word-fun ediff-forward-word-function))
1190 (ediff-eval-in-buffer buf
1191 (skip-chars-forward ediff-whitespace)
1192 (while (> n 1)
1193 (funcall fwd-word-fun)
1194 (skip-chars-forward ediff-whitespace)
1195 (setq n (1- n)))
1196 (if (and flag (> n 0))
1197 (funcall fwd-word-fun))
1198 (point))))
1199
1200
1201 ;;; Local Variables:
1202 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1203 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
1204 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
1205 ;;; End:
1206
1207 (provide 'ediff-diff)
1208
1209
1210 ;; ediff-diff.el ends here