Mercurial > emacs
comparison lisp/ediff-diff.el @ 15480:43a3308fcf61
*** empty log message ***
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Sat, 22 Jun 1996 01:54:34 +0000 |
parents | bd6c4ed55f9c |
children | b394c4c8b299 |
comparison
equal
deleted
inserted
replaced
15479:78863db629bb | 15480:43a3308fcf61 |
---|---|
1 ;;; ediff-diff.el --- diff-related utilities | 1 ;;; ediff-diff.el --- diff-related utilities |
2 | 2 |
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | 5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> |
6 | 6 |
7 ;; This file is part of GNU Emacs. | 7 ;; This file is part of GNU Emacs. |
8 | 8 |
26 (require 'ediff-init) | 26 (require 'ediff-init) |
27 | 27 |
28 | 28 |
29 (defvar ediff-shell | 29 (defvar ediff-shell |
30 (cond ((eq system-type 'emx) "cmd") ; OS/2 | 30 (cond ((eq system-type 'emx) "cmd") ; OS/2 |
31 ((eq system-type 'ms-dos) shell-file-name) ; no standard name on MS-DOS | 31 ((memq system-type '(ms-dos windows-nt windows-95)) |
32 shell-file-name) ; no standard name on MS-DOS | |
32 ((memq system-type '(vax-vms axp-vms)) "*dcl*") ; VMS | 33 ((memq system-type '(vax-vms axp-vms)) "*dcl*") ; VMS |
33 (t "sh")) ; UNIX | 34 (t "sh")) ; UNIX |
34 "*The shell used to run diff and patch. If user's .profile or | 35 "*The shell used to run diff and patch. If user's .profile or |
35 .cshrc files are set up correctly, any shell will do. However, some people | 36 .cshrc files are set up correctly, any shell will do. However, some people |
36 set $prompt or other things incorrectly, which leads to undesirable output | 37 set $prompt or other things incorrectly, which leads to undesirable output |
61 "*Program to be used for three-way comparison. | 62 "*Program to be used for three-way comparison. |
62 Must produce output compatible with Unix's diff3 program.") | 63 Must produce output compatible with Unix's diff3 program.") |
63 (defvar ediff-diff3-options "" | 64 (defvar ediff-diff3-options "" |
64 "*Options to pass to `ediff-diff3-program'.") | 65 "*Options to pass to `ediff-diff3-program'.") |
65 (defvar ediff-diff3-ok-lines-regexp | 66 (defvar ediff-diff3-ok-lines-regexp |
66 "^\\([1-3]:\\|====\\| \\|.*Warning *:\\|.*No newline\\|.*missing newline\\)" | 67 "^\\([1-3]:\\|====\\| \\|.*Warning *:\\|.*No newline\\|.*missing newline\\|^\C-m$\\)" |
67 "*Regexp that matches normal output lines from `ediff-diff3-program'. | 68 "*Regexp that matches normal output lines from `ediff-diff3-program'. |
68 Lines that do not match are assumed to be error messages.") | 69 Lines that do not match are assumed to be error messages.") |
69 | 70 |
70 ;; keeps the status of the current diff in 3-way jobs. | 71 ;; keeps the status of the current diff in 3-way jobs. |
71 ;; the status can be =diff(A), =diff(B), or =diff(A+B) | 72 ;; the status can be =diff(A), =diff(B), or =diff(A+B) |
72 (ediff-defvar-local ediff-diff-status "" "") | 73 (ediff-defvar-local ediff-diff-status "" "") |
73 | |
74 ;; Support for patch | |
75 | |
76 (defvar ediff-patch-program "patch" | |
77 "*Name of the program that applies patches.") | |
78 (defvar ediff-patch-options "" | |
79 "*Options to pass to ediff-patch-program.") | |
80 | |
81 ;; The buffer of the patch file. | |
82 (defvar ediff-patch-buf nil) | |
83 ;; The buffer where patch would display its diagnostics. | |
84 (defvar ediff-patch-diagnostics nil) | |
85 | 74 |
86 | 75 |
87 ;;; Fine differences | 76 ;;; Fine differences |
88 | 77 |
89 (ediff-defvar-local ediff-auto-refine (if (ediff-has-face-support-p) 'on 'nix) | 78 (ediff-defvar-local ediff-auto-refine (if (ediff-has-face-support-p) 'on 'nix) |
97 (ediff-defvar-local ediff-ignore-similar-regions nil | 86 (ediff-defvar-local ediff-ignore-similar-regions nil |
98 "*If t, skip over difference regions that differ only in the white space and line breaks. | 87 "*If t, skip over difference regions that differ only in the white space and line breaks. |
99 This variable can be set either in .emacs or toggled interactively. | 88 This variable can be set either in .emacs or toggled interactively. |
100 Use `setq-default' if setting it in .emacs") | 89 Use `setq-default' if setting it in .emacs") |
101 | 90 |
102 (ediff-defvar-local ediff-auto-refine-limit 700 | 91 (ediff-defvar-local ediff-auto-refine-limit 1400 |
103 "Auto-refine only those regions that are smaller than this number of bytes.") | 92 "*Auto-refine only the regions of this size \(in bytes\) or less.") |
104 | 93 |
105 ;;; General | 94 ;;; General |
106 | 95 |
107 (defvar ediff-diff-ok-lines-regexp | 96 (defvar ediff-diff-ok-lines-regexp |
108 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\|.*Warning *:\\|.*No newline\\|.*missing newline\\)" | 97 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\|.*Warning *:\\|.*No +newline\\|.*missing +newline\\|^\C-m$\\)" |
109 "Regexp that matches normal output lines from `ediff-diff-program'. | 98 "Regexp that matches normal output lines from `ediff-diff-program'. |
110 This is mostly lifted from Emerge, except that Ediff also considers | 99 This is mostly lifted from Emerge, except that Ediff also considers |
111 warnings and `Missing newline'-type messages to be normal output. | 100 warnings and `Missing newline'-type messages to be normal output. |
112 Lines that do not match are assumed to be error messages.") | 101 Lines that do not match are assumed to be error messages.") |
113 | 102 |
136 (defun ediff-setup-diff-regions (file-A file-B file-C) | 125 (defun ediff-setup-diff-regions (file-A file-B file-C) |
137 ;;; ;; Force all minibuffers to display ediff's messages. | 126 ;;; ;; Force all minibuffers to display ediff's messages. |
138 ;;; ;; When xemacs implements minibufferless frames, this won't be necessary | 127 ;;; ;; When xemacs implements minibufferless frames, this won't be necessary |
139 ;;; (if ediff-xemacs-p (setq synchronize-minibuffers t)) | 128 ;;; (if ediff-xemacs-p (setq synchronize-minibuffers t)) |
140 | 129 |
130 ;; create, if it doesn't exist | |
141 (or (ediff-buffer-live-p ediff-diff-buffer) | 131 (or (ediff-buffer-live-p ediff-diff-buffer) |
142 (setq ediff-diff-buffer | 132 (setq ediff-diff-buffer |
143 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*")))) | 133 (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*")))) |
144 | 134 (ediff-make-diff2-buffer ediff-diff-buffer file-A file-B) |
145 (message "Computing differences ...") | |
146 (ediff-exec-process ediff-diff-program ediff-diff-buffer 'synchronize | |
147 ediff-diff-options file-A file-B) | |
148 | |
149 (ediff-prepare-error-list ediff-diff-ok-lines-regexp ediff-diff-buffer) | 135 (ediff-prepare-error-list ediff-diff-ok-lines-regexp ediff-diff-buffer) |
150 ;;(message "Computing differences ... done") | |
151 (ediff-convert-diffs-to-overlays | 136 (ediff-convert-diffs-to-overlays |
152 (ediff-extract-diffs | 137 (ediff-extract-diffs |
153 ediff-diff-buffer ediff-word-mode ediff-narrow-bounds))) | 138 ediff-diff-buffer ediff-word-mode ediff-narrow-bounds))) |
139 | |
140 ;; fill in DIFF-BUFFER with the output from the diff program run on FILE1 and | |
141 ;; FILE2 | |
142 ;; Return the length of that buffer. | |
143 (defun ediff-make-diff2-buffer (diff-buffer file1 file2) | |
144 (cond ((< (ediff-file-size file1) 0) | |
145 (message "Can't diff remote files: %s" | |
146 (ediff-abbreviate-file-name file1)) | |
147 (sit-for 2) | |
148 ;; 1 is an error exit code | |
149 1) | |
150 ((< (ediff-file-size file2) 0) | |
151 (message "Can't diff remote file: %s" | |
152 (ediff-abbreviate-file-name file2)) | |
153 (sit-for 2) | |
154 (message "") | |
155 ;; 1 is an error exit code | |
156 1) | |
157 (t (message "Computing differences between %s and %s ..." | |
158 (file-name-nondirectory file1) | |
159 (file-name-nondirectory file2)) | |
160 ;; this erases the diff buffer automatically | |
161 (ediff-exec-process ediff-diff-program | |
162 diff-buffer | |
163 'synchronize | |
164 ediff-diff-options file1 file2) | |
165 ;;(message "Computing differences ... done") | |
166 (message "") | |
167 (ediff-eval-in-buffer diff-buffer | |
168 (buffer-size))))) | |
169 | |
170 | |
154 | 171 |
155 ;; If file-A/B/C is nil, do 2-way comparison with the non-nil buffers | 172 ;; If file-A/B/C is nil, do 2-way comparison with the non-nil buffers |
156 ;; This function works for diff3 and diff2 jobs | 173 ;; This function works for diff3 and diff2 jobs |
157 (defun ediff-setup-fine-diff-regions (file-A file-B file-C reg-num) | 174 (defun ediff-setup-fine-diff-regions (file-A file-B file-C reg-num) |
158 (or (ediff-buffer-live-p ediff-fine-diff-buffer) | 175 (or (ediff-buffer-live-p ediff-fine-diff-buffer) |
498 ;; if `flag' is 'skip then don't compute fine diffs for this region. | 515 ;; if `flag' is 'skip then don't compute fine diffs for this region. |
499 (defun ediff-make-fine-diffs (&optional n flag) | 516 (defun ediff-make-fine-diffs (&optional n flag) |
500 (or n (setq n ediff-current-difference)) | 517 (or n (setq n ediff-current-difference)) |
501 | 518 |
502 (if (< ediff-number-of-differences 1) | 519 (if (< ediff-number-of-differences 1) |
503 (error "Sorry, it is not my job to munch identical variants...")) | 520 (error ediff-NO-DIFFERENCES)) |
504 | 521 |
505 (if ediff-word-mode | 522 (if ediff-word-mode |
506 (setq flag 'skip | 523 (setq flag 'skip |
507 ediff-auto-refine 'nix)) | 524 ediff-auto-refine 'nix)) |
508 | 525 |
522 cumulative-fine-diff-length) | 539 cumulative-fine-diff-length) |
523 | 540 |
524 (cond ((and (eq flag 'noforce) (ediff-get-fine-diff-vector n 'A)) | 541 (cond ((and (eq flag 'noforce) (ediff-get-fine-diff-vector n 'A)) |
525 ;; don't compute fine diffs if diff vector exists | 542 ;; don't compute fine diffs if diff vector exists |
526 (if (ediff-no-fine-diffs-p n) | 543 (if (ediff-no-fine-diffs-p n) |
527 (ediff-message-if-verbose | 544 ;;(ediff-message-if-verbose |
545 (message | |
528 "Only white-space differences in region %d" (1+ n)))) | 546 "Only white-space differences in region %d" (1+ n)))) |
529 ;; If one of the regions is empty (or 2 in 3way comparison) | 547 ;; If one of the regions is empty (or 2 in 3way comparison) |
530 ;; then don't refine. | 548 ;; then don't refine. |
531 ;; If the region happens to be entirely whitespace or empty then | 549 ;; If the region happens to be entirely whitespace or empty then |
532 ;; mark as such. | 550 ;; mark as such. |
546 (1+ n) | 564 (1+ n) |
547 (cond (empty-A 'A) | 565 (cond (empty-A 'A) |
548 (empty-B 'B) | 566 (empty-B 'B) |
549 (empty-C 'C))) | 567 (empty-C 'C))) |
550 ) | 568 ) |
551 ;; if all regions happen to be whitespace, indicate this | 569 ;; if all regions happen to be whitespace |
552 (if (and whitespace-A whitespace-B whitespace-C) | 570 (if (and whitespace-A whitespace-B whitespace-C) |
571 ;; mark as space only | |
553 (ediff-mark-diff-as-space-only n t) | 572 (ediff-mark-diff-as-space-only n t) |
573 ;; if some regions are white and others don't, then mark as | |
574 ;; non-white-space-only | |
554 (ediff-mark-diff-as-space-only n nil))) | 575 (ediff-mark-diff-as-space-only n nil))) |
555 ;; don't compute fine diffs for this region | 576 ;; don't compute fine diffs for this region |
556 ((eq flag 'skip) | 577 ((eq flag 'skip) |
557 (or (ediff-get-fine-diff-vector n 'A) | 578 (or (ediff-get-fine-diff-vector n 'A) |
558 (memq ediff-auto-refine '(off nix)) | 579 (memq ediff-auto-refine '(off nix)) |
559 (ediff-message-if-verbose | 580 (ediff-message-if-verbose |
560 "Region %d exceeds auto-refine limit. `%s' force-refines" | 581 "Region %d exceeds auto-refine limit. Type `%s' to refine" |
561 (1+ n) | 582 (1+ n) |
562 (substitute-command-keys | 583 (substitute-command-keys |
563 "\\[ediff-make-or-kill-fine-diffs]") | 584 "\\[ediff-make-or-kill-fine-diffs]") |
564 ))) | 585 ))) |
565 (t | 586 (t |
603 (cond ((and ediff-3way-job whitespace-A) | 624 (cond ((and ediff-3way-job whitespace-A) |
604 (ediff-setup-fine-diff-regions nil file-B file-C n)) | 625 (ediff-setup-fine-diff-regions nil file-B file-C n)) |
605 ((and ediff-3way-job whitespace-B) | 626 ((and ediff-3way-job whitespace-B) |
606 (ediff-setup-fine-diff-regions file-A nil file-C n)) | 627 (ediff-setup-fine-diff-regions file-A nil file-C n)) |
607 ((and ediff-3way-job | 628 ((and ediff-3way-job |
608 (or whitespace-C | 629 ;; In merge-jobs, whitespace-C is t, since |
609 (and ediff-merge-job | 630 ;; ediff-empty-diff-region-p returns t in this case |
610 (ediff-looks-like-combined-merge n)))) | 631 whitespace-C) |
611 (ediff-setup-fine-diff-regions file-A file-B nil n)) | 632 (ediff-setup-fine-diff-regions file-A file-B nil n)) |
612 (t | 633 (t |
613 (ediff-setup-fine-diff-regions file-A file-B file-C n))) | 634 (ediff-setup-fine-diff-regions file-A file-B file-C n))) |
614 | 635 |
615 (setq cumulative-fine-diff-length | 636 (setq cumulative-fine-diff-length |
616 (+ (length (ediff-get-fine-diff-vector n 'A)) | 637 (+ (length (ediff-get-fine-diff-vector n 'A)) |
617 (length (ediff-get-fine-diff-vector n 'B)) | 638 (length (ediff-get-fine-diff-vector n 'B)) |
618 (if file-C | 639 ;; in merge jobs, the merge buffer is never refined |
619 (length | 640 (if (and file-C (not ediff-merge-job)) |
620 (ediff-get-fine-diff-vector n 'C)) | 641 (length (ediff-get-fine-diff-vector n 'C)) |
621 0))) | 642 0))) |
622 | 643 |
623 (cond ((or | 644 (cond ((or |
624 ;; all regions are white space | 645 ;; all regions are white space |
625 (and whitespace-A whitespace-B whitespace-C) | 646 (and whitespace-A whitespace-B whitespace-C) |
626 ;; none is white space and no fine diffs detected | 647 ;; none is white space and no fine diffs detected |
630 (eq cumulative-fine-diff-length 0))) | 651 (eq cumulative-fine-diff-length 0))) |
631 (ediff-mark-diff-as-space-only n t) | 652 (ediff-mark-diff-as-space-only n t) |
632 (ediff-message-if-verbose | 653 (ediff-message-if-verbose |
633 "Only white-space differences in region %d" (1+ n))) | 654 "Only white-space differences in region %d" (1+ n))) |
634 ((eq cumulative-fine-diff-length 0) | 655 ((eq cumulative-fine-diff-length 0) |
635 (ediff-mark-diff-as-space-only n nil) | 656 (ediff-mark-diff-as-space-only n t) |
636 (ediff-message-if-verbose | 657 (ediff-message-if-verbose |
637 "Only white-space differences in region %d %s" | 658 "Only white-space differences in region %d %s" |
638 (1+ n) | 659 (1+ n) |
639 (cond (whitespace-A "in buffers B & C") | 660 (cond (whitespace-A "in buffers B & C") |
640 (whitespace-B "in buffers A & C") | 661 (whitespace-B "in buffers A & C") |
845 (goto-char (point-min)) | 866 (goto-char (point-min)) |
846 (while (re-search-forward ediff-match-diff3-line nil t) | 867 (while (re-search-forward ediff-match-diff3-line nil t) |
847 ;; leave point after matched line | 868 ;; leave point after matched line |
848 (beginning-of-line 2) | 869 (beginning-of-line 2) |
849 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1)))) | 870 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1)))) |
850 ;; if the A and B files are the same and not 3way-comparison, | 871 ;; if the files A and B are the same and not 3way-comparison, |
851 ;; ignore the difference | 872 ;; ignore the difference |
852 (if (or three-way-comp (not (string-equal agreement "3"))) | 873 (if (or three-way-comp (not (string-equal agreement "3"))) |
853 (let* ((a-begin (car (ediff-get-diff3-group "1"))) | 874 (let* ((a-begin (car (ediff-get-diff3-group "1"))) |
854 (a-end (nth 1 (ediff-get-diff3-group "1"))) | 875 (a-end (nth 1 (ediff-get-diff3-group "1"))) |
855 (b-begin (car (ediff-get-diff3-group "2"))) | 876 (b-begin (car (ediff-get-diff3-group "2"))) |
1162 (if (and flag (> n 0)) | 1183 (if (and flag (> n 0)) |
1163 (funcall fwd-word-fun)) | 1184 (funcall fwd-word-fun)) |
1164 (point)))) | 1185 (point)))) |
1165 | 1186 |
1166 | 1187 |
1188 ;;; Local Variables: | |
1189 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
1190 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1) | |
1191 ;;; End: | |
1192 | |
1167 (provide 'ediff-diff) | 1193 (provide 'ediff-diff) |
1168 | 1194 |
1169 | 1195 |
1170 ;; ediff-diff.el ends here | 1196 ;; ediff-diff.el ends here |