comparison lisp/ediff-util.el @ 26263:4f315ca65976

*** empty log message ***
author Michael Kifer <kifer@cs.stonybrook.edu>
date Mon, 01 Nov 1999 07:16:15 +0000
parents fb6b9c37cdc4
children 6306740f6938
comparison
equal deleted inserted replaced
26262:c416a18b0a5d 26263:4f315ca65976
26 (provide 'ediff-util) 26 (provide 'ediff-util)
27 27
28 ;; Compiler pacifier 28 ;; Compiler pacifier
29 (defvar ediff-patch-diagnostics) 29 (defvar ediff-patch-diagnostics)
30 (defvar ediff-patchbufer) 30 (defvar ediff-patchbufer)
31 (defvar ediff-use-toolbar-p)
32 (defvar ediff-toolbar-height)
31 (defvar ediff-toolbar) 33 (defvar ediff-toolbar)
32 (defvar ediff-toolbar-3way) 34 (defvar ediff-toolbar-3way)
33 (defvar bottom-toolbar) 35 (defvar bottom-toolbar)
34 (defvar bottom-toolbar-visible-p) 36 (defvar bottom-toolbar-visible-p)
35 (defvar bottom-toolbar-height) 37 (defvar bottom-toolbar-height)
36 (defvar mark-active) 38 (defvar mark-active)
39 (defvar ediff-emacs-p)
37 40
38 (eval-when-compile 41 (eval-when-compile
39 (let ((load-path (cons (expand-file-name ".") load-path))) 42 (let ((load-path (cons (expand-file-name ".") load-path)))
40 (or (featurep 'ediff-init) 43 (or (featurep 'ediff-init)
41 (load "ediff-init.el" nil nil 'nosuffix)) 44 (load "ediff-init.el" nil nil 'nosuffix))
188 (define-key ediff-mode-map "a" 'ediff-copy-A-to-C) 191 (define-key ediff-mode-map "a" 'ediff-copy-A-to-C)
189 (define-key ediff-mode-map "b" 'ediff-copy-B-to-C) 192 (define-key ediff-mode-map "b" 'ediff-copy-B-to-C)
190 (define-key ediff-mode-map "r" 'ediff-restore-diff-in-merge-buffer) 193 (define-key ediff-mode-map "r" 'ediff-restore-diff-in-merge-buffer)
191 (define-key ediff-mode-map "s" 'ediff-shrink-window-C) 194 (define-key ediff-mode-map "s" 'ediff-shrink-window-C)
192 (define-key ediff-mode-map "+" 'ediff-combine-diffs) 195 (define-key ediff-mode-map "+" 'ediff-combine-diffs)
193 (define-key ediff-mode-map "$" 'ediff-toggle-show-clashes-only) 196 (define-key ediff-mode-map "$" nil)
197 (define-key ediff-mode-map "$$" 'ediff-toggle-show-clashes-only)
198 (define-key ediff-mode-map "$*" 'ediff-toggle-skip-changed-regions)
194 (define-key ediff-mode-map "&" 'ediff-re-merge)) 199 (define-key ediff-mode-map "&" 'ediff-re-merge))
195 (ediff-3way-comparison-job 200 (ediff-3way-comparison-job
196 (define-key ediff-mode-map "ab" 'ediff-copy-A-to-B) 201 (define-key ediff-mode-map "ab" 'ediff-copy-A-to-B)
197 (define-key ediff-mode-map "ba" 'ediff-copy-B-to-A) 202 (define-key ediff-mode-map "ba" 'ediff-copy-B-to-A)
198 (define-key ediff-mode-map "ac" 'ediff-copy-A-to-C) 203 (define-key ediff-mode-map "ac" 'ediff-copy-A-to-C)
283 (make-local-variable 'ediff-split-window-function) 288 (make-local-variable 'ediff-split-window-function)
284 (make-local-variable 'ediff-default-variant) 289 (make-local-variable 'ediff-default-variant)
285 (make-local-variable 'ediff-merge-window-share) 290 (make-local-variable 'ediff-merge-window-share)
286 (make-local-variable 'ediff-window-setup-function) 291 (make-local-variable 'ediff-window-setup-function)
287 (make-local-variable 'ediff-keep-variants) 292 (make-local-variable 'ediff-keep-variants)
293
294 (make-local-hook 'ediff-after-quit-hook-internal)
288 295
289 ;; unwrap set up parameters passed as argument 296 ;; unwrap set up parameters passed as argument
290 (while setup-parameters 297 (while setup-parameters
291 (set (car (car setup-parameters)) (cdr (car setup-parameters))) 298 (set (car (car setup-parameters)) (cdr (car setup-parameters)))
292 (setq setup-parameters (cdr setup-parameters))) 299 (setq setup-parameters (cdr setup-parameters)))
316 (if ediff-merge-job 323 (if ediff-merge-job
317 (let ((buf 324 (let ((buf
318 ;; If default variant is `combined', the right stuff is 325 ;; If default variant is `combined', the right stuff is
319 ;; inserted by ediff-do-merge 326 ;; inserted by ediff-do-merge
320 ;; Note: at some point, we tried to put ancestor buffer here 327 ;; Note: at some point, we tried to put ancestor buffer here
321 ;; (which is currently buffer C. This didn't work right 328 ;; (which is currently buffer C. This didn't work right
322 ;; because the merge buffer will contain lossage: diff regions 329 ;; because the merge buffer will contain lossage: diff regions
323 ;; in the ancestor, which correspond to revisions that agree 330 ;; in the ancestor, which correspond to revisions that agree
324 ;; in both buf A and B. 331 ;; in both buf A and B.
325 (cond ((eq ediff-default-variant 'default-B) 332 (cond ((eq ediff-default-variant 'default-B)
326 buffer-B) 333 buffer-B)
498 505
499 (select-window ediff-control-window) 506 (select-window ediff-control-window)
500 (ediff-visible-region) 507 (ediff-visible-region)
501 508
502 (run-hooks 'startup-hooks) 509 (run-hooks 'startup-hooks)
503 (ediff-arrange-auto-save-in-merge-jobs merge-buffer-file) 510 (ediff-arrange-autosave-in-merge-jobs merge-buffer-file)
504 511
505 (ediff-refresh-mode-lines) 512 (ediff-refresh-mode-lines)
506 (setq buffer-read-only t) 513 (setq buffer-read-only t)
507 (setq ediff-session-registry 514 (setq ediff-session-registry
508 (cons control-buffer ediff-session-registry)) 515 (cons control-buffer ediff-session-registry))
550 (goto-char (point-min)) 557 (goto-char (point-min))
551 (skip-chars-forward ediff-whitespace))) 558 (skip-chars-forward ediff-whitespace)))
552 559
553 ;; This executes in control buffer and sets auto-save, visited file name, etc, 560 ;; This executes in control buffer and sets auto-save, visited file name, etc,
554 ;; in the merge buffer 561 ;; in the merge buffer
555 (defun ediff-arrange-auto-save-in-merge-jobs (merge-buffer-file) 562 (defun ediff-arrange-autosave-in-merge-jobs (merge-buffer-file)
556 (if (not ediff-merge-job) 563 (if (not ediff-merge-job)
557 () 564 ()
558 (if (stringp merge-buffer-file) 565 (if (stringp merge-buffer-file)
559 (setq ediff-autostore-merges t 566 (setq ediff-autostore-merges t
560 ediff-merge-store-file merge-buffer-file)) 567 ediff-merge-store-file merge-buffer-file))
581 (interactive) 588 (interactive)
582 (ediff-barf-if-not-control-buffer) 589 (ediff-barf-if-not-control-buffer)
583 (if (and (ediff-buffer-live-p ediff-ancestor-buffer) 590 (if (and (ediff-buffer-live-p ediff-ancestor-buffer)
584 (not 591 (not
585 (y-or-n-p 592 (y-or-n-p
586 "Ancestor buffer will not be used. Recompute diffs anyway? "))) 593 "Ancestor buffer will not be used. Recompute diffs anyway? ")))
587 (error "Recomputation of differences canceled")) 594 (error "Recomputation of differences canceled"))
588 595
589 (let ((point-A (ediff-with-current-buffer ediff-buffer-A (point))) 596 (let ((point-A (ediff-with-current-buffer ediff-buffer-A (point)))
590 ;;(point-B (ediff-with-current-buffer ediff-buffer-B (point))) 597 ;;(point-B (ediff-with-current-buffer ediff-buffer-B (point)))
591 (tmp-buffer (get-buffer-create ediff-tmp-buffer)) 598 (tmp-buffer (get-buffer-create ediff-tmp-buffer))
640 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also) 647 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
641 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also) 648 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
642 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also) 649 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
643 (ediff-clear-diff-vector 650 (ediff-clear-diff-vector
644 'ediff-difference-vector-Ancestor 'fine-diffs-also) 651 'ediff-difference-vector-Ancestor 'fine-diffs-also)
645 ;; let them garbage collect. we can't use the ancestor after recomputing 652 ;; let them garbage collect. we can't use the ancestor after recomputing
646 ;; the diffs. 653 ;; the diffs.
647 (setq ediff-difference-vector-Ancestor nil 654 (setq ediff-difference-vector-Ancestor nil
648 ediff-ancestor-buffer nil 655 ediff-ancestor-buffer nil
649 ediff-state-of-merge nil) 656 ediff-state-of-merge nil)
650 657
676 683
677 (ediff-jump-to-difference (ediff-diff-at-point 'A point-A)) 684 (ediff-jump-to-difference (ediff-diff-at-point 'A point-A))
678 (message "") 685 (message "")
679 )) 686 ))
680 687
681 ;; Not bound to any key---to dangerous. A user can do it if necessary. 688 ;; Not bound to any key---to dangerous. A user can do it if necessary.
682 (defun ediff-revert-buffers-then-recompute-diffs (noconfirm) 689 (defun ediff-revert-buffers-then-recompute-diffs (noconfirm)
683 "Revert buffers A, B and C. Then rerun Ediff on file A and file B." 690 "Revert buffers A, B and C. Then rerun Ediff on file A and file B."
684 (interactive "P") 691 (interactive "P")
685 (ediff-barf-if-not-control-buffer) 692 (ediff-barf-if-not-control-buffer)
686 (let ((bufA ediff-buffer-A) 693 (let ((bufA ediff-buffer-A)
687 (bufB ediff-buffer-B) 694 (bufB ediff-buffer-B)
688 (bufC ediff-buffer-C) 695 (bufC ediff-buffer-C)
945 (cond ((setq wind (ediff-get-visible-buffer-window ediff-ancestor-buffer)) 952 (cond ((setq wind (ediff-get-visible-buffer-window ediff-ancestor-buffer))
946 (raise-frame (window-frame wind))) 953 (raise-frame (window-frame wind)))
947 (t (set-window-buffer ediff-window-C ediff-ancestor-buffer))))) 954 (t (set-window-buffer ediff-window-C ediff-ancestor-buffer)))))
948 955
949 (defun ediff-make-or-kill-fine-diffs (arg) 956 (defun ediff-make-or-kill-fine-diffs (arg)
950 "Compute fine diffs. With negative prefix arg, kill fine diffs. 957 "Compute fine diffs. With negative prefix arg, kill fine diffs.
951 In both cases, operates on the currrent difference region." 958 In both cases, operates on the currrent difference region."
952 (interactive "P") 959 (interactive "P")
953 (ediff-barf-if-not-control-buffer) 960 (ediff-barf-if-not-control-buffer)
954 (cond ((eq arg '-) 961 (cond ((eq arg '-)
955 (ediff-clear-fine-differences ediff-current-difference)) 962 (ediff-clear-fine-differences ediff-current-difference))
999 ((ediff-file-checked-out-p file) 1006 ((ediff-file-checked-out-p file)
1000 'toggle-read-only) 1007 'toggle-read-only)
1001 (file-writable 'toggle-read-only) 1008 (file-writable 'toggle-read-only)
1002 (t (key-binding "\C-x\C-q"))))) 1009 (t (key-binding "\C-x\C-q")))))
1003 ;; If the file is checked in, make sure we don't make buffer modifiable 1010 ;; If the file is checked in, make sure we don't make buffer modifiable
1004 ;; without warning the user. The user can fool our checks by making the 1011 ;; without warning the user. The user can fool our checks by making the
1005 ;; buffer non-RO without checking the file out. We regard this as a 1012 ;; buffer non-RO without checking the file out. We regard this as a
1006 ;; user problem. 1013 ;; user problem.
1007 (if (and (ediff-file-checked-in-p file) 1014 (if (and (ediff-file-checked-in-p file)
1008 ;; If ctl-buf is null, this means we called this 1015 ;; If ctl-buf is null, this means we called this
1009 ;; non-interactively, in which case don't ask questions 1016 ;; non-interactively, in which case don't ask questions
1010 ctl-buf) 1017 ctl-buf)
1011 (cond ((not buffer-read-only) 1018 (cond ((not buffer-read-only)
1012 (setq toggle-ro-cmd 'toggle-read-only)) 1019 (setq toggle-ro-cmd 'toggle-read-only))
1013 ((and (or (beep 1) t) ; always beep 1020 ((and (or (beep 1) t) ; always beep
1014 (y-or-n-p 1021 (y-or-n-p
1015 (format 1022 (format
1016 "File %s is under version control. Check it out? " 1023 "File %s is under version control. Check it out? "
1017 (ediff-abbreviate-file-name file)))) 1024 (ediff-abbreviate-file-name file))))
1018 ;; if we checked the file out, we should also change the 1025 ;; if we checked the file out, we should also change the
1019 ;; original state of buffer-read-only to nil. If we don't 1026 ;; original state of buffer-read-only to nil. If we don't
1020 ;; do this, the mode line will show %%, since the file was 1027 ;; do this, the mode line will show %%, since the file was
1021 ;; RO before ediff started, so the user will think the file 1028 ;; RO before ediff started, so the user will think the file
1053 (checkout-function (key-binding "\C-x\C-q"))) 1060 (checkout-function (key-binding "\C-x\C-q")))
1054 (if (and (ediff-file-checked-in-p file) 1061 (if (and (ediff-file-checked-in-p file)
1055 (or (beep 1) t) 1062 (or (beep 1) t)
1056 (y-or-n-p 1063 (y-or-n-p
1057 (format 1064 (format
1058 "File %s is under version control. Check it out? " 1065 "File %s is under version control. Check it out? "
1059 (ediff-abbreviate-file-name file)))) 1066 (ediff-abbreviate-file-name file))))
1060 (ediff-with-current-buffer buf 1067 (ediff-with-current-buffer buf
1061 (command-execute checkout-function))))) 1068 (command-execute checkout-function)))))
1062 1069
1063 1070
1090 (or (not (featurep 'vc-hooks)) 1097 (or (not (featurep 'vc-hooks))
1091 (and (vc-backend file) 1098 (and (vc-backend file)
1092 (vc-locking-user file)))) 1099 (vc-locking-user file))))
1093 (defsubst ediff-file-checked-in-p (file) 1100 (defsubst ediff-file-checked-in-p (file)
1094 (and (featurep 'vc-hooks) 1101 (and (featurep 'vc-hooks)
1095 (vc-backend file) 1102 ;; CVS files are considered not checked in
1103 (not (memq (vc-backend file) '(nil CVS)))
1096 (not (vc-locking-user file)))) 1104 (not (vc-locking-user file))))
1097 1105
1098 (defun ediff-file-compressed-p (file) 1106 (defun ediff-file-compressed-p (file)
1099 (condition-case nil 1107 (condition-case nil
1100 (require 'jka-compr) 1108 (require 'jka-compr)
1160 ediff-regexp-hide-B hide-regexp 1168 ediff-regexp-hide-B hide-regexp
1161 ediff-regexp-focus-A ediff-regexp-focus-B 1169 ediff-regexp-focus-A ediff-regexp-focus-B
1162 ediff-regexp-focus-B focus-regexp)) 1170 ediff-regexp-focus-B focus-regexp))
1163 1171
1164 ;; The following is needed for XEmacs, since there one can't move 1172 ;; The following is needed for XEmacs, since there one can't move
1165 ;; overlay to another buffer. In Emacs, this swap is redundant. 1173 ;; overlay to another buffer. In Emacs, this swap is redundant.
1166 (if (ediff-has-face-support-p) 1174 (if (ediff-has-face-support-p)
1167 (if ediff-3way-comparison-job 1175 (if ediff-3way-comparison-job
1168 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-C 1176 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-C
1169 ediff-current-diff-overlay-C ediff-current-diff-overlay-B 1177 ediff-current-diff-overlay-C ediff-current-diff-overlay-B
1170 ediff-current-diff-overlay-B overlay) 1178 ediff-current-diff-overlay-B overlay)
1254 (setq window-setup-func 'ediff-setup-windows-multiframe))) 1262 (setq window-setup-func 'ediff-setup-windows-multiframe)))
1255 1263
1256 ;; change default 1264 ;; change default
1257 (setq-default ediff-window-setup-function window-setup-func) 1265 (setq-default ediff-window-setup-function window-setup-func)
1258 ;; change in all active ediff sessions 1266 ;; change in all active ediff sessions
1259 (mapcar (function (lambda(buf) 1267 (mapcar (lambda(buf) (ediff-with-current-buffer buf
1260 (ediff-with-current-buffer buf 1268 (setq ediff-window-setup-function window-setup-func
1261 (setq ediff-window-setup-function window-setup-func 1269 ediff-window-B nil)))
1262 ediff-window-B nil))))
1263 ediff-session-registry) 1270 ediff-session-registry)
1264 (if (ediff-in-control-buffer-p) 1271 (if (ediff-in-control-buffer-p)
1265 (ediff-recenter 'no-rehighlight)))) 1272 (ediff-recenter 'no-rehighlight))))
1266 1273
1267 1274
1279 (if (ediff-use-toolbar-p) 1286 (if (ediff-use-toolbar-p)
1280 (ediff-kill-bottom-toolbar)) 1287 (ediff-kill-bottom-toolbar))
1281 ;; do this only after killing the toolbar 1288 ;; do this only after killing the toolbar
1282 (setq ediff-use-toolbar-p (not ediff-use-toolbar-p)) 1289 (setq ediff-use-toolbar-p (not ediff-use-toolbar-p))
1283 1290
1284 (mapcar (function (lambda(buf) 1291 (mapcar (lambda(buf)
1285 (ediff-with-current-buffer buf 1292 (ediff-with-current-buffer buf
1286 ;; force redisplay 1293 ;; force redisplay
1287 (setq ediff-window-config-saved "") 1294 (setq ediff-window-config-saved "")
1288 ))) 1295 ))
1289 ediff-session-registry) 1296 ediff-session-registry)
1290 (if (ediff-in-control-buffer-p) 1297 (if (ediff-in-control-buffer-p)
1291 (ediff-recenter 'no-rehighlight))))) 1298 (ediff-recenter 'no-rehighlight)))))
1292 1299
1293 1300
1325 )) 1332 ))
1326 1333
1327 ;; Merging 1334 ;; Merging
1328 1335
1329 (defun ediff-toggle-show-clashes-only () 1336 (defun ediff-toggle-show-clashes-only ()
1330 "Toggle the mode where only the regions where both buffers differ with the ancestor are shown." 1337 "Toggle the mode that shows only the merge regions where both variants differ from the ancestor."
1331 (interactive) 1338 (interactive)
1332 (ediff-barf-if-not-control-buffer) 1339 (ediff-barf-if-not-control-buffer)
1333 (if (not ediff-merge-with-ancestor-job) 1340 (if (not ediff-merge-with-ancestor-job)
1334 (error "This command makes sense only when merging with an ancestor")) 1341 (error "This command makes sense only when merging with an ancestor"))
1335 (setq ediff-show-clashes-only (not ediff-show-clashes-only)) 1342 (setq ediff-show-clashes-only (not ediff-show-clashes-only))
1336 (if ediff-show-clashes-only 1343 (if ediff-show-clashes-only
1337 (message "Focus on regions where both buffers differ from the ancestor") 1344 (message "Focus on regions where both buffers differ from the ancestor")
1338 (message "Canceling focus on regions where changes clash"))) 1345 (message "Canceling focus on regions where changes clash")))
1346
1347 (defun ediff-toggle-skip-changed-regions ()
1348 "Toggle the mode that skips the merge regions that differ from the default."
1349 (interactive)
1350 (ediff-barf-if-not-control-buffer)
1351 (setq ediff-skip-merge-regions-that-differ-from-default
1352 (not ediff-skip-merge-regions-that-differ-from-default))
1353 (if ediff-skip-merge-regions-that-differ-from-default
1354 (message "Skipping regions that differ from default setting")
1355 (message "Showing regions that differ from default setting")))
1356
1357
1339 1358
1340 ;; Widening/narrowing 1359 ;; Widening/narrowing
1341 1360
1342 (defun ediff-toggle-narrow-region () 1361 (defun ediff-toggle-narrow-region ()
1343 "Toggle narrowing in buffers A, B, and C. 1362 "Toggle narrowing in buffers A, B, and C.
1348 (if (eq ediff-visible-bounds ediff-wide-bounds) 1367 (if (eq ediff-visible-bounds ediff-wide-bounds)
1349 (setq ediff-visible-bounds ediff-narrow-bounds) 1368 (setq ediff-visible-bounds ediff-narrow-bounds)
1350 (setq ediff-visible-bounds ediff-wide-bounds)) 1369 (setq ediff-visible-bounds ediff-wide-bounds))
1351 (ediff-recenter 'no-rehighlight)) 1370 (ediff-recenter 'no-rehighlight))
1352 1371
1353 ;; Narrow bufs A/B/C to ediff-visible-bounds. If this is currently set to 1372 ;; Narrow bufs A/B/C to ediff-visible-bounds. If this is currently set to
1354 ;; ediff-wide-bounds, then this actually widens. 1373 ;; ediff-wide-bounds, then this actually widens.
1355 ;; This function does nothing if job-name is not 1374 ;; This function does nothing if job-name is not
1356 ;; ediff-regions-wordwise/linewise or ediff-windows-wordwise/linewise. 1375 ;; ediff-regions-wordwise/linewise or ediff-windows-wordwise/linewise.
1357 ;; Does nothing if buffer-A = buffer-B since we can't narrow 1376 ;; Does nothing if buffer-A = buffer-B since we can't narrow
1358 ;; to two different regions in one buffer. 1377 ;; to two different regions in one buffer.
1522 ;; no argument means default amount 1541 ;; no argument means default amount
1523 default-amount)))))) 1542 default-amount))))))
1524 1543
1525 1544
1526 ;;BEG, END show the region to be positioned. 1545 ;;BEG, END show the region to be positioned.
1527 ;;JOB-NAME holds ediff-job-name. The ediff-windows job positions regions 1546 ;;JOB-NAME holds ediff-job-name. The ediff-windows job positions regions
1528 ;;differently. 1547 ;;differently.
1529 (defun ediff-position-region (beg end pos job-name) 1548 (defun ediff-position-region (beg end pos job-name)
1530 (if (> end (point-max)) 1549 (if (> end (point-max))
1531 (setq end (point-max))) 1550 (setq end (point-max)))
1532 (if ediff-windows-job 1551 (if ediff-windows-job
1630 (interactive "p") 1649 (interactive "p")
1631 (ediff-barf-if-not-control-buffer) 1650 (ediff-barf-if-not-control-buffer)
1632 (if (< ediff-current-difference ediff-number-of-differences) 1651 (if (< ediff-current-difference ediff-number-of-differences)
1633 (let ((n (min ediff-number-of-differences 1652 (let ((n (min ediff-number-of-differences
1634 (+ ediff-current-difference (or arg 1)))) 1653 (+ ediff-current-difference (or arg 1))))
1635 non-clash-skip regexp-skip) 1654 non-clash-skip skip-changed regexp-skip)
1636 1655
1637 (ediff-visible-region) 1656 (ediff-visible-region)
1638 (or (>= n ediff-number-of-differences) 1657 (or (>= n ediff-number-of-differences)
1639 (setq regexp-skip (funcall ediff-skip-diff-region-function n)) 1658 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1640 ;; this won't exec if regexp-skip is t 1659 ;; this won't exec if regexp-skip is t
1641 (setq non-clash-skip (ediff-merge-region-is-non-clash n)) 1660 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1661 skip-changed
1662 (ediff-skip-merge-region-if-changed-from-default-p n))
1642 (ediff-install-fine-diff-if-necessary n)) 1663 (ediff-install-fine-diff-if-necessary n))
1664 ;; Skip loop
1643 (while (and (< n ediff-number-of-differences) 1665 (while (and (< n ediff-number-of-differences)
1644 (or 1666 (or
1645 ;; regexp skip 1667 ;; regexp skip
1646 regexp-skip 1668 regexp-skip
1647 ;; skip clashes, if necessary 1669 ;; skip clashes, if necessary
1648 non-clash-skip 1670 non-clash-skip
1671 ;; skip processed regions
1672 skip-changed
1649 ;; skip difference regions that differ in white space 1673 ;; skip difference regions that differ in white space
1650 (and ediff-ignore-similar-regions 1674 (and ediff-ignore-similar-regions
1651 (eq (ediff-no-fine-diffs-p n) t)))) 1675 (or (eq (ediff-no-fine-diffs-p n) t)
1676 (and (ediff-merge-job)
1677 (eq (ediff-no-fine-diffs-p n) 'C)))
1678 )))
1652 (setq n (1+ n)) 1679 (setq n (1+ n))
1653 (if (= 0 (mod n 20)) 1680 (if (= 0 (mod n 20))
1654 (message "Skipped over region %d and counting ..." n)) 1681 (message "Skipped over region %d and counting ..." n))
1655 (or (>= n ediff-number-of-differences) 1682 (or (>= n ediff-number-of-differences)
1656 (setq regexp-skip (funcall ediff-skip-diff-region-function n)) 1683 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1657 ;; this won't exec if regexp-skip is t 1684 ;; this won't exec if regexp-skip is t
1658 (setq non-clash-skip (ediff-merge-region-is-non-clash n)) 1685 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1686 skip-changed
1687 (ediff-skip-merge-region-if-changed-from-default-p n))
1659 (ediff-install-fine-diff-if-necessary n)) 1688 (ediff-install-fine-diff-if-necessary n))
1660 ) 1689 )
1661 (message "") 1690 (message "")
1662 (ediff-unselect-and-select-difference n) 1691 (ediff-unselect-and-select-difference n)
1663 ) ; let 1692 ) ; let
1669 With a prefix argument, go back that many differences." 1698 With a prefix argument, go back that many differences."
1670 (interactive "p") 1699 (interactive "p")
1671 (ediff-barf-if-not-control-buffer) 1700 (ediff-barf-if-not-control-buffer)
1672 (if (> ediff-current-difference -1) 1701 (if (> ediff-current-difference -1)
1673 (let ((n (max -1 (- ediff-current-difference (or arg 1)))) 1702 (let ((n (max -1 (- ediff-current-difference (or arg 1))))
1674 non-clash-skip regexp-skip) 1703 non-clash-skip skip-changed regexp-skip)
1675 1704
1676 (ediff-visible-region) 1705 (ediff-visible-region)
1677 (or (< n 0) 1706 (or (< n 0)
1678 (setq regexp-skip (funcall ediff-skip-diff-region-function n)) 1707 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1679 ;; this won't exec if regexp-skip is t 1708 ;; this won't exec if regexp-skip is t
1680 (setq non-clash-skip (ediff-merge-region-is-non-clash n)) 1709 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1710 skip-changed
1711 (ediff-skip-merge-region-if-changed-from-default-p n))
1681 (ediff-install-fine-diff-if-necessary n)) 1712 (ediff-install-fine-diff-if-necessary n))
1682 (while (and (> n -1) 1713 (while (and (> n -1)
1683 (or 1714 (or
1684 ;; regexp skip 1715 ;; regexp skip
1685 regexp-skip 1716 regexp-skip
1686 ;; skip clashes, if necessary 1717 ;; skip clashes, if necessary
1687 non-clash-skip 1718 non-clash-skip
1719 ;; skipp changed regions
1720 skip-changed
1688 ;; skip difference regions that differ in white space 1721 ;; skip difference regions that differ in white space
1689 (and ediff-ignore-similar-regions 1722 (and ediff-ignore-similar-regions
1690 (eq (ediff-no-fine-diffs-p n) t)))) 1723 (or (eq (ediff-no-fine-diffs-p n) t)
1724 (and (ediff-merge-job)
1725 (eq (ediff-no-fine-diffs-p n) 'C)))
1726 )))
1691 (if (= 0 (mod (1+ n) 20)) 1727 (if (= 0 (mod (1+ n) 20))
1692 (message "Skipped over region %d and counting ..." (1+ n))) 1728 (message "Skipped over region %d and counting ..." (1+ n)))
1693 (setq n (1- n)) 1729 (setq n (1- n))
1694 (or (< n 0) 1730 (or (< n 0)
1695 (setq regexp-skip (funcall ediff-skip-diff-region-function n)) 1731 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1696 ;; this won't exec if regexp-skip is t 1732 ;; this won't exec if regexp-skip is t
1697 (setq non-clash-skip (ediff-merge-region-is-non-clash n)) 1733 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1734 skip-changed
1735 (ediff-skip-merge-region-if-changed-from-default-p n))
1698 (ediff-install-fine-diff-if-necessary n)) 1736 (ediff-install-fine-diff-if-necessary n))
1699 ) 1737 )
1700 (message "") 1738 (message "")
1701 (ediff-unselect-and-select-difference n) 1739 (ediff-unselect-and-select-difference n)
1702 ) ; let 1740 ) ; let
1724 this-command (1+ difference-number) ediff-number-of-differences))) 1762 this-command (1+ difference-number) ediff-number-of-differences)))
1725 1763
1726 (defun ediff-jump-to-difference-at-point (arg) 1764 (defun ediff-jump-to-difference-at-point (arg)
1727 "Go to difference closest to the point in buffer A, B, or C. 1765 "Go to difference closest to the point in buffer A, B, or C.
1728 The buffer depends on last command character \(a, b, or c\) that invoked this 1766 The buffer depends on last command character \(a, b, or c\) that invoked this
1729 command. For instance, if the command was `ga' then the point value in buffer A 1767 command. For instance, if the command was `ga' then the point value in buffer
1730 is used. 1768 A is used.
1731 With a prefix argument, synchronize all files around the current point position 1769 With a prefix argument, synchronize all files around the current point position
1732 in the specified buffer." 1770 in the specified buffer."
1733 (interactive "P") 1771 (interactive "P")
1734 (ediff-barf-if-not-control-buffer) 1772 (ediff-barf-if-not-control-buffer)
1735 (let* ((buf-type (ediff-char-to-buftype last-command-char)) 1773 (let* ((buf-type (ediff-char-to-buftype last-command-char))
1780 1818
1781 1819
1782 ;; find region most related to the current point position (or POS, if given) 1820 ;; find region most related to the current point position (or POS, if given)
1783 ;; returns diff number as seen by the user (i.e., 1+ the internal 1821 ;; returns diff number as seen by the user (i.e., 1+ the internal
1784 ;; representation) 1822 ;; representation)
1785 ;; The optional argument WHICH-DIFF can be `after' or `before'. If `after', 1823 ;; The optional argument WHICH-DIFF can be `after' or `before'. If `after',
1786 ;; find the diff after the point. If `before', find the diff before the 1824 ;; find the diff after the point. If `before', find the diff before the
1787 ;; point. If the point is inside a diff, return that diff. 1825 ;; point. If the point is inside a diff, return that diff.
1788 (defun ediff-diff-at-point (buf-type &optional pos which-diff) 1826 (defun ediff-diff-at-point (buf-type &optional pos which-diff)
1789 (let ((buffer (ediff-get-buffer buf-type)) 1827 (let ((buffer (ediff-get-buffer buf-type))
1790 (ctl-buffer ediff-control-buffer) 1828 (ctl-buffer ediff-control-buffer)
1791 (max-dif-num (1- ediff-number-of-differences)) 1829 (max-dif-num (1- ediff-number-of-differences))
1792 (diff-no -1) 1830 (diff-no -1)
1827 "Copy buffer-X'th difference region to buffer Y \(X,Y are A, B, or C\). 1865 "Copy buffer-X'th difference region to buffer Y \(X,Y are A, B, or C\).
1828 If numerical prefix argument, copy the difference specified in the arg. 1866 If numerical prefix argument, copy the difference specified in the arg.
1829 Otherwise, copy the difference given by `ediff-current-difference'. 1867 Otherwise, copy the difference given by `ediff-current-difference'.
1830 This command assumes it is bound to a 2-character key sequence, `ab', `ba', 1868 This command assumes it is bound to a 2-character key sequence, `ab', `ba',
1831 `ac', etc., which is used to determine the types of buffers to be used for 1869 `ac', etc., which is used to determine the types of buffers to be used for
1832 copying difference regions. The first character in the sequence specifies 1870 copying difference regions. The first character in the sequence specifies
1833 the source buffer and the second specifies the target. 1871 the source buffer and the second specifies the target.
1834 1872
1835 If the second optional argument, a 2-character string, is given, use it to 1873 If the second optional argument, a 2-character string, is given, use it to
1836 determine the source and the target buffers instead of the command keys." 1874 determine the source and the target buffers instead of the command keys."
1837 (interactive "P") 1875 (interactive "P")
1851 ;; recenter with rehighlighting, but no messages 1889 ;; recenter with rehighlighting, but no messages
1852 (ediff-recenter))) 1890 (ediff-recenter)))
1853 1891
1854 (defun ediff-copy-A-to-B (arg) 1892 (defun ediff-copy-A-to-B (arg)
1855 "Copy ARGth difference region from buffer A to B. 1893 "Copy ARGth difference region from buffer A to B.
1856 ARG is a prefix argument. If nil, copy the current difference region." 1894 ARG is a prefix argument. If nil, copy the current difference region."
1857 (interactive "P") 1895 (interactive "P")
1858 (ediff-diff-to-diff arg "ab")) 1896 (ediff-diff-to-diff arg "ab"))
1859 1897
1860 (defun ediff-copy-B-to-A (arg) 1898 (defun ediff-copy-B-to-A (arg)
1861 "Copy ARGth difference region from buffer B to A. 1899 "Copy ARGth difference region from buffer B to A.
1862 ARG is a prefix argument. If nil, copy the current difference region." 1900 ARG is a prefix argument. If nil, copy the current difference region."
1863 (interactive "P") 1901 (interactive "P")
1864 (ediff-diff-to-diff arg "ba")) 1902 (ediff-diff-to-diff arg "ba"))
1865 1903
1866 (defun ediff-copy-A-to-C (arg) 1904 (defun ediff-copy-A-to-C (arg)
1867 "Copy ARGth difference region from buffer A to buffer C. 1905 "Copy ARGth difference region from buffer A to buffer C.
1868 ARG is a prefix argument. If nil, copy the current difference region." 1906 ARG is a prefix argument. If nil, copy the current difference region."
1869 (interactive "P") 1907 (interactive "P")
1870 (ediff-diff-to-diff arg "ac")) 1908 (ediff-diff-to-diff arg "ac"))
1871 1909
1872 (defun ediff-copy-B-to-C (arg) 1910 (defun ediff-copy-B-to-C (arg)
1873 "Copy ARGth difference region from buffer B to buffer C. 1911 "Copy ARGth difference region from buffer B to buffer C.
1874 ARG is a prefix argument. If nil, copy the current difference region." 1912 ARG is a prefix argument. If nil, copy the current difference region."
1875 (interactive "P") 1913 (interactive "P")
1876 (ediff-diff-to-diff arg "bc")) 1914 (ediff-diff-to-diff arg "bc"))
1877 1915
1878 (defun ediff-copy-C-to-B (arg) 1916 (defun ediff-copy-C-to-B (arg)
1879 "Copy ARGth difference region from buffer C to B. 1917 "Copy ARGth difference region from buffer C to B.
1880 ARG is a prefix argument. If nil, copy the current difference region." 1918 ARG is a prefix argument. If nil, copy the current difference region."
1881 (interactive "P") 1919 (interactive "P")
1882 (ediff-diff-to-diff arg "cb")) 1920 (ediff-diff-to-diff arg "cb"))
1883 1921
1884 (defun ediff-copy-C-to-A (arg) 1922 (defun ediff-copy-C-to-A (arg)
1885 "Copy ARGth difference region from buffer C to A. 1923 "Copy ARGth difference region from buffer C to A.
1886 ARG is a prefix argument. If nil, copy the current difference region." 1924 ARG is a prefix argument. If nil, copy the current difference region."
1887 (interactive "P") 1925 (interactive "P")
1888 (ediff-diff-to-diff arg "ca")) 1926 (ediff-diff-to-diff arg "ca"))
1889 1927
1890 1928
1891 1929
1892 ;; Copy diff N from FROM-BUF-TYPE \(given as A, B or C\) to TO-BUF-TYPE. 1930 ;; Copy diff N from FROM-BUF-TYPE \(given as A, B or C\) to TO-BUF-TYPE.
1893 ;; If optional DO-NOT-SAVE is non-nil, do not save the old value of the 1931 ;; If optional DO-NOT-SAVE is non-nil, do not save the old value of the
1894 ;; target diff. This is used in merging, when constructing the merged 1932 ;; target diff. This is used in merging, when constructing the merged
1895 ;; version. 1933 ;; version.
1896 (defun ediff-copy-diff (n from-buf-type to-buf-type 1934 (defun ediff-copy-diff (n from-buf-type to-buf-type
1897 &optional batch-invocation reg-to-copy) 1935 &optional batch-invocation reg-to-copy)
1898 (let* ((to-buf (ediff-get-buffer to-buf-type)) 1936 (let* ((to-buf (ediff-get-buffer to-buf-type))
1899 ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type))) 1937 ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type)))
1958 (ediff-clear-fine-differences n)) 1996 (ediff-clear-fine-differences n))
1959 1997
1960 (ediff-refresh-mode-lines) 1998 (ediff-refresh-mode-lines)
1961 1999
1962 ;; For diff2 jobs, don't recompute fine diffs, since we know there 2000 ;; For diff2 jobs, don't recompute fine diffs, since we know there
1963 ;; aren't any. So we clear diffs after ediff-recenter. 2001 ;; aren't any. So we clear diffs after ediff-recenter.
1964 (if (and saved-p (not three-way)) 2002 (if (and saved-p (not three-way))
1965 (ediff-clear-fine-differences n)) 2003 (ediff-clear-fine-differences n))
1966 ;; Make sure that the message about saving and how to restore is seen 2004 ;; Make sure that the message about saving and how to restore is seen
1967 ;; by the user 2005 ;; by the user
1968 (message messg)) 2006 (message messg))
1984 (if n-th-diff-saved ;; n-th diff saved, but for another buffer 2022 (if n-th-diff-saved ;; n-th diff saved, but for another buffer
1985 (nconc n-th-diff-saved (list (cons buf reg))) 2023 (nconc n-th-diff-saved (list (cons buf reg)))
1986 (setq ediff-killed-diffs-alist ;; create record for n-th diff 2024 (setq ediff-killed-diffs-alist ;; create record for n-th diff
1987 (cons (list n (cons buf reg)) 2025 (cons (list n (cons buf reg))
1988 ediff-killed-diffs-alist)))) 2026 ediff-killed-diffs-alist))))
1989 (message "Saving old diff region #%d of buffer %S. To recover, type `r%s'" 2027 (message "Saving old diff region #%d of buffer %S. To recover, type `r%s'"
1990 (1+ n) buf-type 2028 (1+ n) buf-type
1991 (if ediff-merge-job 2029 (if ediff-merge-job
1992 "" (downcase (symbol-name buf-type)))) 2030 "" (downcase (symbol-name buf-type))))
1993 )) 2031 ))
1994 2032
1999 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved)))) 2037 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
2000 2038
2001 (if this-buf-n-th-diff-saved 2039 (if this-buf-n-th-diff-saved
2002 (if (yes-or-no-p 2040 (if (yes-or-no-p
2003 (format 2041 (format
2004 "You've previously copied diff region %d to buffer %S. Confirm " 2042 "You've previously copied diff region %d to buffer %S. Confirm "
2005 (1+ n) buf-type)) 2043 (1+ n) buf-type))
2006 t 2044 t
2007 (error "Quit")) 2045 (error "Quit"))
2008 t))) 2046 t)))
2009 2047
2042 (car conds) 2080 (car conds)
2043 (mapconcat 'prin1-to-string (cdr conds) " ")) 2081 (mapconcat 'prin1-to-string (cdr conds) " "))
2044 (beep 1))) 2082 (beep 1)))
2045 2083
2046 ;; Clearing fine diffs is necessary for 2084 ;; Clearing fine diffs is necessary for
2047 ;; ediff-unselect-and-select-difference to properly recompute them. We 2085 ;; ediff-unselect-and-select-difference to properly recompute them. We
2048 ;; can't rely on ediff-copy-diff to clear this vector, as the user might 2086 ;; can't rely on ediff-copy-diff to clear this vector, as the user might
2049 ;; have modified diff regions after copying and, thus, may have recomputed 2087 ;; have modified diff regions after copying and, thus, may have recomputed
2050 ;; fine diffs. 2088 ;; fine diffs.
2051 (if recovered 2089 (if recovered
2052 (ediff-clear-fine-differences n)) 2090 (ediff-clear-fine-differences n))
2079 (let (ediff-verbose-p) 2117 (let (ediff-verbose-p)
2080 (ediff-recenter))) 2118 (ediff-recenter)))
2081 2119
2082 (defun ediff-restore-diff-in-merge-buffer (arg) 2120 (defun ediff-restore-diff-in-merge-buffer (arg)
2083 "Restore ARGth diff in the merge buffer. 2121 "Restore ARGth diff in the merge buffer.
2084 ARG is a prefix argument. If nil, restore the current diff." 2122 ARG is a prefix argument. If nil, restore the current diff."
2085 (interactive "P") 2123 (interactive "P")
2086 (ediff-restore-diff arg ?c)) 2124 (ediff-restore-diff arg ?c))
2087 2125
2088 2126
2089 (defun ediff-toggle-regexp-match () 2127 (defun ediff-toggle-regexp-match ()
2200 buf A region doesn't match `ediff-regexp-focus-A' and buf B region 2238 buf A region doesn't match `ediff-regexp-focus-A' and buf B region
2201 doesn't match `ediff-regexp-focus-B'. 2239 doesn't match `ediff-regexp-focus-B'.
2202 This function returns nil if the region number N (specified as 2240 This function returns nil if the region number N (specified as
2203 an argument) is not to be ignored and t if region N is to be ignored. 2241 an argument) is not to be ignored and t if region N is to be ignored.
2204 2242
2205 N is a region number used by Ediff internally. It is 1 less 2243 N is a region number used by Ediff internally. It is 1 less
2206 the number seen by the user." 2244 the number seen by the user."
2207 (if (ediff-valid-difference-p n) 2245 (if (ediff-valid-difference-p n)
2208 (let* ((ctl-buf ediff-control-buffer) 2246 (let* ((ctl-buf ediff-control-buffer)
2209 (regex-A ediff-regexp-focus-A) 2247 (regex-A ediff-regexp-focus-A)
2210 (regex-B ediff-regexp-focus-B) 2248 (regex-B ediff-regexp-focus-B)
2241 Regions to be ignored are those where buf A region matches 2279 Regions to be ignored are those where buf A region matches
2242 `ediff-regexp-hide-A' and buf B region matches `ediff-regexp-hide-B'. 2280 `ediff-regexp-hide-A' and buf B region matches `ediff-regexp-hide-B'.
2243 This function returns nil if the region number N (specified as 2281 This function returns nil if the region number N (specified as
2244 an argument) is not to be ignored and t if region N is to be ignored. 2282 an argument) is not to be ignored and t if region N is to be ignored.
2245 2283
2246 N is a region number used by Ediff internally. It is 1 less 2284 N is a region number used by Ediff internally. It is 1 less
2247 the number seen by the user." 2285 the number seen by the user."
2248 (if (ediff-valid-difference-p n) 2286 (if (ediff-valid-difference-p n)
2249 (let* ((ctl-buf ediff-control-buffer) 2287 (let* ((ctl-buf ediff-control-buffer)
2250 (regex-A ediff-regexp-hide-A) 2288 (regex-A ediff-regexp-hide-A)
2251 (regex-B ediff-regexp-hide-B) 2289 (regex-B ediff-regexp-hide-B)
2288 flags of the compared file buffers, kills Ediff buffers for this session 2326 flags of the compared file buffers, kills Ediff buffers for this session
2289 \(but not buffers A, B, C\). 2327 \(but not buffers A, B, C\).
2290 2328
2291 If `ediff-keep-variants' is nil, the user will be asked whether the buffers 2329 If `ediff-keep-variants' is nil, the user will be asked whether the buffers
2292 containing the variants should be removed \(if they haven't been modified\). 2330 containing the variants should be removed \(if they haven't been modified\).
2293 If it is t, they will be preserved unconditionally. A prefix argument, 2331 If it is t, they will be preserved unconditionally. A prefix argument,
2294 temporarily reverses the meaning of this variable." 2332 temporarily reverses the meaning of this variable."
2295 (interactive "P") 2333 (interactive "P")
2296 (ediff-barf-if-not-control-buffer) 2334 (ediff-barf-if-not-control-buffer)
2297 (let ((ctl-buf (current-buffer))) 2335 (let ((ctl-buf (current-buffer)))
2298 (if (y-or-n-p (format "Quit this Ediff session%s? " 2336 (if (y-or-n-p (format "Quit this Ediff session%s? "
2313 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also) 2351 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
2314 (ediff-clear-diff-vector 'ediff-difference-vector-Ancestor 'fine-diffs-also) 2352 (ediff-clear-diff-vector 'ediff-difference-vector-Ancestor 'fine-diffs-also)
2315 2353
2316 (ediff-delete-temp-files) 2354 (ediff-delete-temp-files)
2317 2355
2318 ;; Restore visibility range. This affects only ediff-*-regions/windows. 2356 ;; Restore visibility range. This affects only ediff-*-regions/windows.
2319 ;; Since for other job names ediff-visible-region sets 2357 ;; Since for other job names ediff-visible-region sets
2320 ;; ediff-visible-bounds to ediff-wide-bounds, the settings below are 2358 ;; ediff-visible-bounds to ediff-wide-bounds, the settings below are
2321 ;; ignored for such jobs. 2359 ;; ignored for such jobs.
2322 (if ediff-quit-widened 2360 (if ediff-quit-widened
2323 (setq ediff-visible-bounds ediff-wide-bounds) 2361 (setq ediff-visible-bounds ediff-wide-bounds)
2324 (setq ediff-visible-bounds ediff-narrow-bounds)) 2362 (setq ediff-visible-bounds ediff-narrow-bounds))
2325 2363
2326 ;; Apply selective display to narrow or widen 2364 ;; Apply selective display to narrow or widen
2327 (ediff-visible-region) 2365 (ediff-visible-region)
2328 (mapcar (function (lambda (overl) 2366 (mapcar (lambda (overl)
2329 (if (ediff-overlayp overl) 2367 (if (ediff-overlayp overl)
2330 (ediff-delete-overlay overl)))) 2368 (ediff-delete-overlay overl)))
2331 ediff-wide-bounds) 2369 ediff-wide-bounds)
2332 (mapcar (function (lambda (overl) 2370 (mapcar (lambda (overl)
2333 (if (ediff-overlayp overl) 2371 (if (ediff-overlayp overl)
2334 (ediff-delete-overlay overl)))) 2372 (ediff-delete-overlay overl)))
2335 ediff-narrow-bounds) 2373 ediff-narrow-bounds)
2336 2374
2337 ;; restore buffer mode line id's in buffer-A/B/C 2375 ;; restore buffer mode line id's in buffer-A/B/C
2338 (let ((control-buffer ediff-control-buffer) 2376 (let ((control-buffer ediff-control-buffer)
2339 (meta-buffer ediff-meta-buffer) 2377 (meta-buffer ediff-meta-buffer)
2378 (after-quit-hook-internal ediff-after-quit-hook-internal)
2340 (session-number ediff-meta-session-number) 2379 (session-number ediff-meta-session-number)
2341 ;; suitable working frame 2380 ;; suitable working frame
2342 (warp-frame (if (and (ediff-window-display-p) (eq ediff-grab-mouse t)) 2381 (warp-frame (if (and (ediff-window-display-p) (eq ediff-grab-mouse t))
2343 (cond ((window-live-p ediff-window-A) 2382 (cond ((window-live-p ediff-window-A)
2344 (window-frame ediff-window-A)) 2383 (window-frame ediff-window-A))
2392 (condition-case nil 2431 (condition-case nil
2393 (if (ediff-merge-job) 2432 (if (ediff-merge-job)
2394 (run-hooks 'ediff-quit-merge-hook)) 2433 (run-hooks 'ediff-quit-merge-hook))
2395 (quit)) 2434 (quit))
2396 2435
2397 ;; good place to kill buffers A/B/C
2398 (run-hooks 'ediff-cleanup-hook) 2436 (run-hooks 'ediff-cleanup-hook)
2437
2438 ;; now kill buffers A/B/C, if requested
2399 (let ((ediff-keep-variants ediff-keep-variants)) 2439 (let ((ediff-keep-variants ediff-keep-variants))
2400 (if reverse-default-keep-variants 2440 (if reverse-default-keep-variants
2401 (setq ediff-keep-variants (not ediff-keep-variants))) 2441 (setq ediff-keep-variants (not ediff-keep-variants)))
2402 (or ediff-keep-variants (ediff-janitor 'ask))) 2442 (or ediff-keep-variants (ediff-janitor 'ask)))
2403 2443
2444 ;; one hook here is ediff-cleanup-mess, which kills the control buffer and
2445 ;; other auxiliary buffers. we made it into a hook to let the users do their
2446 ;; own cleanup, if needed.
2404 (run-hooks 'ediff-quit-hook) 2447 (run-hooks 'ediff-quit-hook)
2405 (ediff-update-meta-buffer meta-buffer nil session-number) 2448 (ediff-update-meta-buffer meta-buffer nil session-number)
2406 2449
2407 ;; warp mouse into a working window 2450 ;; warp mouse into a working window
2408 (setq warp-frame ; if mouse is over a reasonable frame, use it 2451 (setq warp-frame ; if mouse is over a reasonable frame, use it
2409 (cond ((ediff-good-frame-under-mouse)) 2452 (cond ((ediff-good-frame-under-mouse))
2410 (t warp-frame))) 2453 (t warp-frame)))
2411 (if (frame-live-p warp-frame) 2454 (if (and (ediff-window-display-p) (frame-live-p warp-frame) ediff-grab-mouse)
2412 (set-mouse-position (if ediff-emacs-p 2455 (set-mouse-position (if ediff-emacs-p
2413 warp-frame 2456 warp-frame
2414 (frame-selected-window warp-frame)) 2457 (frame-selected-window warp-frame))
2415 2 1)) 2458 2 1))
2416 2459
2417 (if (ediff-buffer-live-p meta-buffer) 2460 (run-hooks 'after-quit-hook-internal)
2418 (ediff-show-meta-buffer meta-buffer session-number))
2419 )) 2461 ))
2420 2462
2421 ;; Returns frame under mouse, if this frame is not a minibuffer 2463 ;; Returns frame under mouse, if this frame is not a minibuffer
2422 ;; frame. Otherwise: nil 2464 ;; frame. Otherwise: nil
2423 (defun ediff-good-frame-under-mouse () 2465 (defun ediff-good-frame-under-mouse ()
2424 (let ((frame-or-win (car (mouse-position))) 2466 (let ((frame-or-win (car (mouse-position)))
2425 (buf-name "") 2467 (buf-name "")
2426 frame obj-ok) 2468 frame obj-ok)
2427 (setq obj-ok 2469 (setq obj-ok
2447 2489
2448 2490
2449 ;; Kill control buffer, other auxiliary Ediff buffers. 2491 ;; Kill control buffer, other auxiliary Ediff buffers.
2450 ;; Leave one of the frames split between buffers A/B/C 2492 ;; Leave one of the frames split between buffers A/B/C
2451 (defun ediff-cleanup-mess () 2493 (defun ediff-cleanup-mess ()
2452 (let ((buff-A ediff-buffer-A) 2494 (let* ((buff-A ediff-buffer-A)
2453 (buff-B ediff-buffer-B) 2495 (buff-B ediff-buffer-B)
2454 (buff-C ediff-buffer-C) 2496 (buff-C ediff-buffer-C)
2455 (ctl-buf ediff-control-buffer) 2497 (ctl-buf ediff-control-buffer)
2456 (ctl-frame ediff-control-frame) 2498 (ctl-frame ediff-control-frame)
2457 (three-way-job ediff-3way-job)) 2499 (three-way-job ediff-3way-job)
2458 2500 (main-frame (cond ((window-live-p ediff-window-A)
2501 (window-frame ediff-window-A))
2502 ((window-live-p ediff-window-B)
2503 (window-frame ediff-window-B)))))
2504
2459 (ediff-kill-buffer-carefully ediff-diff-buffer) 2505 (ediff-kill-buffer-carefully ediff-diff-buffer)
2460 (ediff-kill-buffer-carefully ediff-custom-diff-buffer) 2506 (ediff-kill-buffer-carefully ediff-custom-diff-buffer)
2461 (ediff-kill-buffer-carefully ediff-fine-diff-buffer) 2507 (ediff-kill-buffer-carefully ediff-fine-diff-buffer)
2462 (ediff-kill-buffer-carefully ediff-tmp-buffer) 2508 (ediff-kill-buffer-carefully ediff-tmp-buffer)
2463 (ediff-kill-buffer-carefully ediff-error-buffer) 2509 (ediff-kill-buffer-carefully ediff-error-buffer)
2472 (if (not (ediff-multiframe-setup-p)) 2518 (if (not (ediff-multiframe-setup-p))
2473 (ediff-kill-bottom-toolbar)) 2519 (ediff-kill-bottom-toolbar))
2474 2520
2475 (ediff-kill-buffer-carefully ctl-buf) 2521 (ediff-kill-buffer-carefully ctl-buf)
2476 2522
2477 (delete-other-windows) 2523 (if (frame-live-p main-frame)
2524 (progn
2525 (select-frame main-frame)
2526 (delete-other-windows)))
2478 2527
2479 ;; display only if not visible 2528 ;; display only if not visible
2480 (condition-case nil 2529 (condition-case nil
2481 (or (ediff-get-visible-buffer-window buff-B) 2530 (or (ediff-get-visible-buffer-window buff-B)
2482 (switch-to-buffer buff-B)) 2531 (switch-to-buffer buff-B))
2535 (defun ediff-maybe-save-and-delete-merge (&optional save-and-continue) 2584 (defun ediff-maybe-save-and-delete-merge (&optional save-and-continue)
2536 "Default hook to run on quitting a merge job. 2585 "Default hook to run on quitting a merge job.
2537 This can also be used to save merge buffer in the middle of an Ediff session. 2586 This can also be used to save merge buffer in the middle of an Ediff session.
2538 2587
2539 If the optional SAVE-AND-CONTINUE argument is non-nil, save merge buffer and 2588 If the optional SAVE-AND-CONTINUE argument is non-nil, save merge buffer and
2540 continue. Otherwise: 2589 continue. Otherwise:
2541 If `ediff-autostore-merges' is nil, this does nothing. 2590 If `ediff-autostore-merges' is nil, this does nothing.
2542 If it is t, it saves the merge buffer in the file `ediff-merge-store-file' 2591 If it is t, it saves the merge buffer in the file `ediff-merge-store-file'
2543 or asks the user, if the latter is nil. It then asks the user whether to 2592 or asks the user, if the latter is nil. It then asks the user whether to
2544 delete the merge buffer. 2593 delete the merge buffer.
2545 If `ediff-autostore-merges' is neither nil nor t, the merge buffer is saved 2594 If `ediff-autostore-merges' is neither nil nor t, the merge buffer is saved
2546 only if this merge job is part of a group, i.e., was invoked from within 2595 only if this merge job is part of a group, i.e., was invoked from within
2547 `ediff-merge-directories', `ediff-merge-directory-revisions', and such." 2596 `ediff-merge-directories', `ediff-merge-directory-revisions', and such."
2548 (let ((merge-store-file ediff-merge-store-file) 2597 (let ((merge-store-file ediff-merge-store-file)
2560 (ediff-write-merge-buffer-and-maybe-kill 2609 (ediff-write-merge-buffer-and-maybe-kill
2561 ediff-buffer-C merge-store-file nil save-and-continue)) 2610 ediff-buffer-C merge-store-file nil save-and-continue))
2562 ((and (ediff-buffer-live-p ediff-meta-buffer) 2611 ((and (ediff-buffer-live-p ediff-meta-buffer)
2563 (ediff-with-current-buffer ediff-meta-buffer 2612 (ediff-with-current-buffer ediff-meta-buffer
2564 (ediff-merge-metajob))) 2613 (ediff-merge-metajob)))
2565 ;; This case shouldn't occur, as the parent metajob must pass on 2614 ;; The parent metajob passed nil as the autostore file.
2566 ;; a file name, ediff-merge-store-file, where to save the result 2615 nil)))
2567 ;; of the merge.
2568 ;; Ask where to save anyway--will decide what to do here later.
2569 (setq merge-store-file
2570 (read-file-name "Save the merge buffer in file: "))
2571 (ediff-write-merge-buffer-and-maybe-kill
2572 ediff-buffer-C merge-store-file nil save-and-continue))))
2573 )) 2616 ))
2574 2617
2575 ;; write merge buffer. If the optional argument save-and-continue is non-nil, 2618 ;; write merge buffer. If the optional argument save-and-continue is non-nil,
2576 ;; then don't kill the merge buffer 2619 ;; then don't kill the merge buffer
2577 (defun ediff-write-merge-buffer-and-maybe-kill (buf file 2620 (defun ediff-write-merge-buffer-and-maybe-kill (buf file
2578 &optional 2621 &optional
2579 show-file save-and-continue) 2622 show-file save-and-continue)
2580 (ediff-with-current-buffer buf 2623 (ediff-with-current-buffer buf
2584 (write-region (point-min) (point-max) file) 2627 (write-region (point-min) (point-max) file)
2585 (if show-file 2628 (if show-file
2586 (progn 2629 (progn
2587 (message "Merge buffer saved in: %s" file) 2630 (message "Merge buffer saved in: %s" file)
2588 (set-buffer-modified-p nil) 2631 (set-buffer-modified-p nil)
2589 (sit-for 2))) 2632 (sit-for 3)))
2590 (if (and 2633 (if (and
2591 (not save-and-continue) 2634 (not save-and-continue)
2592 (y-or-n-p "Merge buffer saved in file. Now kill the buffer? ")) 2635 (y-or-n-p "Merge buffer saved. Now kill the buffer? "))
2593 (ediff-kill-buffer-carefully buf)))))) 2636 (ediff-kill-buffer-carefully buf))))))
2594 2637
2595 ;; The default way of suspending Ediff. 2638 ;; The default way of suspending Ediff.
2596 ;; Buries Ediff buffers, kills all windows. 2639 ;; Buries Ediff buffers, kills all windows.
2597 (defun ediff-default-suspend-function () 2640 (defun ediff-default-suspend-function ()
2726 (if ediff-ignore-similar-regions 2769 (if ediff-ignore-similar-regions
2727 "Ignoring" "Showing"))) 2770 "Ignoring" "Showing")))
2728 (if (and ediff-merge-job ediff-show-clashes-only) 2771 (if (and ediff-merge-job ediff-show-clashes-only)
2729 (princ 2772 (princ
2730 "\nFocusing on regions where both buffers differ from the ancestor")) 2773 "\nFocusing on regions where both buffers differ from the ancestor"))
2774 (if (and ediff-skip-merge-regions-that-differ-from-default ediff-merge-job)
2775 (princ
2776 "\nSkipping merge regions that differ from default setting"))
2731 2777
2732 (cond ((eq ediff-skip-diff-region-function 'ediff-show-all-diffs) 2778 (cond ((eq ediff-skip-diff-region-function 'ediff-show-all-diffs)
2733 (princ "\nSelective browsing by regexp is off\n")) 2779 (princ "\nSelective browsing by regexp is off\n"))
2734 ((eq ediff-skip-diff-region-function 2780 ((eq ediff-skip-diff-region-function
2735 ediff-hide-regexp-matches-function) 2781 ediff-hide-regexp-matches-function)
2849 2895
2850 (ediff-with-current-buffer control-buf (ediff-refresh-mode-lines)) 2896 (ediff-with-current-buffer control-buf (ediff-refresh-mode-lines))
2851 ))) 2897 )))
2852 2898
2853 2899
2900 ;; This is adapted from a similar function in `emerge.el'.
2901 ;; PROMPT should not have a trailing ': ', so that it can be modified
2902 ;; according to context.
2903 ;; If DEFAULT-FILE is set, it should be used as the default value.
2904 ;; If DEFAULT-DIR is non-nil, use it as the default directory.
2905 ;; Otherwise, use the value of Emacs' variable `default-directory.'
2854 (defun ediff-read-file-name (prompt default-dir default-file) 2906 (defun ediff-read-file-name (prompt default-dir default-file)
2855 ; This is a modified version of a similar function in `emerge.el'.
2856 ; PROMPT should not have trailing ': ', so that it can be modified
2857 ; according to context.
2858 ; If default-file is set, it should be used as the default value.
2859 ; If default-dir is non-nil, use it as the default directory.
2860 ; Otherwise, use the value of Emacs' variable `default-directory.'
2861
2862 ;; hack default-dir if it is not set 2907 ;; hack default-dir if it is not set
2863 (setq default-dir 2908 (setq default-dir
2864 (file-name-as-directory 2909 (file-name-as-directory
2865 (ediff-abbreviate-file-name 2910 (ediff-abbreviate-file-name
2866 (expand-file-name (or default-dir 2911 (expand-file-name (or default-dir
2897 (setq f (expand-file-name 2942 (setq f (expand-file-name
2898 (file-name-nondirectory default-file) f))) 2943 (file-name-nondirectory default-file) f)))
2899 f)) 2944 f))
2900 2945
2901 ;; If PREFIX is given, then it is used as a prefix for the temp file 2946 ;; If PREFIX is given, then it is used as a prefix for the temp file
2902 ;; name. Otherwise, `ediff' is used. If FILE is given, use this 2947 ;; name. Otherwise, `ediff' is used. If FILE is given, use this
2903 ;; file and don't create a new one. 2948 ;; file and don't create a new one.
2904 ;; On MS-DOS, make sure the prefix isn't too long, or else 2949 ;; In MS-DOS, make sure the prefix isn't too long, or else
2905 ;; `make-temp-name' isn't guaranteed to return a unique filename. 2950 ;; `make-temp-name' isn't guaranteed to return a unique filename.
2906 ;; Also, save buffer from START to END in the file. 2951 ;; Also, save buffer from START to END in the file.
2907 ;; START defaults to (point-min), END to (point-max) 2952 ;; START defaults to (point-min), END to (point-max)
2908 (defun ediff-make-temp-file (buff &optional prefix given-file start end) 2953 (defun ediff-make-temp-file (buff &optional prefix given-file start end)
2909 (let* ((p (ediff-convert-standard-filename (or prefix "ediff"))) 2954 (let* ((p (ediff-convert-standard-filename (or prefix "ediff")))
2910 (short-p p) 2955 (short-p p)
2956 (coding-system-for-write 'no-conversion)
2911 f short-f) 2957 f short-f)
2912 (if (and (fboundp 'msdos-long-file-names) 2958 (if (and (fboundp 'msdos-long-file-names)
2913 (not (msdos-long-file-names)) 2959 (not (msdos-long-file-names))
2914 (> (length p) 2)) 2960 (> (length p) 2))
2915 (setq short-p (substring p 0 2))) 2961 (setq short-p (substring p 0 2)))
2916 2962
2917 (setq f (concat ediff-temp-file-prefix p) 2963 (setq f (concat ediff-temp-file-prefix p)
2918 short-f (concat ediff-temp-file-prefix short-p) 2964 short-f (concat ediff-temp-file-prefix short-p)
2919 f (cond (given-file) 2965 f (cond (given-file)
2920 ((find-file-name-handler f 'find-file-noselect) 2966 ((find-file-name-handler f 'find-file-noselect)
2921 ;; to thwart file handlers in write-region, e.g., if file 2967 ;; to thwart file handlers in write-region, e.g., if file
2922 ;; name ends with .Z or .gz 2968 ;; name ends with .Z or .gz
2923 ;; This is needed so that patches produced by ediff will 2969 ;; This is needed so that patches produced by ediff will
2924 ;; have more meaningful names 2970 ;; have more meaningful names
2925 (make-temp-file short-f)) 2971 (ediff-make-empty-tmp-file short-f))
2926 ;; Prefix is most often the same as the file name for the 2972 (prefix
2927 ;; variant. Here we are trying to use the original file name 2973 ;; Prefix is most often the same as the file name for the
2928 ;; but in the temp directory. 2974 ;; variant. Here we are trying to use the original file
2929 ((and prefix (not (file-exists-p f))) f) 2975 ;; name but in the temp directory.
2930 ;; If a file with the orig name exists, add some random stuff 2976 (ediff-make-empty-tmp-file f 'keep-name))
2931 ;; to it. 2977 (t
2932 (t (make-temp-file short-f)))) 2978 ;; If don't care about name, add some random stuff
2979 ;; to proposed file name.
2980 (ediff-make-empty-tmp-file short-f))))
2933 2981
2934 ;; create the file 2982 ;; create the file
2935 (ediff-with-current-buffer buff 2983 (ediff-with-current-buffer buff
2936 (write-region (if start start (point-min)) 2984 (write-region (if start start (point-min))
2937 (if end end (point-max)) 2985 (if end end (point-max))
2938 f 2986 f
2939 nil ; don't append---erase 2987 nil ; don't append---erase
2940 'no-message) 2988 'no-message)
2941 (set-file-modes f ediff-temp-file-mode) 2989 (set-file-modes f ediff-temp-file-mode)
2942 (expand-file-name f)))) 2990 (expand-file-name f))))
2991
2992 ;; Create a temporary file.
2993 ;; The returned file name (created by appending some random characters at the
2994 ;; end of PROPOSED-NAME is guaranteed to point to a newly created empty file.
2995 ;; This is a replacement for make-temp-name, which eliminates a security hole.
2996 ;; If KEEP-PROPOSED-NAME isn't nil, try to keep PROPOSED-NAME, unless such file
2997 ;; already exists.
2998 ;; It is a modified version of make-temp-file in emacs 20.5
2999 (defun ediff-make-empty-tmp-file (proposed-name &optional keep-proposed-name)
3000 (let ((file proposed-name))
3001 (while (condition-case ()
3002 (progn
3003 (if (or (file-exists-p file) (not keep-proposed-name))
3004 (setq file (make-temp-name proposed-name)))
3005 (write-region "" nil file nil 'silent nil 'excl)
3006 nil)
3007 (file-already-exists t))
3008 ;; the file was somehow created by someone else between
3009 ;; `make-temp-name' and `write-region', let's try again.
3010 nil)
3011 file))
3012
2943 3013
2944 ;; Quote metacharacters (using \) when executing diff in Unix, but not in 3014 ;; Quote metacharacters (using \) when executing diff in Unix, but not in
2945 ;; EMX OS/2 3015 ;; EMX OS/2
2946 ;;(defun ediff-protect-metachars (str) 3016 ;;(defun ediff-protect-metachars (str)
2947 ;; (or (memq system-type '(emx vax-vms axp-vms)) 3017 ;; (or (memq system-type '(emx vax-vms axp-vms))
2963 ;; First check if the file has been modified since the buffer visited it. 3033 ;; First check if the file has been modified since the buffer visited it.
2964 (if (verify-visited-file-modtime (current-buffer)) 3034 (if (verify-visited-file-modtime (current-buffer))
2965 (if (buffer-modified-p) 3035 (if (buffer-modified-p)
2966 ;; If buffer is not obsolete and is modified, offer to save 3036 ;; If buffer is not obsolete and is modified, offer to save
2967 (if (yes-or-no-p 3037 (if (yes-or-no-p
2968 (format "Buffer out of sync with visited file. Save file %s? " 3038 (format "Buffer out of sync with visited file. Save file %s? "
2969 buffer-file-name)) 3039 buffer-file-name))
2970 (condition-case nil 3040 (condition-case nil
2971 (save-buffer) 3041 (save-buffer)
2972 (error 3042 (error
2973 (beep) 3043 (beep)
2975 (error "Buffer is out of sync for file %s" buffer-file-name)) 3045 (error "Buffer is out of sync for file %s" buffer-file-name))
2976 ;; If buffer is not obsolete and is not modified, do nothing 3046 ;; If buffer is not obsolete and is not modified, do nothing
2977 nil) 3047 nil)
2978 ;; If buffer is obsolete, offer to revert 3048 ;; If buffer is obsolete, offer to revert
2979 (if (yes-or-no-p 3049 (if (yes-or-no-p
2980 (format "Buffer is out of sync with visited file. REVERT file %s? " 3050 (format "Buffer is out of sync with visited file. REVERT file %s? "
2981 buffer-file-name)) 3051 buffer-file-name))
2982 (progn 3052 (progn
2983 (if file-magic 3053 (if file-magic
2984 (erase-buffer)) 3054 (erase-buffer))
2985 (revert-buffer t t)) 3055 (revert-buffer t t))
3189 ;; (ediff-activate-mark) 3259 ;; (ediff-activate-mark)
3190 ) 3260 )
3191 ;; (sit-for 0) 3261 ;; (sit-for 0)
3192 3262
3193 ;; At this point, possibilities contains either the window char A/B/C 3263 ;; At this point, possibilities contains either the window char A/B/C
3194 ;; that was not selected, or it is nil. We delete the window that is not 3264 ;; that was not selected, or it is nil. We delete the window that is not
3195 ;; selected. 3265 ;; selected.
3196 (if possibilities 3266 (if possibilities
3197 (ediff-with-current-buffer ctl-buf 3267 (ediff-with-current-buffer ctl-buf
3198 (let* ((wind-to-delete (eval 3268 (let* ((wind-to-delete (eval
3199 (ediff-get-symbol-from-alist 3269 (ediff-get-symbol-from-alist
3202 (frame (window-frame wind-to-delete))) 3272 (frame (window-frame wind-to-delete)))
3203 (delete-window wind-to-delete) 3273 (delete-window wind-to-delete)
3204 (select-frame frame) 3274 (select-frame frame)
3205 (balance-windows)))) 3275 (balance-windows))))
3206 (or (y-or-n-p 3276 (or (y-or-n-p
3207 "Please check regions selected for comparison. Continue? ") 3277 "Please check regions selected for comparison. Continue? ")
3208 (setq quit-now t)) 3278 (setq quit-now t))
3209 3279
3210 (ediff-with-current-buffer bufA 3280 (ediff-with-current-buffer bufA
3211 (widen)) 3281 (widen))
3212 (ediff-with-current-buffer bufB 3282 (ediff-with-current-buffer bufB
3213 (widen)) 3283 (widen))
3214 (if quit-now 3284 (if quit-now
3215 (ediff-with-current-buffer ctl-buf 3285 (ediff-with-current-buffer ctl-buf
3216 (ediff-recenter) 3286 (ediff-recenter)
3217 (sit-for 0) 3287 (sit-for 0)
3218 (error "All right. Make up your mind and come back..."))) 3288 (error "All right. Make up your mind and come back...")))
3219 3289
3220 (ediff-regions-internal 3290 (ediff-regions-internal
3221 bufA begA endA bufB begB endB 3291 bufA begA endA bufB begB endB
3222 nil ; setup-hook 3292 nil ; setup-hook
3223 'ediff-regions-linewise ; job name 3293 'ediff-regions-linewise ; job name
3289 ;; BUF-TYPE should be a symbol -- `A', `B', or `C'. 3359 ;; BUF-TYPE should be a symbol -- `A', `B', or `C'.
3290 ;; POS is either `beg' or `end'--it specifies whether you want the position at 3360 ;; POS is either `beg' or `end'--it specifies whether you want the position at
3291 ;; the beginning of a difference or at the end. 3361 ;; the beginning of a difference or at the end.
3292 ;; 3362 ;;
3293 ;; The optional argument N says which difference (default: 3363 ;; The optional argument N says which difference (default:
3294 ;; `ediff-current-difference'). N is the internal difference number (1- what 3364 ;; `ediff-current-difference'). N is the internal difference number (1- what
3295 ;; the user sees). The optional argument CONTROL-BUF says 3365 ;; the user sees). The optional argument CONTROL-BUF says
3296 ;; which control buffer is in effect in case it is not the current 3366 ;; which control buffer is in effect in case it is not the current
3297 ;; buffer. 3367 ;; buffer.
3298 (defun ediff-get-diff-posn (buf-type pos &optional n control-buf) 3368 (defun ediff-get-diff-posn (buf-type pos &optional n control-buf)
3299 (let (diff-overlay) 3369 (let (diff-overlay)
3331 ;; null out difference overlays so they won't slow down future 3401 ;; null out difference overlays so they won't slow down future
3332 ;; editing operations 3402 ;; editing operations
3333 ;; VEC is either a difference vector or a fine-diff vector 3403 ;; VEC is either a difference vector or a fine-diff vector
3334 (defun ediff-clear-diff-vector (vec-var &optional fine-diffs-also) 3404 (defun ediff-clear-diff-vector (vec-var &optional fine-diffs-also)
3335 (if (vectorp (symbol-value vec-var)) 3405 (if (vectorp (symbol-value vec-var))
3336 (mapcar (function 3406 (mapcar (lambda (elt)
3337 (lambda (elt) 3407 (ediff-delete-overlay
3338 (ediff-delete-overlay 3408 (ediff-get-diff-overlay-from-diff-record elt))
3339 (ediff-get-diff-overlay-from-diff-record elt)) 3409 (if fine-diffs-also
3340 (if fine-diffs-also 3410 (ediff-clear-fine-diff-vector elt))
3341 (ediff-clear-fine-diff-vector elt)) 3411 )
3342 ))
3343 (symbol-value vec-var))) 3412 (symbol-value vec-var)))
3344 ;; allow them to be garbage collected 3413 ;; allow them to be garbage collected
3345 (set vec-var nil)) 3414 (set vec-var nil))
3346 3415
3347 3416
3348 3417
3349 ;;; Misc 3418 ;;; Misc
3350 3419
3351 ;; In Emacs, this just makes overlay. In the future, when Emacs will start 3420 ;; In Emacs, this just makes overlay. In the future, when Emacs will start
3352 ;; supporting sticky overlays, this function will make a sticky overlay. 3421 ;; supporting sticky overlays, this function will make a sticky overlay.
3353 ;; BEG and END are expressions telling where overlay starts. 3422 ;; BEG and END are expressions telling where overlay starts.
3354 ;; If they are numbers or buffers, then all is well. Otherwise, they must 3423 ;; If they are numbers or buffers, then all is well. Otherwise, they must
3355 ;; be expressions to be evaluated in buffer BUF in order to get the overlay 3424 ;; be expressions to be evaluated in buffer BUF in order to get the overlay
3356 ;; bounds. 3425 ;; bounds.
3357 ;; If BUFF is not a live buffer, then return nil; otherwise, return the 3426 ;; If BUFF is not a live buffer, then return nil; otherwise, return the
3358 ;; newly created overlay. 3427 ;; newly created overlay.
3359 (defun ediff-make-bullet-proof-overlay (beg end buff) 3428 (defun ediff-make-bullet-proof-overlay (beg end buff)
3385 3454
3386 ;; Like other-buffer, but prefers visible buffers and ignores temporary or 3455 ;; Like other-buffer, but prefers visible buffers and ignores temporary or
3387 ;; other insignificant buffers (those beginning with "^[ *]"). 3456 ;; other insignificant buffers (those beginning with "^[ *]").
3388 ;; Gets one arg--buffer name or a list of buffer names (it won't return 3457 ;; Gets one arg--buffer name or a list of buffer names (it won't return
3389 ;; these buffers). 3458 ;; these buffers).
3390 (defun ediff-other-buffer (buff-lst) 3459 ;; EXCL-BUFF-LIST is an exclusion list.
3391 (or (listp buff-lst) (setq buff-lst (list buff-lst))) 3460 (defun ediff-other-buffer (excl-buff-lst)
3392 (let* ((frame-buffers (buffer-list)) 3461 (or (listp excl-buff-lst) (setq excl-buff-lst (list excl-buff-lst)))
3393 (buff-name-list 3462 (let* ((all-buffers (buffer-list))
3463 (prefered-buffer (car all-buffers))
3464 visible-dired-buffers
3465 (excl-buff-name-list
3394 (mapcar 3466 (mapcar
3395 (function (lambda (b) 3467 (lambda (b) (cond ((stringp b) b)
3396 (cond ((stringp b) b) 3468 ((bufferp b) (buffer-name b))))
3397 ((bufferp b) (buffer-name b))))) 3469 excl-buff-lst))
3398 buff-lst)) 3470 ;; if at least one buffer on the exclusion list is dired, then force
3471 ;; all others to be dired. This is because this means that the user
3472 ;; has already chosen a dired buffer before
3473 (use-dired-major-mode
3474 (cond ((null (ediff-buffer-live-p (car excl-buff-lst))) 'unknown)
3475 ((eq (ediff-with-current-buffer (car excl-buff-lst) major-mode)
3476 'dired-mode)
3477 'yes)
3478 (t 'no)))
3479 ;; significant-buffers must be visible and not belong
3480 ;; to the exclusion list `buff-list'
3481 ;; We also exclude temporary buffers, but keep mail and gnus buffers
3482 ;; Furthermore, we exclude dired buffers, unless they are the only
3483 ;; ones visible (and there are at least two of them).
3484 ;; Also, any visible window not on the exclusion list that is first in
3485 ;; the buffer list is chosen regardless. (This is because the user
3486 ;; clicked on it or did something to distinguish it).
3399 (significant-buffers 3487 (significant-buffers
3400 (mapcar 3488 (mapcar
3401 (function (lambda (x) 3489 (lambda (x)
3402 (cond ((member (buffer-name x) buff-name-list) nil) 3490 (cond ((member (buffer-name x) excl-buff-name-list) nil)
3403 ((not (ediff-get-visible-buffer-window x)) nil) 3491 ((not (ediff-get-visible-buffer-window x)) nil)
3492 ((eq x prefered-buffer) x)
3493 ;; if prev selected buffer is dired, look only at
3494 ;; dired.
3495 ((eq use-dired-major-mode 'yes)
3496 (if (eq (ediff-with-current-buffer x major-mode)
3497 'dired-mode)
3498 x nil))
3499 ((eq (ediff-with-current-buffer x major-mode)
3500 'dired-mode)
3501 (if (null use-dired-major-mode)
3502 ;; don't know if we must enforce dired.
3503 ;; Remember this buffer in case
3504 ;; dired buffs are the only ones visible.
3505 (setq visible-dired-buffers
3506 (cons x visible-dired-buffers)))
3507 ;; skip, if dired is not forced
3508 nil)
3509 ((memq (ediff-with-current-buffer x major-mode)
3510 '(rmail-mode
3511 vm-mode
3512 gnus-article-mode
3513 mh-show-mode))
3514 x)
3404 ((string-match "^[ *]" (buffer-name x)) nil) 3515 ((string-match "^[ *]" (buffer-name x)) nil)
3405 ((memq (ediff-with-current-buffer x major-mode) 3516 ((string= "*scratch*" (buffer-name x)) nil)
3406 '(dired-mode)) 3517 (t x)))
3407 nil) 3518 all-buffers))
3408 (t x)))) 3519 (clean-significant-buffers (delq nil significant-buffers))
3409 frame-buffers))
3410 (buffers (delq nil significant-buffers))
3411 less-significant-buffers) 3520 less-significant-buffers)
3521
3522 (if (and (null clean-significant-buffers)
3523 (> (length visible-dired-buffers) 0))
3524 (setq clean-significant-buffers visible-dired-buffers))
3412 3525
3413 (cond (buffers (car buffers)) 3526 (cond (clean-significant-buffers (car clean-significant-buffers))
3414 ;; try also buffers that are not displayed in windows 3527 ;; try also buffers that are not displayed in windows
3415 ((setq less-significant-buffers 3528 ((setq less-significant-buffers
3416 (delq nil 3529 (delq nil
3417 (mapcar 3530 (mapcar
3418 (function 3531 (lambda (x)
3419 (lambda (x) 3532 (cond ((member (buffer-name x) excl-buff-name-list)
3420 (cond ((member (buffer-name x) buff-name-list) nil) 3533 nil)
3421 ((string-match "^[ *]" (buffer-name x)) nil) 3534 ((eq use-dired-major-mode 'yes)
3422 ((memq 3535 (if (eq (ediff-with-current-buffer
3423 (ediff-with-current-buffer x major-mode) 3536 x major-mode)
3424 '(dired-mode)) 3537 'dired-mode)
3425 nil) 3538 x nil))
3426 (t x)))) 3539 ((eq (ediff-with-current-buffer x major-mode)
3427 frame-buffers))) 3540 'dired-mode)
3541 nil)
3542 ((string-match "^[ *]" (buffer-name x)) nil)
3543 ((string= "*scratch*" (buffer-name x)) nil)
3544 (t x)))
3545 all-buffers)))
3428 (car less-significant-buffers)) 3546 (car less-significant-buffers))
3429 (t (other-buffer (current-buffer)))) 3547 (t "*scratch*"))
3430 )) 3548 ))
3431 3549
3432 3550
3433 ;; Construct a unique buffer name. 3551 ;; Construct a unique buffer name.
3434 ;; The first one tried is prefixsuffix, then prefix<2>suffix, 3552 ;; The first one tried is prefixsuffix, then prefix<2>suffix,
3467 ediff-word-mode 3585 ediff-word-mode
3468 buffer-name 3586 buffer-name
3469 ediff-device-type 3587 ediff-device-type
3470 )) 3588 ))
3471 (setq salutation " 3589 (setq salutation "
3472 Congratulations! You may have unearthed a bug in Ediff! 3590 Congratulations! You may have unearthed a bug in Ediff!
3473 3591
3474 Please make a concise and accurate summary of what happened 3592 Please make a concise and accurate summary of what happened
3475 and mail it to the address above. 3593 and mail it to the address above.
3476 ----------------------------------------------------------- 3594 -----------------------------------------------------------
3477 ") 3595 ")
3484 (delete-other-windows) 3602 (delete-other-windows)
3485 (insert " 3603 (insert "
3486 Please read this first: 3604 Please read this first:
3487 ---------------------- 3605 ----------------------
3488 3606
3489 Some ``bugs'' may actually be no bugs at all. For instance, if you are 3607 Some ``bugs'' may actually be no bugs at all. For instance, if you are
3490 reporting that certain difference regions are not matched as you think they 3608 reporting that certain difference regions are not matched as you think they
3491 should, this is most likely due to the way Unix diff program decides what 3609 should, this is most likely due to the way Unix diff program decides what
3492 constitutes a difference region. Ediff is an Emacs interface to diff, and 3610 constitutes a difference region. Ediff is an Emacs interface to diff, and
3493 it has nothing to do with those decisions---it only takes the output from 3611 it has nothing to do with those decisions---it only takes the output from
3494 diff and presents it in a way that is better suited for human browsing and 3612 diff and presents it in a way that is better suited for human browsing and
3495 manipulation. 3613 manipulation.
3496 3614
3497 If Emacs happens to dump core, this is NOT an Ediff problem---it is 3615 If Emacs happens to dump core, this is NOT an Ediff problem---it is
3498 an Emacs bug. Report this to Emacs maintainers. 3616 an Emacs bug. Report this to Emacs maintainers.
3499 3617
3500 Another popular topic for reports is compilation messages. Because Ediff 3618 Another popular topic for reports is compilation messages. Because Ediff
3501 interfaces to several other packages and runs under Emacs and XEmacs, 3619 interfaces to several other packages and runs under Emacs and XEmacs,
3502 byte-compilation may produce output like this: 3620 byte-compilation may produce output like this:
3503 3621
3571 3689
3572 ;; The next two are modified versions from emerge.el. 3690 ;; The next two are modified versions from emerge.el.
3573 ;; VARS must be a list of symbols 3691 ;; VARS must be a list of symbols
3574 ;; ediff-save-variables returns an association list: ((var . val) ...) 3692 ;; ediff-save-variables returns an association list: ((var . val) ...)
3575 (defsubst ediff-save-variables (vars) 3693 (defsubst ediff-save-variables (vars)
3576 (mapcar (function (lambda (v) (cons v (symbol-value v)))) 3694 (mapcar (lambda (v) (cons v (symbol-value v)))
3577 vars)) 3695 vars))
3578 ;; VARS is a list of variable symbols. 3696 ;; VARS is a list of variable symbols.
3579 (defun ediff-restore-variables (vars assoc-list) 3697 (defun ediff-restore-variables (vars assoc-list)
3580 (while vars 3698 (while vars
3581 (set (car vars) (cdr (assoc (car vars) assoc-list))) 3699 (set (car vars) (cdr (assoc (car vars) assoc-list)))
3624 (if (ediff-buffer-live-p ediff-ancestor-buffer) 3742 (if (ediff-buffer-live-p ediff-ancestor-buffer)
3625 (ediff-with-current-buffer ediff-ancestor-buffer 3743 (ediff-with-current-buffer ediff-ancestor-buffer
3626 (ediff-restore-variables ediff-protected-variables values-Ancestor))) 3744 (ediff-restore-variables ediff-protected-variables values-Ancestor)))
3627 )) 3745 ))
3628 3746
3629 ;; save BUFFER in FILE. used in hooks. 3747 ;; save BUFFER in FILE. used in hooks.
3630 (defun ediff-save-buffer-in-file (buffer file) 3748 (defun ediff-save-buffer-in-file (buffer file)
3631 (ediff-with-current-buffer buffer 3749 (ediff-with-current-buffer buffer
3632 (write-file file))) 3750 (write-file file)))
3633 3751
3634 3752
3667 (add-hook post-hook 'ediff-calc-command-time nil t) 3785 (add-hook post-hook 'ediff-calc-command-time nil t)
3668 (message "Ediff profiling enabled")))) 3786 (message "Ediff profiling enabled"))))
3669 3787
3670 (defun ediff-print-diff-vector (diff-vector-var) 3788 (defun ediff-print-diff-vector (diff-vector-var)
3671 (princ (format "\n*** %S ***\n" diff-vector-var)) 3789 (princ (format "\n*** %S ***\n" diff-vector-var))
3672 (mapcar (function 3790 (mapcar (lambda (overl-vec)
3673 (lambda (overl-vec) 3791 (princ
3674 (princ 3792 (format
3675 (format 3793 "Diff %d: \tOverlay: %S
3676 "Diff %d: \tOverlay: %S
3677 \t\tFine diffs: %s 3794 \t\tFine diffs: %s
3678 \t\tNo-fine-diff-flag: %S 3795 \t\tNo-fine-diff-flag: %S
3679 \t\tState-of-diff:\t %S 3796 \t\tState-of-diff:\t %S
3680 \t\tState-of-merge:\t %S 3797 \t\tState-of-merge:\t %S
3681 " 3798 "
3682 (1+ (ediff-overlay-get (aref overl-vec 0) 'ediff-diff-num)) 3799 (1+ (ediff-overlay-get (aref overl-vec 0) 'ediff-diff-num))
3683 (aref overl-vec 0) 3800 (aref overl-vec 0)
3684 ;; fine-diff-vector 3801 ;; fine-diff-vector
3685 (if (= (length (aref overl-vec 1)) 0) 3802 (if (= (length (aref overl-vec 1)) 0)
3686 "none\n" 3803 "none\n"
3687 (mapconcat 'prin1-to-string 3804 (mapconcat 'prin1-to-string
3688 (aref overl-vec 1) "\n\t\t\t ")) 3805 (aref overl-vec 1) "\n\t\t\t "))
3689 (aref overl-vec 2) ; no fine diff flag 3806 (aref overl-vec 2) ; no fine diff flag
3690 (aref overl-vec 3) ; state-of-diff 3807 (aref overl-vec 3) ; state-of-diff
3691 (aref overl-vec 4) ; state-of-merge 3808 (aref overl-vec 4) ; state-of-merge
3692 )))) 3809 )))
3693 (eval diff-vector-var))) 3810 (eval diff-vector-var)))
3694 3811
3695 3812
3696 3813
3697 (defun ediff-debug-info () 3814 (defun ediff-debug-info ()
3758 (setq elt (car list) 3875 (setq elt (car list)
3759 res (cons elt res) 3876 res (cons elt res)
3760 list (cdr list))) 3877 list (cdr list)))
3761 (nreverse res)) 3878 (nreverse res))
3762 (car list))) 3879 (car list)))
3763 3880
3764 3881
3765 ;; don't report error if version control package wasn't found 3882 ;; don't report error if version control package wasn't found
3766 ;;(ediff-load-version-control 'silent) 3883 ;;(ediff-load-version-control 'silent)
3767 3884
3768 (run-hooks 'ediff-load-hook) 3885 (run-hooks 'ediff-load-hook)