comparison lisp/ediff-diff.el @ 49588:37645a051842

Trailing whitespace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 11:26:42 +0000
parents 1b4ba54b52de
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49587:e82b3fe06d4c 49588:37645a051842
124 are `-I REGEXP', to ignore changes whose lines match the REGEXP." 124 are `-I REGEXP', to ignore changes whose lines match the REGEXP."
125 :type '(repeat string) 125 :type '(repeat string)
126 :group 'ediff-diff) 126 :group 'ediff-diff)
127 127
128 (defcustom ediff-diff-options "" 128 (defcustom ediff-diff-options ""
129 "*Options to pass to `ediff-diff-program'. 129 "*Options to pass to `ediff-diff-program'.
130 If Unix diff is used as `ediff-diff-program', then the most useful options are 130 If Unix diff is used as `ediff-diff-program', then the most useful options are
131 `-w', to ignore space, and `-i', to ignore case of letters. 131 `-w', to ignore space, and `-i', to ignore case of letters.
132 At present, the option `-c' is not allowed." 132 At present, the option `-c' is not allowed."
133 :set 'ediff-reset-diff-options 133 :set 'ediff-reset-diff-options
134 :type 'string 134 :type 'string
162 162
163 ;; keeps the status of the current diff in 3-way jobs. 163 ;; keeps the status of the current diff in 3-way jobs.
164 ;; the status can be =diff(A), =diff(B), or =diff(A+B) 164 ;; the status can be =diff(A), =diff(B), or =diff(A+B)
165 (ediff-defvar-local ediff-diff-status "" "") 165 (ediff-defvar-local ediff-diff-status "" "")
166 166
167 167
168 ;;; Fine differences 168 ;;; Fine differences
169 169
170 (ediff-defvar-local ediff-auto-refine (if (ediff-has-face-support-p) 'on 'nix) 170 (ediff-defvar-local ediff-auto-refine (if (ediff-has-face-support-p) 'on 'nix)
171 "If `on', Ediff auto-highlights fine diffs for the current diff region. 171 "If `on', Ediff auto-highlights fine diffs for the current diff region.
172 If `off', auto-highlighting is not used. If `nix', no fine diffs are shown 172 If `off', auto-highlighting is not used. If `nix', no fine diffs are shown
180 This variable can be set either in .emacs or toggled interactively. 180 This variable can be set either in .emacs or toggled interactively.
181 Use `setq-default' if setting it in .emacs") 181 Use `setq-default' if setting it in .emacs")
182 182
183 (ediff-defvar-local ediff-auto-refine-limit 1400 183 (ediff-defvar-local ediff-auto-refine-limit 1400
184 "*Auto-refine only the regions of this size \(in bytes\) or less.") 184 "*Auto-refine only the regions of this size \(in bytes\) or less.")
185 185
186 ;;; General 186 ;;; General
187 187
188 (defvar ediff-diff-ok-lines-regexp 188 (defvar ediff-diff-ok-lines-regexp
189 (concat 189 (concat
190 "^\\(" 190 "^\\("
213 213
214 The function should take three mandatory arguments, file-A, file-B, and 214 The function should take three mandatory arguments, file-A, file-B, and
215 file-C. It may ignore file C for diff2 jobs. It should also take 215 file-C. It may ignore file C for diff2 jobs. It should also take
216 one optional arguments, diff-number to refine.") 216 one optional arguments, diff-number to refine.")
217 217
218 218
219 ;;; Functions 219 ;;; Functions
220 220
221 ;; Generate the difference vector and overlays for the two files 221 ;; Generate the difference vector and overlays for the two files
222 ;; With optional arg REG-TO-REFINE, refine this region. 222 ;; With optional arg REG-TO-REFINE, refine this region.
223 ;; File-C argument is not used here. It is there just because 223 ;; File-C argument is not used here. It is there just because
226 ;; ediff-setup-diff-regions3, which takes 4 arguments. 226 ;; ediff-setup-diff-regions3, which takes 4 arguments.
227 (defun ediff-setup-diff-regions (file-A file-B file-C) 227 (defun ediff-setup-diff-regions (file-A file-B file-C)
228 ;; looking either for '-c' or a 'c' in a set of clustered non-long options 228 ;; looking either for '-c' or a 'c' in a set of clustered non-long options
229 (if (string-match "^-c\\| -c\\|-[^- ]+c" ediff-diff-options) 229 (if (string-match "^-c\\| -c\\|-[^- ]+c" ediff-diff-options)
230 (error "Option `-c' is not allowed in `ediff-diff-options'")) 230 (error "Option `-c' is not allowed in `ediff-diff-options'"))
231 231
232 ;; create, if it doesn't exist 232 ;; create, if it doesn't exist
233 (or (ediff-buffer-live-p ediff-diff-buffer) 233 (or (ediff-buffer-live-p ediff-diff-buffer)
234 (setq ediff-diff-buffer 234 (setq ediff-diff-buffer
235 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*")))) 235 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
236 (ediff-make-diff2-buffer ediff-diff-buffer file-A file-B) 236 (ediff-make-diff2-buffer ediff-diff-buffer file-A file-B)
266 'synchronize 266 'synchronize
267 ediff-diff-options file1 file2) 267 ediff-diff-options file1 file2)
268 (message "") 268 (message "")
269 (ediff-with-current-buffer diff-buffer 269 (ediff-with-current-buffer diff-buffer
270 (buffer-size)))))) 270 (buffer-size))))))
271 271
272 272
273 273
274 ;; If file-A/B/C is nil, do 2-way comparison with the non-nil buffers 274 ;; If file-A/B/C is nil, do 2-way comparison with the non-nil buffers
275 ;; This function works for diff3 and diff2 jobs 275 ;; This function works for diff3 and diff2 jobs
276 (defun ediff-setup-fine-diff-regions (file-A file-B file-C reg-num) 276 (defun ediff-setup-fine-diff-regions (file-A file-B file-C reg-num)
277 (or (ediff-buffer-live-p ediff-fine-diff-buffer) 277 (or (ediff-buffer-live-p ediff-fine-diff-buffer)
278 (setq ediff-fine-diff-buffer 278 (setq ediff-fine-diff-buffer
279 (get-buffer-create 279 (get-buffer-create
280 (ediff-unique-buffer-name "*ediff-fine-diff" "*")))) 280 (ediff-unique-buffer-name "*ediff-fine-diff" "*"))))
281 281
282 (let (diff3-job diff-program diff-options ok-regexp diff-list) 282 (let (diff3-job diff-program diff-options ok-regexp diff-list)
283 (setq diff3-job ediff-3way-job 283 (setq diff3-job ediff-3way-job
284 diff-program (if diff3-job ediff-diff3-program ediff-diff-program) 284 diff-program (if diff3-job ediff-diff3-program ediff-diff-program)
285 diff-options (if diff3-job ediff-diff3-options ediff-diff-options) 285 diff-options (if diff3-job ediff-diff3-options ediff-diff-options)
286 ok-regexp (if diff3-job 286 ok-regexp (if diff3-job
287 ediff-diff3-ok-lines-regexp 287 ediff-diff3-ok-lines-regexp
288 ediff-diff-ok-lines-regexp)) 288 ediff-diff-ok-lines-regexp))
289 289
290 (ediff-message-if-verbose "Refining difference region %d ..." (1+ reg-num)) 290 (ediff-message-if-verbose "Refining difference region %d ..." (1+ reg-num))
291 (ediff-exec-process diff-program ediff-fine-diff-buffer 'synchronize 291 (ediff-exec-process diff-program ediff-fine-diff-buffer 'synchronize
292 diff-options 292 diff-options
293 ;; The shuffle below is because we can compare 3-way 293 ;; The shuffle below is because we can compare 3-way
294 ;; or in several 2-way fashions, like fA fC, fA fB, 294 ;; or in several 2-way fashions, like fA fC, fA fB,
296 (if file-A file-A file-B) 296 (if file-A file-A file-B)
297 (if file-B file-B file-A) 297 (if file-B file-B file-A)
298 (if diff3-job 298 (if diff3-job
299 (if file-C file-C file-B)) 299 (if file-C file-C file-B))
300 ) ; exec process 300 ) ; exec process
301 301
302 (ediff-prepare-error-list ok-regexp ediff-fine-diff-buffer) 302 (ediff-prepare-error-list ok-regexp ediff-fine-diff-buffer)
303 (ediff-message-if-verbose 303 (ediff-message-if-verbose
304 "") 304 "")
305 ;; "Refining difference region %d ... done" (1+ reg-num)) 305 ;; "Refining difference region %d ... done" (1+ reg-num))
306 306
307 (setq diff-list 307 (setq diff-list
308 (if diff3-job 308 (if diff3-job
309 (ediff-extract-diffs3 309 (ediff-extract-diffs3
310 ediff-fine-diff-buffer '3way-comparison 'word-mode) 310 ediff-fine-diff-buffer '3way-comparison 'word-mode)
311 (ediff-extract-diffs ediff-fine-diff-buffer 'word-mode))) 311 (ediff-extract-diffs ediff-fine-diff-buffer 'word-mode)))
325 (mapcar (lambda (elt) 325 (mapcar (lambda (elt)
326 (aset elt 4 nil) 326 (aset elt 4 nil)
327 (aset elt 5 nil)) 327 (aset elt 5 nil))
328 (cdr diff-list))) 328 (cdr diff-list)))
329 )) 329 ))
330 330
331 (ediff-convert-fine-diffs-to-overlays diff-list reg-num) 331 (ediff-convert-fine-diffs-to-overlays diff-list reg-num)
332 )) 332 ))
333 333
334 334
335 (defun ediff-prepare-error-list (ok-regexp diff-buff) 335 (defun ediff-prepare-error-list (ok-regexp diff-buff)
336 (or (ediff-buffer-live-p ediff-error-buffer) 336 (or (ediff-buffer-live-p ediff-error-buffer)
337 (setq ediff-error-buffer 337 (setq ediff-error-buffer
338 (get-buffer-create (ediff-unique-buffer-name 338 (get-buffer-create (ediff-unique-buffer-name
339 "*ediff-errors" "*")))) 339 "*ediff-errors" "*"))))
366 (a-prev 1) ; this is needed to set the first diff line correctly 366 (a-prev 1) ; this is needed to set the first diff line correctly
367 (b-prev 1) 367 (b-prev 1)
368 (c-prev 1) 368 (c-prev 1)
369 diff-list shift-A shift-B 369 diff-list shift-A shift-B
370 ) 370 )
371 371
372 ;; diff list contains word numbers, unless changed later 372 ;; diff list contains word numbers, unless changed later
373 (setq diff-list (cons (if word-mode 'words 'points) 373 (setq diff-list (cons (if word-mode 'words 'points)
374 diff-list)) 374 diff-list))
375 ;; we don't use visibility bounds for buffer C when merging 375 ;; we don't use visibility bounds for buffer C when merging
376 (if bounds 376 (if bounds
378 (ediff-overlay-start 378 (ediff-overlay-start
379 (ediff-get-value-according-to-buffer-type 'A bounds)) 379 (ediff-get-value-according-to-buffer-type 'A bounds))
380 shift-B 380 shift-B
381 (ediff-overlay-start 381 (ediff-overlay-start
382 (ediff-get-value-according-to-buffer-type 'B bounds)))) 382 (ediff-get-value-according-to-buffer-type 'B bounds))))
383 383
384 ;; reset point in buffers A/B/C 384 ;; reset point in buffers A/B/C
385 (ediff-with-current-buffer A-buffer 385 (ediff-with-current-buffer A-buffer
386 (goto-char (if shift-A shift-A (point-min)))) 386 (goto-char (if shift-A shift-A (point-min))))
387 (ediff-with-current-buffer B-buffer 387 (ediff-with-current-buffer B-buffer
388 (goto-char (if shift-B shift-B (point-min)))) 388 (goto-char (if shift-B shift-B (point-min))))
389 (if (ediff-buffer-live-p C-buffer) 389 (if (ediff-buffer-live-p C-buffer)
390 (ediff-with-current-buffer C-buffer 390 (ediff-with-current-buffer C-buffer
391 (goto-char (point-min)))) 391 (goto-char (point-min))))
392 392
393 (ediff-with-current-buffer diff-buffer 393 (ediff-with-current-buffer diff-buffer
394 (goto-char (point-min)) 394 (goto-char (point-min))
395 (while (re-search-forward ediff-match-diff-line nil t) 395 (while (re-search-forward ediff-match-diff-line nil t)
396 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1) 396 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1)
397 (match-end 1)))) 397 (match-end 1))))
421 b-begin (1+ b-begin) 421 b-begin (1+ b-begin)
422 b-end b-begin) 422 b-end b-begin)
423 ;; (string-equal diff-type "c") 423 ;; (string-equal diff-type "c")
424 (setq a-end (1+ a-end) 424 (setq a-end (1+ a-end)
425 b-end (1+ b-end)))) 425 b-end (1+ b-end))))
426 426
427 (if (eq ediff-default-variant 'default-B) 427 (if (eq ediff-default-variant 'default-B)
428 (setq c-begin b-begin 428 (setq c-begin b-begin
429 c-end b-end) 429 c-end b-end)
430 (setq c-begin a-begin 430 (setq c-begin a-begin
431 c-end a-end)) 431 c-end a-end))
432 432
433 ;; compute main diff vector 433 ;; compute main diff vector
434 (if word-mode 434 (if word-mode
435 ;; make diff-list contain word numbers 435 ;; make diff-list contain word numbers
436 (setq diff-list 436 (setq diff-list
437 (nconc diff-list 437 (nconc diff-list
498 nil nil ; dummy ancestor 498 nil nil ; dummy ancestor
499 nil nil ; dummy state of diff & merge 499 nil nil ; dummy state of diff & merge
500 nil ; dummy state of ancestor 500 nil ; dummy state of ancestor
501 ))) 501 )))
502 ))) 502 )))
503 503
504 ))) ; end ediff-with-current-buffer 504 ))) ; end ediff-with-current-buffer
505 diff-list 505 diff-list
506 )) 506 ))
507 507
508 508
509 (defun ediff-convert-diffs-to-overlays (diff-list) 509 (defun ediff-convert-diffs-to-overlays (diff-list)
510 (ediff-set-diff-overlays-in-one-buffer 'A diff-list) 510 (ediff-set-diff-overlays-in-one-buffer 'A diff-list)
511 (ediff-set-diff-overlays-in-one-buffer 'B diff-list) 511 (ediff-set-diff-overlays-in-one-buffer 'B diff-list)
512 (if ediff-3way-job 512 (if ediff-3way-job
528 ;; the first elt designates type of list 528 ;; the first elt designates type of list
529 (cdr diff-list)) 529 (cdr diff-list))
530 ))) 530 )))
531 (message "Processing difference regions ... done")) 531 (message "Processing difference regions ... done"))
532 532
533 533
534 (defun ediff-set-diff-overlays-in-one-buffer (buf-type diff-list) 534 (defun ediff-set-diff-overlays-in-one-buffer (buf-type diff-list)
535 (let* ((current-diff -1) 535 (let* ((current-diff -1)
536 (buff (ediff-get-buffer buf-type)) 536 (buff (ediff-get-buffer buf-type))
537 ;; ediff-extract-diffs puts the type of diff-list as the first elt 537 ;; ediff-extract-diffs puts the type of diff-list as the first elt
538 ;; of this list. The type is either 'points or 'words 538 ;; of this list. The type is either 'points or 'words
546 diff-overlay-list list-element total-diffs 546 diff-overlay-list list-element total-diffs
547 begin end pt-saved overlay state-of-diff) 547 begin end pt-saved overlay state-of-diff)
548 548
549 (setq diff-list (cdr diff-list)) ; discard diff list type 549 (setq diff-list (cdr diff-list)) ; discard diff list type
550 (setq total-diffs (length diff-list)) 550 (setq total-diffs (length diff-list))
551 551
552 ;; shift, if necessary 552 ;; shift, if necessary
553 (ediff-with-current-buffer buff (setq pt-saved shift)) 553 (ediff-with-current-buffer buff (setq pt-saved shift))
554 554
555 (while diff-list 555 (while diff-list
556 (setq current-diff (1+ current-diff) 556 (setq current-diff (1+ current-diff)
557 list-element (car diff-list) 557 list-element (car diff-list)
558 begin (aref list-element (cond ((eq buf-type 'A) 0) 558 begin (aref list-element (cond ((eq buf-type 'A) 0)
559 ((eq buf-type 'B) 2) 559 ((eq buf-type 'B) 2)
563 ((eq buf-type 'B) 3) 563 ((eq buf-type 'B) 3)
564 ((eq buf-type 'C) 5) 564 ((eq buf-type 'C) 5)
565 (t 7))) ; Ancestor 565 (t 7))) ; Ancestor
566 state-of-diff (aref list-element 8) 566 state-of-diff (aref list-element 8)
567 ) 567 )
568 568
569 (cond ((and (not (eq buf-type state-of-diff)) 569 (cond ((and (not (eq buf-type state-of-diff))
570 (not (eq buf-type 'Ancestor)) 570 (not (eq buf-type 'Ancestor))
571 (memq state-of-diff '(A B C))) 571 (memq state-of-diff '(A B C)))
572 (setq state-of-diff 572 (setq state-of-diff
573 (car (delq buf-type (delq state-of-diff (list 'A 'B 'C))))) 573 (car (delq buf-type (delq state-of-diff (list 'A 'B 'C)))))
574 (setq state-of-diff (format "=diff(%S)" state-of-diff)) 574 (setq state-of-diff (format "=diff(%S)" state-of-diff))
575 ) 575 )
576 (t (setq state-of-diff nil))) 576 (t (setq state-of-diff nil)))
577 577
578 ;; Put overlays at appropriate places in buffer 578 ;; Put overlays at appropriate places in buffer
579 ;; convert word numbers to points, if necessary 579 ;; convert word numbers to points, if necessary
580 (if (eq diff-list-type 'words) 580 (if (eq diff-list-type 'words)
581 (progn 581 (progn
582 (ediff-with-current-buffer buff (goto-char pt-saved)) 582 (ediff-with-current-buffer buff (goto-char pt-saved))
584 end (ediff-goto-word end buff 'end)) 584 end (ediff-goto-word end buff 'end))
585 (if (> end limit) (setq end limit)) 585 (if (> end limit) (setq end limit))
586 (if (> begin end) (setq begin end)) 586 (if (> begin end) (setq begin end))
587 (setq pt-saved (ediff-with-current-buffer buff (point))))) 587 (setq pt-saved (ediff-with-current-buffer buff (point)))))
588 (setq overlay (ediff-make-bullet-proof-overlay begin end buff)) 588 (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
589 589
590 (ediff-overlay-put overlay 'priority ediff-shadow-overlay-priority) 590 (ediff-overlay-put overlay 'priority ediff-shadow-overlay-priority)
591 (ediff-overlay-put overlay 'ediff-diff-num current-diff) 591 (ediff-overlay-put overlay 'ediff-diff-num current-diff)
592 (if (and (ediff-has-face-support-p) 592 (if (and (ediff-has-face-support-p)
593 ediff-use-faces ediff-highlight-all-diffs) 593 ediff-use-faces ediff-highlight-all-diffs)
594 (ediff-set-overlay-face 594 (ediff-set-overlay-face
607 diff-overlay-list 607 diff-overlay-list
608 (list (vector overlay nil nil state-of-diff))) 608 (list (vector overlay nil nil state-of-diff)))
609 diff-list 609 diff-list
610 (cdr diff-list)) 610 (cdr diff-list))
611 ) ; while 611 ) ; while
612 612
613 (set (ediff-get-symbol-from-alist buf-type ediff-difference-vector-alist) 613 (set (ediff-get-symbol-from-alist buf-type ediff-difference-vector-alist)
614 (vconcat diff-overlay-list)) 614 (vconcat diff-overlay-list))
615 )) 615 ))
616 616
617 ;; `n' is the diff region to work on. Default is ediff-current-difference. 617 ;; `n' is the diff region to work on. Default is ediff-current-difference.
618 ;; if `flag' is 'noforce then make fine-diffs only if this region's fine 618 ;; if `flag' is 'noforce then make fine-diffs only if this region's fine
619 ;; diffs have not been computed before. 619 ;; diffs have not been computed before.
620 ;; if `flag' is 'skip then don't compute fine diffs for this region. 620 ;; if `flag' is 'skip then don't compute fine diffs for this region.
621 (defun ediff-make-fine-diffs (&optional n flag) 621 (defun ediff-make-fine-diffs (&optional n flag)
622 (or n (setq n ediff-current-difference)) 622 (or n (setq n ediff-current-difference))
623 623
624 (if (< ediff-number-of-differences 1) 624 (if (< ediff-number-of-differences 1)
625 (error ediff-NO-DIFFERENCES)) 625 (error ediff-NO-DIFFERENCES))
626 626
627 (if ediff-word-mode 627 (if ediff-word-mode
628 (setq flag 'skip 628 (setq flag 'skip
629 ediff-auto-refine 'nix)) 629 ediff-auto-refine 'nix))
630 630
631 (or (< n 0) 631 (or (< n 0)
632 (>= n ediff-number-of-differences) 632 (>= n ediff-number-of-differences)
633 ;; n is within the range 633 ;; n is within the range
634 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer)) 634 (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
635 (file-A ediff-temp-file-A) 635 (file-A ediff-temp-file-A)
640 (empty-C (ediff-empty-diff-region-p n 'C)) 640 (empty-C (ediff-empty-diff-region-p n 'C))
641 (whitespace-A (ediff-whitespace-diff-region-p n 'A)) 641 (whitespace-A (ediff-whitespace-diff-region-p n 'A))
642 (whitespace-B (ediff-whitespace-diff-region-p n 'B)) 642 (whitespace-B (ediff-whitespace-diff-region-p n 'B))
643 (whitespace-C (ediff-whitespace-diff-region-p n 'C)) 643 (whitespace-C (ediff-whitespace-diff-region-p n 'C))
644 cumulative-fine-diff-length) 644 cumulative-fine-diff-length)
645 645
646 (cond ;; If one of the regions is empty (or 2 in 3way comparison) 646 (cond ;; If one of the regions is empty (or 2 in 3way comparison)
647 ;; then don't refine. 647 ;; then don't refine.
648 ;; If the region happens to be entirely whitespace or empty then 648 ;; If the region happens to be entirely whitespace or empty then
649 ;; mark as such. 649 ;; mark as such.
650 ((> (length (delq nil (list empty-A empty-B empty-C))) 1) 650 ((> (length (delq nil (list empty-A empty-B empty-C))) 1)
704 ediff-buffer-A 704 ediff-buffer-A
705 tmp-buffer 705 tmp-buffer
706 ediff-control-buffer) 706 ediff-control-buffer)
707 (setq file-A 707 (setq file-A
708 (ediff-make-temp-file tmp-buffer "fineDiffA" file-A)) 708 (ediff-make-temp-file tmp-buffer "fineDiffA" file-A))
709 709
710 (ediff-wordify 710 (ediff-wordify
711 (ediff-get-diff-posn 'B 'beg n) 711 (ediff-get-diff-posn 'B 'beg n)
712 (ediff-get-diff-posn 'B 'end n) 712 (ediff-get-diff-posn 'B 'end n)
713 ediff-buffer-B 713 ediff-buffer-B
714 tmp-buffer 714 tmp-buffer
715 ediff-control-buffer) 715 ediff-control-buffer)
716 (setq file-B 716 (setq file-B
717 (ediff-make-temp-file tmp-buffer "fineDiffB" file-B)) 717 (ediff-make-temp-file tmp-buffer "fineDiffB" file-B))
718 718
719 (if ediff-3way-job 719 (if ediff-3way-job
720 (progn 720 (progn
721 (ediff-wordify 721 (ediff-wordify
722 (ediff-get-diff-posn 'C 'beg n) 722 (ediff-get-diff-posn 'C 'beg n)
723 (ediff-get-diff-posn 'C 'end n) 723 (ediff-get-diff-posn 'C 'end n)
725 tmp-buffer 725 tmp-buffer
726 ediff-control-buffer) 726 ediff-control-buffer)
727 (setq file-C 727 (setq file-C
728 (ediff-make-temp-file 728 (ediff-make-temp-file
729 tmp-buffer "fineDiffC" file-C)))) 729 tmp-buffer "fineDiffC" file-C))))
730 730
731 ;; save temp file names. 731 ;; save temp file names.
732 (setq ediff-temp-file-A file-A 732 (setq ediff-temp-file-A file-A
733 ediff-temp-file-B file-B 733 ediff-temp-file-B file-B
734 ediff-temp-file-C file-C) 734 ediff-temp-file-C file-C)
735 735
736 ;; set the new vector of fine diffs, if none exists 736 ;; set the new vector of fine diffs, if none exists
737 (cond ((and ediff-3way-job whitespace-A) 737 (cond ((and ediff-3way-job whitespace-A)
738 (ediff-setup-fine-diff-regions nil file-B file-C n)) 738 (ediff-setup-fine-diff-regions nil file-B file-C n))
739 ((and ediff-3way-job whitespace-B) 739 ((and ediff-3way-job whitespace-B)
740 (ediff-setup-fine-diff-regions file-A nil file-C n)) 740 (ediff-setup-fine-diff-regions file-A nil file-C n))
743 ;; ediff-empty-diff-region-p returns t in this case 743 ;; ediff-empty-diff-region-p returns t in this case
744 whitespace-C) 744 whitespace-C)
745 (ediff-setup-fine-diff-regions file-A file-B nil n)) 745 (ediff-setup-fine-diff-regions file-A file-B nil n))
746 (t 746 (t
747 (ediff-setup-fine-diff-regions file-A file-B file-C n))) 747 (ediff-setup-fine-diff-regions file-A file-B file-C n)))
748 748
749 (setq cumulative-fine-diff-length 749 (setq cumulative-fine-diff-length
750 (+ (length (ediff-get-fine-diff-vector n 'A)) 750 (+ (length (ediff-get-fine-diff-vector n 'A))
751 (length (ediff-get-fine-diff-vector n 'B)) 751 (length (ediff-get-fine-diff-vector n 'B))
752 ;; in merge jobs, the merge buffer is never refined 752 ;; in merge jobs, the merge buffer is never refined
753 (if (and file-C (not ediff-merge-job)) 753 (if (and file-C (not ediff-merge-job))
754 (length (ediff-get-fine-diff-vector n 'C)) 754 (length (ediff-get-fine-diff-vector n 'C))
755 0))) 755 0)))
756 756
757 (cond ((or 757 (cond ((or
758 ;; all regions are white space 758 ;; all regions are white space
759 (and whitespace-A whitespace-B whitespace-C) 759 (and whitespace-A whitespace-B whitespace-C)
760 ;; none is white space and no fine diffs detected 760 ;; none is white space and no fine diffs detected
761 (and (not whitespace-A) 761 (and (not whitespace-A)
779 (ediff-mark-diff-as-space-only n nil))) 779 (ediff-mark-diff-as-space-only n nil)))
780 ) 780 )
781 ) ; end cond 781 ) ; end cond
782 (ediff-set-fine-diff-properties n) 782 (ediff-set-fine-diff-properties n)
783 ))) 783 )))
784 784
785 ;; Interface to ediff-make-fine-diffs. Checks for auto-refine limit, etc. 785 ;; Interface to ediff-make-fine-diffs. Checks for auto-refine limit, etc.
786 (defun ediff-install-fine-diff-if-necessary (n) 786 (defun ediff-install-fine-diff-if-necessary (n)
787 (cond ((and (eq ediff-auto-refine 'on) 787 (cond ((and (eq ediff-auto-refine 'on)
788 ediff-use-faces 788 ediff-use-faces
789 (not (eq ediff-highlighting-style 'off)) 789 (not (eq ediff-highlighting-style 'off))
795 (> ediff-auto-refine-limit 795 (> ediff-auto-refine-limit
796 (- (ediff-get-diff-posn 'B 'end n) 796 (- (ediff-get-diff-posn 'B 'end n)
797 (ediff-get-diff-posn 'B 'beg n)))) 797 (ediff-get-diff-posn 'B 'beg n))))
798 (ediff-make-fine-diffs n 'noforce) 798 (ediff-make-fine-diffs n 'noforce)
799 (ediff-make-fine-diffs n 'skip))) 799 (ediff-make-fine-diffs n 'skip)))
800 800
801 ;; highlight iff fine diffs already exist 801 ;; highlight iff fine diffs already exist
802 ((eq ediff-auto-refine 'off) 802 ((eq ediff-auto-refine 'off)
803 (ediff-make-fine-diffs n 'skip)))) 803 (ediff-make-fine-diffs n 'skip))))
804 804
805 805
806 ;; if fine diff vector is not set for diff N, then do nothing 806 ;; if fine diff vector is not set for diff N, then do nothing
807 (defun ediff-set-fine-diff-properties (n &optional default) 807 (defun ediff-set-fine-diff-properties (n &optional default)
808 (or (not (ediff-has-face-support-p)) 808 (or (not (ediff-has-face-support-p))
809 (< n 0) 809 (< n 0)
810 (>= n ediff-number-of-differences) 810 (>= n ediff-number-of-differences)
812 (progn 812 (progn
813 (ediff-set-fine-diff-properties-in-one-buffer 'A n default) 813 (ediff-set-fine-diff-properties-in-one-buffer 'A n default)
814 (ediff-set-fine-diff-properties-in-one-buffer 'B n default) 814 (ediff-set-fine-diff-properties-in-one-buffer 'B n default)
815 (if ediff-3way-job 815 (if ediff-3way-job
816 (ediff-set-fine-diff-properties-in-one-buffer 'C n default))))) 816 (ediff-set-fine-diff-properties-in-one-buffer 'C n default)))))
817 817
818 (defun ediff-set-fine-diff-properties-in-one-buffer (buf-type 818 (defun ediff-set-fine-diff-properties-in-one-buffer (buf-type
819 n &optional default) 819 n &optional default)
820 (let ((fine-diff-vector (ediff-get-fine-diff-vector n buf-type)) 820 (let ((fine-diff-vector (ediff-get-fine-diff-vector n buf-type))
821 (face (if default 821 (face (if default
822 'default 822 'default
834 0))))) 834 0)))))
835 (mapcar (lambda (overl) 835 (mapcar (lambda (overl)
836 (ediff-set-overlay-face overl face) 836 (ediff-set-overlay-face overl face)
837 (ediff-overlay-put overl 'priority priority)) 837 (ediff-overlay-put overl 'priority priority))
838 fine-diff-vector))) 838 fine-diff-vector)))
839 839
840 ;; Set overlays over the regions that denote delimiters 840 ;; Set overlays over the regions that denote delimiters
841 (defun ediff-set-fine-overlays-for-combined-merge (diff-list reg-num) 841 (defun ediff-set-fine-overlays-for-combined-merge (diff-list reg-num)
842 (let (overlay overlay-list) 842 (let (overlay overlay-list)
843 (while diff-list 843 (while diff-list
844 (condition-case nil 844 (condition-case nil
854 ) 854 )
855 (setq overlay-list (reverse overlay-list)) 855 (setq overlay-list (reverse overlay-list))
856 (ediff-set-fine-diff-vector 856 (ediff-set-fine-diff-vector
857 reg-num 'C (apply 'vector overlay-list)) 857 reg-num 'C (apply 'vector overlay-list))
858 )) 858 ))
859 859
860 860
861 ;; Convert diff list to overlays for a given DIFF-REGION 861 ;; Convert diff list to overlays for a given DIFF-REGION
862 ;; in buffer of type BUF-TYPE 862 ;; in buffer of type BUF-TYPE
863 (defun ediff-set-fine-overlays-in-one-buffer (buf-type diff-list region-num) 863 (defun ediff-set-fine-overlays-in-one-buffer (buf-type diff-list region-num)
864 (let* ((current-diff -1) 864 (let* ((current-diff -1)
865 (reg-start (ediff-get-diff-posn buf-type 'beg region-num)) 865 (reg-start (ediff-get-diff-posn buf-type 'beg region-num))
869 begin end overlay) 869 begin end overlay)
870 870
871 (ediff-clear-fine-differences-in-one-buffer region-num buf-type) 871 (ediff-clear-fine-differences-in-one-buffer region-num buf-type)
872 (setq diff-list (cdr diff-list)) ; discard list type (words or points) 872 (setq diff-list (cdr diff-list)) ; discard list type (words or points)
873 (ediff-with-current-buffer buff (goto-char reg-start)) 873 (ediff-with-current-buffer buff (goto-char reg-start))
874 874
875 ;; if it is a combined merge then set overlays in buff C specially 875 ;; if it is a combined merge then set overlays in buff C specially
876 (if (and ediff-merge-job (eq buf-type 'C) 876 (if (and ediff-merge-job (eq buf-type 'C)
877 (setq combined-merge-diff-list 877 (setq combined-merge-diff-list
878 (ediff-looks-like-combined-merge region-num))) 878 (ediff-looks-like-combined-merge region-num)))
879 (ediff-set-fine-overlays-for-combined-merge 879 (ediff-set-fine-overlays-for-combined-merge
895 (setq begin (ediff-goto-word (1+ begin) buff) 895 (setq begin (ediff-goto-word (1+ begin) buff)
896 end (ediff-goto-word end buff 'end)) 896 end (ediff-goto-word end buff 'end))
897 (setq overlay (ediff-make-bullet-proof-overlay begin end buff)) 897 (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
898 ;; record all overlays for this difference region 898 ;; record all overlays for this difference region
899 (setq diff-overlay-list (nconc diff-overlay-list (list overlay)))) 899 (setq diff-overlay-list (nconc diff-overlay-list (list overlay))))
900 900
901 (setq diff-list (cdr diff-list)) 901 (setq diff-list (cdr diff-list))
902 ) ; while 902 ) ; while
903 ;; convert the list of difference information into a vector 903 ;; convert the list of difference information into a vector
904 ;; for fast access 904 ;; for fast access
905 (ediff-set-fine-diff-vector 905 (ediff-set-fine-diff-vector
962 (b-prev 1) 962 (b-prev 1)
963 (c-prev 1) 963 (c-prev 1)
964 (anc-prev 1) 964 (anc-prev 1)
965 diff-list shift-A shift-B shift-C 965 diff-list shift-A shift-B shift-C
966 ) 966 )
967 967
968 ;; diff list contains word numbers or points, depending on word-mode 968 ;; diff list contains word numbers or points, depending on word-mode
969 (setq diff-list (cons (if word-mode 'words 'points) 969 (setq diff-list (cons (if word-mode 'words 'points)
970 diff-list)) 970 diff-list))
971 (if bounds 971 (if bounds
972 (setq shift-A 972 (setq shift-A
977 (ediff-get-value-according-to-buffer-type 'B bounds)) 977 (ediff-get-value-according-to-buffer-type 'B bounds))
978 shift-C 978 shift-C
979 (if three-way-comp 979 (if three-way-comp
980 (ediff-overlay-start 980 (ediff-overlay-start
981 (ediff-get-value-according-to-buffer-type 'C bounds))))) 981 (ediff-get-value-according-to-buffer-type 'C bounds)))))
982 982
983 ;; reset point in buffers A, B, C 983 ;; reset point in buffers A, B, C
984 (ediff-with-current-buffer A-buffer 984 (ediff-with-current-buffer A-buffer
985 (goto-char (if shift-A shift-A (point-min)))) 985 (goto-char (if shift-A shift-A (point-min))))
986 (ediff-with-current-buffer B-buffer 986 (ediff-with-current-buffer B-buffer
987 (goto-char (if shift-B shift-B (point-min)))) 987 (goto-char (if shift-B shift-B (point-min))))
989 (ediff-with-current-buffer C-buffer 989 (ediff-with-current-buffer C-buffer
990 (goto-char (if shift-C shift-C (point-min))))) 990 (goto-char (if shift-C shift-C (point-min)))))
991 (if (ediff-buffer-live-p anc-buffer) 991 (if (ediff-buffer-live-p anc-buffer)
992 (ediff-with-current-buffer anc-buffer 992 (ediff-with-current-buffer anc-buffer
993 (goto-char (point-min)))) 993 (goto-char (point-min))))
994 994
995 (ediff-with-current-buffer diff-buffer 995 (ediff-with-current-buffer diff-buffer
996 (goto-char (point-min)) 996 (goto-char (point-min))
997 (while (re-search-forward ediff-match-diff3-line nil t) 997 (while (re-search-forward ediff-match-diff3-line nil t)
998 ;; leave point after matched line 998 ;; leave point after matched line
999 (beginning-of-line 2) 999 (beginning-of-line 2)
1021 c-begin c-end 1021 c-begin c-end
1022 a-begin-pt a-end-pt 1022 a-begin-pt a-end-pt
1023 b-begin-pt b-end-pt 1023 b-begin-pt b-end-pt
1024 c-begin-pt c-end-pt 1024 c-begin-pt c-end-pt
1025 anc-begin-pt anc-end-pt) 1025 anc-begin-pt anc-end-pt)
1026 1026
1027 (setq state-of-ancestor 1027 (setq state-of-ancestor
1028 (= c-or-anc-begin c-or-anc-end)) 1028 (= c-or-anc-begin c-or-anc-end))
1029 1029
1030 (cond (three-way-comp 1030 (cond (three-way-comp
1031 (setq c-begin c-or-anc-begin 1031 (setq c-begin c-or-anc-begin
1034 (setq c-begin b-begin 1034 (setq c-begin b-begin
1035 c-end b-end)) 1035 c-end b-end))
1036 (t 1036 (t
1037 (setq c-begin a-begin 1037 (setq c-begin a-begin
1038 c-end a-end))) 1038 c-end a-end)))
1039 1039
1040 ;; compute main diff vector 1040 ;; compute main diff vector
1041 (if word-mode 1041 (if word-mode
1042 ;; make diff-list contain word numbers 1042 ;; make diff-list contain word numbers
1043 (setq diff-list 1043 (setq diff-list
1044 (nconc diff-list 1044 (nconc diff-list
1103 state-of-merge 1103 state-of-merge
1104 state-of-ancestor 1104 state-of-ancestor
1105 ))) 1105 )))
1106 ))) 1106 )))
1107 )) 1107 ))
1108 1108
1109 ))) ; end ediff-with-current-buffer 1109 ))) ; end ediff-with-current-buffer
1110 diff-list 1110 diff-list
1111 )) 1111 ))
1112 1112
1113 ;; Generate the difference vector and overlays for three files 1113 ;; Generate the difference vector and overlays for three files
1114 ;; File-C is either the third file to compare (in case of 3-way comparison) 1114 ;; File-C is either the third file to compare (in case of 3-way comparison)
1115 ;; or it is the ancestor file. 1115 ;; or it is the ancestor file.
1116 (defun ediff-setup-diff-regions3 (file-A file-B file-C) 1116 (defun ediff-setup-diff-regions3 (file-A file-B file-C)
1117 (or (ediff-buffer-live-p ediff-diff-buffer) 1117 (or (ediff-buffer-live-p ediff-diff-buffer)
1118 (setq ediff-diff-buffer 1118 (setq ediff-diff-buffer
1119 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*")))) 1119 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
1120 1120
1121 (message "Computing differences ...") 1121 (message "Computing differences ...")
1122 (ediff-exec-process ediff-diff3-program ediff-diff-buffer 'synchronize 1122 (ediff-exec-process ediff-diff3-program ediff-diff-buffer 'synchronize
1123 ediff-diff3-options file-A file-B file-C) 1123 ediff-diff3-options file-A file-B file-C)
1124 1124
1125 (ediff-prepare-error-list ediff-diff3-ok-lines-regexp ediff-diff-buffer) 1125 (ediff-prepare-error-list ediff-diff3-ok-lines-regexp ediff-diff-buffer)
1126 ;;(message "Computing differences ... done") 1126 ;;(message "Computing differences ... done")
1127 (ediff-convert-diffs-to-overlays 1127 (ediff-convert-diffs-to-overlays
1128 (ediff-extract-diffs3 1128 (ediff-extract-diffs3
1129 ediff-diff-buffer 1129 ediff-diff-buffer
1130 ediff-word-mode ediff-3way-comparison-job ediff-narrow-bounds) 1130 ediff-word-mode ediff-3way-comparison-job ediff-narrow-bounds)
1131 )) 1131 ))
1132 1132
1133 1133
1134 ;; Execute PROGRAM asynchronously, unless OS/2, Windows-*, or DOS, or unless 1134 ;; Execute PROGRAM asynchronously, unless OS/2, Windows-*, or DOS, or unless
1135 ;; SYNCH is non-nil. BUFFER must be a buffer object, and must be alive. The 1135 ;; SYNCH is non-nil. BUFFER must be a buffer object, and must be alive. The
1136 ;; OPTIONS arg is a list of options to pass to PROGRAM. It may be a blank 1136 ;; OPTIONS arg is a list of options to pass to PROGRAM. It may be a blank
1137 ;; string. All elements in FILES must be strings. We also delete nil from 1137 ;; string. All elements in FILES must be strings. We also delete nil from
1174 (setq mode-line-process '(":%s")) 1174 (setq mode-line-process '(":%s"))
1175 (set-process-sentinel proc 'ediff-process-sentinel) 1175 (set-process-sentinel proc 'ediff-process-sentinel)
1176 (set-process-filter proc 'ediff-process-filter) 1176 (set-process-filter proc 'ediff-process-filter)
1177 ))) 1177 )))
1178 (store-match-data data)))) 1178 (store-match-data data))))
1179 1179
1180 ;; This is shell-command-filter from simple.el in Emacs. 1180 ;; This is shell-command-filter from simple.el in Emacs.
1181 ;; Copied here because XEmacs doesn't have it. 1181 ;; Copied here because XEmacs doesn't have it.
1182 (defun ediff-process-filter (proc string) 1182 (defun ediff-process-filter (proc string)
1183 ;; Do save-excursion by hand so that we can leave point numerically unchanged 1183 ;; Do save-excursion by hand so that we can leave point numerically unchanged
1184 ;; despite an insertion immediately after it. 1184 ;; despite an insertion immediately after it.
1198 (set-window-start window pos) 1198 (set-window-start window pos)
1199 ;; Finish our save-excursion. 1199 ;; Finish our save-excursion.
1200 (if opoint 1200 (if opoint
1201 (goto-char opoint)) 1201 (goto-char opoint))
1202 (set-buffer obuf)))) 1202 (set-buffer obuf))))
1203 1203
1204 ;; like shell-command-sentinel but doesn't print an exit status message 1204 ;; like shell-command-sentinel but doesn't print an exit status message
1205 ;; we do this because diff always exits with status 1, if diffs are found 1205 ;; we do this because diff always exits with status 1, if diffs are found
1206 ;; so shell-command-sentinel displays a confusing message to the user 1206 ;; so shell-command-sentinel displays a confusing message to the user
1207 (defun ediff-process-sentinel (process signal) 1207 (defun ediff-process-sentinel (process signal)
1208 (if (and (memq (process-status process) '(exit signal)) 1208 (if (and (memq (process-status process) '(exit signal))
1210 (progn 1210 (progn
1211 (save-excursion 1211 (save-excursion
1212 (set-buffer (process-buffer process)) 1212 (set-buffer (process-buffer process))
1213 (setq mode-line-process nil)) 1213 (setq mode-line-process nil))
1214 (delete-process process)))) 1214 (delete-process process))))
1215 1215
1216 1216
1217 ;;; Word functions used to refine the current diff 1217 ;;; Word functions used to refine the current diff
1218 1218
1219 (defvar ediff-forward-word-function 'ediff-forward-word 1219 (defvar ediff-forward-word-function 'ediff-forward-word
1220 "*Function to call to move to the next word. 1220 "*Function to call to move to the next word.
1295 (erase-buffer) 1295 (erase-buffer)
1296 (insert diff-string) 1296 (insert diff-string)
1297 (goto-char (point-min)) 1297 (goto-char (point-min))
1298 (skip-chars-forward ediff-whitespace) 1298 (skip-chars-forward ediff-whitespace)
1299 (delete-region (point-min) (point)) 1299 (delete-region (point-min) (point))
1300 1300
1301 (while (not (eobp)) 1301 (while (not (eobp))
1302 (funcall forward-word-function) 1302 (funcall forward-word-function)
1303 (setq sv-point (point)) 1303 (setq sv-point (point))
1304 (skip-chars-forward ediff-whitespace) 1304 (skip-chars-forward ediff-whitespace)
1305 (delete-region sv-point (point)) 1305 (delete-region sv-point (point))
1306 (insert "\n"))))) 1306 (insert "\n")))))
1307 1307
1308 ;; copy string specified as BEG END from IN-BUF to OUT-BUF 1308 ;; copy string specified as BEG END from IN-BUF to OUT-BUF
1309 (defun ediff-copy-to-buffer (beg end in-buffer out-buffer) 1309 (defun ediff-copy-to-buffer (beg end in-buffer out-buffer)
1310 (with-current-buffer out-buffer 1310 (with-current-buffer out-buffer
1311 (erase-buffer) 1311 (erase-buffer)
1312 (insert-buffer-substring in-buffer beg end) 1312 (insert-buffer-substring in-buffer beg end)