summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Heuer <kwzh@gnu.org>1995-03-16 22:34:51 +0000
committerKarl Heuer <kwzh@gnu.org>1995-03-16 22:34:51 +0000
commit475f903199bbb603461e326c72fda636497b1e21 (patch)
treedd87bf10aa91a60b584cde31f4756d45137f162b
parent0f0b0a86ad91de36f76c6dd124cb9debcc26f8de (diff)
downloademacs-475f903199bbb603461e326c72fda636497b1e21.tar.gz
Initial revision
-rw-r--r--lisp/ediff-diff.el1154
-rw-r--r--lisp/ediff-init.el1189
-rw-r--r--lisp/ediff-merg.el259
-rw-r--r--lisp/ediff-util.el3398
-rw-r--r--lisp/ediff-wind.el1098
5 files changed, 7098 insertions, 0 deletions
diff --git a/lisp/ediff-diff.el b/lisp/ediff-diff.el
new file mode 100644
index 00000000000..0a9aa299b02
--- /dev/null
+++ b/lisp/ediff-diff.el
@@ -0,0 +1,1154 @@
+;;; ediff-diff.el --- diff-related utilities
+;;; Copyright (C) 1994 Free Software Foundation, Inc.
+
+;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+(require 'ediff-init)
+
+
+(defvar ediff-shell
+ (cond ((eq system-type 'emx) "cmd") ; OS/2
+ ((memq system-type '(vax-vms axp-vms)) "*dcl*") ; VMS
+ (t "sh")) ; UNIX
+ "*The shell used to run diff and patch. If user's .profile or
+.cshrc files are set up correctly, any shell will do. However, some people
+set $prompt or other things incorrectly, which leads to undesirable output
+messages. These may cause Ediff to fail. In such a case, set ediff-shell
+to a shell that you are not using or, better, fix your shell's startup file.")
+
+
+(defvar ediff-diff-program "diff"
+ "*Program to use for generating the differential of the two files.")
+(defvar ediff-diff-options ""
+ "*Options to pass to `ediff-diff-program'.
+If diff\(1\) is used as `ediff-diff-program', then the most useful options are
+`-w', to ignore space, and `-i', to ignore case of letters.
+At present, the option `-c' is ignored, since Ediff doesn't understand this
+type of output.")
+
+(defvar ediff-custom-diff-program ediff-diff-program
+ "*Program to use for generating custom diff output for saving it in a file.
+This output is not used by Ediff internally.")
+(defvar ediff-custom-diff-options "-c"
+ "*Options to pass to `ediff-custom-diff-program'.")
+
+;;; Support for diff3
+
+(defvar ediff-match-diff3-line "^====\\(.?\\)$"
+ "Pattern to match lines produced by diff3 that describe differences.")
+(defvar ediff-diff3-program "diff3"
+ "*Program to be used for three-way comparison.
+Must produce output compatible with Unix's diff3 program.")
+(defvar ediff-diff3-options ""
+ "*Options to pass to `ediff-diff3-program'.")
+(defvar ediff-diff3-ok-lines-regexp
+ "^\\([1-3]:\\|====\\| \\|.*Warning *:\\|.*No newline\\|.*missing newline\\)"
+ "*Regexp that matches normal output lines from `ediff-diff3-program'.
+Lines that do not match are assumed to be error messages.")
+
+;; keeps the status of the current diff in 3-way jobs.
+;; the status can be =diff(A), =diff(B), or =diff(A+B)
+(ediff-defvar-local ediff-diff-status "" "")
+
+;; Support for patch
+
+(defvar ediff-patch-program "patch"
+ "*Name of the program that applies patches.")
+(defvar ediff-patch-options ""
+ "*Options to pass to ediff-patch-program.")
+
+;; The buffer of the patch file.
+(defvar ediff-patch-buf nil)
+;; The buffer where patch would display its diagnostics.
+(defvar ediff-patch-diagnostics nil)
+
+
+;;; Fine differences
+
+(ediff-defvar-local ediff-auto-refine (if window-system 'on 'nix)
+ "If `on', Ediff auto-highlights fine diffs for the current diff region.
+If `off', auto-highlighting is not used. If `nix', no fine diffs are shown
+at all, unless the user force-refines the region by hitting `*'.
+
+This variable can be set either in .emacs or toggled interactively.
+Use `setq-default' if setting it in .emacs")
+
+(ediff-defvar-local ediff-ignore-similar-regions nil
+ "*If t, skip over difference regions that differ only in the white space and line breaks.
+This variable can be set either in .emacs or toggled interactively.
+Use `setq-default' if setting it in .emacs")
+
+(ediff-defvar-local ediff-auto-refine-limit 700
+ "Auto-refine only those regions that are smaller than this number of bytes.")
+
+;;; General
+
+(defvar ediff-diff-ok-lines-regexp
+ "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\|.*Warning *:\\|.*No newline\\|.*missing newline\\)"
+ "Regexp that matches normal output lines from `ediff-diff-program'.
+This is mostly lifted from Emerge, except that Ediff also considers
+warnings and `Missing newline'-type messages to be normal output.
+Lines that do not match are assumed to be error messages.")
+
+(defvar ediff-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
+ (concat "^" x "\\([acd]\\)" x "$"))
+ "Pattern to match lines produced by diff that describe differences.")
+
+(ediff-defvar-local ediff-setup-diff-regions-function nil
+ "value is a function symbol depending on the kind of job is to be done.
+For 2-way jobs and for ediff-merge, it should be `ediff-setup-diff-regions'.
+For jobs requiring diff3, it should be `ediff-setup-diff-regions3'.
+
+The function should take three mandatory arguments, file-A, file-B, and
+file-C. It may ignore file C for diff2 jobs. It should also take
+one optional arguments, diff-number to refine.")
+
+
+
+;;; Functions
+
+;; Generate the difference vector and overlays for the two files
+;; With optional arg REG-TO-REFINE, refine this region.
+;; File-C argument is not used here. It is there just because
+;; ediff-setup-diff-regions is called via a funcall to
+;; ediff-setup-diff-regions-function, which can also have the value
+;; ediff-setup-diff-regions3, which takes 4 arguments.
+(defun ediff-setup-diff-regions (file-A file-B file-C)
+ ;; force all minibuffers to display ediff's messages.
+ ;; when xemacs implements minibufferless screens, this won't be necessary
+ (if ediff-xemacs-p (setq synchronize-minibuffers t))
+
+ (or (ediff-buffer-live-p ediff-diff-buffer)
+ (setq ediff-diff-buffer
+ (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
+ (or (ediff-buffer-live-p ediff-custom-diff-buffer)
+ (setq ediff-custom-diff-buffer
+ (get-buffer-create
+ (ediff-unique-buffer-name "*ediff-custom-diff" "*"))))
+
+ (ediff-eval-in-buffer ediff-diff-buffer
+ (erase-buffer)
+ ;; shell-command tends to display old shell command buffers even when it
+ ;; puts output in another buffer---probably an Emacs bug.
+ (ediff-kill-buffer-carefully "*Shell Command Output*")
+ (let ((shell-file-name ediff-shell))
+ (message "Computing differences ...") (sit-for 0)
+ (shell-command
+ (format "%s %s %s %s"
+ ediff-diff-program ediff-diff-options
+ (ediff-protect-metachars file-A)
+ (ediff-protect-metachars file-B))
+ t)
+ ))
+
+ ;; compute custom diffs
+ (let ((shell-file-name ediff-shell)
+ (recomp-diff-key
+ (string-to-char
+ (substitute-command-keys "\\[ediff-update-diffs]"))))
+ (if (or (= (buffer-size) 0) ; was the first time
+ (eq last-command-char recomp-diff-key)) ; was a recompute cmd
+ ;; do asynchronously & insert output in ediff-custom-diff-buffer
+ (ediff-shell-command
+ (format "%s %s %s %s"
+ ediff-custom-diff-program ediff-custom-diff-options
+ (ediff-protect-metachars file-A)
+ (ediff-protect-metachars file-B))
+ ediff-custom-diff-buffer)))
+
+ (ediff-prepare-error-list ediff-diff-ok-lines-regexp ediff-diff-buffer)
+ (message "Computing differences ... done")(sit-for 0)
+ (ediff-convert-diffs-to-overlays
+ (ediff-extract-diffs
+ ediff-diff-buffer ediff-word-mode ediff-narrow-bounds))
+ )
+
+;; If file-A/B/C is nil, do 2-way comparison with the non-nil buffers
+;; This function works for diff3 and diff2 jobs
+(defun ediff-setup-fine-diff-regions (file-A file-B file-C reg-num)
+ (or (ediff-buffer-live-p ediff-fine-diff-buffer)
+ (setq ediff-fine-diff-buffer
+ (get-buffer-create
+ (ediff-unique-buffer-name "*ediff-fine-diff" "*"))))
+
+ (let (diff3-job diff-program diff-options ok-regexp diff-list)
+ (setq diff3-job ediff-3way-job
+ diff-program (if diff3-job ediff-diff3-program ediff-diff-program)
+ diff-options ""
+ ok-regexp (if diff3-job
+ ediff-diff3-ok-lines-regexp
+ ediff-diff-ok-lines-regexp))
+
+ (ediff-eval-in-buffer ediff-fine-diff-buffer
+ (erase-buffer)
+ ;; shell-command tends to display old shell command buffers even when
+ ;; it puts output in another buffer---probably an Emacs bug.
+ (ediff-kill-buffer-carefully "*Shell Command Output*")
+ (let ((shell-file-name ediff-shell))
+ (message "Refining difference region %d ..." (1+ reg-num))
+ (shell-command
+ (format "%s %s %s %s %s"
+ diff-program diff-options
+ (if file-A
+ (ediff-protect-metachars file-A)
+ (ediff-protect-metachars file-B))
+ (if file-B
+ (ediff-protect-metachars file-B)
+ (ediff-protect-metachars file-A))
+ (if diff3-job
+ (if file-C
+ (ediff-protect-metachars file-C)
+ (ediff-protect-metachars file-B))
+ "")
+ )
+ t)
+ ))
+
+ (ediff-prepare-error-list ok-regexp ediff-fine-diff-buffer)
+ (message "Refining difference region %d ... done" (1+ reg-num))
+
+ (setq diff-list
+ (if diff3-job
+ (ediff-extract-diffs3
+ ediff-fine-diff-buffer '3way-comparison 'word-mode)
+ (ediff-extract-diffs ediff-fine-diff-buffer 'word-mode)))
+ ;; fixup diff-list
+ (if diff3-job
+ (cond ((not file-A)
+ (mapcar (function (lambda (elt)
+ (aset elt 0 nil)
+ (aset elt 1 nil)))
+ (cdr diff-list)))
+ ((not file-B)
+ (mapcar (function (lambda (elt)
+ (aset elt 2 nil)
+ (aset elt 3 nil)))
+ (cdr diff-list)))
+ ((not file-C)
+ (mapcar (function (lambda (elt)
+ (aset elt 4 nil)
+ (aset elt 5 nil)))
+ (cdr diff-list)))
+ ))
+
+ (ediff-convert-fine-diffs-to-overlays diff-list reg-num)
+ ))
+
+
+(defun ediff-prepare-error-list (ok-regexp diff-buff)
+ (ediff-eval-in-buffer ediff-error-buffer
+ (erase-buffer)
+ (insert-buffer diff-buff)
+ (delete-matching-lines ok-regexp)
+ (if (memq system-type '(vax-vms axp-vms))
+ (delete-matching-lines "^$")))
+ ;; If diff reports errors, show them then quit.
+ (if (/= 0 (ediff-eval-in-buffer ediff-error-buffer (buffer-size)))
+ (let ((ctl-buf ediff-control-buffer)
+ (error-buf ediff-error-buffer))
+ (ediff-skip-unsuitable-frames)
+ (switch-to-buffer error-buf)
+ (ediff-kill-buffer-carefully ctl-buf)
+ (error "Errors in diff output. Diff output is in %S" diff-buff))))
+
+;; BOUNDS specifies visibility bounds to use.
+;; WORD-MODE tells whether we are in the word-mode or not.
+;; If WORD-MODE, also construct vector of diffs using word numbers.
+;; Else, use point values.
+;; This function handles diff-2 jobs including the case of
+;; merging buffers and files without ancestor.
+(defun ediff-extract-diffs (diff-buffer word-mode &optional bounds)
+ (let ((A-buffer ediff-buffer-A)
+ (B-buffer ediff-buffer-B)
+ (C-buffer ediff-buffer-C)
+ (a-prev 1) ; this is needed to set the first diff line correctly
+ (b-prev 1)
+ (c-prev 1)
+ diff-list shift-A shift-B
+ )
+
+ ;; diff list contains word numbers, unless changed later
+ (setq diff-list (cons (if word-mode 'words 'points)
+ diff-list))
+ ;; we don't use visibility bounds for buffer C when merging
+ (if bounds
+ (setq shift-A
+ (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type 'A bounds))
+ shift-B
+ (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type 'B bounds))))
+
+ ;; reset point in buffers A/B/C
+ (ediff-eval-in-buffer A-buffer
+ (goto-char (if shift-A shift-A (point-min))))
+ (ediff-eval-in-buffer B-buffer
+ (goto-char (if shift-B shift-B (point-min))))
+ (if (ediff-buffer-live-p C-buffer)
+ (ediff-eval-in-buffer C-buffer
+ (goto-char (point-min))))
+
+ (ediff-eval-in-buffer diff-buffer
+ (goto-char (point-min))
+ (while (re-search-forward ediff-match-diff-line nil t)
+ (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1)
+ (match-end 1))))
+ (a-end (let ((b (match-beginning 3))
+ (e (match-end 3)))
+ (if b
+ (string-to-int (buffer-substring b e))
+ a-begin)))
+ (diff-type (buffer-substring (match-beginning 4) (match-end 4)))
+ (b-begin (string-to-int (buffer-substring (match-beginning 5)
+ (match-end 5))))
+ (b-end (let ((b (match-beginning 7))
+ (e (match-end 7)))
+ (if b
+ (string-to-int (buffer-substring b e))
+ b-begin)))
+ a-begin-pt a-end-pt b-begin-pt b-end-pt
+ c-begin c-end c-begin-pt c-end-pt)
+ ;; fix the beginning and end numbers, because diff is somewhat
+ ;; strange about how it numbers lines
+ (if (string-equal diff-type "a")
+ (setq b-end (1+ b-end)
+ a-begin (1+ a-begin)
+ a-end a-begin)
+ (if (string-equal diff-type "d")
+ (setq a-end (1+ a-end)
+ b-begin (1+ b-begin)
+ b-end b-begin)
+ ;; (string-equal diff-type "c")
+ (setq a-end (1+ a-end)
+ b-end (1+ b-end))))
+
+ (if (eq ediff-default-variant 'default-B)
+ (setq c-begin b-begin
+ c-end b-end)
+ (setq c-begin a-begin
+ c-end a-end))
+
+ ;; compute main diff vector
+ (if word-mode
+ ;; make diff-list contain word numbers
+ (setq diff-list
+ (nconc diff-list
+ (list
+ (if (ediff-buffer-live-p C-buffer)
+ (vector (- a-begin a-prev) (- a-end a-begin)
+ (- b-begin b-prev) (- b-end b-begin)
+ (- c-begin c-prev) (- c-end c-begin)
+ nil ; state of diff
+ nil ; state of merge
+ )
+ (vector (- a-begin a-prev) (- a-end a-begin)
+ (- b-begin b-prev) (- b-end b-begin)
+ nil nil ; dummy buf C
+ nil ; state of diff
+ nil ; state of merge
+ ))
+ ))
+ a-prev a-end
+ b-prev b-end
+ c-prev c-end)
+ ;; else convert lines to points
+ (ediff-eval-in-buffer A-buffer
+ (forward-line (- a-begin a-prev))
+ (setq a-begin-pt (point))
+ (forward-line (- a-end a-begin))
+ (setq a-end-pt (point)
+ a-prev a-end))
+ (ediff-eval-in-buffer B-buffer
+ (forward-line (- b-begin b-prev))
+ (setq b-begin-pt (point))
+ (forward-line (- b-end b-begin))
+ (setq b-end-pt (point)
+ b-prev b-end))
+ (if (ediff-buffer-live-p C-buffer)
+ (ediff-eval-in-buffer C-buffer
+ (forward-line (- c-begin c-prev))
+ (setq c-begin-pt (point))
+ (forward-line (- c-end c-begin))
+ (setq c-end-pt (point)
+ c-prev c-end)))
+ (setq diff-list
+ (nconc
+ diff-list
+ (list
+ (if (ediff-buffer-live-p C-buffer)
+ (vector
+ a-begin-pt a-end-pt b-begin-pt b-end-pt
+ c-begin-pt c-end-pt
+ ;; state of diff
+ ;; shows which buff is different from the other two
+ (if (eq ediff-default-variant 'default-B) 'A 'B)
+ ;; state of merge
+ ediff-default-variant
+ )
+ (vector a-begin-pt a-end-pt b-begin-pt b-end-pt
+ nil nil ; dummy buf C
+ nil nil ; dummy state of diff & merge
+ )))
+ )))
+
+ ))) ; end ediff-eval-in-buffer
+ diff-list
+ ))
+
+
+(defun ediff-set-diff-overlays-in-one-buffer (buf-type diff-list)
+ (let* ((current-diff -1)
+ (buff (ediff-get-buffer buf-type))
+ ;; ediff-extract-diffs puts the type of diff-list as the first elt
+ ;; of this list. The type is either 'points or 'words
+ (diff-list-type (car diff-list))
+ (shift (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ buf-type ediff-narrow-bounds)))
+ (limit (ediff-overlay-end
+ (ediff-get-value-according-to-buffer-type
+ buf-type ediff-narrow-bounds)))
+ diff-overlay-list list-element total-diffs
+ begin end pt-saved overlay state-of-diff state-of-merge)
+
+ (setq diff-list (cdr diff-list)) ; discard diff list type
+ (setq total-diffs (length diff-list))
+
+ ;; shift, if necessary
+ (ediff-eval-in-buffer buff (setq pt-saved shift))
+
+ (while diff-list
+ (setq current-diff (1+ current-diff)
+ list-element (car diff-list)
+ begin (aref list-element (cond ((eq buf-type 'A) 0)
+ ((eq buf-type 'B) 2)
+ (t 4))) ; buff C
+ end (aref list-element (cond ((eq buf-type 'A) 1)
+ ((eq buf-type 'B) 3)
+ (t 5))) ; buff C
+ state-of-diff (aref list-element 6)
+ state-of-merge (aref list-element 7))
+
+ (cond ((and (not (eq buf-type state-of-diff))
+ (memq state-of-diff '(A B C)))
+ (setq state-of-diff
+ (car (delq buf-type (delq state-of-diff (list 'A 'B 'C)))))
+ (setq state-of-diff (format "=diff(%S)" state-of-diff))
+ (if (and ediff-merge-job state-of-merge (eq buf-type 'C))
+ (setq state-of-merge (format "%S" state-of-merge)))
+ )
+ (t (setq state-of-diff nil
+ state-of-merge nil)))
+
+ ;; Put overlays at appropriate places in buffer
+ ;; convert word numbers to points, if necessary
+ (if (eq diff-list-type 'words)
+ (progn
+ (ediff-eval-in-buffer buff (goto-char pt-saved))
+ (setq begin (ediff-goto-word (1+ begin) buff)
+ end (ediff-goto-word end buff 'end))
+ (if (> end limit) (setq end limit))
+ (if (> begin end) (setq begin end))
+ (setq pt-saved (ediff-eval-in-buffer buff (point)))))
+ (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
+
+ ;; Priorities of overlays should be equal in all ediff control
+ ;; panel buffers. Otherwise it won't work due to Emacs
+ ;; bug, as insert-in-front-hooks will be called
+ ;; only on behalf of the buffer with higher priority.
+ (ediff-overlay-put overlay 'priority ediff-shadow-overlay-priority)
+ (ediff-overlay-put overlay 'ediff-diff-num current-diff)
+ (ediff-overlay-put
+ overlay 'insert-in-front-hooks '(ediff-insert-in-front))
+ (ediff-overlay-put
+ overlay 'face (if (ediff-odd-p current-diff)
+ (intern
+ (format "ediff-odd-diff-face-%S-var" buf-type))
+ (intern
+ (format "ediff-even-diff-face-%S-var" buf-type))))
+
+ (if (= 0 (mod current-diff 10))
+ (message "Buffer %S: Processing difference region %d of %d"
+ buf-type current-diff total-diffs))
+ ;; record all overlays for this difference
+ ;; the second elt, nill, is a place holder for the fine diff vector.
+ ;; the last nil is a place holder for no-fine-diffs flag.
+ (setq diff-overlay-list
+ (nconc
+ diff-overlay-list
+ (list (vector overlay nil nil state-of-diff state-of-merge)))
+ diff-list
+ (cdr diff-list))
+ ) ; while
+
+ (set (intern (format "ediff-difference-vector-%S" buf-type))
+ (apply 'vector diff-overlay-list))
+ ))
+
+;; `n' is the diff region to work on. Default is ediff-current-difference.
+;; if `flag' is 'noforce then make fine-diffs only if this region's fine
+;; diffs have not been computed before.
+;; if `flag' is 'skip then don't compute fine diffs for this region.
+;;
+(defun ediff-make-fine-diffs (&optional n flag)
+ (or n (setq n ediff-current-difference))
+
+ (if (< ediff-number-of-differences 1)
+ (error "No differences found"))
+
+ (if ediff-word-mode
+ (setq flag 'skip
+ ediff-auto-refine 'nix))
+
+ (or (< n 0)
+ (>= n ediff-number-of-differences)
+ ;; n is within the range
+ (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer))
+ (file-A ediff-temp-file-A)
+ (file-B ediff-temp-file-B)
+ (file-C ediff-temp-file-C)
+ (empty-A (ediff-empty-diff-region-p n 'A))
+ (empty-B (ediff-empty-diff-region-p n 'B))
+ (empty-C (ediff-empty-diff-region-p n 'C))
+ (whitespace-A (ediff-whitespace-diff-region-p n 'A))
+ (whitespace-B (ediff-whitespace-diff-region-p n 'B))
+ (whitespace-C (ediff-whitespace-diff-region-p n 'C))
+ cumulative-fine-diff-length)
+
+ (cond ((and (eq flag 'noforce) (ediff-get-fine-diff-vector n 'A))
+ ;; don't compute fine diffs if diff vector exists
+ (if (and (ediff-no-fine-diffs-p n) ediff-verbose-p)
+ (message "Only white-space differences in region %d"
+ (1+ n))))
+ ;; if one of the regions is empty (or 2 in 3way comparison
+ ;; then don't refine
+ ((> (length (delq nil (list empty-A empty-B empty-C))) 1)
+ (if (and (ediff-looks-like-combined-merge n)
+ ediff-merge-job)
+ (ediff-set-fine-overlays-in-one-buffer 'C nil n))
+ (if ediff-verbose-p
+ (if ediff-3way-comparison-job
+ (message
+ "Region %d is empty in all buffers but %S"
+ (1+ n)
+ (cond ((not empty-A) 'A)
+ ((not empty-B) 'B)
+ ((not empty-C) 'C)))
+ (message
+ "Region %d in buffer %S is empty"
+ (1+ n)
+ (cond (empty-A 'A)
+ (empty-B 'B)
+ (empty-C 'C)))
+ ))
+ ;; if all regions happen to be empty, say, as a result of
+ ;; deletions from non-empty regions, then mark as space only
+ (if (and empty-A empty-B empty-C)
+ (ediff-mark-diff-as-space-only n t)
+ (ediff-mark-diff-as-space-only n nil)))
+ ;; don't compute fine diffs for this region
+ ((eq flag 'skip)
+ (or (ediff-get-fine-diff-vector n 'A)
+ (memq ediff-auto-refine '(off nix))
+ (not ediff-verbose-p)
+ (message
+ "Region %d exceeds auto-refine limit. `%s' force-refines"
+ (1+ n)
+ (substitute-command-keys "\\[ediff-make-or-kill-fine-diffs]")
+ )))
+ (t
+ ;; delete old fine diffs
+ ;;(ediff-clear-fine-differences n)
+ ;; recompute fine diffs
+ (ediff-wordify
+ (ediff-get-diff-posn 'A 'beg n)
+ (ediff-get-diff-posn 'A 'end n)
+ ediff-buffer-A
+ tmp-buffer
+ ediff-control-buffer)
+ (ediff-eval-in-buffer tmp-buffer
+ (setq file-A (ediff-make-temp-file "fineDiffA" file-A)))
+
+ (ediff-wordify
+ (ediff-get-diff-posn 'B 'beg n)
+ (ediff-get-diff-posn 'B 'end n)
+ ediff-buffer-B
+ tmp-buffer
+ ediff-control-buffer)
+ (ediff-eval-in-buffer tmp-buffer
+ (setq file-B (ediff-make-temp-file "fineDiffB" file-B)))
+
+ (if ediff-3way-job
+ (progn
+ (ediff-wordify
+ (ediff-get-diff-posn 'C 'beg n)
+ (ediff-get-diff-posn 'C 'end n)
+ ediff-buffer-C
+ tmp-buffer
+ ediff-control-buffer)
+ (ediff-eval-in-buffer tmp-buffer
+ (setq file-C
+ (ediff-make-temp-file "fineDiffC" file-C)))))
+
+ ;; save temp file names.
+ (setq ediff-temp-file-A file-A
+ ediff-temp-file-B file-B
+ ediff-temp-file-C file-C)
+
+ ;; set the new vector of fine diffs, if none exists
+ (cond ((and ediff-3way-job whitespace-A)
+ (ediff-setup-fine-diff-regions nil file-B file-C n))
+ ((and ediff-3way-job whitespace-B)
+ (ediff-setup-fine-diff-regions file-A nil file-C n))
+ ((and ediff-3way-job
+ (or whitespace-C
+ (and ediff-merge-job
+ (ediff-looks-like-combined-merge n))))
+ (ediff-setup-fine-diff-regions file-A file-B nil n))
+ (t
+ (ediff-setup-fine-diff-regions file-A file-B file-C n)))
+
+ (setq cumulative-fine-diff-length
+ (+ (length (ediff-get-fine-diff-vector n 'A))
+ (length (ediff-get-fine-diff-vector n 'B))
+ (if file-C
+ (length
+ (ediff-get-fine-diff-vector n 'C))
+ 0)))
+
+ (cond ((or
+ ;; all regions are white space
+ (and whitespace-A whitespace-B whitespace-C)
+ ;; none is white space and no fine diffs detected
+ (and (not whitespace-A)
+ (not whitespace-B)
+ (not (and ediff-3way-job whitespace-C))
+ (eq cumulative-fine-diff-length 0)))
+ (ediff-mark-diff-as-space-only n t)
+ (message
+ "Only white-space differences in region %d" (1+ n)))
+ ((eq cumulative-fine-diff-length 0)
+ (ediff-mark-diff-as-space-only n nil)
+ (message
+ "Only white-space differences in region %d %s"
+ (1+ n)
+ (cond (whitespace-A "in buffers B & C")
+ (whitespace-B "in buffers A & C")
+ (whitespace-C "in buffers A & B"))))
+ (t
+ (ediff-mark-diff-as-space-only n nil)))
+ )
+ ) ; end cond
+ (ediff-set-fine-diff-properties n)
+ )))
+
+;; Interface to ediff-make-fine-diffs. Checks for auto-refine limit, etc.
+(defun ediff-install-fine-diff-if-necessary (n)
+ (cond ((eq ediff-auto-refine 'on)
+ (if (and
+ (> ediff-auto-refine-limit
+ (- (ediff-get-diff-posn 'A 'end n)
+ (ediff-get-diff-posn 'A 'beg n)))
+ (> ediff-auto-refine-limit
+ (- (ediff-get-diff-posn 'B 'end n)
+ (ediff-get-diff-posn 'B 'beg n))))
+ (ediff-make-fine-diffs n 'noforce)
+ (ediff-make-fine-diffs n 'skip)))
+
+ ;; highlight iff fine diffs already exist
+ ((eq ediff-auto-refine 'off)
+ (ediff-make-fine-diffs n 'skip))))
+
+
+;; if fine diff vector is not set for diff N, then do nothing
+(defun ediff-set-fine-diff-properties (n &optional default)
+ (or (not window-system)
+ (< n 0)
+ (>= n ediff-number-of-differences)
+ ;; in a window system, set faces and priorities of fine overlays
+ (progn
+ (ediff-set-fine-diff-properties-in-one-buffer 'A n default)
+ (ediff-set-fine-diff-properties-in-one-buffer 'B n default)
+ (if ediff-3way-job
+ (ediff-set-fine-diff-properties-in-one-buffer 'C n default)))))
+
+(defun ediff-set-fine-diff-properties-in-one-buffer (buf-type
+ n &optional default)
+ (let ((fine-diff-vector (ediff-get-fine-diff-vector n buf-type))
+ (face (if default
+ 'default
+ (face-name
+ (intern (format "ediff-fine-diff-face-%S" buf-type)))))
+;; (if (and (eq buf-type 'C)
+;; (ediff-looks-like-combined-merge n))
+;; 'ediff-combined-diff-face
+;; (face-name
+;; (intern (format "ediff-fine-diff-face-%S" buf-type))))))
+ (priority (if default
+ 0
+ (1+ (or (ediff-overlay-get
+ (symbol-value
+ (intern
+ (format
+ "ediff-current-diff-overlay-%S" buf-type)))
+ 'priority)
+ 0)))))
+ (mapcar
+ (function (lambda (overl)
+ (ediff-overlay-put overl 'face face)
+ (ediff-overlay-put overl 'priority priority)))
+ fine-diff-vector)))
+
+;; This assumes buffer C and that the region looks like a combination of
+;; regions in buffer A and C.
+(defun ediff-set-fine-overlays-for-combined-merge (diff-list reg-num)
+ (let (overlay1 overlay2 overlay3)
+ (setq overlay1 (ediff-make-bullet-proof-overlay (nth 0 diff-list)
+ (nth 1 diff-list)
+ ediff-buffer-C)
+ overlay2 (ediff-make-bullet-proof-overlay (nth 2 diff-list)
+ (nth 3 diff-list)
+ ediff-buffer-C)
+ overlay3 (ediff-make-bullet-proof-overlay (nth 4 diff-list)
+ (nth 5 diff-list)
+ ediff-buffer-C))
+ (ediff-set-fine-diff-vector reg-num 'C (vector overlay1 overlay2 overlay3))
+ ))
+
+
+;; Convert diff list to overlays for a given DIFF-REGION
+;; in buffer of type BUF-TYPE
+(defun ediff-set-fine-overlays-in-one-buffer (buf-type diff-list region-num)
+ (let* ((current-diff -1)
+ (reg-start (ediff-get-diff-posn buf-type 'beg region-num))
+ (buff (ediff-get-buffer buf-type))
+ combined-merge-diff-list
+ diff-overlay-list list-element
+ begin end overlay)
+
+ (ediff-clear-fine-differences-in-one-buffer region-num buf-type)
+ (setq diff-list (cdr diff-list)) ; discard list type (words or points)
+ (ediff-eval-in-buffer buff (goto-char reg-start))
+
+ ;; if it is a combined merge then set overlays in buff C specially
+ (if (and ediff-merge-job (eq buf-type 'C)
+ (setq combined-merge-diff-list
+ (ediff-looks-like-combined-merge region-num)))
+ (ediff-set-fine-overlays-for-combined-merge
+ combined-merge-diff-list region-num)
+ ;; regular fine diff
+ (while diff-list
+ (setq current-diff (1+ current-diff)
+ list-element (car diff-list)
+ begin (aref list-element (cond ((eq buf-type 'A) 0)
+ ((eq buf-type 'B) 2)
+ (t 4))) ; buf C
+ end (aref list-element (cond ((eq buf-type 'A) 1)
+ ((eq buf-type 'B) 3)
+ (t 5)))) ; buf C
+ (if (not (or begin end))
+ () ; skip this diff
+ ;; Put overlays at appropriate places in buffers
+ ;; convert lines to points, if necessary
+ (setq begin (ediff-goto-word (1+ begin) buff)
+ end (ediff-goto-word end buff 'end))
+ (setq overlay (ediff-make-bullet-proof-overlay begin end buff))
+ ;; record all overlays for this difference region
+ (setq diff-overlay-list (nconc diff-overlay-list (list overlay))))
+
+ (setq diff-list (cdr diff-list))
+ ) ; while
+ ;; convert the list of difference information into a vector
+ ;; for fast access
+ (ediff-set-fine-diff-vector
+ region-num buf-type (apply 'vector diff-overlay-list))
+ )))
+
+
+;; Stolen from emerge.el
+(defun ediff-get-diff3-group (file)
+ ;; This save-excursion allows ediff-get-diff3-group to be called for the
+ ;; various groups of lines (1, 2, 3) in any order, and for the lines to
+ ;; appear in any order. The reason this is necessary is that Gnu diff3
+ ;; can produce the groups in the order 1, 2, 3 or 1, 3, 2.
+ (save-excursion
+ (re-search-forward
+ (concat "^" file ":\\([0-9]+\\)\\(,\\([0-9]+\\)\\)?\\([ac]\\)$"))
+ (beginning-of-line 2)
+ ;; treatment depends on whether it is an "a" group or a "c" group
+ (if (string-equal (buffer-substring (match-beginning 4) (match-end 4)) "c")
+ ;; it is a "c" group
+ (if (match-beginning 2)
+ ;; it has two numbers
+ (list (string-to-int
+ (buffer-substring (match-beginning 1) (match-end 1)))
+ (1+ (string-to-int
+ (buffer-substring (match-beginning 3) (match-end 3)))))
+ ;; it has one number
+ (let ((x (string-to-int
+ (buffer-substring (match-beginning 1) (match-end 1)))))
+ (list x (1+ x))))
+ ;; it is an "a" group
+ (let ((x (1+ (string-to-int
+ (buffer-substring (match-beginning 1) (match-end 1))))))
+ (list x x)))))
+
+
+;; If WORD-MODE, construct vector of diffs using word numbers.
+;; Else, use point values.
+;; WORD-MODE also tells if we are in the word-mode or not.
+;; If THREE-WAY-COMP, then it is a 3-way comparison. Else, it is merging
+;; with ancestor, in which case buffer-C contents is identical to buffer-A
+;; contents (unless buffer-A is narrowed.
+;; BOUNDS specifies visibility bounds to use.
+(defun ediff-extract-diffs3 (diff-buffer word-mode three-way-comp
+ &optional bounds)
+ (let ((A-buffer ediff-buffer-A)
+ (B-buffer ediff-buffer-B)
+ (C-buffer ediff-buffer-C)
+ (a-prev 1) ; needed to set the first diff line correctly
+ (b-prev 1)
+ (c-prev 1)
+ diff-list shift-A shift-B shift-C
+ )
+
+ ;; diff list contains word numbers or points, depending on word-mode
+ (setq diff-list (cons (if word-mode 'words 'points)
+ diff-list))
+ (if bounds
+ (setq shift-A
+ (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type 'A bounds))
+ shift-B
+ (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type 'B bounds))
+ shift-C
+ (if three-way-comp
+ (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type 'C bounds)))))
+
+ ;; reset point in buffers A, B, C
+ (ediff-eval-in-buffer A-buffer
+ (goto-char (if shift-A shift-A (point-min))))
+ (ediff-eval-in-buffer B-buffer
+ (goto-char (if shift-B shift-B (point-min))))
+ (ediff-eval-in-buffer C-buffer
+ (goto-char (if shift-C shift-C (point-min))))
+
+ (ediff-eval-in-buffer diff-buffer
+ (goto-char (point-min))
+ (while (re-search-forward ediff-match-diff3-line nil t)
+ ;; leave point after matched line
+ (beginning-of-line 2)
+ (let ((agreement (buffer-substring (match-beginning 1) (match-end 1))))
+ ;; if the A and B files are the same and not 3way-comparison,
+ ;; ignore the difference
+ (if (or three-way-comp (not (string-equal agreement "3")))
+ (let* ((a-begin (car (ediff-get-diff3-group "1")))
+ (a-end (nth 1 (ediff-get-diff3-group "1")))
+ (b-begin (car (ediff-get-diff3-group "2")))
+ (b-end (nth 1 (ediff-get-diff3-group "2")))
+ (state-of-merge
+ (cond ((string-equal agreement "1") 'prefer-A)
+ ((string-equal agreement "2") 'prefer-B)
+ (t ediff-default-variant)))
+ (state-of-diff-merge
+ (if (memq state-of-merge '(default-A prefer-A)) 'B 'A))
+ (state-of-diff-comparison
+ (cond ((string-equal agreement "1") 'A)
+ ((string-equal agreement "2") 'B)
+ ((string-equal agreement "3") 'C)))
+ c-begin c-end
+ a-begin-pt a-end-pt
+ b-begin-pt b-end-pt c-begin-pt c-end-pt)
+
+ (if three-way-comp
+ (setq c-begin (car (ediff-get-diff3-group "3"))
+ c-end (nth 1 (ediff-get-diff3-group "3")))
+ (if (eq ediff-default-variant 'default-B)
+ (setq c-begin b-begin
+ c-end b-end)
+ (setq c-begin a-begin
+ c-end a-end)))
+
+ ;; compute main diff vector
+ (if word-mode
+ ;; make diff-list contain word numbers
+ (setq diff-list
+ (nconc diff-list
+ (list (vector
+ (- a-begin a-prev) (- a-end a-begin)
+ (- b-begin b-prev) (- b-end b-begin)
+ (- c-begin c-prev) (- c-end c-begin)
+ nil nil))) ; state of diff & merge
+ a-prev a-end
+ b-prev b-end
+ c-prev c-end)
+ ;; else convert lines to points
+ (ediff-eval-in-buffer A-buffer
+ (forward-line (- a-begin a-prev))
+ (setq a-begin-pt (point))
+ (forward-line (- a-end a-begin))
+ (setq a-end-pt (point)
+ a-prev a-end))
+ (ediff-eval-in-buffer B-buffer
+ (forward-line (- b-begin b-prev))
+ (setq b-begin-pt (point))
+ (forward-line (- b-end b-begin))
+ (setq b-end-pt (point)
+ b-prev b-end))
+ (ediff-eval-in-buffer C-buffer
+ (forward-line (- c-begin c-prev))
+ (setq c-begin-pt (point))
+ (forward-line (- c-end c-begin))
+ (setq c-end-pt (point)
+ c-prev c-end))
+ (setq diff-list
+ (nconc
+ diff-list
+ ;; if comparing with ancestor, then there also is a
+ ;; state-of-difference marker
+ (if three-way-comp
+ (list (vector
+ a-begin-pt a-end-pt
+ b-begin-pt b-end-pt
+ c-begin-pt c-end-pt
+ state-of-diff-comparison
+ nil ; state of merge
+ ))
+ (list (vector a-begin-pt a-end-pt
+ b-begin-pt b-end-pt
+ c-begin-pt c-end-pt
+ state-of-diff-merge
+ state-of-merge
+ )))
+ )))
+ ))
+
+ ))) ; end ediff-eval-in-buffer
+ diff-list
+ ))
+
+;; Generate the difference vector and overlays for three files
+;; File-C is either the third file to compare (in case of 3-way comparison)
+;; or it is the ancestor file.
+(defun ediff-setup-diff-regions3 (file-A file-B file-C)
+
+ ;; force all minibuffers to display ediff's messages.
+ ;; when xemacs implements minibufferless screens, this won't be necessary
+ (if ediff-xemacs-p (setq synchronize-minibuffers t))
+
+ (or (ediff-buffer-live-p ediff-diff-buffer)
+ (setq ediff-diff-buffer
+ (get-buffer-create (ediff-unique-buffer-name "*ediff-diff" "*"))))
+
+ (ediff-eval-in-buffer ediff-diff-buffer
+ (erase-buffer)
+ ;; shell-command tends to display old shell command buffers even when it
+ ;; puts output in another buffer---probably an Emacs bug.
+ (ediff-kill-buffer-carefully "*Shell Command Output*")
+ (let ((shell-file-name ediff-shell))
+ (message "Computing differences ...")(sit-for 0)
+ (shell-command
+ (format "%s %s %s %s %s"
+ ediff-diff3-program ediff-diff3-options
+ (ediff-protect-metachars file-A)
+ (ediff-protect-metachars file-B)
+ (ediff-protect-metachars file-C))
+ t)
+ ))
+
+ (ediff-prepare-error-list ediff-diff3-ok-lines-regexp ediff-diff-buffer)
+ (message "Computing differences ... done")(sit-for 0)
+ (ediff-convert-diffs-to-overlays
+ (ediff-extract-diffs3
+ ediff-diff-buffer
+ ediff-word-mode ediff-3way-comparison-job ediff-narrow-bounds)
+ ))
+
+
+;; Execute shell COMMAND asynchronously and insert output in BUFFER.
+;; BUFFER must be a buffer object, and must be alive.
+;; There should be NO ampersand at the end of the command.
+;; We introduce this command because Emacs shell-command doesn't let us
+;; insert output in current buffer asynchronously.
+;; Most of this command was stolen from Emacs shell-command."
+(defun ediff-shell-command (command buffer)
+ (let ((data (match-data)))
+ (unwind-protect
+ (let ((directory default-directory)
+ proc)
+ ;; If will kill a process, query first.
+ (setq proc (get-buffer-process buffer))
+ (if proc (kill-process proc))
+ (save-excursion
+ (set-buffer buffer)
+ (erase-buffer)
+ (setq default-directory directory)
+ (setq proc (start-process "Shell" buffer
+ shell-file-name "-c" command))
+ (setq mode-line-process '(":%s"))
+ (set-process-sentinel proc 'ediff-shell-command-sentinel)
+ (set-process-filter proc 'ediff-shell-command-filter)
+ ))
+ (store-match-data data))))
+
+;; This is shell-command-filter from simple.el in FSF Emacs.
+;; Copied here because XEmacs doesn't have it.
+(defun ediff-shell-command-filter (proc string)
+ ;; Do save-excursion by hand so that we can leave point numerically unchanged
+ ;; despite an insertion immediately after it.
+ (let* ((obuf (current-buffer))
+ (buffer (process-buffer proc))
+ opoint
+ (window (get-buffer-window buffer))
+ (pos (window-start window)))
+ (unwind-protect
+ (progn
+ (set-buffer buffer)
+ (or (= (point) (point-max))
+ (setq opoint (point)))
+ (goto-char (point-max))
+ (insert-before-markers string))
+ ;; insert-before-markers moved this marker: set it back.
+ (set-window-start window pos)
+ ;; Finish our save-excursion.
+ (if opoint
+ (goto-char opoint))
+ (set-buffer obuf))))
+
+;; like shell-command-sentinel but doesn't print an exit status message
+;; we do this because diff always exits with status 1, if diffs are found
+;; so shell-command-sentinel displays a confusing message to the user
+(defun ediff-shell-command-sentinel (process signal)
+ (if (and (memq (process-status process) '(exit signal))
+ (buffer-name (process-buffer process)))
+ (progn
+ (save-excursion
+ (set-buffer (process-buffer process))
+ (setq mode-line-process nil))
+ (delete-process process))))
+
+
+;;; Word functions used to refine the current diff
+
+(defvar ediff-forward-word-function 'ediff-forward-word
+ "*Function to call to move to the next word.
+Used for splitting difference regions into individual words.")
+
+(defvar ediff-whitespace " \n\t\f"
+ "*Characters constituting white space.
+These characters are ignored when differing regions are split into words.")
+
+;;(defvar ediff-word-1 "a-zA-Z---_`'.?!:"
+(defvar ediff-word-1 "a-zA-Z---_"
+ "*Characters that constitute words of type 1.
+More precisely, [ediff-word-1] is a regexp that matches type 1 words.
+See `ediff-forward-word' for more details.")
+
+(defvar ediff-word-2 "0-9.,"
+ "*Characters that constitute words of type 2.
+More precisely, [ediff-word-2] is a regexp that matches type 2 words.
+See `ediff-forward-word' for more details.")
+
+(defvar ediff-word-3 "`'?!:;\"{}[]()"
+ "*Characters that constitute words of type 3.
+More precisely, [ediff-word-3] is a regexp that matches type 3 words.
+See `ediff-forward-word' for more details.")
+
+(defvar ediff-word-4
+ (concat "^" ediff-word-1 ediff-word-2 ediff-word-3 ediff-whitespace)
+ "*Characters that constitute words of type 4.
+More precisely, [ediff-word-4] is a regexp that matches type 4 words.
+See `ediff-forward-word' for more details.")
+
+;; Split region along word boundaries. Each word will be on its own line.
+;; Output to buffer out-buffer.
+(defun ediff-forward-word ()
+ "Move point one word forward.
+There are four types of words, each of which consists entirely of
+characters in `ediff-word-1', `ediff-word-2', `ediff-word-3', or
+`ediff-word-4'. Words are recognized by passing these in turn as the
+argument to `skip-chars-forward'."
+ (or (> (skip-chars-forward ediff-word-1) 0)
+ (> (skip-chars-forward ediff-word-2) 0)
+ (> (skip-chars-forward ediff-word-3) 0)
+ (> (skip-chars-forward ediff-word-4) 0)
+ ))
+
+(defun ediff-wordify (beg end in-buffer out-buffer &optional control-buf)
+ (let (sv-point string)
+ (save-excursion
+ (set-buffer in-buffer)
+ (setq string (buffer-substring beg end))
+
+ (set-buffer out-buffer)
+ (erase-buffer)
+ (insert string)
+ (goto-char (point-min))
+ (skip-chars-forward ediff-whitespace)
+ (delete-region (point-min) (point))
+
+ (while (not (eobp))
+ ;; eval incontrol buf to let user create local versions for
+ ;; different invocations
+ (if control-buf
+ (funcall
+ (ediff-eval-in-buffer control-buf ediff-forward-word-function))
+ (funcall ediff-forward-word-function))
+ (setq sv-point (point))
+ (skip-chars-forward ediff-whitespace)
+ (delete-region sv-point (point))
+ (insert "\n")))))
+
+;; copy string from BEG END from IN-BUF to OUT-BUF
+(defun ediff-copy-to-buffer (beg end in-buffer out-buffer)
+ (let (string)
+ (save-excursion
+ (set-buffer in-buffer)
+ (setq string (buffer-substring beg end))
+
+ (set-buffer out-buffer)
+ (erase-buffer)
+ (insert string)
+ (goto-char (point-min)))))
+
+
+;; goto word #n starting at current position in buffer `buf'
+;; For ediff, a word is either a string of a-z,A-Z, incl `-' and `_';
+;; or a string of other non-blanks. A blank is a \n\t\f
+;; If `flag' is non-nil, goto the end of the n-th word.
+(defun ediff-goto-word (n buf &optional flag)
+ ;; remember val ediff-forward-word-function has in ctl buf
+ (let ((fwd-word-fun ediff-forward-word-function))
+ (ediff-eval-in-buffer buf
+ (skip-chars-forward ediff-whitespace)
+ (while (> n 1)
+ (funcall fwd-word-fun)
+ (skip-chars-forward ediff-whitespace)
+ (setq n (1- n)))
+ (if (and flag (> n 0))
+ (funcall fwd-word-fun))
+ (point))))
+
+
+(provide 'ediff-diff)
+
+
+;; ediff-diff.el ends here
diff --git a/lisp/ediff-init.el b/lisp/ediff-init.el
new file mode 100644
index 00000000000..2d0d1b2decc
--- /dev/null
+++ b/lisp/ediff-init.el
@@ -0,0 +1,1189 @@
+;;; ediff-init.el --- Macros, variables and defsubsts used by Ediff
+;;; Copyright (C) 1994 Free Software Foundation, Inc.
+
+;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+(defconst ediff-xemacs-p (string-match "\\(Lucid\\|Xemacs\\)" emacs-version)
+ "Whether it is XEmacs.")
+(defconst ediff-emacs-p (not ediff-xemacs-p)
+ "Whether it is Emacs.")
+
+;;; Macros
+(defmacro ediff-odd-p (arg)
+ (` (eq (logand (, arg) 1) 1)))
+
+(defmacro ediff-buffer-live-p (buf)
+ (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf))))))
+
+(defmacro ediff-get-buffer (arg)
+ (` (cond ((eq (, arg) 'A) ediff-buffer-A)
+ ((eq (, arg) 'B) ediff-buffer-B)
+ ((eq (, arg) 'C) ediff-buffer-C)
+ )
+ ))
+
+(defmacro ediff-get-value-according-to-buffer-type (buf-type list)
+ (` (cond ((eq (, buf-type) 'A) (nth 0 (, list)))
+ ((eq (, buf-type) 'B) (nth 1 (, list)))
+ ((eq (, buf-type) 'C) (nth 2 (, list))))))
+
+(defmacro ediff-char-to-buftype (arg)
+ (` (cond ((memq (, arg) '(?a ?A)) 'A)
+ ((memq (, arg) '(?b ?B)) 'B)
+ ((memq (, arg) '(?c ?C)) 'C)
+ )
+ ))
+
+(defmacro ediff-get-difference (n buf-type)
+ (` (aref
+ (symbol-value
+ (intern (format "ediff-difference-vector-%S" (, buf-type)))) (, n))))
+
+;; tell if it has been previously determined that the region has
+;; no diffs other than the white space and newlines
+;; The argument, N, is the diff region number used by Ediff to index the
+;; diff vector. It is 1 less than the number seen by the user.
+;;
+;; A difference vector has the form:
+;; [diff diff diff ...]
+;; where each diff has the form:
+;; [overlay fine-diff-vector no-fine-diffs-flag]
+;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
+(defmacro ediff-no-fine-diffs-p (n)
+ (` (aref (ediff-get-difference (, n) 'A) 2)))
+
+(defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
+ (` (aref (, diff-rec) 0)))
+
+(defmacro ediff-get-diff-overlay (n buf-type)
+ (` (ediff-get-diff-overlay-from-diff-record
+ (ediff-get-difference (, n) (, buf-type)))))
+
+(defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
+ (` (aref (, diff-rec) 1)))
+
+(defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
+ (` (aset (ediff-get-difference (, n) (, buf-type)) 1 (, fine-vec))))
+
+(defmacro ediff-get-state-of-diff (n buf-type)
+ (` (if (ediff-buffer-live-p ediff-buffer-C)
+ (aref (ediff-get-difference (, n) (, buf-type)) 3))))
+(defmacro ediff-set-state-of-diff (n buf-type val)
+ (` (aset (ediff-get-difference (, n) (, buf-type)) 3 (, val))))
+(defmacro ediff-get-state-of-merge (n)
+ (` (if (ediff-buffer-live-p ediff-buffer-C)
+ (aref (ediff-get-difference (, n) 'C) 4))))
+(defmacro ediff-set-state-of-merge (n val)
+ (` (aset (ediff-get-difference (, n) 'C) 4 (, val))))
+
+;; if flag is t, puts a mark on diff region saying that
+;; the differences are in white space only. If flag is nil,
+;; the region is marked as essential (i.e., differences are
+;; not just in the white space and newlines.)
+(defmacro ediff-mark-diff-as-space-only (n flag)
+ (` (aset (ediff-get-difference (, n) 'A) 2 (, flag))))
+
+(defmacro ediff-get-fine-diff-vector (n buf-type)
+ (` (ediff-get-fine-diff-vector-from-diff-record
+ (ediff-get-difference (, n) (, buf-type)))))
+
+
+;; Defines SYMBOL as an advertised local variable.
+;; Performs a defvar, then executes `make-variable-buffer-local' on
+;; the variable. Also sets the `permanent-local' property,
+;; so that `kill-all-local-variables' (called by major-mode setting
+;; commands) won't destroy Ediff control variables.
+;;
+;; Plagiarised from `emerge-defvar-local' for XEmacs.
+(defmacro ediff-defvar-local (var value doc)
+ (` (progn
+ (defvar (, var) (, value) (, doc))
+ (make-variable-buffer-local '(, var))
+ (put '(, var) 'permanent-local t))))
+
+;; Macro to switch to BUFFER, evaluate FORMS, returns to original buffer.
+;; Differs from `save-excursion' in that it doesn't save the point and mark.
+;; This is essentially `emerge-eval-in-buffer' with the test for live buffers."
+(defmacro ediff-eval-in-buffer (buffer &rest forms)
+ (` (let ((StartBuffer (current-buffer)))
+ (if (ediff-buffer-live-p (, buffer))
+ (unwind-protect
+ (progn
+ (set-buffer (, buffer))
+ (,@ forms))
+ (set-buffer StartBuffer))
+ (or (eq this-command 'ediff-quit)
+ (error
+ "You've killed an essential Ediff buffer---Please quit Ediff"))
+ ))))
+
+
+(defmacro ediff-multiframe-setup-p ()
+ (` (and window-system ediff-multiframe)))
+
+(defmacro ediff-narrow-control-frame-p ()
+ (` (and (ediff-multiframe-setup-p)
+ (equal ediff-help-message ediff-brief-message-string))))
+
+(defmacro ediff-3way-comparison-job ()
+ (` (memq
+ ediff-job-name
+ '(ediff-files3 ediff-buffers3))))
+(ediff-defvar-local ediff-3way-comparison-job nil "")
+
+(defmacro ediff-merge-job ()
+ (` (memq
+ ediff-job-name
+ '(ediff-merge-files
+ ediff-merge-buffers
+ ediff-merge-files-with-ancestor
+ ediff-merge-buffers-with-ancestor
+ ediff-merge-revisions
+ ediff-merge-revisions-with-ancestor))))
+(ediff-defvar-local ediff-merge-job nil "")
+
+(defmacro ediff-merge-with-ancestor-job ()
+ (` (memq
+ ediff-job-name
+ '(ediff-merge-files-with-ancestor
+ ediff-merge-buffers-with-ancestor
+ ediff-merge-revisions-with-ancestor))))
+(ediff-defvar-local ediff-merge-with-ancestor-job nil "")
+
+(defmacro ediff-3way-job ()
+ (` (or ediff-3way-comparison-job ediff-merge-job)))
+(ediff-defvar-local ediff-3way-job nil "")
+
+;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
+;; of diff3.
+(defmacro ediff-diff3-job ()
+ (` (or ediff-3way-comparison-job
+ ediff-merge-with-ancestor-job)))
+(ediff-defvar-local ediff-diff3-job nil "")
+
+(defmacro ediff-word-mode-job ()
+ (` (memq
+ ediff-job-name
+ '(ediff-windows ediff-small-regions ediff-large-regions))))
+(ediff-defvar-local ediff-word-mode-job nil "")
+
+
+;; Hook variables
+
+(defvar ediff-before-setup-windows-hooks nil
+ "*Hooks to run before Ediff sets its own window config.
+This can be used to save the previous window config, which can be restored
+on ediff-quit or ediff-suspend.")
+(defvar ediff-after-setup-windows-hooks nil
+ "*Hooks to run after Ediff sets its own window config.
+This can be used to set up control window or icon in a desired place.")
+(defvar ediff-before-setup-control-frame-hooks nil
+ "*Hooks run before setting up the frame to display Ediff Control Panel.
+Can be used to change control frame parameters to position it where it
+is desirable.")
+(defvar ediff-after-setup-control-frame-hooks nil
+ "*Hooks run after setting up the frame to display Ediff Control Panel.
+Can be used to move the frame where it is desired.")
+(defvar ediff-startup-hooks nil
+ "*Hooks to run in the control buffer after Ediff has been set up.")
+(defvar ediff-select-hooks nil
+ "*Hooks to run after a difference has been selected.")
+(defvar ediff-unselect-hooks nil
+ "*Hooks to run after a difference has been unselected.")
+(defvar ediff-prepare-buffer-hooks nil
+ "*Hooks called after buffers A, B, and C are set up.")
+(defvar ediff-load-hooks nil
+ "*Hook run after Ediff is loaded. Can be used to change defaults.")
+
+(defvar ediff-mode-hooks nil
+ "*Hook run just after ediff-mode is set up in the control buffer.
+This is done before any windows or frames are created. One can use it to
+set local variables that determine how the display looks like.")
+(defvar ediff-keymap-setup-hooks nil
+ "*Hook run just after the default bindings in Ediff keymap are set up.")
+
+(defvar ediff-display-help-hooks nil
+ "*Hooks run after preparing the help message.")
+
+(defvar ediff-suspend-hooks (list 'ediff-default-suspend-hook)
+ "*Hooks to run in the Ediff control buffer when Ediff is suspended.")
+(defvar ediff-quit-hooks (list 'ediff-cleanup-mess)
+ "*Hooks to run in the Ediff control buffer after finishing Ediff.")
+
+;; There will be deleted in due time
+(make-variable-buffer-local 'local-write-file-hooks)
+(make-variable-buffer-local 'before-change-function)
+
+
+;; Help messages
+
+(defconst ediff-long-help-message-head
+ " Moving around | Toggling features | Manipulations
+=====================|===========================|============================="
+ "The head of the full help message.")
+(defconst ediff-long-help-message-tail
+ "=====================|===========================|=============================
+ i -status info | ? -help off | G -send bug report
+-------------------------------------------------------------------------------
+X,Y (x,y) on the left are meta-symbols for the keys A,B,C (a,b,c).
+X,Y on the right are meta-symbols for buffers A,B,C.
+A,B,C on the right denote the working buffers A,B,C, respectively."
+ "The tail of the full-help message.")
+
+(defconst ediff-long-help-message-compare3
+ "
+p,DEL -previous diff | | -vert/horiz split | xy -copy buf X's region to Y
+n,SPC -next diff | h -hiliting | rx -restore buf X's old diff
+ j -jump to diff | @ -auto-refinement | * -refine current region
+ gx -goto X's point| | ! -update diff regions
+ C-l -recenter | ## -ignore whitespace |
+ v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
+ </> -scroll lt/rt | X -read-only in buf X | wd -save diff output
+ z/q -suspend/quit | m -wide display | ~ -rotate buffers
+"
+ "Normally, not a user option. See `ediff-help-message' for details.")
+
+(defconst ediff-long-help-message-compare2
+ "
+p,DEL -previous diff | | -vert/horiz split |a/b -copy A/B's region to B/A
+n,SPC -next diff | h -hiliting | rx -restore buf X's old diff
+ j -jump to diff | @ -auto-refinement | * -refine current region
+ gx -goto X's point| | ! -update diff regions
+ C-l -recenter | ## -ignore whitespace |
+ v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
+ </> -scroll lt/rt | X -read-only in buf X | wd -save diff output
+ z/q -suspend/quit | m -wide display | ~ -swap buffers
+"
+ "Normally, not a user option. See `ediff-help-message' for details.")
+
+(defconst ediff-long-help-message-word-mode
+ "
+p,DEL -previous diff | | -vert/horiz split | xy -copy buf X's region to Y
+n,SPC -next diff | h -hiliting | rx -restore buf X's old diff
+ j -jump to diff | |
+ gx -goto X's point| % -narrow/widen buffs | ! -recompute diffs
+ C-l -recenter | |
+ v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
+ </> -scroll lt/rt | X -read-only in buf X | wd -save diff output
+ z/q -suspend/quit | m -wide display | ~ -swap buffers
+"
+ "Normally, not a user option. See `ediff-help-message' for details.")
+
+(defconst ediff-long-help-message-merge
+ "
+p,DEL -previous diff | | -vert/horiz split | x -copy buf X's region to C
+n,SPC -next diff | h -hiliting | r -restore buf C's old diff
+ j -jump to diff | @ -auto-refinement | * -refine current region
+ gx -goto X's point| ## -ignore whitespace | ! -update diff regions
+ C-l -recenter | #f/#h -focus/hide regions | + -combine diff regions
+ v/V -scroll up/dn | X -read-only in buf X | wx -save buf X
+ </> -scroll lt/rt | m -wide display | wd -save diff output
+ z/q -suspend/quit | s -shrink window C | ~ -swap buffers
+ | $ -show clashes only | & -merge w/new default
+"
+ "Normally, not a user option. See `ediff-help-message' for details.")
+
+;; The actual long help message.
+(ediff-defvar-local ediff-long-help-message ""
+ "Normally, not a user option. See `ediff-help-message' for details.")
+
+(defconst ediff-brief-message-string
+ " ? - help "
+ "Contents of the brief help message.")
+;; The actual brief help message
+(ediff-defvar-local ediff-brief-help-message ""
+ "Normally, not a user option. See `ediff-help-message' for details.")
+
+(ediff-defvar-local ediff-brief-help-message-custom nil
+ "The brief help message that the user can customize.
+If the user sets this to a parameter-less function, Ediff will use it to
+produce the brief help message. This function must return a string.")
+(ediff-defvar-local ediff-long-help-message-custom nil
+ "The long help message that the user can customize.
+See `ediff-brief-help-message-custom' for more.")
+
+(defvar ediff-prefer-long-help-message nil
+ "*If t, Ediff starts with a long help message. Short help msg otherwise.")
+
+;; The actual help message.
+(ediff-defvar-local ediff-help-message ""
+ "The actual help message.
+Normally, the user shouldn't touch this. However, if you want Ediff to
+start up with different help messages for different jobs, you can change
+the value of this variable and the variables `ediff-help-message-*' in
+`ediff-startup-hooks'.")
+
+;; Selective browsing
+
+(ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
+ "Function that determines the next/previous diff region to show.
+Should return t for regions to be ignored and nil otherwise.
+This function gets a region number as an argument. The region number
+is the one used internally by Ediff. It is 1 less than the number seen
+by the user.")
+
+;; Regexp that determines buf A regions to focus on when skipping to diff
+(ediff-defvar-local ediff-regexp-focus-A "" "")
+;; Regexp that determines buf B regions to focus on when skipping to diff
+(ediff-defvar-local ediff-regexp-focus-B "" "")
+;; Regexp that determines buf C regions to focus on when skipping to diff
+(ediff-defvar-local ediff-regexp-focus-C "" "")
+;; connective that determines whether to focus regions that match both or
+;; one of the regexps
+(ediff-defvar-local ediff-focus-regexp-connective 'and "")
+
+;; Regexp that determines buf A regions to ignore when skipping to diff
+(ediff-defvar-local ediff-regexp-hide-A "" "")
+;; Regexp that determines buf B regions to ignore when skipping to diff
+(ediff-defvar-local ediff-regexp-hide-B "" "")
+;; Regexp that determines buf C regions to ignore when skipping to diff
+(ediff-defvar-local ediff-regexp-hide-C "" "")
+;; connective that determines whether to hide regions that match both or
+;; one of the regexps
+(ediff-defvar-local ediff-hide-regexp-connective 'and "")
+
+
+(defvar ediff-ange-ftp-ftp-name (if ediff-xemacs-p
+ 'ange-ftp-ftp-path
+ 'ange-ftp-ftp-name)
+ "Function ange-ftp uses to find out if file is remote.")
+
+
+;; Copying difference regions between buffers.
+(ediff-defvar-local ediff-killed-diffs-alist nil
+ "A list of killed diffs.
+A diff is saved here if it is replaced by a diff
+from another buffer. This alist has the form:
+\((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
+where some buffer-objects may be missing.")
+
+
+;; Highlighting
+(defvar ediff-before-flag-bol "->>\n"
+ "*Flag placed above the highlighted block of differences.
+Must end with newline.")
+(defvar ediff-after-flag-eol "<<-\n"
+ "*Flag placed below the highlighted block of differences.
+Must end with newline.")
+
+(defvar ediff-before-flag-mol "->>"
+ "*Like ediff-before-flag, used when a difference starts in mid-line.")
+(defvar ediff-after-flag-mol "<<-"
+ "*Like ediff-after-flag, used when a difference starts in mid-line.")
+
+(ediff-defvar-local ediff-before-flag-A nil
+ "This is the actual ASCII before-flag in effect in buffer A.
+It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
+on whether the selected difference region starts in the middle of a line
+or at the beginning of a line.")
+(ediff-defvar-local ediff-after-flag-A nil
+ "This is the actual ASCII after-flag in effect in buffer A.
+It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
+on whether the selected difference region starts in the middle of a line
+or at the beginning of a line.")
+
+(ediff-defvar-local ediff-before-flag-B nil
+ "This is the actual ASCII before-flag in effect in buffer B.
+It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
+on whether the selected difference region starts in the middle of a line
+or at the beginning of a line.")
+(ediff-defvar-local ediff-after-flag-B nil
+ "This is the actual ASCII after-flag in effect in buffer B.
+It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
+on whether the selected difference region starts in the middle of a line
+or at the beginning of a line.")
+
+(ediff-defvar-local ediff-before-flag-C nil
+ "This is the actual ASCII before-flag in effect in buffer C.
+It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
+on whether the selected difference region starts in the middle of a line
+or at the beginning of a line.")
+(ediff-defvar-local ediff-after-flag-C nil
+ "This is the actual ASCII after-flag in effect in buffer C.
+It is either `ediff-before-flag-mol' or `ediff-before-flag-bol' depending
+on whether the selected difference region starts in the middle of a line
+or at the beginning of a line.")
+
+
+(ediff-defvar-local ediff-use-faces t
+ "If t, differences are highlighted using faces on a window system.
+If nil, they are highlighted using ASCII flags, ediff-before-flag
+and ediff-after-flag. On a non-window system, differences are always
+highlighted using ASCII flags.
+This variable can be set either in .emacs or toggled interactively.
+Use `setq-default' if setting it in .emacs")
+
+
+;; this indicates that diff regions are word-size, so fine diffs are
+;; permanently nixed; used in ediff-windows and ediff-small-regions
+(ediff-defvar-local ediff-word-mode nil "")
+;; Name of the job (ediff-files, ediff-windows, etc.
+(ediff-defvar-local ediff-job-name nil "")
+
+;; Narrowing and ediff-region/windows support
+;; This is a list (overlay-A overlay-B overlay-C)
+;; If set, Ediff compares only those parts of buffers A/B/C that lie within
+;; the bounds of these overlays.
+(ediff-defvar-local ediff-narrow-bounds nil "")
+
+;; List (overlay-A overlay-B overlay-C), where each overlay spans the
+;; entire corresponding buffer.
+(ediff-defvar-local ediff-wide-bounds nil "")
+
+;; Current visibility boundaries in buffers A, B, and C.
+;; This is also a list of overlays. When the user toggles narrow/widen,
+;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
+;; and back.
+(ediff-defvar-local ediff-visible-bounds nil "")
+
+(ediff-defvar-local ediff-start-narrowed t
+ "Non-nil means start narrowed, if doing ediff-windows, ediff-small-regions,
+or ediff-large-regions.")
+(ediff-defvar-local ediff-quit-widened t
+ "*Non-nil means: when finished, Ediff widens buffers A/B.
+Actually, Ediff restores the scope of visibility that existed at startup.")
+
+(ediff-defvar-local ediff-highlight-all-diffs t
+ "If nil, only the selected differences are highlighted.
+This variable can be set either in .emacs or toggled interactively, using
+ediff-toggle-hilit. Use `setq-default' to set it.")
+
+;; A var local to each control panel buffer. Indicates highlighting style
+;; in effect for this buffer: `face', `ascii', nil -- temporarily
+;; unhighlighted, `off' -- turned off \(on a dumb terminal only\).
+(ediff-defvar-local ediff-highlighting-style nil "")
+
+
+;; Variables that control each Ediff session. They are local to the
+;; control buffer.
+
+;; Mode variables
+;; The buffer in which the A variant is stored.
+(ediff-defvar-local ediff-buffer-A nil "")
+;; The buffer in which the B variant is stored.
+(ediff-defvar-local ediff-buffer-B nil "")
+;; The buffer in which the C variant is stored.
+(ediff-defvar-local ediff-buffer-C nil "")
+;; Ancestor buffer
+(ediff-defvar-local ediff-ancestor-buffer nil "")
+;; The control buffer of ediff.
+(ediff-defvar-local ediff-control-buffer nil "")
+
+
+;; The suffix of the control buffer name.
+(ediff-defvar-local ediff-control-buffer-suffix nil "")
+;; Same as ediff-control-buffer-suffix, but without <,>.
+;; It's a number rather than string.
+(ediff-defvar-local ediff-control-buffer-number nil "")
+
+
+;; There three are to be deleted in due time
+;; Working values of ediff-saved-variables for buffer A.
+(ediff-defvar-local ediff-buffer-A-values nil "")
+;; working values of ediff-saved-variables for buffer B.
+(ediff-defvar-local ediff-buffer-B-values nil "")
+;; working values of ediff-saved-variables for buffer C.
+(ediff-defvar-local ediff-buffer-C-values nil "")
+
+;; The original values of ediff-protected-variables for buffer A
+(ediff-defvar-local ediff-buffer-A-values-orig nil "")
+;; The original values of ediff-protected-variables for buffer B
+(ediff-defvar-local ediff-buffer-B-values-orig nil "")
+;; The original values of ediff-protected-variables for buffer C
+(ediff-defvar-local ediff-buffer-C-values-orig nil "")
+;; Buffer-local variables to be saved then restored during Ediff sessions
+(defconst ediff-protected-variables '(buffer-read-only
+ mode-line-format))
+
+;; These three vars are to be deleted when emacs gets before/after strings
+;; Remember ediff-saved-variables for ediff-buffer-A as they were at setup.
+(ediff-defvar-local ediff-buffer-A-values-setup nil "")
+;; Remembers ediff-saved-variables for ediff-buffer-B as they were at setup.
+(ediff-defvar-local ediff-buffer-B-values-setup nil "")
+;; Remembers ediff-saved-variables for ediff-buffer-C as they were at setup.
+(ediff-defvar-local ediff-buffer-C-values-setup nil "")
+
+;; Vector of differences between the variants. Each difference is
+;; represented by a vector of two overlays plus a vector of fine diffs,
+;; plus a no-fine-diffs flag. The first overlay spans the
+;; difference region in the A buffer and the second overlays the diff in
+;; the B buffer. If a difference section is empty, the corresponding
+;; overlay's endpoints coincide.
+;;
+;; The precise form of a difference vector for one buffer is:
+;; [diff diff diff ...]
+;; where each diff has the form:
+;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-difference
+;; state-of-merge]
+;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
+;; no-fine-diffs-flag says if there are fine differences.
+;; state-of-difference is A, B, C, or nil, indicating which buffer is
+;; different from the other two (used only in 3-way jobs.
+;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
+;; indicates the way a diff region was created in buffer C.
+(ediff-defvar-local ediff-difference-vector-A nil "")
+(ediff-defvar-local ediff-difference-vector-B nil "")
+(ediff-defvar-local ediff-difference-vector-C nil "")
+
+;; The difference that is currently selected.
+(ediff-defvar-local ediff-current-difference -1 "")
+;; Number of differences found.
+(ediff-defvar-local ediff-number-of-differences nil "")
+
+;; Buffer containing the output of diff, which is used by Ediff to step
+;; through files.
+(ediff-defvar-local ediff-diff-buffer nil "")
+;; Like ediff-diff-buffer, but contains context diff. It is not used by
+;; Ediff, but it is saved in a file, if user requests so.
+(ediff-defvar-local ediff-custom-diff-buffer nil "")
+;; Buffer used for diff-style fine differences between regions.
+(ediff-defvar-local ediff-fine-diff-buffer nil "")
+;; Temporary buffer used for computing fine differences.
+(defconst ediff-tmp-buffer " *ediff-tmp*" "")
+;; Buffer used for messages
+(defconst ediff-msg-buffer " *ediff-message*" "")
+;; Buffer containing the output of diff when diff returns errors.
+(ediff-defvar-local ediff-error-buffer nil "")
+;; Buffer to display debug info
+(ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
+
+;; to be deleted in due time
+;; List of ediff control panels associated with each buffer A/B.
+(ediff-defvar-local ediff-this-buffer-control-sessions nil "")
+
+;; to be deleted in due time
+;; List of difference overlays disturbed by working with the current diff.
+(defvar ediff-disturbed-overlays nil "")
+
+;; Priority of non-selected overlays.
+(defvar ediff-shadow-overlay-priority 100 "")
+
+
+(if ediff-xemacs-p
+ (progn
+ (fset 'ediff-read-event (symbol-function 'next-command-event))
+ (fset 'ediff-overlayp (symbol-function 'extentp))
+ (fset 'ediff-make-overlay (symbol-function 'make-extent))
+ (fset 'ediff-delete-overlay (symbol-function 'delete-extent))
+ (fset 'ediff-overlay-buffer (symbol-function 'extent-buffer))
+ (fset 'ediff-overlay-p (symbol-function 'extentp))
+ (fset 'ediff-overlay-get (symbol-function 'extent-property)))
+ (fset 'ediff-read-event (symbol-function 'read-event))
+ (fset 'ediff-overlayp (symbol-function 'overlayp))
+ (fset 'ediff-make-overlay (symbol-function 'make-overlay))
+ (fset 'ediff-delete-overlay (symbol-function 'delete-overlay))
+ (fset 'ediff-overlay-buffer (symbol-function 'overlay-buffer))
+ (fset 'ediff-overlay-p (symbol-function 'overlayp))
+ (fset 'ediff-overlay-get (symbol-function 'overlay-get)))
+
+;; A fix for NeXT Step
+;; Should probably be eliminated in later versions.
+(if (and window-system (eq window-system 'ns))
+ (progn
+ (fset 'x-display-color-p (symbol-function 'ns-display-color-p))
+ (fset 'x-color-defined-p (symbol-function 'ns-color-defined-p))
+ (fset 'x-display-pixel-height (symbol-function 'ns-display-pixel-height))
+ (fset 'x-display-pixel-width (symbol-function 'ns-display-pixel-width))
+ ))
+
+(if ediff-xemacs-p
+ (progn
+ (fset 'ediff-make-frame (symbol-function 'make-screen))
+ ;;(fset 'ediff-make-frame-invisible
+ ;; (symbol-function 'make-screen-invisible))
+ (fset 'ediff-raise-frame (symbol-function 'raise-screen))
+ (fset 'ediff-iconify-frame (symbol-function 'iconify-screen))
+ (fset 'ediff-delete-frame (symbol-function 'delete-screen))
+ (fset 'ediff-frame-visible-p (symbol-function 'screen-visible-p))
+ (fset 'ediff-select-frame (symbol-function 'select-screen))
+ (fset 'ediff-selected-frame (symbol-function 'selected-screen))
+ ;;(fset 'ediff-frame-selected-window
+ ;; (symbol-function 'screen-selected-window))
+ (fset 'ediff-frame-parameters (symbol-function 'screen-parameters))
+ ;;(fset 'ediff-frame-pixel-width (symbol-function 'screen-pixel-width))
+ (fset 'ediff-frame-width (symbol-function 'screen-width))
+ (fset 'ediff-modify-frame-parameters
+ (symbol-function 'modify-screen-parameters))
+ (fset 'ediff-frame-live-p (symbol-function 'screen-live-p))
+ (fset 'ediff-window-frame (symbol-function 'window-screen))
+ (if window-system
+ (progn
+ (fset 'ediff-display-color-p (symbol-function 'x-color-display-p))
+ (fset 'ediff-valid-color-p (symbol-function 'x-valid-color-name-p))
+ (fset 'ediff-get-face (symbol-function 'get-face)))))
+ (if window-system
+ (progn
+ (fset 'ediff-make-frame (symbol-function 'make-frame))
+ ;;(fset 'ediff-make-frame-invisible
+ ;; (symbol-function 'make-frame-invisible))
+ (fset 'ediff-raise-frame (symbol-function 'raise-frame))
+ (fset 'ediff-iconify-frame (symbol-function 'iconify-frame))
+ (fset 'ediff-delete-frame (symbol-function 'delete-frame))
+ (fset 'ediff-frame-visible-p (symbol-function 'frame-visible-p))
+ (fset 'ediff-window-frame (symbol-function 'window-frame))
+ (fset 'ediff-select-frame (symbol-function 'select-frame))
+ (fset 'ediff-selected-frame (symbol-function 'selected-frame))
+ ;;(fset 'ediff-frame-selected-window
+ ;; (symbol-function 'frame-selected-window))
+ (fset 'ediff-frame-parameters (symbol-function 'frame-parameters))
+ ;;(fset 'ediff-frame-pixel-width (symbol-function 'frame-pixel-width))
+ (fset 'ediff-frame-width (symbol-function 'frame-width))
+ (fset 'ediff-modify-frame-parameters
+ (symbol-function 'modify-frame-parameters))
+ (fset 'ediff-frame-live-p (symbol-function 'frame-live-p))
+ ))
+
+ (if window-system
+ (progn
+ (fset 'ediff-display-color-p (symbol-function 'x-display-color-p))
+ ;; Temporary fix for OS/2 users
+ ;; pm-win.el in PM-Emacs should be fixed.
+ (if (eq window-system 'pm)
+ (fset 'ediff-valid-color-p
+ (function (lambda (color) (assoc color pm-color-alist))))
+ (fset 'ediff-valid-color-p (symbol-function 'x-color-defined-p)))
+
+ (fset 'ediff-get-face (symbol-function 'internal-get-face))))
+ )
+
+;; not a window system
+(if (not window-system)
+ (progn
+ (fset 'ediff-window-frame (function (lambda (wind) (if wind 1 nil)) ))
+ (fset 'ediff-selected-frame 'selected-window)
+ (fset 'ediff-frame-width 'window-width)
+ (fset 'ediff-make-current-diff-overlay (function (lambda (type) nil)))))
+
+(if (not window-system)
+ ()
+ (defun ediff-set-face (ground face color)
+ "Sets face foreground/background."
+ (if (ediff-valid-color-p color)
+ (if (eq ground 'foreground)
+ (set-face-foreground face color)
+ (set-face-background face color))
+ (cond ((memq face
+ '(ediff-current-diff-face-A
+ ediff-current-diff-face-B
+ ediff-current-diff-face-C))
+ (copy-face 'highlight face))
+ ((memq face
+ '(ediff-fine-diff-face-A
+ ediff-fine-diff-face-B
+ ediff-fine-diff-face-C
+;; ediff-combined-diff-face
+ ))
+ (copy-face 'secondary-selection face)
+ (set-face-underline-p face t))
+ ((memq face
+ '(ediff-even-diff-face-A ediff-odd-diff-face-A
+ ediff-even-diff-face-B ediff-odd-diff-face-B
+ ediff-even-diff-face-C ediff-odd-diff-face-C))
+ (copy-face 'secondary-selection face)))))
+
+ (defvar ediff-current-diff-face-A
+ (progn
+ (make-face 'ediff-current-diff-face-A)
+ (or (face-differs-from-default-p 'ediff-current-diff-face-A)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face
+ 'foreground 'ediff-current-diff-face-A "firebrick")
+ (ediff-set-face
+ 'background 'ediff-current-diff-face-A "pale green"))
+ (t
+ (if ediff-xemacs-p
+ (copy-face 'modeline 'ediff-current-diff-face-A)
+ (copy-face 'highlight 'ediff-current-diff-face-A))
+ )))
+ 'ediff-current-diff-face-A)
+ "Face for highlighting the selected difference in buffer A.")
+
+ (defvar ediff-current-diff-face-B
+ (progn
+ (make-face 'ediff-current-diff-face-B)
+ (or (face-differs-from-default-p 'ediff-current-diff-face-B)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face
+ 'foreground 'ediff-current-diff-face-B "DarkOrchid")
+ (ediff-set-face
+ 'background 'ediff-current-diff-face-B "Yellow"))
+ (t
+ (if ediff-xemacs-p
+ (copy-face 'modeline 'ediff-current-diff-face-B)
+ (copy-face 'highlight 'ediff-current-diff-face-B))
+ )))
+ 'ediff-current-diff-face-B)
+ "Face for highlighting the selected difference in buffer B.")
+
+
+ (defvar ediff-current-diff-face-C
+ (progn
+ (make-face 'ediff-current-diff-face-C)
+ (or (face-differs-from-default-p 'ediff-current-diff-face-C)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face
+ 'foreground 'ediff-current-diff-face-C "Navy")
+ (ediff-set-face
+ 'background 'ediff-current-diff-face-C "Pink"))
+ (t
+ (if ediff-xemacs-p
+ (copy-face 'modeline 'ediff-current-diff-face-C)
+ (copy-face 'highlight 'ediff-current-diff-face-C))
+ )))
+ 'ediff-current-diff-face-C)
+ "Face for highlighting the selected difference in buffer C.")
+
+ (defvar ediff-fine-diff-face-A
+ (progn
+ (make-face 'ediff-fine-diff-face-A)
+ (or (face-differs-from-default-p 'ediff-fine-diff-face-A)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face 'foreground 'ediff-fine-diff-face-A
+ "Navy")
+ (ediff-set-face 'background 'ediff-fine-diff-face-A
+ "sky blue"))
+ (t (set-face-underline-p 'ediff-fine-diff-face-A t))))
+ 'ediff-fine-diff-face-A)
+ "Face for highlighting the refinement of the selected diff in buffer A.")
+
+ (defvar ediff-fine-diff-face-B
+ (progn
+ (make-face 'ediff-fine-diff-face-B)
+ (or (face-differs-from-default-p 'ediff-fine-diff-face-B)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face 'foreground 'ediff-fine-diff-face-B "Black")
+ (ediff-set-face 'background 'ediff-fine-diff-face-B "cyan"))
+ (t (set-face-underline-p 'ediff-fine-diff-face-B t))))
+ 'ediff-fine-diff-face-B)
+ "Face for highlighting the refinement of the selected diff in buffer B.")
+
+ (defvar ediff-fine-diff-face-C
+ (progn
+ (make-face 'ediff-fine-diff-face-C)
+ (or (face-differs-from-default-p 'ediff-fine-diff-face-C)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face 'foreground 'ediff-fine-diff-face-C "black")
+ (ediff-set-face
+ 'background 'ediff-fine-diff-face-C "Turquoise"))
+ (t (set-face-underline-p 'ediff-fine-diff-face-C t))))
+ 'ediff-fine-diff-face-C)
+ "Face for highlighting the refinement of the selected diff in buffer C.")
+
+;; (defvar ediff-combined-diff-face
+;; (progn
+;; (make-face 'ediff-combined-diff-face)
+;; (or (face-differs-from-default-p 'ediff-combined-diff-face)
+;; (cond ((ediff-display-color-p)
+;; (ediff-set-face 'foreground 'ediff-combined-diff-face "black")
+;; (ediff-set-face
+;; 'background 'ediff-combined-diff-face "Plum"))
+;; (t (set-face-underline-p 'ediff-combined-diff-face t))))
+;; 'ediff-combined-diff-face)
+;; "Face for highlighting combined selected diff regions in buffer C.")
+
+ (defvar ediff-even-diff-face-A
+ (progn
+ (make-face 'ediff-even-diff-face-A)
+ (or (face-differs-from-default-p 'ediff-even-diff-face-A)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face
+ 'foreground 'ediff-even-diff-face-A "black")
+ (ediff-set-face
+ 'background 'ediff-even-diff-face-A "light grey"))
+ (t
+ (copy-face 'italic 'ediff-even-diff-face-A))))
+ 'ediff-even-diff-face-A)
+ "Face used to highlight even-numbered differences in buffer A.")
+
+ (defvar ediff-even-diff-face-B
+ (progn
+ (make-face 'ediff-even-diff-face-B)
+ (or (face-differs-from-default-p 'ediff-even-diff-face-B)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face
+ 'foreground 'ediff-even-diff-face-B "White")
+ (ediff-set-face
+ 'background 'ediff-even-diff-face-B "Gray"))
+ (t
+ (copy-face 'italic 'ediff-even-diff-face-B))))
+ 'ediff-even-diff-face-B)
+ "Face used to highlight even-numbered differences in buffer B.")
+
+ (defvar ediff-even-diff-face-C
+ (progn
+ (make-face 'ediff-even-diff-face-C)
+ (copy-face 'ediff-even-diff-face-A 'ediff-even-diff-face-C)
+ 'ediff-even-diff-face-C)
+ "Face used to highlight even-numbered differences in buffer C.")
+
+ (defvar ediff-odd-diff-face-A
+ (progn
+ (make-face 'ediff-odd-diff-face-A)
+ (or (face-differs-from-default-p 'ediff-odd-diff-face-A)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face
+ 'foreground 'ediff-odd-diff-face-A "White")
+ (ediff-set-face
+ 'background 'ediff-odd-diff-face-A "Gray"))
+ (t
+ (copy-face 'italic 'ediff-odd-diff-face-A))))
+ 'ediff-odd-diff-face-A)
+ "Face used to highlight odd-numbered differences in buffer A.")
+
+ (defvar ediff-odd-diff-face-B
+ (progn
+ (make-face 'ediff-odd-diff-face-B)
+ (or (face-differs-from-default-p 'ediff-odd-diff-face-B)
+ (cond ((ediff-display-color-p)
+ (ediff-set-face
+ 'foreground 'ediff-odd-diff-face-B "Black")
+ (ediff-set-face
+ 'background 'ediff-odd-diff-face-B "light grey"))
+ (t
+ (copy-face 'italic 'ediff-odd-diff-face-B))))
+ 'ediff-odd-diff-face-B)
+ "Face used to highlight odd-numbered differences in buffer B.")
+
+ (defvar ediff-odd-diff-face-C
+ (progn
+ (make-face 'ediff-odd-diff-face-C)
+ (copy-face 'ediff-odd-diff-face-A 'ediff-odd-diff-face-C)
+ 'ediff-odd-diff-face-C)
+ "Face used to highlight odd-numbered differences in buffer C.")
+
+ ;; Create *-var faces. These are the actual faces used to highlight
+ ;; odd-numbered difference regions.
+ ;; They are used as follows: when highlighting is turned on,
+ ;; ediff-odd/even-diff-face-A/B/C are copied
+ ;; into ediff-odd/even-diff-face-A/B/C-var, and all odd/even overlays become
+ ;; highlighted. When highlighting is turned off, then the face 'default is
+ ;; copied into ediff-odd/even-diff-face-A/B/C-var, thereby unhighlighting all
+ ;; difference regions.
+ (make-face 'ediff-even-diff-face-A-var)
+ (make-face 'ediff-even-diff-face-B-var)
+ (make-face 'ediff-even-diff-face-C-var)
+ (make-face 'ediff-odd-diff-face-A-var)
+ (make-face 'ediff-odd-diff-face-B-var)
+ (make-face 'ediff-odd-diff-face-C-var)
+
+ ;; initialize *-var faces
+ (defun ediff-init-var-faces ()
+ (copy-face (if (and ediff-use-faces ediff-highlight-all-diffs)
+ ediff-even-diff-face-A 'default)
+ 'ediff-even-diff-face-A-var)
+ (copy-face (if (and ediff-use-faces ediff-highlight-all-diffs)
+ ediff-even-diff-face-B 'default)
+ 'ediff-even-diff-face-B-var)
+ (copy-face (if (and ediff-use-faces ediff-highlight-all-diffs)
+ ediff-even-diff-face-C 'default)
+ 'ediff-even-diff-face-C-var)
+ (copy-face (if (and ediff-use-faces ediff-highlight-all-diffs)
+ ediff-odd-diff-face-A 'default)
+ 'ediff-odd-diff-face-A-var)
+ (copy-face (if (and ediff-use-faces ediff-highlight-all-diffs)
+ ediff-odd-diff-face-B 'default)
+ 'ediff-odd-diff-face-B-var)
+ (copy-face (if (and ediff-use-faces ediff-highlight-all-diffs)
+ ediff-odd-diff-face-C 'default)
+ 'ediff-odd-diff-face-C-var)
+ )
+
+
+;;; Overlays
+
+ (ediff-defvar-local ediff-current-diff-overlay-A nil
+ "Overlay for the current difference region in buffer A.")
+ (ediff-defvar-local ediff-current-diff-overlay-B nil
+ "Overlay for the current difference region in buffer B.")
+ (ediff-defvar-local ediff-current-diff-overlay-C nil
+ "Overlay for the current difference region in buffer C.")
+
+ (defun ediff-make-current-diff-overlay (type)
+ (let ((overlay (intern (format "ediff-current-diff-overlay-%S" type)))
+ (buffer (ediff-get-buffer type))
+ (face (face-name
+ (symbol-value
+ (intern (format "ediff-current-diff-face-%S" type))))))
+ (set overlay
+ (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer))
+ (ediff-overlay-put (symbol-value overlay) 'face face)
+ (ediff-overlay-put (symbol-value overlay) 'ediff ediff-control-buffer)
+ ))
+
+ ;; Compute priority of ediff overlay.
+ (defun ediff-highest-priority (start end buffer)
+ (let ((pos (max 1 (1- start)))
+ ovr-list)
+ (if ediff-xemacs-p
+ (1+ ediff-shadow-overlay-priority)
+ (ediff-eval-in-buffer buffer
+ (while (< pos (min (point-max) (1+ end)))
+ (setq ovr-list (append (overlays-at pos) ovr-list))
+ (setq pos (next-overlay-change pos)))
+ (1+ (apply '+
+ (mapcar (function
+ (lambda (ovr)
+ (if ovr
+ (or (ediff-overlay-get ovr 'priority) 0)
+ 0)))
+ ovr-list)
+ ))
+ ))))
+
+) ; end of window-system-only code.
+
+
+(defvar ediff-toggle-read-only-function nil
+ "*Specifies the function to be used to toggle read-only.
+If nil, Ediff tries to deduce the function from the binding of C-x C-q.
+Normally, this is the `toggle-read-only' function, but, if version
+control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
+
+(ediff-defvar-local ediff-file-checked-out-flag nil
+ "If t, indicates that buffer has been already checked out.")
+
+
+
+;;; Misc
+
+;; when emacs will have before/after-string in overlays, this variable will
+;; be deleted
+(defconst ediff-saved-variables
+ '(;;buffer-read-only
+ buffer-auto-save-file-name)
+ "Buffer-local variables saved and restored during an Ediff session.")
+
+;; to be deleted in due time
+(defconst ediff-working-values '(nil)
+ "Values to be assigned to `ediff-saved-variables' during diff.")
+
+;; if nil, this silences some messages
+(defconst ediff-verbose-p t)
+
+(defvar ediff-no-emacs-help-in-control-buffer nil
+ "*Non-nil means C-h should not invoke Emacs help in control buffer.
+Instead, C-h jumps to previous difference.")
+
+(defvar ediff-temp-file-prefix
+ (let ((env (or (getenv "TMPDIR")
+ (getenv "TMP")
+ (getenv "TEMP")))
+ d)
+ (setq d (if (and env (> (length env) 0))
+ env
+ (if (memq system-type '(vax-vms axp-vms))
+ "SYS$SCRATCH:"
+ "/tmp")))
+ ;; The following is to make sure we get something to which we can
+ ;; add directory levels on VMS.
+ (setq d (file-name-as-directory (directory-file-name d)))
+ ;;(concat d "ediff")
+ )
+ "*Prefix to put on Ediff temporary file names.
+Do not start with `~/' or `~user-name/'.")
+
+(defvar ediff-temp-file-mode 384 ; u=rw only
+ "*Mode for Ediff temporary files.")
+
+;; Metacharacters that have to be protected from the shell when executing
+;; a diff/diff3 command.
+(defvar ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
+ "Characters that must be quoted with \\ when used in a shell command line.
+More precisely, a regexp to match any one such character.")
+
+
+(ediff-defvar-local ediff-temp-file-A nil
+ "Temporary file used for refining difference regions in buffer A.")
+(ediff-defvar-local ediff-temp-file-B nil
+ "Temporary file used for refining difference regions in buffer B.")
+(ediff-defvar-local ediff-temp-file-C nil
+ "Temporary file used for refining difference regions in buffer C.")
+
+;;; In-line functions
+
+(defsubst ediff-file-remote-p (file-name)
+ (if (fboundp ediff-ange-ftp-ftp-name)
+ (funcall ediff-ange-ftp-ftp-name file-name)))
+
+(defsubst ediff-frame-has-menubar ()
+ (and window-system
+ (if ediff-xemacs-p
+ current-menubar
+ (let ((lines (cdr (assq 'menu-bar-lines
+ (frame-parameters (ediff-selected-frame))))))
+ (or (eq lines t) (and (numberp lines) (< 0 lines))))
+ )))
+
+(defsubst ediff-frame-unsplittable-p (frame)
+ (cdr (assq 'unsplittable (ediff-frame-parameters frame))))
+
+(defsubst ediff-get-next-window (wind prev-wind)
+ (or (window-live-p wind)
+ (setq wind (if prev-wind
+ (next-window wind)
+ (selected-window)))))
+
+(defsubst ediff-convert-diffs-to-overlays (diff-list)
+ (ediff-set-diff-overlays-in-one-buffer 'A diff-list)
+ (ediff-set-diff-overlays-in-one-buffer 'B diff-list)
+ (if ediff-3way-job
+ (ediff-set-diff-overlays-in-one-buffer 'C diff-list))
+ (message "Processing difference regions ... done"))
+
+
+(defsubst ediff-kill-buffer-carefully (buf)
+ "Kill buffer BUF if it exists."
+ (if (ediff-buffer-live-p buf)
+ (kill-buffer (get-buffer buf))))
+
+
+(defsubst ediff-highlight-diff (n)
+ "Put face on diff N. Invoked for X displays only."
+ (ediff-highlight-diff-in-one-buffer n 'A)
+ (ediff-highlight-diff-in-one-buffer n 'B)
+ (ediff-highlight-diff-in-one-buffer n 'C))
+
+
+(defsubst ediff-unhighlight-diff ()
+ "Remove overlays from buffers A, B, and C."
+ (ediff-unhighlight-diff-in-one-buffer 'A)
+ (ediff-unhighlight-diff-in-one-buffer 'B)
+ (ediff-unhighlight-diff-in-one-buffer 'C))
+
+;; delete highlighting overlays, restore faces to their original form
+(defsubst ediff-unhighlight-diffs-totally ()
+ (ediff-unhighlight-diffs-totally-in-one-buffer 'A)
+ (ediff-unhighlight-diffs-totally-in-one-buffer 'B)
+ (ediff-unhighlight-diffs-totally-in-one-buffer 'C))
+
+
+;; arg is a record for a given diff in a difference vector
+;; this record is itself a vector
+(defsubst ediff-clear-fine-diff-vector (diff-record)
+ (if diff-record
+ (mapcar 'ediff-delete-overlay
+ (ediff-get-fine-diff-vector-from-diff-record diff-record))))
+
+(defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
+ (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
+ (ediff-set-fine-diff-vector n buf-type nil))
+
+(defsubst ediff-clear-fine-differences (n)
+ (ediff-clear-fine-differences-in-one-buffer n 'A)
+ (ediff-clear-fine-differences-in-one-buffer n 'B)
+ (if ediff-3way-job
+ (ediff-clear-fine-differences-in-one-buffer n 'C)))
+
+
+(defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num)
+ (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num)
+ (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num)
+ (if ediff-3way-job
+ (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num)
+ ))
+
+(defsubst ediff-mouse-event-p (event)
+ (if ediff-xemacs-p
+ (button-event-p event)
+ (string-match "mouse" (format "%S" (event-basic-type event)))
+ ))
+
+(defsubst ediff-frame-iconified-p (frame)
+ (if (and window-system (ediff-frame-live-p frame))
+ (if ediff-xemacs-p
+ (screen-iconified-p frame)
+ (eq (frame-visible-p frame) 'icon))))
+
+(defsubst ediff-window-visible-p (wind)
+ (and (window-live-p wind)
+ ;; under non-wondow system, window-live-p also means window is visible
+ (or (not window-system)
+ (ediff-frame-visible-p (ediff-window-frame wind)))))
+
+
+(defsubst ediff-frame-char-width (frame)
+ (if ediff-xemacs-p
+ (/ (screen-pixel-width frame) (screen-width frame))
+ (frame-char-width frame)))
+
+(defsubst ediff-frame-char-height (frame)
+ (if ediff-xemacs-p
+ (/ (screen-pixel-height frame) (screen-height frame))
+ (frame-char-height frame)))
+
+
+(defsubst ediff-empty-overlay-p (overl)
+ (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
+
+;; t if diff region is empty.
+;; In case of buffer C, t also if it is not a 3way
+;; comparison job (merging jobs return t as well).
+(defun ediff-empty-diff-region-p (n buf-type)
+ (if (eq buf-type 'C)
+ (or (not ediff-3way-comparison-job)
+ (= (ediff-get-diff-posn 'C 'beg n)
+ (ediff-get-diff-posn 'C 'end n)))
+ (= (ediff-get-diff-posn buf-type 'beg n)
+ (ediff-get-diff-posn buf-type 'end n))))
+
+;; Test if diff region is white space only.
+;; If 2-way job and buf-type = C, then returns t.
+(defun ediff-whitespace-diff-region-p (n buf-type)
+ (or (and (eq buf-type 'C) (not ediff-3way-job))
+ (let ((beg (ediff-get-diff-posn buf-type 'beg n))
+ (end (ediff-get-diff-posn buf-type 'end n)))
+ (ediff-eval-in-buffer (ediff-get-buffer buf-type)
+ (save-excursion
+ (goto-char beg)
+ (skip-chars-forward ediff-whitespace)
+ (>= (point) end))))))
+
+;; temporarily uses DIR to abbreviate file name
+;; if DIR is nil, use default-directory
+(defsubst ediff-abbreviate-filename (file dir)
+ (let* ((dir (or dir default-directory))
+ (directory-abbrev-alist (list (cons dir ""))))
+ (abbreviate-file-name file)))
+
+(defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
+ (ediff-eval-in-buffer
+ (ediff-eval-in-buffer ctrl-buf (ediff-get-buffer buf-type))
+ (buffer-substring
+ (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf))
+ (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf)))))
+
+;; If ediff modified mode line, strip the modification
+(defsubst ediff-strip-mode-line-format ()
+ (if (member (car mode-line-format) '(" A: " " B: " " C: "))
+ (setq mode-line-format (nth 2 mode-line-format))))
+
+;; Verify that we have a difference selected.
+(defsubst ediff-valid-difference-p (&optional n)
+ (or n (setq n ediff-current-difference))
+ (and (>= n 0) (< n ediff-number-of-differences)))
+
+(defsubst ediff-show-all-diffs (n)
+ "Don't skip difference regions."
+ nil)
+
+(provide 'ediff-init)
+
+
+;;; ediff-init.el ends here
diff --git a/lisp/ediff-merg.el b/lisp/ediff-merg.el
new file mode 100644
index 00000000000..92235b640dc
--- /dev/null
+++ b/lisp/ediff-merg.el
@@ -0,0 +1,259 @@
+;;; ediff-merg.el --- merging utilities
+;;; Copyright (C) 1994 Free Software Foundation, Inc.
+
+;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+(require 'ediff-init)
+
+
+(defvar ediff-default-variant 'default-A
+ "*The variant to be used as a default for buffer C in merging.
+Valid values are the symbols `default-A', `default-B', and `combined'.")
+
+(defvar ediff-combination-pattern
+ '("#ifdef NEW /* variant A */" "#else /* variant B */" "#endif /* NEW */")
+ "*Pattern to be used for combining difference regions in buffers A and B.
+The value is (STRING1 STRING2 STRING3). The combined text will look like this:
+
+STRING1
+diff region from variant A
+STRING2
+diff region from variant B
+STRING3
+")
+
+(ediff-defvar-local ediff-show-clashes-only nil
+ "*If t, show only those diff regions where both buffers disagree with the ancestor.
+This means that regions that have status prefer-A or prefer-B will be
+skiped over. Nil means show all regions.")
+
+
+(defsubst ediff-get-combined-region (n)
+ (concat (nth 0 ediff-combination-pattern) "\n"
+ (ediff-get-region-contents n 'A ediff-control-buffer)
+ (nth 1 ediff-combination-pattern) "\n"
+ (ediff-get-region-contents n 'B ediff-control-buffer)
+ (nth 2 ediff-combination-pattern) "\n"))
+
+(defsubst ediff-set-state-of-all-diffs-in-all-buffers (ctl-buf)
+ (let ((n 0))
+ (while (< n ediff-number-of-differences)
+ (ediff-set-state-of-diff-in-all-buffers n ctl-buf)
+ (setq n (1+ n)))))
+
+(defun ediff-set-state-of-diff-in-all-buffers (n ctl-buf)
+ (let ((regA (ediff-get-region-contents n 'A ctl-buf))
+ (regB (ediff-get-region-contents n 'B ctl-buf))
+ (regC (ediff-get-region-contents n 'C ctl-buf)))
+ (cond ((string= regA regB)
+ (ediff-set-state-of-diff n 'A "=diff(B)")
+ (ediff-set-state-of-diff n 'B "=diff(A)")
+ (ediff-set-state-of-diff n 'C nil))
+ ((string= regA regC)
+ (ediff-set-state-of-diff n 'A "=diff(C)")
+ (ediff-set-state-of-diff n 'C "=diff(A)")
+ (ediff-set-state-of-diff n 'B nil))
+ ((string= regB regC)
+ (ediff-set-state-of-diff n 'C "=diff(B)")
+ (ediff-set-state-of-diff n 'B "=diff(C)")
+ (ediff-set-state-of-diff n 'A nil))
+ ((string= regC (ediff-get-combined-region n))
+ (ediff-set-state-of-diff n 'A nil)
+ (ediff-set-state-of-diff n 'B nil)
+ (ediff-set-state-of-diff n 'C "=diff(A+B)"))
+ (t (ediff-set-state-of-diff n 'A nil)
+ (ediff-set-state-of-diff n 'B nil)
+ (ediff-set-state-of-diff n 'C nil)))
+ ))
+
+;; Go over all diffs starting with DIFF-NUM and copy regions into buffer C
+;; according to the state of the difference.
+;; Since ediff-copy-diff refuses to copy identical diff regions, there is
+;; no need to optimize ediff-do-merge any further.
+;;
+;; If re-merging, change state of merge in all diffs starting with
+;; DIFF-NUM, except those where the state is prefer-* or where it is
+;; default-* but the region appears to be modified with respect to its
+;; original form.
+;; Also, prevent copying when there is a danger of overriding a modified
+;; region in buffer C.
+(defun ediff-do-merge (diff-num &optional remerging)
+ (if (< diff-num 0) (setq diff-num 0))
+ (let ((n diff-num)
+ (default-state-of-merge (format "%S" ediff-default-variant))
+ do-not-copy
+ state-of-merge)
+
+ (while (< n ediff-number-of-differences)
+
+ (if (= (mod n 10) 0)
+ (message "%s buffers A & B into C ... region %d of %d"
+ (if remerging "Re-merging" "Merging")
+ n
+ ediff-number-of-differences))
+
+ (setq state-of-merge (ediff-get-state-of-merge n))
+ (setq do-not-copy (string= state-of-merge default-state-of-merge))
+
+ (if remerging
+ (let ((reg-A (ediff-get-region-contents n 'A ediff-control-buffer))
+ (reg-B (ediff-get-region-contents n 'B ediff-control-buffer))
+ (reg-C (ediff-get-region-contents n 'C ediff-control-buffer)))
+
+ (if (or
+ ;; has been edited since it was first set by default
+ (and (string= state-of-merge "default-A")
+ (not (string= reg-A reg-C)))
+ ;; has been edited since first set by default
+ (and (string= state-of-merge "default-B")
+ (not (string= reg-B reg-C)))
+ ;; was prefered--ignore
+ (string-match "prefer" state-of-merge)
+ ;; was combined--ignore
+ (string= state-of-merge "combined"))
+
+ (setq do-not-copy t))
+
+ ;; change state of merge for this diff, if necessary
+ (if (and (string-match "default" state-of-merge) (not do-not-copy))
+ (ediff-set-state-of-merge
+ n (format "%S" ediff-default-variant)))
+ ))
+
+ ;; state-of-merge may have changed via ediff-set-state-of-merge, so
+ ;; check it out again
+ (setq state-of-merge (ediff-get-state-of-merge n))
+
+ (or do-not-copy
+ (if (string= state-of-merge "combined")
+ ;; use n+1 because ediff-combine-diffs works via user numbering
+ ;; of diffs, which is 1+ to what ediff uses internally
+ (ediff-combine-diffs (1+ n) 'batch)
+ (ediff-copy-diff n
+ (if (string-match "-A" state-of-merge) 'A 'B)
+ 'C
+ 'batch)))
+ (setq n (1+ n)))
+ (message "Merging buffers A & B into C ... Done")
+ ))
+
+
+(defun ediff-re-merge ()
+ "Remerge unmodified diff regions using a new default. Start with the current region."
+ (interactive)
+ (let* ((default-variant-alist
+ (list '("default-A") '("default-B") '("combined")))
+ (actual-alist
+ (delete (list (symbol-name ediff-default-variant))
+ default-variant-alist)))
+ (setq ediff-default-variant
+ (intern
+ (completing-read
+ (format "Current merge default is `%S'. New default: "
+ ediff-default-variant)
+ actual-alist nil 'must-match)))
+ (ediff-do-merge ediff-current-difference 'remerge)
+ (ediff-recenter)
+ ))
+
+(defun ediff-shrink-window-C (arg)
+ "Shrink window C to just one line.
+With a prefix argument, returns window C to its normal size.
+Used only for merging jobs."
+ (interactive "P")
+ (if (not ediff-merge-job)
+ (error "ediff-shrink-window-C can be used only for merging jobs"))
+ (cond ((eq arg '-) (setq arg -1))
+ ((not (numberp arg)) (setq arg nil)))
+ (cond ((null arg)
+ (let ((ediff-merge-window-share
+ (if (< (window-height ediff-window-C) 3)
+ ediff-merge-window-share 0)))
+ (setq ediff-window-config-saved "") ; force redisplay
+ (ediff-recenter 'no-rehighlight)))
+ ((and (< arg 0) (> (window-height ediff-window-C) 2))
+ (setq ediff-merge-window-share (* ediff-merge-window-share 0.9))
+ (setq ediff-window-config-saved "") ; force redisplay
+ (ediff-recenter 'no-rehighlight))
+ ((and (> arg 0) (> (window-height ediff-window-A) 2))
+ (setq ediff-merge-window-share (* ediff-merge-window-share 1.1))
+ (setq ediff-window-config-saved "") ; force redisplay
+ (ediff-recenter 'no-rehighlight))))
+
+
+;; N here is the user's region number. It is 1+ what Ediff uses internally.
+(defun ediff-combine-diffs (n &optional batch-invocation)
+ "Combine Nth diff regions of buffers A and B and place the combination in C.
+Combining is done using the list in variable `ediff-combination-pattern'."
+ (interactive "P")
+ (setq n (if n (1- n) ediff-current-difference))
+
+ (let (regA regB reg-combined)
+ (setq regA (ediff-get-region-contents n 'A ediff-control-buffer)
+ regB (ediff-get-region-contents n 'B ediff-control-buffer))
+
+ (setq reg-combined (concat (nth 0 ediff-combination-pattern) "\n"
+ regA
+ (nth 1 ediff-combination-pattern) "\n"
+ regB
+ (nth 2 ediff-combination-pattern) "\n"))
+
+ (ediff-copy-diff n nil 'C batch-invocation reg-combined))
+
+ (or batch-invocation
+ (ediff-recenter 'no-rehighlight)))
+
+
+;; Checks if the region in buff C looks like a combination of the regions
+;; in buffers A and B. Returns a list (reg-a-beg reg-a-end reg-b-beg reg-b-end)
+;; These refer to where the copies of region A and B start and end in buffer C
+(defun ediff-looks-like-combined-merge (region-num)
+ (if ediff-merge-job
+ (let ((combined (string-match (regexp-quote "(A+B)")
+ (or (ediff-get-state-of-diff region-num 'C)
+ "")))
+ (reg-beg (ediff-get-diff-posn 'C 'beg region-num))
+ (reg-end (ediff-get-diff-posn 'C 'end region-num))
+ (pat1 (nth 0 ediff-combination-pattern))
+ (pat2 (nth 1 ediff-combination-pattern))
+ (pat3 (nth 2 ediff-combination-pattern))
+ reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end)
+
+ (if combined
+ (ediff-eval-in-buffer ediff-buffer-C
+ (goto-char reg-beg)
+ (search-forward pat1 reg-end 'noerror)
+ (setq reg-a-beg (match-beginning 0))
+ (setq reg-a-end (match-end 0))
+ (search-forward pat2 reg-end 'noerror)
+ (setq reg-b-beg (match-beginning 0))
+ (setq reg-b-end (match-end 0))
+ (search-forward pat3 reg-end 'noerror)
+ (setq reg-c-beg (match-beginning 0))
+ (setq reg-c-end (match-end 0))))
+
+ (if (and reg-a-beg reg-a-end reg-b-beg reg-b-end)
+ (list reg-a-beg reg-a-end reg-b-beg reg-b-end reg-c-beg reg-c-end))
+ )))
+
+
+(provide 'ediff-merg)
+
+;; ediff-merg.el ends here
diff --git a/lisp/ediff-util.el b/lisp/ediff-util.el
new file mode 100644
index 00000000000..ba02bc1588f
--- /dev/null
+++ b/lisp/ediff-util.el
@@ -0,0 +1,3398 @@
+;;; ediff-util.el --- the core commands and utilities of ediff
+;;; Copyright (C) 1994 Free Software Foundation, Inc.
+
+;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+;;; Code:
+
+(require 'ediff-init)
+
+
+;;; Functions
+
+(defun ediff-mode ()
+ "Ediff mode is used by the Ediff file-difference package.
+It is entered only through one of the following commands:
+ `ediff'
+ `ediff-files'
+ `ediff-buffers'
+ `ediff3'
+ `ediff-files3'
+ `ediff-buffers3'
+ `ediff-merge'
+ `ediff-merge-files'
+ `ediff-merge-files-with-ancestor'
+ `ediff-merge-buffers'
+ `ediff-merge-buffers-with-ancestor'
+ `ediff-merge-revisions'
+ `ediff-merge-revisions-with-ancestor'
+ `ediff-windows'
+ `ediff-small-regions'
+ `ediff-large-regions'
+ `epatch'
+ `ediff-patch-file'
+ `ediff-patch-buffer'
+ `epatch-buffer'
+ `ediff-revision'
+
+Commands:
+\\{ediff-mode-map}"
+ (kill-all-local-variables)
+ (setq major-mode 'ediff-mode)
+ (setq mode-name "Ediff")
+ (run-hooks 'ediff-mode-hooks))
+
+(defun ediff-version ()
+ "Return string describing the version of Ediff.
+When called interactively, displays the version."
+ (interactive)
+ (if (interactive-p)
+ (message (ediff-version))
+ (format "Ediff %s of %s" ediff-version ediff-date)))
+
+
+(require 'ediff-diff)
+(require 'ediff-merg)
+
+
+;;; Build keymaps
+
+(ediff-defvar-local ediff-mode-map nil
+ "Local keymap used in Ediff mode.
+This is local to each Ediff Control Panel, so they may vary from invocation
+to invocation.")
+
+;; Set up the keymap in the control buffer
+(defun ediff-set-keys ()
+ "Set up Ediff keymap, if necessary."
+ (if (null ediff-mode-map)
+ (ediff-setup-keymap))
+ (use-local-map ediff-mode-map))
+
+;; Reload Ediff keymap. For debugging only.
+(defun ediff-reload-keymap ()
+ (interactive)
+ (setq ediff-mode-map nil)
+ (ediff-set-keys))
+
+
+(defun ediff-setup-keymap ()
+ "Set up the keymap used in the control buffer of Ediff."
+ (setq ediff-mode-map (make-sparse-keymap))
+ (suppress-keymap ediff-mode-map)
+
+ (define-key ediff-mode-map "p" 'ediff-previous-difference)
+ (define-key ediff-mode-map "\C-?" 'ediff-previous-difference)
+ (define-key ediff-mode-map [backspace] 'ediff-previous-difference)
+ (define-key ediff-mode-map [delete] 'ediff-previous-difference)
+ (define-key ediff-mode-map "\C-h" (if ediff-no-emacs-help-in-control-buffer
+ 'ediff-previous-difference nil))
+ (define-key ediff-mode-map "n" 'ediff-next-difference)
+ (define-key ediff-mode-map " " 'ediff-next-difference)
+ (define-key ediff-mode-map "j" 'ediff-jump-to-difference)
+ (define-key ediff-mode-map "g" nil)
+ (define-key ediff-mode-map "ga" 'ediff-jump-to-difference-at-point)
+ (define-key ediff-mode-map "gb" 'ediff-jump-to-difference-at-point)
+ (define-key ediff-mode-map "q" 'ediff-quit)
+ (define-key ediff-mode-map "z" 'ediff-suspend)
+ (define-key ediff-mode-map "\C-l" 'ediff-recenter)
+ (define-key ediff-mode-map "|" 'ediff-toggle-split)
+ (define-key ediff-mode-map "h" 'ediff-toggle-hilit)
+ (or ediff-word-mode
+ (define-key ediff-mode-map "@" 'ediff-toggle-autorefine))
+ (if ediff-word-mode-job
+ (define-key ediff-mode-map "%" 'ediff-toggle-narrow-region))
+ (define-key ediff-mode-map "~" 'ediff-swap-buffers)
+ (define-key ediff-mode-map "v" 'ediff-scroll-vertically)
+ (define-key ediff-mode-map "\C-v" 'ediff-scroll-vertically)
+ (define-key ediff-mode-map "^" 'ediff-scroll-vertically)
+ (define-key ediff-mode-map "\M-v" 'ediff-scroll-vertically)
+ (define-key ediff-mode-map "V" 'ediff-scroll-vertically)
+ (define-key ediff-mode-map "<" 'ediff-scroll-horizontally)
+ (define-key ediff-mode-map ">" 'ediff-scroll-horizontally)
+ (define-key ediff-mode-map "i" 'ediff-status-info)
+ (define-key ediff-mode-map "?" 'ediff-toggle-help)
+ (define-key ediff-mode-map "!" 'ediff-update-diffs)
+ (or ediff-word-mode
+ (define-key ediff-mode-map "*" 'ediff-make-or-kill-fine-diffs))
+ (define-key ediff-mode-map "a" nil)
+ (define-key ediff-mode-map "b" nil)
+ (define-key ediff-mode-map "r" nil)
+ (cond (ediff-merge-job
+ ;; In merging, we allow only A->C and B->C copying.
+ (define-key ediff-mode-map "a" (function
+ (lambda (arg)
+ (interactive "P")
+ (ediff-diff-to-diff arg "ac"))))
+ (define-key ediff-mode-map "b" (function
+ (lambda (arg)
+ (interactive "P")
+ (ediff-diff-to-diff arg "bc"))))
+ (define-key ediff-mode-map "r" (function
+ (lambda (arg)
+ (interactive "P")
+ (ediff-restore-diff arg ?c))))
+ (define-key ediff-mode-map "s" 'ediff-shrink-window-C)
+ (define-key ediff-mode-map "+" 'ediff-combine-diffs)
+ (define-key ediff-mode-map "$" 'ediff-toggle-show-clashes-only)
+ (define-key ediff-mode-map "&" 'ediff-re-merge))
+ (ediff-3way-comparison-job
+ (define-key ediff-mode-map "ab" 'ediff-diff-to-diff)
+ (define-key ediff-mode-map "ba" 'ediff-diff-to-diff)
+ (define-key ediff-mode-map "ac" 'ediff-diff-to-diff)
+ (define-key ediff-mode-map "bc" 'ediff-diff-to-diff)
+ (define-key ediff-mode-map "c" nil)
+ (define-key ediff-mode-map "ca" 'ediff-diff-to-diff)
+ (define-key ediff-mode-map "cb" 'ediff-diff-to-diff)
+ (define-key ediff-mode-map "ra" 'ediff-restore-diff)
+ (define-key ediff-mode-map "rb" 'ediff-restore-diff)
+ (define-key ediff-mode-map "rc" 'ediff-restore-diff)
+ (define-key ediff-mode-map "C" 'ediff-toggle-read-only))
+ (t ; 2-way comparison
+ (define-key ediff-mode-map "a" (function
+ (lambda (arg)
+ (interactive "P")
+ (ediff-diff-to-diff arg "ab"))))
+ (define-key ediff-mode-map "b" (function
+ (lambda (arg)
+ (interactive "P")
+ (ediff-diff-to-diff arg "ba"))))
+ (define-key ediff-mode-map "ra" 'ediff-restore-diff)
+ (define-key ediff-mode-map "rb" 'ediff-restore-diff))
+ ) ; cond
+ (define-key ediff-mode-map "G" 'ediff-submit-report)
+ (define-key ediff-mode-map "#" nil)
+ (define-key ediff-mode-map "#h" 'ediff-toggle-regexp-match)
+ (define-key ediff-mode-map "#f" 'ediff-toggle-regexp-match)
+ (or ediff-word-mode
+ (define-key ediff-mode-map "##" 'ediff-toggle-skip-similar))
+ (define-key ediff-mode-map "o" nil)
+ (define-key ediff-mode-map "A" 'ediff-toggle-read-only)
+ (define-key ediff-mode-map "B" 'ediff-toggle-read-only)
+ (define-key ediff-mode-map "w" nil)
+ (define-key ediff-mode-map "wa" 'ediff-save-buffer)
+ (define-key ediff-mode-map "wb" 'ediff-save-buffer)
+ (define-key ediff-mode-map "wd" 'ediff-save-buffer)
+ (if ediff-3way-job
+ (progn
+ (define-key ediff-mode-map "wc" 'ediff-save-buffer)
+ (define-key ediff-mode-map "gc" 'ediff-jump-to-difference-at-point)
+ ))
+
+ (define-key ediff-mode-map "m" 'ediff-toggle-wide-display)
+
+ (define-key ediff-mode-map "k" nil)
+ (define-key ediff-mode-map "kkk" 'ediff-reload-keymap) ; for debugging
+
+ ;; Allow ediff-mode-map to be referenced indirectly
+ (fset 'ediff-mode-map ediff-mode-map)
+ (run-hooks 'ediff-keymap-setup-hooks))
+
+
+;;; Setup functions
+
+(require 'ediff-wind)
+
+;; Common startup entry for all Ediff functions
+(defun ediff-setup (buffer-A file-A buffer-B file-B buffer-C file-C
+ startup-hooks setup-parameters)
+ (setq file-A (expand-file-name file-A))
+ (setq file-B (expand-file-name file-B))
+ (if (stringp file-C)
+ (setq file-C (expand-file-name file-C)))
+ (let* ((control-buffer-name
+ (ediff-unique-buffer-name "*Ediff Control Panel" "*"))
+ (control-buffer (ediff-eval-in-buffer buffer-A
+ (get-buffer-create control-buffer-name))))
+ (ediff-eval-in-buffer control-buffer
+ (ediff-mode)
+
+ ;; unwrap set up parameters passed as argument
+ (while setup-parameters
+ (set (car (car setup-parameters)) (cdr (car setup-parameters)))
+ (setq setup-parameters (cdr setup-parameters)))
+
+ ;; set variables classifying the current ediff job
+ (setq ediff-3way-comparison-job (ediff-3way-comparison-job)
+ ediff-merge-job (ediff-merge-job)
+ ediff-merge-with-ancestor-job (ediff-merge-with-ancestor-job)
+ ediff-3way-job (ediff-3way-job)
+ ediff-diff3-job (ediff-diff3-job)
+ ediff-word-mode-job (ediff-word-mode-job))
+
+ (make-local-variable 'ediff-prefer-long-help-message)
+ (make-local-variable 'ediff-prefer-iconified-control-frame)
+ (make-local-variable 'ediff-split-window-function)
+ (make-local-variable 'ediff-default-variant)
+ (make-local-variable 'ediff-merge-window-share)
+
+ ;; adjust for merge jobs
+ (if ediff-merge-job
+ (let ((buf
+ ;; Use buf A even if `combined'. The right stuff is
+ ;; inserted by ediff-do-merge
+ (if (eq ediff-default-variant 'default-B) buffer-B buffer-A)))
+
+ (setq ediff-split-window-function
+ ediff-merge-split-window-function)
+
+ ;; remember the ancestor buffer, if any
+ (setq ediff-ancestor-buffer buffer-C)
+
+ (setq buffer-C
+ (get-buffer-create
+ (ediff-unique-buffer-name "*ediff-merge" "*")))
+ (save-excursion
+ (set-buffer buffer-C)
+ (insert-buffer buf))))
+ (setq buffer-read-only nil
+ ediff-buffer-A buffer-A
+ ediff-buffer-B buffer-B
+ ediff-buffer-C buffer-C
+ ediff-control-buffer control-buffer)
+
+ (setq ediff-control-buffer-suffix
+ (if (string-match "<[0-9]*>" control-buffer-name)
+ (substring control-buffer-name
+ (match-beginning 0) (match-end 0))
+ "")
+ ediff-control-buffer-number
+ (max
+ 0
+ (1-
+ (string-to-number
+ (substring
+ ediff-control-buffer-suffix
+ (or
+ (string-match "[0-9]+" ediff-control-buffer-suffix)
+ 0))))))
+
+ (setq ediff-error-buffer (get-buffer-create (ediff-unique-buffer-name
+ "*ediff-errors" "*")))
+
+ (ediff-eval-in-buffer buffer-A (ediff-strip-mode-line-format))
+ (ediff-eval-in-buffer buffer-B (ediff-strip-mode-line-format))
+ (if ediff-3way-job
+ (ediff-eval-in-buffer buffer-C (ediff-strip-mode-line-format)))
+
+ (ediff-save-protected-variables) ; save variables to be restored on exit
+
+ ;; This will be deleted when emacs gets before/after strings
+ (ediff-remember-buffer-characteristics t) ; remember at setup
+
+ ;; ediff-setup-diff-regions-function must be set after setup
+ ;; parameters are processed.
+ (setq ediff-setup-diff-regions-function
+ (if ediff-diff3-job
+ 'ediff-setup-diff-regions3
+ 'ediff-setup-diff-regions))
+
+ (if ediff-xemacs-p
+ ()
+ (make-local-variable 'default-minibuffer-frame))
+
+ (setq ediff-wide-bounds
+ (list (ediff-make-bullet-proof-overlay
+ '(point-min) '(point-max) ediff-buffer-A)
+ (ediff-make-bullet-proof-overlay
+ '(point-min) '(point-max) ediff-buffer-B)
+ (ediff-make-bullet-proof-overlay
+ '(point-min) '(point-max) ediff-buffer-C)))
+
+ ;; This has effect only on ediff-windows/regions
+ ;; In all other cases, ediff-visible-region sets visibility bounds to
+ ;; ediff-wide-bounds, and ediff-narrow-bounds are ignored.
+ (if ediff-start-narrowed
+ (setq ediff-visible-bounds ediff-narrow-bounds)
+ (setq ediff-visible-bounds ediff-wide-bounds))
+
+ (ediff-set-keys) ; comes after parameter setup
+
+ ;; set up ediff-narrow-bounds, if not set
+ (or ediff-narrow-bounds
+ (setq ediff-narrow-bounds ediff-wide-bounds))
+
+ ;; The following will go away once before/after-string overlay
+ ;; properties are added to emacs 19. The only thing that will remain
+ ;; are the calls to ediff-prepare-buffer-hooks, nuking the selective
+ ;; display, and setting files A/B r/o for merge.
+
+ ;; All these must be inside ediff-eval-in-buffer control-buffer,
+ ;; since these vars are local to control-buffer
+ ;; These won't run if there are errors in diff
+ (ediff-eval-in-buffer ediff-buffer-A
+ (ediff-nuke-selective-display)
+ (run-hooks 'ediff-prepare-buffer-hooks)
+ (if (ediff-eval-in-buffer control-buffer ediff-merge-job)
+ (setq buffer-read-only t))
+ (add-hook 'local-write-file-hooks 'ediff-block-write-file)
+ (setq before-change-function 'ediff-before-change-guard)
+ ;; add control-buffer to the list of sessions
+ (or (memq control-buffer ediff-this-buffer-control-sessions)
+ (setq ediff-this-buffer-control-sessions
+ (cons control-buffer ediff-this-buffer-control-sessions)))
+ )
+ (ediff-eval-in-buffer ediff-buffer-B
+ (ediff-nuke-selective-display)
+ (run-hooks 'ediff-prepare-buffer-hooks)
+ (if (ediff-eval-in-buffer control-buffer ediff-merge-job)
+ (setq buffer-read-only t))
+ (add-hook 'local-write-file-hooks 'ediff-block-write-file)
+ (setq before-change-function 'ediff-before-change-guard)
+ ;; add control-buffer to the list of sessions
+ (or (memq control-buffer ediff-this-buffer-control-sessions)
+ (setq ediff-this-buffer-control-sessions
+ (cons control-buffer ediff-this-buffer-control-sessions)))
+ )
+ (if ediff-3way-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (ediff-nuke-selective-display)
+ (run-hooks 'ediff-prepare-buffer-hooks)
+ (add-hook 'local-write-file-hooks 'ediff-block-write-file)
+ (setq before-change-function 'ediff-before-change-guard)
+ ;; add control-buffer to the list of sessions
+ (or (memq control-buffer ediff-this-buffer-control-sessions)
+ (setq ediff-this-buffer-control-sessions
+ (cons control-buffer
+ ediff-this-buffer-control-sessions)))
+ ))
+
+ ;; must come after setting up ediff-narrow-bounds AND after
+ ;; nuking selective display
+ (funcall ediff-setup-diff-regions-function file-A file-B file-C)
+ (setq ediff-number-of-differences (length ediff-difference-vector-A))
+ (setq ediff-current-difference -1)
+
+ (ediff-make-current-diff-overlay 'A)
+ (ediff-make-current-diff-overlay 'B)
+ (if ediff-3way-job
+ (ediff-make-current-diff-overlay 'C))
+
+ (if window-system
+ (ediff-init-var-faces))
+
+ (ediff-setup-windows buffer-A buffer-B buffer-C control-buffer)
+
+ (let ((shift-A (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ 'A ediff-narrow-bounds)))
+ (shift-B (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ 'B ediff-narrow-bounds)))
+ (shift-C (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ 'C ediff-narrow-bounds))))
+ ;; position point in buf A
+ (save-excursion
+ (select-window ediff-window-A)
+ (goto-char shift-A))
+ ;; position point in buf B
+ (save-excursion
+ (select-window ediff-window-B)
+ (goto-char shift-B))
+ (if ediff-3way-job
+ (save-excursion
+ (select-window ediff-window-C)
+ (goto-char shift-C)))
+ )
+
+ (select-window ediff-control-window)
+ (ediff-visible-region)
+
+ ;; The following is a hack to placate OS/2
+ ;; The problem is that OS/2 doesn't let us delete files used by other
+ ;; processes. Thus, in ediff-buffers and other functions, we can't
+ ;; delete temp files because they might be used by the asynchronous
+ ;; process that computes custom diffs. So, under OS/1 we have to wait
+ ;; for some time until custom diffs are done.
+ (if (eq system-type 'emx)
+ (ediff-eval-in-buffer ediff-custom-diff-buffer
+ (let ((proc (get-buffer-process (current-buffer))))
+ (while (and (processp proc)
+ (eq (process-status proc) 'run))
+ (message "Waiting for the diff program to quit")
+ (sleep-for 1)
+ )
+ (message "")
+ )))
+
+ (run-hooks 'startup-hooks 'ediff-startup-hooks)
+ (ediff-refresh-mode-lines)
+ (setq buffer-read-only t))))
+
+
+;; This function assumes that we are in the window where control buffer is
+;; to reside.
+(defun ediff-setup-control-buffer (ctl-buf)
+ "Set up window for control buffer."
+ (if (window-dedicated-p (selected-window))
+ (set-buffer ctl-buf) ; we are in control frame but just in case
+ (switch-to-buffer ctl-buf))
+ (let ((window-min-height 1))
+ (erase-buffer)
+ (ediff-set-help-message)
+ (insert ediff-help-message)
+ (shrink-window-if-larger-than-buffer)
+ (if (not ediff-multiframe)
+ (ediff-indent-help-message))
+ (set-buffer-modified-p nil)
+ (ediff-refresh-mode-lines)
+ (setq ediff-control-window (selected-window))
+ (setq ediff-window-config-saved
+ (format "%S%S%S%S%S"
+ ediff-control-window
+ ediff-window-A
+ ediff-window-B
+ ediff-window-C
+ ediff-split-window-function))
+ (goto-char (point-min))
+ (skip-chars-forward ediff-whitespace)))
+
+;; assuming we are in control window, calculate length of the first line in
+;; help message
+(defun ediff-help-message-line-length ()
+ (save-excursion
+ (goto-char (point-min))
+ (if ediff-prefer-long-help-message
+ (next-line 1))
+ (end-of-line)
+ (current-column)))
+
+
+(defun ediff-indent-help-message ()
+ (let* ((shift (/ (max 0 (- (ediff-frame-width (ediff-selected-frame))
+ (ediff-help-message-line-length)))
+ 2))
+ (str (make-string shift ?\ )))
+ (save-excursion
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (insert str)
+ (beginning-of-line)
+ (forward-line 1)))))
+
+
+(defun ediff-set-help-message ()
+ (setq ediff-long-help-message
+ (cond ((and ediff-long-help-message-custom
+ (or (symbolp ediff-long-help-message-custom)
+ (consp ediff-long-help-message-custom)))
+ (funcall ediff-long-help-message-custom))
+ (ediff-word-mode
+ (concat ediff-long-help-message-head
+ ediff-long-help-message-word-mode
+ ediff-long-help-message-tail))
+ (ediff-merge-job
+ (concat ediff-long-help-message-head
+ ediff-long-help-message-merge
+ ediff-long-help-message-tail))
+ (ediff-diff3-job
+ (concat ediff-long-help-message-head
+ ediff-long-help-message-compare3
+ ediff-long-help-message-tail))
+ (t
+ (concat ediff-long-help-message-head
+ ediff-long-help-message-compare2
+ ediff-long-help-message-tail))))
+ (setq ediff-brief-help-message
+ (cond ((and ediff-brief-help-message-custom
+ (or (symbolp ediff-brief-help-message-custom)
+ (consp ediff-brief-help-message-custom)))
+ (funcall ediff-brief-help-message-custom))
+ ((stringp ediff-brief-help-message-custom)
+ ediff-brief-help-message-custom)
+ ((ediff-multiframe-setup-p) ediff-brief-message-string)
+ (t ; long brief msg, not multiframe --- put in the middle
+ ediff-brief-message-string)
+ ))
+ (setq ediff-help-message (if ediff-prefer-long-help-message
+ ediff-long-help-message
+ ediff-brief-help-message))
+ (run-hooks 'ediff-display-help-hooks)
+ )
+
+
+
+
+;;; Commands for working with Ediff
+
+(defun ediff-update-diffs ()
+ "Recompute difference regions in buffers A, B, and C.
+Buffers are not synchronized with their respective files, so changes done
+to these buffers are not saved at this point---the user can do this later,
+if necessary."
+ (interactive)
+ (let ((point-A (ediff-eval-in-buffer ediff-buffer-A (point)))
+ ;;(point-B (ediff-eval-in-buffer ediff-buffer-B (point)))
+ (tmp-buffer (get-buffer-create ediff-tmp-buffer))
+ (buf-A-file-name
+ (file-name-nondirectory (or (buffer-file-name ediff-buffer-A)
+ (buffer-name ediff-buffer-A)
+ )))
+ (buf-B-file-name
+ (file-name-nondirectory (or (buffer-file-name ediff-buffer-B)
+ (buffer-name ediff-buffer-B)
+ )))
+ (buf-C-file-name
+ (file-name-nondirectory (or (buffer-file-name ediff-buffer-C)
+ ;; if (null ediff-buffer-C), there is
+ ;; no danger, since we later check if
+ ;; ediff-buffer-C is alive
+ (buffer-name ediff-buffer-C)
+ )))
+ (overl-A (ediff-get-value-according-to-buffer-type
+ 'A ediff-narrow-bounds))
+ (overl-B (ediff-get-value-according-to-buffer-type
+ 'B ediff-narrow-bounds))
+ (overl-C (ediff-get-value-according-to-buffer-type
+ 'C ediff-narrow-bounds))
+ beg-A end-A beg-B end-B beg-C end-C
+ file-A file-B file-C)
+ (ediff-unselect-and-select-difference -1)
+
+ (setq beg-A (ediff-overlay-start overl-A)
+ beg-B (ediff-overlay-start overl-B)
+ beg-C (ediff-overlay-start overl-C)
+ end-A (ediff-overlay-end overl-A)
+ end-B (ediff-overlay-end overl-B)
+ end-C (ediff-overlay-end overl-C))
+
+ (if ediff-word-mode
+ (progn
+ (ediff-wordify beg-A end-A ediff-buffer-A tmp-buffer)
+ (ediff-eval-in-buffer tmp-buffer
+ (setq file-A (ediff-make-temp-file "regA")))
+ (ediff-wordify beg-B end-B ediff-buffer-B tmp-buffer)
+ (ediff-eval-in-buffer tmp-buffer
+ (setq file-B (ediff-make-temp-file "regB")))
+ (if ediff-3way-job
+ (progn
+ (ediff-wordify beg-C end-C ediff-buffer-C tmp-buffer)
+ (ediff-eval-in-buffer tmp-buffer
+ (setq file-C (ediff-make-temp-file "regC")))))
+ )
+ ;; not word-mode
+ (ediff-eval-in-buffer ediff-buffer-A
+ (setq file-A (ediff-make-temp-file buf-A-file-name)))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (setq file-B (ediff-make-temp-file buf-B-file-name)))
+ (if ediff-3way-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (setq file-C (ediff-make-temp-file buf-C-file-name))))
+ )
+
+ (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
+ (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
+ (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
+ (setq ediff-killed-diffs-alist nil) ; invalidate saved killed diff regions
+
+ ;; In case of merge job, full it into thinking that it is just doing
+ ;; comparison
+ (let ((ediff-setup-diff-regions-function ediff-setup-diff-regions-function)
+ (ediff-job-name ediff-job-name))
+ (if ediff-merge-job
+ (setq ediff-setup-diff-regions-function 'ediff-setup-diff-regions3
+ ediff-job-name 'ediff-files3))
+ (funcall ediff-setup-diff-regions-function file-A file-B file-C))
+
+ (setq ediff-number-of-differences (length ediff-difference-vector-A))
+ (delete-file file-A)
+ (delete-file file-B)
+ (if file-C
+ (delete-file file-C))
+
+ (if ediff-3way-job
+ (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
+
+ (ediff-jump-to-difference (ediff-diff-at-point 'A point-A))
+ (message "")
+ ))
+
+;; Not bound to any key---to dangerous. A user can do it if necessary.
+(defun ediff-revert-buffers-then-recompute-diffs (noconfirm)
+ "Revert buffers A, B and C. Then rerun Ediff on file A and file B."
+ (interactive "P")
+ (let ((bufA ediff-buffer-A)
+ (bufB ediff-buffer-B)
+ (bufC ediff-buffer-C)
+ (ctl-buf ediff-control-buffer)
+ (ancestor-buf ediff-ancestor-buffer)
+ (ancestor-job ediff-merge-with-ancestor-job)
+ (merge ediff-merge-job)
+ (comparison ediff-3way-comparison-job))
+ (ediff-eval-in-buffer bufA
+ (revert-buffer t noconfirm))
+ (ediff-eval-in-buffer bufB
+ (revert-buffer t noconfirm))
+ ;; this should only be executed in a 3way comparison, not in merge
+ (if comparison
+ (ediff-eval-in-buffer bufC
+ (revert-buffer t noconfirm)))
+ (if merge
+ (progn
+ (set-buffer ctl-buf)
+ (ediff-really-quit)
+ (kill-buffer bufC)
+ (if ancestor-job
+ (ediff-merge-buffers-with-ancestor bufA bufB ancestor-buf)
+ (ediff-merge-buffers bufA bufB)))
+ (ediff-update-diffs))))
+
+
+;; optional NO-REHIGHLIGHT says to not rehighlight buffers
+(defun ediff-recenter (&optional no-rehighlight)
+ "Bring the highlighted region of all buffers being compared into view.
+Reestablish the default three-window display."
+ (interactive)
+
+ ;; force all minibuffer to display ediff's messages.
+ ;; when xemacs implements minibufferless screens, this won't be necessary
+ (if ediff-xemacs-p (setq synchronize-minibuffers t))
+
+ (setq ediff-disturbed-overlays nil) ; clear after use
+ (let (buffer-read-only)
+ (if (and (ediff-buffer-live-p ediff-buffer-A)
+ (ediff-buffer-live-p ediff-buffer-B)
+ (or (not ediff-3way-job)
+ (ediff-buffer-live-p ediff-buffer-C))
+ )
+ (ediff-setup-windows
+ ediff-buffer-A ediff-buffer-B ediff-buffer-C ediff-control-buffer)
+ (or (eq this-command 'ediff-quit)
+ (message
+ "You've killed an essential Ediff buffer---Please quit Ediff"
+ (beep 1)))
+ ))
+
+ ;; set visibility range appropriate to this invocation of Ediff.
+ (ediff-visible-region)
+
+ ;; raise
+ (if (and window-system
+ (symbolp this-command)
+ (symbolp last-command)
+ ;; Either one of the display-changing commands
+ (or (memq this-command
+ '(ediff-recenter
+ ediff-toggle-wide-display ediff-toggle-multiframe))
+ ;; Or one of the movement cmds and prev cmd was an Ediff cmd
+ ;; This avoids rasing frames unnecessarily.
+ (and (memq this-command
+ '(ediff-next-difference
+ ediff-previous-difference
+ ediff-jump-to-difference
+ ediff-jump-to-difference-at-point))
+ (not (string-match "^ediff-" (symbol-name last-command)))
+ )))
+ (progn
+ (if (window-live-p ediff-window-A)
+ (ediff-raise-frame (ediff-window-frame ediff-window-A)))
+ (if (window-live-p ediff-window-B)
+ (ediff-raise-frame (ediff-window-frame ediff-window-B)))
+ (if (window-live-p ediff-window-C)
+ (ediff-raise-frame (ediff-window-frame ediff-window-C)))))
+ (if (and window-system
+ (ediff-frame-live-p ediff-control-frame)
+ (not (ediff-frame-iconified-p ediff-control-frame)))
+ (ediff-raise-frame ediff-control-frame))
+
+ ;; Redisplay whatever buffers are showing, if there is a selected difference
+ (let* ((control-frame ediff-control-frame)
+ (control-buf ediff-control-buffer))
+ (if (and (ediff-buffer-live-p ediff-buffer-A)
+ (ediff-buffer-live-p ediff-buffer-B)
+ (or (not ediff-3way-job)
+ (ediff-buffer-live-p ediff-buffer-C))
+ (ediff-valid-difference-p))
+ (progn
+ (or no-rehighlight
+ (ediff-operate-on-flags 'insert))
+
+ (ediff-recenter-one-window 'A)
+ (ediff-recenter-one-window 'B)
+ (if ediff-3way-job
+ (ediff-recenter-one-window 'C))
+
+ (if (and (ediff-multiframe-setup-p)
+ (not (ediff-frame-iconified-p ediff-control-frame)))
+ (progn
+ (set-mouse-position control-frame 1 0)
+ (if (ediff-check-version '< 19 11 'xemacs) (sit-for 0))
+ (or ediff-xemacs-p
+ (cond ((eq window-system 'ns)
+ (unfocus-frame (selected-frame)))
+ (t (unfocus-frame))))
+ ))
+ ))
+ (ediff-eval-in-buffer control-buf
+ (ediff-refresh-mode-lines))
+ ))
+
+;; this function returns to the window it was called from
+;; (which was the control window)
+(defun ediff-recenter-one-window (buf-type)
+ (let* (;; context must be saved before switching to windows A/B/C
+ (ctl-wind (selected-window))
+ (shift (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ buf-type ediff-narrow-bounds)))
+ (job-name ediff-job-name)
+ (control-buf ediff-control-buffer)
+ (before-flag-shift
+ (if (eq ediff-highlighting-style 'ascii)
+ (1- (length
+ (symbol-value
+ (intern (format "ediff-before-flag-%S" buf-type)))))
+ 0))
+ (after-flag-shift
+ (if (eq ediff-highlighting-style 'ascii)
+ (1- (length
+ (symbol-value
+ (intern (format "ediff-after-flag-%S" buf-type)))))
+ 0))
+ (window-name (intern (format "ediff-window-%S" buf-type)))
+ (window (if (window-live-p (symbol-value window-name))
+ (symbol-value window-name))))
+
+ (if (and window (eq job-name 'ediff-windows))
+ (set-window-start window
+ (- shift before-flag-shift)))
+ (if window
+ (progn
+ (select-window window)
+ (ediff-deactivate-mark)
+ (ediff-position-region
+ (- (ediff-get-diff-posn buf-type 'beg nil control-buf)
+ before-flag-shift)
+ (+ (ediff-get-diff-posn buf-type 'end nil control-buf)
+ after-flag-shift)
+ (ediff-get-diff-posn buf-type 'beg nil control-buf)
+ job-name
+ )))
+ (select-window ctl-wind)
+ ))
+
+
+;; This will have to be refined for 3way jobs
+(defun ediff-toggle-split ()
+ "Toggle vertical/horizontal window split.
+Does nothing if file-A and file-B are in different frames."
+ (interactive)
+ (let* ((wind-A (if (window-live-p ediff-window-A) ediff-window-A))
+ (wind-B (if (window-live-p ediff-window-B) ediff-window-B))
+ (wind-C (if (window-live-p ediff-window-C) ediff-window-C))
+ (frame-A (if wind-A (ediff-window-frame wind-A)))
+ (frame-B (if wind-B (ediff-window-frame wind-B)))
+ (frame-C (if wind-C (ediff-window-frame wind-C))))
+ (if (or (eq frame-A frame-B)
+ (not (ediff-frame-live-p frame-A))
+ (not (ediff-frame-live-p frame-B))
+ (if ediff-3way-comparison-job
+ (or (not (ediff-frame-live-p frame-C))
+ (eq frame-A frame-C) (eq frame-B frame-C))))
+ (setq ediff-split-window-function
+ (if (eq ediff-split-window-function 'split-window-vertically)
+ 'split-window-horizontally
+ 'split-window-vertically))
+ (message "Buffers being compared are in different frames"))
+ (ediff-recenter 'no-rehighlight)))
+
+(defun ediff-toggle-hilit ()
+ "Switch between highlighting using ASCII flags and highlighting using faces.
+On a dumb terminal, switches between ASCII highlighting and no highlighting."
+ (interactive)
+ (if (not window-system)
+ (if (eq ediff-highlighting-style 'ascii)
+ (progn
+ (message "ASCII highlighting flags removed")
+ (ediff-unselect-and-select-difference ediff-current-difference
+ 'unselect-only)
+ (setq ediff-highlighting-style 'off))
+ (ediff-unselect-and-select-difference ediff-current-difference
+ 'select-only))
+ (ediff-unselect-and-select-difference ediff-current-difference
+ 'unselect-only)
+ ;; cycle through highlighting
+ (cond ((and ediff-use-faces ediff-highlight-all-diffs)
+ (message "Unhighlighting unselected difference regions")
+ (setq ediff-highlight-all-diffs nil))
+ (ediff-use-faces
+ (message "Highlighting with ASCII flags")
+ (setq ediff-use-faces nil))
+ (t
+ (message "Re-highlighting all difference regions")
+ (setq ediff-use-faces t
+ ediff-highlight-all-diffs t)))
+
+ (if (and ediff-use-faces ediff-highlight-all-diffs)
+ (if (not (face-differs-from-default-p 'ediff-odd-diff-face-A-var))
+ (progn
+ (copy-face ediff-odd-diff-face-A 'ediff-odd-diff-face-A-var)
+ (copy-face ediff-odd-diff-face-B 'ediff-odd-diff-face-B-var)
+ (copy-face ediff-odd-diff-face-C 'ediff-odd-diff-face-C-var)
+ (copy-face ediff-even-diff-face-A 'ediff-even-diff-face-A-var)
+ (copy-face ediff-even-diff-face-B 'ediff-even-diff-face-B-var)
+ (copy-face ediff-even-diff-face-C 'ediff-even-diff-face-C-var)
+ ))
+ (copy-face 'default 'ediff-odd-diff-face-A-var)
+ (copy-face 'default 'ediff-odd-diff-face-B-var)
+ (copy-face 'default 'ediff-odd-diff-face-C-var)
+ (copy-face 'default 'ediff-even-diff-face-A-var)
+ (copy-face 'default 'ediff-even-diff-face-B-var)
+ (copy-face 'default 'ediff-even-diff-face-C-var))
+
+ (ediff-unselect-and-select-difference
+ ediff-current-difference 'select-only))
+ (ediff-operate-on-flags 'insert)
+ )
+
+(defun ediff-toggle-autorefine ()
+ "Toggle auto-refine mode."
+ (interactive)
+ (if ediff-word-mode
+ (error "No fine differences in this mode"))
+ (cond ((eq ediff-auto-refine 'nix)
+ (setq ediff-auto-refine 'on)
+ (ediff-make-fine-diffs ediff-current-difference 'noforce)
+ (message "Auto-refining is ON"))
+ ((eq ediff-auto-refine 'on)
+ (message "Auto-refining is OFF")
+ (setq ediff-auto-refine 'off))
+ (t ;; nix 'em
+ (ediff-set-fine-diff-properties ediff-current-difference 'default)
+ (message "Refinements are HIDDEN")
+ (setq ediff-auto-refine 'nix))
+ ))
+
+(defun ediff-make-or-kill-fine-diffs (arg)
+ "Compute fine diffs. With negative prefix arg, kill fine diffs.
+In both cases, operates on the currrent difference region."
+ (interactive "P")
+ (cond ((eq arg '-)
+ (ediff-clear-fine-differences ediff-current-difference))
+ ((and (numberp arg) (< arg 0))
+ (ediff-clear-fine-differences ediff-current-difference))
+ (t (ediff-make-fine-diffs))))
+
+
+(defun ediff-toggle-help ()
+ "Toggle short/long help message."
+ (interactive)
+ (let (buffer-read-only)
+ (erase-buffer)
+ (setq ediff-prefer-long-help-message (not ediff-prefer-long-help-message))
+ (ediff-set-help-message))
+ ;; remember the icon status of the control frame when the user requested
+ ;; full control message
+ (if (and ediff-prefer-long-help-message (ediff-multiframe-setup-p))
+ (setq ediff-prefer-iconified-control-frame
+ (ediff-frame-iconified-p ediff-control-frame)))
+
+ (setq ediff-window-config-saved "") ; force redisplay
+ (ediff-recenter 'no-rehighlight))
+
+
+;; Optional argument, BUF, is passed only in a startup hook.
+(defun ediff-toggle-read-only (&optional buff)
+ "Toggles read-only in buffers being compared.
+If buffer is under version control and locked, check it out first."
+ (interactive)
+
+ (or buff (ediff-recenter))
+
+ ;; eval in buf A/B/C
+ (ediff-eval-in-buffer
+ (or buff (ediff-get-buffer (ediff-char-to-buftype last-command-char)))
+ (let* ((file (buffer-file-name (current-buffer)))
+ (file-writable (and file (file-writable-p file)))
+ (toggle-ro-cmd (cond (ediff-toggle-read-only-function)
+ (ediff-file-checked-out-flag 'toggle-read-only)
+ (file-writable 'toggle-read-only)
+ (t (key-binding "\C-x\C-q")))))
+ (if (and toggle-ro-cmd
+ (string-match "toggle-read-only" (symbol-name toggle-ro-cmd)))
+ (save-excursion
+ (save-window-excursion
+ (setq ediff-file-checked-out-flag t)
+ (command-execute toggle-ro-cmd)))
+ (error "Don't know how to toggle read-only in buffer %S"
+ (current-buffer)))
+ ;; Check if we made the current buffer updatable, but its file is RO.
+ ;; Signal a warning in this case.
+ (if (and file (not buffer-read-only)
+ (eq this-command 'ediff-toggle-read-only)
+ (not file-writable))
+ (message "Warning: file %s is read-only"
+ (abbreviate-file-name file) (beep 1)))
+ )))
+
+(defun ediff-swap-buffers ()
+ "Rotate the display of buffers A, B, and C."
+ (interactive)
+ (if (and (window-live-p ediff-window-A) (window-live-p ediff-window-B))
+ (let ((buf ediff-buffer-A)
+ (values ediff-buffer-A-values-orig)
+ (diff-vec ediff-difference-vector-A)
+ (hide-regexp ediff-regexp-hide-A)
+ (focus-regexp ediff-regexp-focus-A)
+ (wide-visibility-p (eq ediff-visible-bounds ediff-wide-bounds))
+ (overlay (if window-system ediff-current-diff-overlay-A))
+ )
+ (if ediff-3way-comparison-job
+ (progn
+ (set-window-buffer ediff-window-A ediff-buffer-C)
+ (set-window-buffer ediff-window-B ediff-buffer-A)
+ (set-window-buffer ediff-window-C ediff-buffer-B)
+ )
+ (set-window-buffer ediff-window-A ediff-buffer-B)
+ (set-window-buffer ediff-window-B ediff-buffer-A))
+ ;; swap diff buffers
+ (if ediff-3way-comparison-job
+ (setq ediff-buffer-A ediff-buffer-C
+ ediff-buffer-C ediff-buffer-B
+ ediff-buffer-B buf)
+ (setq ediff-buffer-A ediff-buffer-B
+ ediff-buffer-B buf))
+
+ ;; swap saved buffer characteristics
+ (if ediff-3way-comparison-job
+ (setq ediff-buffer-A-values-orig ediff-buffer-C-values-orig
+ ediff-buffer-C-values-orig ediff-buffer-B-values-orig
+ ediff-buffer-B-values-orig values)
+ (setq ediff-buffer-A-values-orig ediff-buffer-B-values-orig
+ ediff-buffer-B-values-orig values))
+
+ ;; swap diff vectors
+ (if ediff-3way-comparison-job
+ (setq ediff-difference-vector-A ediff-difference-vector-C
+ ediff-difference-vector-C ediff-difference-vector-B
+ ediff-difference-vector-B diff-vec)
+ (setq ediff-difference-vector-A ediff-difference-vector-B
+ ediff-difference-vector-B diff-vec))
+
+ ;; swap hide/focus regexp
+ (if ediff-3way-comparison-job
+ (setq ediff-regexp-hide-A ediff-regexp-hide-C
+ ediff-regexp-hide-C ediff-regexp-hide-B
+ ediff-regexp-hide-B hide-regexp
+ ediff-regexp-focus-A ediff-regexp-focus-C
+ ediff-regexp-focus-C ediff-regexp-focus-B
+ ediff-regexp-focus-B focus-regexp)
+ (setq ediff-regexp-hide-A ediff-regexp-hide-B
+ ediff-regexp-hide-B hide-regexp
+ ediff-regexp-focus-A ediff-regexp-focus-B
+ ediff-regexp-focus-B focus-regexp))
+
+ ;; The following is needed for XEmacs, since there one can't move
+ ;; overlay to another buffer. In Emacs, this swap is redundant.
+ (if window-system
+ (if ediff-3way-comparison-job
+ (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-C
+ ediff-current-diff-overlay-C ediff-current-diff-overlay-B
+ ediff-current-diff-overlay-B overlay)
+ (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-B
+ ediff-current-diff-overlay-B overlay)))
+
+ ;; swap wide bounds
+ (setq ediff-wide-bounds
+ (cond (ediff-3way-comparison-job
+ (list (nth 2 ediff-wide-bounds)
+ (nth 0 ediff-wide-bounds)
+ (nth 1 ediff-wide-bounds)))
+ (ediff-3way-job
+ (list (nth 1 ediff-wide-bounds)
+ (nth 0 ediff-wide-bounds)
+ (nth 2 ediff-wide-bounds)))
+ (t
+ (list (nth 1 ediff-wide-bounds)
+ (nth 0 ediff-wide-bounds)))))
+ ;; swap narrow bounds
+ (setq ediff-narrow-bounds
+ (cond (ediff-3way-comparison-job
+ (list (nth 2 ediff-narrow-bounds)
+ (nth 0 ediff-narrow-bounds)
+ (nth 1 ediff-narrow-bounds)))
+ (ediff-3way-job
+ (list (nth 1 ediff-narrow-bounds)
+ (nth 0 ediff-narrow-bounds)
+ (nth 2 ediff-narrow-bounds)))
+ (t
+ (list (nth 1 ediff-narrow-bounds)
+ (nth 0 ediff-narrow-bounds)))))
+ (if wide-visibility-p
+ (setq ediff-visible-bounds ediff-wide-bounds)
+ (setq ediff-visible-bounds ediff-narrow-bounds))
+ ))
+ (if ediff-3way-job
+ (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
+ (ediff-recenter 'no-rehighlight)
+ )
+
+
+(defun ediff-toggle-wide-display ()
+ "Toggle wide/regular display.
+This is especially useful when comparing buffers side-by-side."
+ (interactive)
+ (or window-system
+ (error "Emacs is not running as a window application"))
+ (ediff-recenter 'no-rehighlight) ; make sure buffs are displayed in windows
+ (let ((ctl-buf ediff-control-buffer))
+ (setq ediff-wide-display-p (not ediff-wide-display-p))
+ (if (not ediff-wide-display-p)
+ (ediff-eval-in-buffer ctl-buf
+ (ediff-modify-frame-parameters
+ ediff-wide-display-frame ediff-wide-display-orig-parameters)
+ (sit-for (if ediff-xemacs-p 0.4 0))
+ ;; restore control buf, since ctl window may have been deleted
+ ;; during resizing
+ (set-buffer ctl-buf)
+ (setq ediff-wide-display-orig-parameters nil
+ ediff-window-B nil) ; force update of window config
+ (ediff-recenter 'no-rehighlight))
+ (funcall ediff-make-wide-display-function)
+ (sit-for (if ediff-xemacs-p 0.4 0))
+ (ediff-eval-in-buffer ctl-buf
+ (setq ediff-window-B nil) ; force update of window config
+ (ediff-recenter 'no-rehighlight)))))
+
+(defun ediff-toggle-multiframe ()
+ "Switch from the multiframe display to single-frame display and back.
+This is primarily for debugging, but one can use it for fun, too."
+ (interactive)
+ (if (ediff-check-version '< 19 12 'xemacs)
+ (error "This command doesn't work under XEmacs 19.11 and earlier"))
+ (or window-system
+ (error "Emacs is not running as a window application"))
+ (cond ((eq ediff-window-setup-function 'ediff-setup-windows-multiframe)
+ (setq ediff-window-setup-function 'ediff-setup-windows-plain))
+ ((eq ediff-window-setup-function 'ediff-setup-windows-plain)
+ (setq ediff-window-setup-function 'ediff-setup-windows-multiframe)))
+ (setq ediff-window-B nil)
+ (ediff-recenter 'no-rehighlight))
+
+;; Merging
+
+(defun ediff-toggle-show-clashes-only ()
+ "Toggle the mode where only the regions where both buffers differ with the ancestor are shown."
+ (interactive)
+ (if (not ediff-merge-with-ancestor-job)
+ (error "This command makes sense only when merging with an ancestor"))
+ (setq ediff-show-clashes-only (not ediff-show-clashes-only))
+ (if ediff-show-clashes-only
+ (message "Focus on regions where both buffers differ from the ancestor")
+ (message "Canceling focus on regions where changes clash")))
+
+;; Widening/narrowing
+
+(defun ediff-toggle-narrow-region ()
+ "Toggle narrowing in buffers A, B, and C.
+Used in ediff-windows/regions only."
+ (interactive)
+ (if (eq ediff-buffer-A ediff-buffer-B)
+ (error
+ "Buffers A and B are the same. Can't narrow to two different regions"))
+ (if (eq ediff-visible-bounds ediff-wide-bounds)
+ (setq ediff-visible-bounds ediff-narrow-bounds)
+ (setq ediff-visible-bounds ediff-wide-bounds))
+ (ediff-recenter 'no-rehighlight))
+
+;; Narrow bufs A/B/C to ediff-visible-bounds. If this is currently set to
+;; ediff-wide-bounds, then this actually widens.
+;; This function does nothing if job-name is not ediff-small/large-regions or
+;; ediff-windows.
+;; Does nothing if buffer-A = buffer-B since we can't narrow
+;; to two different regions in one buffer.
+(defun ediff-visible-region ()
+ (if (or (eq ediff-buffer-A ediff-buffer-B)
+ (eq ediff-buffer-A ediff-buffer-C)
+ (eq ediff-buffer-C ediff-buffer-B))
+ ()
+ ;; If ediff-*-regions/windows, ediff-visible-bounds is already set
+ ;; Otherwise, always use full range.
+ (if (not ediff-word-mode-job)
+ (setq ediff-visible-bounds ediff-wide-bounds))
+ (let ((overl-A (ediff-get-value-according-to-buffer-type
+ 'A ediff-visible-bounds))
+ (overl-B (ediff-get-value-according-to-buffer-type
+ 'B ediff-visible-bounds))
+ (overl-C (ediff-get-value-according-to-buffer-type
+ 'C ediff-visible-bounds))
+ )
+ (ediff-eval-in-buffer ediff-buffer-A
+ (narrow-to-region
+ (ediff-overlay-start overl-A) (ediff-overlay-end overl-A)))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (narrow-to-region
+ (ediff-overlay-start overl-B) (ediff-overlay-end overl-B)))
+
+ (if ediff-3way-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (narrow-to-region
+ (ediff-overlay-start overl-C) (ediff-overlay-end overl-C))))
+ )))
+
+
+;; Window scrolling operations
+
+;; Performs some operation on the two file windows (if they are showing).
+;; Traps all errors on the operation in windows A/B/C.
+;; Usually, errors come from scrolling off the
+;; beginning or end of the buffer, and this gives error messages.
+(defun ediff-operate-on-windows (operation arg)
+
+ ;; make sure windows aren't dead
+ (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
+ (ediff-recenter 'no-rehighlight))
+ (if (not (and (ediff-buffer-live-p ediff-buffer-A)
+ (ediff-buffer-live-p ediff-buffer-B)
+ (or (not ediff-3way-job) ediff-buffer-C)
+ ))
+ (error "You've killed an essential Ediff buffer---Please quit Ediff"))
+
+ (let* ((wind (selected-window))
+ (wind-A ediff-window-A)
+ (wind-B ediff-window-B)
+ (wind-C ediff-window-C)
+ (three-way ediff-3way-job))
+
+ (select-window wind-A)
+ (condition-case nil
+ (funcall operation arg)
+ (error))
+ (select-window wind-B)
+ (condition-case nil
+ (funcall operation arg)
+ (error))
+ (if three-way
+ (progn
+ (select-window wind-C)
+ (condition-case nil
+ (funcall operation arg)
+ (error))))
+
+ (select-window wind)))
+
+(defun ediff-scroll-vertically (&optional arg)
+ "Vertically scroll buffers A, B \(and C if appropriate\).
+With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
+the height of window-A."
+ (interactive "P")
+
+ ;; make sure windows aren't dead
+ (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
+ (ediff-recenter 'no-rehighlight))
+ (if (not (and (ediff-buffer-live-p ediff-buffer-A)
+ (ediff-buffer-live-p ediff-buffer-B)
+ (or (not ediff-3way-job)
+ (ediff-buffer-live-p ediff-buffer-C))
+ ))
+ (error "You've killed an essential Ediff buffer---Please quit Ediff"))
+
+ (ediff-operate-on-windows
+ (if (memq last-command-char '(?v ?\C-v))
+ 'scroll-up
+ 'scroll-down)
+ ;; calculate argument to scroll-up/down
+ ;; if there is an explicit argument
+ (if (and arg (not (equal arg '-)))
+ ;; use it
+ (prefix-numeric-value arg)
+ ;; if not, see if we can determine a default amount (the window height)
+ (let* (default-amount)
+ (setq default-amount
+ (- (min (window-height ediff-window-A)
+ (window-height ediff-window-B)
+ (if ediff-3way-job
+ (window-height ediff-window-C)
+ 123) ; some large number
+ )
+ 1 next-screen-context-lines))
+ ;; window found
+ (if arg
+ ;; C-u as argument means half of default amount
+ (/ default-amount 2)
+ ;; no argument means default amount
+ default-amount)))))
+
+
+(defun ediff-scroll-horizontally (&optional arg)
+ "Horizontally scroll buffers A, B \(and C if appropriate\).
+If an argument is given, that is how many columns are scrolled, else nearly
+the width of the A/B/C windows."
+ (interactive "P")
+
+ ;; make sure windows aren't dead
+ (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
+ (ediff-recenter 'no-rehighlight))
+ (if (not (and (ediff-buffer-live-p ediff-buffer-A)
+ (ediff-buffer-live-p ediff-buffer-B)
+ (or (not ediff-3way-job)
+ (ediff-buffer-live-p ediff-buffer-C))
+ ))
+ (error "You've killed an essential Ediff buffer---Please quit Ediff"))
+
+ (ediff-operate-on-windows
+ (if (= last-command-char ?<)
+ 'scroll-left
+ 'scroll-right)
+ ;; calculate argument to scroll-left/right
+ ;; if there is an explicit argument
+ (if (and arg (not (equal arg '-)))
+ ;; use it
+ (prefix-numeric-value arg)
+ ;; if not, see if we can determine a default amount
+ ;; (half the window width)
+ (if (null ediff-control-window)
+ ;; no control window, use nil
+ nil
+ (let ((default-amount
+ (- (/ (min (window-width ediff-window-A)
+ (window-width ediff-window-B)
+ (if ediff-3way-comparison-job
+ (window-width ediff-window-C)
+ 500) ; some large number
+ )
+ 2)
+ 3)))
+ ;; window found
+ (if arg
+ ;; C-u as argument means half of default amount
+ (/ default-amount 2)
+ ;; no argument means default amount
+ default-amount))))))
+
+
+;;BEG, END show the region to be positioned.
+;;JOB-NAME holds ediff-job-name. Ediff-windows job positions regions
+;;differently.
+(defun ediff-position-region (beg end pos job-name)
+ (if (> end (point-max))
+ (setq end (point-max)))
+ (if (eq job-name 'ediff-windows)
+ (if (pos-visible-in-window-p end)
+ () ; do nothing, wind is already positioned
+ ;; at this point, windows are positioned at the beginning of the
+ ;; file regions (not diff-regions) being compared.
+ (save-excursion
+ (move-to-window-line (- (window-height) 2))
+ (let ((amount (+ 2 (count-lines (point) end))))
+ (scroll-up amount))))
+ (set-window-start (selected-window) beg)
+ (if (pos-visible-in-window-p end)
+ ;; Determine the number of lines that the region occupies
+ (let ((lines 0))
+ (while (> end (progn
+ (move-to-window-line lines)
+ (point)))
+ (setq lines (1+ lines)))
+ ;; And position the beginning on the right line
+ (goto-char beg)
+ (recenter (/ (1+ (max (- (1- (window-height (selected-window)))
+ lines)
+ 1)
+ )
+ 2))))
+ (goto-char pos)
+ ))
+
+
+(defun ediff-next-difference (&optional arg)
+ "Advance to the next difference.
+With a prefix argument, go back that many differences."
+ (interactive "P")
+ (if (< ediff-current-difference ediff-number-of-differences)
+ (let ((n (min ediff-number-of-differences
+ (+ ediff-current-difference (if arg arg 1))))
+ regexp-skip buffer-read-only)
+
+ (or (>= n ediff-number-of-differences)
+ (setq regexp-skip (funcall ediff-skip-diff-region-function n))
+ (ediff-install-fine-diff-if-necessary n))
+ (while (and (< n ediff-number-of-differences)
+ (or
+ ;; regexp skip
+ regexp-skip
+ ;; skip clashes, if necessary
+ (and ediff-show-clashes-only
+ (string-match "prefer"
+ (or (ediff-get-state-of-merge n) "")))
+ ;; skip difference regions that differ in white space
+ (and ediff-ignore-similar-regions
+ (ediff-no-fine-diffs-p n))))
+ (setq n (1+ n))
+ (if (= 0 (mod n 20))
+ (message "Skipped over region %d and counting ..." n))
+ (or (>= n ediff-number-of-differences)
+ (setq regexp-skip (funcall ediff-skip-diff-region-function n))
+ (ediff-install-fine-diff-if-necessary n))
+ )
+
+ (ediff-unselect-and-select-difference n)
+ ) ; let
+ (ediff-visible-region)
+ (error "At end of the difference list")))
+
+(defun ediff-previous-difference (&optional arg)
+ "Go to the previous difference.
+With a prefix argument, go back that many differences."
+ (interactive "P")
+ (if (> ediff-current-difference -1)
+ (let ((n (max -1 (- ediff-current-difference (if arg arg 1))))
+ regexp-skip buffer-read-only)
+
+ (or (< n 0)
+ (setq regexp-skip (funcall ediff-skip-diff-region-function n))
+ (ediff-install-fine-diff-if-necessary n))
+ (while (and (> n -1)
+ (or
+ ;; regexp skip
+ regexp-skip
+ ;; skip clashes, if necessary
+ (and ediff-show-clashes-only
+ (string-match "prefer"
+ (or (ediff-get-state-of-merge n) "")))
+ ;; skip difference regions that differ in white space
+ (and ediff-ignore-similar-regions
+ (ediff-no-fine-diffs-p n))))
+ (if (= 0 (mod (1+ n) 20))
+ (message "Skipped over region %d and counting ..." (1+ n)))
+ (setq n (1- n))
+ (or (< n 0)
+ (setq regexp-skip (funcall ediff-skip-diff-region-function n))
+ (ediff-install-fine-diff-if-necessary n))
+ )
+ (ediff-unselect-and-select-difference n)
+ ) ; let
+ (ediff-visible-region)
+ (error "At beginning of the difference list")))
+
+(defun ediff-jump-to-difference (difference-number)
+ "Go to the difference specified as a prefix argument."
+ (interactive "p")
+ (let (buffer-read-only)
+ (setq difference-number (1- difference-number))
+ (if (and (>= difference-number -1)
+ (< difference-number (1+ ediff-number-of-differences)))
+ (ediff-unselect-and-select-difference difference-number)
+ (error "Bad difference number, %d" difference-number))))
+
+(defun ediff-jump-to-difference-at-point ()
+ "Go to difference closest to the point in buffer A, B, or C.
+The type of buffer depends on last command character \(a, b, or c\) that
+invoked this command."
+ (interactive)
+ (let ((buf-type (ediff-char-to-buftype last-command-char))
+ buffer-read-only)
+ (ediff-jump-to-difference (ediff-diff-at-point buf-type))))
+
+
+;; find region most related to the current point position (or POS, if given)
+(defun ediff-diff-at-point (buf-type &optional pos)
+ (let ((buffer (ediff-get-buffer buf-type))
+ (ctl-buffer ediff-control-buffer)
+ (max-dif-num (1- ediff-number-of-differences))
+ (diff-no -1)
+ (prev-beg 0)
+ (prev-end 0)
+ (beg 0)
+ (end 0))
+
+ (ediff-eval-in-buffer buffer
+ (setq pos (or pos (point)))
+ (while (and (or (< pos prev-beg) (> pos beg))
+ (< diff-no max-dif-num))
+ (setq diff-no (1+ diff-no))
+ (setq prev-beg beg
+ prev-end end)
+ (setq beg (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer)
+ end (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
+ )
+
+ (if (< (abs (- pos prev-end))
+ (abs (- pos beg)))
+ diff-no
+ (1+ diff-no)) ; jump-to-diff works with diff nums higher by 1
+ )))
+
+
+;;; Copying diffs.
+
+(defun ediff-diff-to-diff (arg &optional keys)
+ "Copy buffer-X'th diff to buffer Y \(X,Y are A, B, or C\).
+If numerical prefix argument, copy this diff specified in the arg.
+Otherwise, copy the difference given by `ediff-current-difference'.
+This command assumes it is bound to a 2-character key sequence, `ab', `ba',
+`ac', etc., which is used to determine the types of buffers to be used for
+copying difference regions. The first character in the sequence specifies
+the source buffer and the second specifies the target.
+
+If the second optional argument, a 2-character string, is given, use it to
+determine the source and the target buffers instead of the command keys."
+ (interactive "P")
+ (or keys (setq keys (this-command-keys)))
+ (if arg
+ (ediff-jump-to-difference arg))
+ (let* ((key1 (aref keys 0))
+ (key2 (aref keys 1))
+ (char1 (if (and ediff-xemacs-p (eventp key1)) (event-key key1) key1))
+ (char2 (if (and ediff-xemacs-p (eventp key1)) (event-key key2) key2)))
+ (ediff-copy-diff ediff-current-difference
+ (ediff-char-to-buftype char1)
+ (ediff-char-to-buftype char2))
+ (ediff-recenter 'no-rehighlight)))
+
+
+;; Copy diff N from FROM-BUF-TYPE \(given as A, B or C\) to TO-BUF-TYPE.
+;; If optional DO-NOT-SAVE is non-nil, do not save the old value of the
+;; target diff. This is used in merging, when constructing the merged
+;; version.
+(defun ediff-copy-diff (n from-buf-type to-buf-type
+ &optional batch-invocation reg-to-copy)
+ (let* ((to-buf (ediff-get-buffer to-buf-type))
+ ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type)))
+ (ctrl-buf ediff-control-buffer)
+ (saved-p t)
+ (three-way ediff-3way-job)
+ messg
+ ediff-verbose-p
+ reg-to-delete reg-to-delete-beg reg-to-delete-end)
+
+ (ediff-operate-on-flags 'remove)
+ (setq reg-to-delete-beg
+ (ediff-get-diff-posn to-buf-type 'beg n ctrl-buf))
+ (setq reg-to-delete-end
+ (ediff-get-diff-posn to-buf-type 'end n ctrl-buf))
+
+ (if reg-to-copy
+ (setq from-buf-type nil)
+ (setq reg-to-copy (ediff-get-region-contents n from-buf-type ctrl-buf)))
+
+ (setq reg-to-delete (ediff-get-region-contents
+ n to-buf-type ctrl-buf
+ reg-to-delete-beg reg-to-delete-end))
+
+ (setq ediff-disturbed-overlays nil) ; clear before use
+
+ (if (string= reg-to-delete reg-to-copy)
+ (setq saved-p nil) ; refuse to copy identical buffers
+;;; (progn ; refuse to copy identical buffers
+;;; (setq saved-p nil)
+;;; (or batch-invocation
+;;; (message
+;;; "Region %d in buffer %S is identical to that in buffer %S"
+;;; (1+ n) from-buf-type to-buf-type (ding))))
+ ;; seems ok to copy
+ (if (or batch-invocation (ediff-test-save-region n to-buf-type))
+ (condition-case conds
+ (progn
+ (ediff-eval-in-buffer to-buf
+ ;; to prevent flags from interfering if buffer is writable
+ (let ((inhibit-read-only (null buffer-read-only))
+ before-change-function)
+ ;; these two insert a dummy char to overcome a bug in
+ ;; XEmacs, which sometimes prevents 0-length extents
+ ;; from sensing insertion at its end-points.
+ (if ediff-xemacs-p
+ (progn
+ (goto-char reg-to-delete-end)
+ (insert-before-markers "@")))
+
+ (goto-char reg-to-delete-end)
+ (insert-before-markers reg-to-copy)
+
+ ;; delete the dummy char "@"
+ (if ediff-xemacs-p
+ (delete-char 1))
+
+ (if ediff-xemacs-p
+ (progn
+ (ediff-collect-extents-xemacs reg-to-delete-beg)
+ (if (> reg-to-delete-end reg-to-delete-beg)
+ (progn
+ (kill-region reg-to-delete-beg
+ reg-to-delete-end)
+ (if (string= reg-to-copy "")
+ (ediff-adjust-disturbed-extents-xemacs
+ reg-to-delete-beg)))))
+ (if (> reg-to-delete-end reg-to-delete-beg)
+ (kill-region reg-to-delete-beg reg-to-delete-end)
+ (ediff-move-disturbed-overlays reg-to-delete-beg)
+ ))
+ ))
+ (or batch-invocation
+ (setq
+ messg
+ (ediff-save-diff-region n to-buf-type reg-to-delete))))
+ (error (message "ediff-copy-diff: %s %s"
+ (car conds)
+ (mapconcat 'prin1-to-string (cdr conds) " "))
+ (beep 1)
+ (sit-for 2)
+ (setq saved-p nil)
+ )))
+ )
+
+ ;; adjust state of difference in case 3-way and diff was copied ok
+ (if (and saved-p three-way)
+ (ediff-set-state-of-all-diffs-in-all-buffers ctrl-buf))
+
+ (if batch-invocation
+ (ediff-clear-fine-differences n)
+ ;; If diff3 job, we should recompute fine diffs so we clear them
+ ;; before reinserting flags (and thus before ediff-recenter).
+ (if (and saved-p three-way)
+ (ediff-clear-fine-differences n))
+ (ediff-operate-on-flags 'insert)
+ ;; For diff2 jobs, don't recompute fine diffs, since we know there
+ ;; aren't any. So we clear diffs after ediff-recenter.
+ (if (and saved-p (not three-way))
+ (ediff-clear-fine-differences n))
+ ;; Make sure that the message about saving and how to restore is seen
+ ;; by the user
+ (message messg))
+ ))
+
+;; Save Nth diff of buffer BUF-TYPE \(A, B, or C\).
+;; That is to say, the Nth diff on the `ediff-killed-diffs-alist'. REG
+;; is the region to save. It is redundant here, but is passed anyway, for
+;; convenience.
+(defun ediff-save-diff-region (n buf-type reg)
+ (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
+ (buf (ediff-get-buffer buf-type))
+ (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
+
+ (if this-buf-n-th-diff-saved
+ ;; either nothing saved for n-th diff and buffer or we OK'ed
+ ;; overriding
+ (setcdr this-buf-n-th-diff-saved reg)
+ (if n-th-diff-saved ;; n-th diff saved, but for another buffer
+ (nconc n-th-diff-saved (list (cons buf reg)))
+ (setq ediff-killed-diffs-alist ;; create record for n-th diff
+ (cons (list n (cons buf reg))
+ ediff-killed-diffs-alist))))
+ (message "Saving old diff region #%d of buffer %S. To recover, type `r%s'"
+ (1+ n) buf-type
+ (if ediff-merge-job
+ "" (downcase (symbol-name buf-type))))
+ ))
+
+;; Test if saving Nth difference region of buffer BUF-TYPE is possible.
+(defun ediff-test-save-region (n buf-type)
+ (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
+ (buf (ediff-get-buffer buf-type))
+ (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
+
+ (if this-buf-n-th-diff-saved
+ (if (yes-or-no-p
+ (format
+ "You've previously copied diff region %d to buffer %S. Confirm "
+ (1+ n) buf-type))
+ t
+ (error "Quit"))
+ t)))
+
+(defun ediff-pop-diff (n buf-type)
+ "Pop last killed Nth diff region from buffer BUF-TYPE."
+ (let* ((n-th-record (assoc n ediff-killed-diffs-alist))
+ (buf (ediff-get-buffer buf-type))
+ (saved-rec (assoc buf (cdr n-th-record)))
+ (three-way ediff-3way-job)
+ (ctl-buf ediff-control-buffer)
+ ediff-verbose-p
+ saved-diff reg-beg reg-end recovered)
+
+ (if (cdr saved-rec)
+ (setq saved-diff (cdr saved-rec))
+ (if (> ediff-number-of-differences 0)
+ (error "Nothing saved for diff %d in buffer %S" (1+ n) buf-type)
+ (error "No differences found")))
+
+ (ediff-operate-on-flags 'remove)
+
+ (setq reg-beg (ediff-get-diff-posn buf-type 'beg n ediff-control-buffer))
+ (setq reg-end (ediff-get-diff-posn buf-type 'end n ediff-control-buffer))
+ (setq ediff-disturbed-overlays nil) ; clear before use
+
+ (condition-case conds
+ (ediff-eval-in-buffer buf
+ (let ((inhibit-read-only (null buffer-read-only))
+ (before-change-function nil))
+ ;; these two insert a dummy char to overcome a bug in XEmacs,
+ ;; which sometimes prevents 0-length extents from sensing
+ ;; insertion at its end-points.
+ (if ediff-xemacs-p
+ (progn
+ (goto-char reg-end)
+ (insert-before-markers "@")))
+
+ (goto-char reg-end)
+ (insert-before-markers saved-diff)
+
+ ;; delete dummy char
+ (if ediff-xemacs-p
+ (delete-char 1))
+
+ (if ediff-xemacs-p
+ (progn
+ (ediff-collect-extents-xemacs reg-beg)
+ (if (> reg-end reg-beg)
+ (progn
+ (kill-region reg-beg reg-end)
+ (if (string= saved-diff "")
+ (ediff-adjust-disturbed-extents-xemacs reg-beg)))))
+ (if (> reg-end reg-beg)
+ (kill-region reg-beg reg-end)
+ (ediff-move-disturbed-overlays reg-beg)
+ ))
+
+ (setq recovered t)
+ ))
+ (error (message "ediff-pop-diff: %s %s"
+ (car conds)
+ (mapconcat 'prin1-to-string (cdr conds) " "))
+ (beep 1)))
+
+ ;; Clearing fine diffs is necessary in order for ediff-operate-on-flags
+ ;; to properly recompute them. We can't rely on ediff-copy-diff on
+ ;; clearing this vector because the user might have modified diff
+ ;; regions after copying and may have recomputed fine diffs.
+ (if recovered
+ (ediff-clear-fine-differences n))
+
+ ;; adjust state of difference
+ (if (and three-way recovered)
+ (ediff-set-state-of-diff-in-all-buffers n ctl-buf))
+
+ (ediff-operate-on-flags 'insert)
+ (if recovered
+ (progn
+ (setq n-th-record (delq saved-rec n-th-record))
+ (message "Diff region %d in buffer %S restored" (1+ n) buf-type)
+ ))
+ ))
+
+(defun ediff-restore-diff (arg &optional key)
+ "Restore ARGth diff from `ediff-killed-diffs-alist'.
+ARG is a prefix argument. If ARG is nil, restore current-difference.
+
+If the second optional argument, a character, is given, use it to
+determine the target buffer instead of last-command-char"
+ (interactive "P")
+ (if arg
+ (ediff-jump-to-difference arg))
+ (ediff-pop-diff ediff-current-difference
+ (ediff-char-to-buftype (or key last-command-char)))
+ (ediff-recenter 'no-rehighlight))
+
+(defun ediff-toggle-regexp-match ()
+ "Toggle between focusing and hiding of difference regions that match
+a regular expression typed in by the user."
+ (interactive)
+ (let ((regexp-A "")
+ (regexp-B "")
+ (regexp-C "")
+ msg-connective alt-msg-connective alt-connective)
+ (cond
+ ((or (and (eq ediff-skip-diff-region-function
+ 'ediff-focus-on-regexp-matches)
+ (eq last-command-char ?f))
+ (and (eq ediff-skip-diff-region-function 'ediff-hide-regexp-matches)
+ (eq last-command-char ?h)))
+ (message "Selective browsing by regexp turned off")
+ (setq ediff-skip-diff-region-function 'ediff-show-all-diffs))
+ ((eq last-command-char ?h)
+ (setq ediff-skip-diff-region-function 'ediff-hide-regexp-matches
+ regexp-A
+ (read-string
+ (format
+ "Ignore A-regions matching this regexp (default \"%s\"): "
+ ediff-regexp-hide-A))
+ regexp-B
+ (read-string
+ (format
+ "Ignore B-regions matching this regexp (default \"%s\"): "
+ ediff-regexp-hide-B)))
+ (if ediff-3way-comparison-job
+ (setq regexp-C
+ (read-string
+ (format
+ "Ignore C-regions matching this regexp (default \"%s\"): "
+ ediff-regexp-hide-C))))
+ (if (eq ediff-hide-regexp-connective 'and)
+ (setq msg-connective "BOTH"
+ alt-msg-connective "ONE OF"
+ alt-connective 'or)
+ (setq msg-connective "ONE OF"
+ alt-msg-connective "BOTH"
+ alt-connective 'and))
+ (if (y-or-n-p
+ (format
+ "Hiding diff regions that match %s regexps. Use %s instead? "
+ msg-connective alt-msg-connective))
+ (progn
+ (setq ediff-hide-regexp-connective alt-connective)
+ (message "Hiding diff regions that match %s regexps"
+ alt-msg-connective))
+ (message "Hiding diff regions that match %s regexps" msg-connective))
+ (or (string= regexp-A "") (setq ediff-regexp-hide-A regexp-A))
+ (or (string= regexp-B "") (setq ediff-regexp-hide-B regexp-B))
+ (or (string= regexp-C "") (setq ediff-regexp-hide-C regexp-C)))
+ ((eq last-command-char ?f)
+ (setq ediff-skip-diff-region-function 'ediff-focus-on-regexp-matches
+ regexp-A
+ (read-string
+ (format
+ "Focus on A-regions matching this regexp (default \"%s\"): "
+ ediff-regexp-focus-A))
+ regexp-B
+ (read-string
+ (format
+ "Focus on B-regions matching this regexp (default \"%s\"): "
+ ediff-regexp-focus-B)))
+ (if ediff-3way-comparison-job
+ (setq regexp-C
+ (read-string
+ (format
+ "Focus on C-regions matching this regexp (default \"%s\"): "
+ ediff-regexp-focus-C))))
+ (if (eq ediff-focus-regexp-connective 'and)
+ (setq msg-connective "BOTH"
+ alt-msg-connective "ONE OF"
+ alt-connective 'or)
+ (setq msg-connective "ONE OF"
+ alt-msg-connective "BOTH"
+ alt-connective 'and))
+ (if (y-or-n-p
+ (format
+ "Focusing on diff regions that match %s regexps. Use %s instead? "
+ msg-connective alt-msg-connective))
+ (progn
+ (setq ediff-focus-regexp-connective alt-connective)
+ (message "Focusing on diff regions that match %s regexps"
+ alt-msg-connective))
+ (message "Focusing on diff regions that match %s regexps"
+ msg-connective))
+ (or (string= regexp-A "") (setq ediff-regexp-focus-A regexp-A))
+ (or (string= regexp-B "") (setq ediff-regexp-focus-B regexp-B))
+ (or (string= regexp-C "") (setq ediff-regexp-focus-C regexp-C))))))
+
+(defun ediff-toggle-skip-similar ()
+ (interactive)
+ (if (not (eq ediff-auto-refine 'on))
+ (error
+ "Can't skip over whitespace regions: first turn auto-refining on"))
+ (setq ediff-ignore-similar-regions (not ediff-ignore-similar-regions))
+ (if ediff-ignore-similar-regions
+ (message
+ "Skipping regions that differ only in white space & line breaks")
+ (message "Skipping over white-space differences turned off")))
+
+(defun ediff-focus-on-regexp-matches (n)
+ "Focus on diffs that match regexp `ediff-regexp-focus-A/B'.
+Regions to be ignored according to this function are those where
+buf A region doesn't match `ediff-regexp-focus-A' and buf B region
+doesn't match `ediff-regexp-focus-B'.
+This function returns nil if the region number N (specified as
+an argument) is not to be ignored and t if region N is to be ignored.
+
+N is a region number used by Ediff internally. It is 1 less
+the number seen by the user."
+ (if (ediff-valid-difference-p n)
+ (let* ((ctl-buf ediff-control-buffer)
+ (regex-A ediff-regexp-focus-A)
+ (regex-B ediff-regexp-focus-B)
+ (regex-C ediff-regexp-focus-C)
+ (reg-A-match (ediff-eval-in-buffer ediff-buffer-A
+ (goto-char (ediff-get-diff-posn 'A 'beg n ctl-buf))
+ (re-search-forward
+ regex-A
+ (ediff-get-diff-posn 'A 'end n ctl-buf)
+ t)))
+ (reg-B-match (ediff-eval-in-buffer ediff-buffer-B
+ (goto-char (ediff-get-diff-posn 'B 'beg n ctl-buf))
+ (re-search-forward
+ regex-B
+ (ediff-get-diff-posn 'B 'end n ctl-buf)
+ t)))
+ (reg-C-match (if ediff-3way-comparison-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (goto-char
+ (ediff-get-diff-posn 'C 'beg n ctl-buf))
+ (re-search-forward
+ regex-C
+ (ediff-get-diff-posn 'C 'end n ctl-buf)
+ t)))))
+ (not (eval (if ediff-3way-comparison-job
+ (list ediff-focus-regexp-connective
+ reg-A-match reg-B-match reg-C-match)
+ (list ediff-focus-regexp-connective
+ reg-A-match reg-B-match))))
+ )))
+
+(defun ediff-hide-regexp-matches (n)
+ "Hide diffs that match regexp `ediff-regexp-hide-A/B/C'.
+Regions to be ignored are those where buf A region matches
+`ediff-regexp-hide-A' and buf B region matches `ediff-regexp-hide-B'.
+This function returns nil if the region number N (specified as
+an argument) is not to be ignored and t if region N is to be ignored.
+
+N is a region number used by Ediff internally. It is 1 less
+the number seen by the user."
+ (if (ediff-valid-difference-p n)
+ (let* ((ctl-buf ediff-control-buffer)
+ (regex-A ediff-regexp-hide-A)
+ (regex-B ediff-regexp-hide-B)
+ (regex-C ediff-regexp-hide-C)
+ (reg-A-match (ediff-eval-in-buffer ediff-buffer-A
+ (goto-char (ediff-get-diff-posn 'A 'beg n ctl-buf))
+ (re-search-forward
+ regex-A
+ (ediff-get-diff-posn 'A 'end n ctl-buf)
+ t)))
+ (reg-B-match (ediff-eval-in-buffer ediff-buffer-B
+ (goto-char (ediff-get-diff-posn 'B 'beg n ctl-buf))
+ (re-search-forward
+ regex-B
+ (ediff-get-diff-posn 'B 'end n ctl-buf)
+ t)))
+ (reg-C-match (if ediff-3way-comparison-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (goto-char
+ (ediff-get-diff-posn 'C 'beg n ctl-buf))
+ (re-search-forward
+ regex-C
+ (ediff-get-diff-posn 'C 'end n ctl-buf)
+ t)))))
+ (eval (if ediff-3way-comparison-job
+ (list ediff-hide-regexp-connective
+ reg-A-match reg-B-match reg-C-match)
+ (list ediff-hide-regexp-connective reg-A-match reg-B-match)))
+ )))
+
+
+
+;;; Quitting, suspending, etc.
+
+(defun ediff-quit ()
+ "Finish an Ediff session and exit Ediff.
+Unselects the selected difference, if any, restores the read-only and modified
+flags of the compared file buffers, kills Ediff buffers for this session
+\(but not buffers A, B, C\)."
+ (interactive)
+ (if (prog1
+ (y-or-n-p "Do you really want to exit Ediff? ")
+ (message ""))
+ (ediff-really-quit)))
+
+
+;; Perform the quit operations.
+(defun ediff-really-quit ()
+ (ediff-restore-buffer-characteristics t) ; restore as they were at setup
+ (ediff-unhighlight-diffs-totally)
+ (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
+ (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
+ (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
+
+ (ediff-delete-temp-files)
+
+ ;; Restore visibility range. This affects only ediff-*-regions/windows.
+ ;; Since for other job names ediff-visible-region sets
+ ;; ediff-visible-bounds to ediff-wide-bounds, the settings below are
+ ;; ignored for such jobs.
+ (if ediff-quit-widened
+ (setq ediff-visible-bounds ediff-wide-bounds)
+ (setq ediff-visible-bounds ediff-narrow-bounds))
+
+ ;; Apply selective display to narrow or widen
+ (ediff-visible-region)
+ (mapcar (function (lambda (overl)
+ (if (ediff-overlayp overl)
+ (ediff-delete-overlay overl))))
+ ediff-wide-bounds)
+ (mapcar (function (lambda (overl)
+ (if (ediff-overlayp overl)
+ (ediff-delete-overlay overl))))
+ ediff-narrow-bounds)
+
+ ;; restore buffer mode line id's in buffer-A/B/C
+ ;; much of what is here, except for mode line, will be deleted when Emacs
+ ;; acquires before/after-string overlay properties
+ (let ((control-buffer ediff-control-buffer))
+ (condition-case nil
+ (ediff-eval-in-buffer ediff-buffer-A
+ (setq before-change-function nil)
+ (setq ediff-this-buffer-control-sessions
+ (delq control-buffer ediff-this-buffer-control-sessions))
+ (if (null ediff-this-buffer-control-sessions)
+ (setq local-write-file-hooks
+ (delq 'ediff-block-write-file local-write-file-hooks)))
+ (kill-local-variable 'ediff-file-checked-out-flag)
+ (kill-local-variable 'mode-line-buffer-identification)
+ (kill-local-variable 'mode-line-format)
+ )
+ (error))
+
+ (condition-case nil
+ (ediff-eval-in-buffer ediff-buffer-B
+ (setq ediff-this-buffer-control-sessions
+ (delq control-buffer ediff-this-buffer-control-sessions))
+ (if (null ediff-this-buffer-control-sessions)
+ (setq local-write-file-hooks
+ (delq 'ediff-block-write-file local-write-file-hooks)))
+ (setq before-change-function nil)
+ (kill-local-variable 'ediff-file-checked-out-flag)
+ (kill-local-variable 'mode-line-buffer-identification)
+ (kill-local-variable 'mode-line-format)
+ )
+ (error))
+
+ (condition-case nil
+ (ediff-eval-in-buffer ediff-buffer-C
+ (if (null ediff-this-buffer-control-sessions)
+ (setq local-write-file-hooks
+ (delq 'ediff-block-write-file local-write-file-hooks)))
+ (setq before-change-function nil)
+ (kill-local-variable 'ediff-file-checked-out-flag)
+ (kill-local-variable 'mode-line-buffer-identification)
+ (kill-local-variable 'mode-line-format)
+ )
+ (error))
+ )
+ ;; restore state of buffers to what it was before ediff
+ (ediff-restore-protected-variables)
+ (run-hooks 'ediff-quit-hooks))
+
+
+(defun ediff-delete-temp-files ()
+ (if (stringp ediff-temp-file-A)
+ (delete-file ediff-temp-file-A))
+ (if (stringp ediff-temp-file-B)
+ (delete-file ediff-temp-file-B))
+ (if (stringp ediff-temp-file-C)
+ (delete-file ediff-temp-file-C)))
+
+
+;; Kill control buffer, other auxiliary Ediff buffers.
+;; Leave one of the frames split between buffers A/B/C
+(defun ediff-cleanup-mess ()
+ (let ((buff-A ediff-buffer-A)
+ (buff-B ediff-buffer-B)
+ (buff-C ediff-buffer-C)
+ (ctl-buf ediff-control-buffer)
+ (ctl-frame ediff-control-frame)
+ (three-way-job ediff-3way-job))
+
+ (ediff-kill-buffer-carefully ediff-diff-buffer)
+ (ediff-kill-buffer-carefully ediff-custom-diff-buffer)
+ (ediff-kill-buffer-carefully ediff-fine-diff-buffer)
+ (ediff-kill-buffer-carefully ediff-tmp-buffer)
+ (ediff-kill-buffer-carefully ediff-error-buffer)
+ (ediff-kill-buffer-carefully ediff-patch-diagnostics)
+ (ediff-kill-buffer-carefully ediff-msg-buffer)
+ (ediff-kill-buffer-carefully ediff-debug-buffer)
+
+ ;; XEmacs 19.11 has a bug (?) that doesn't let us delete buffer in
+ ;; dedicated window. So, we delete the frame first.
+ (redraw-display)
+ (if (and window-system (ediff-frame-live-p ctl-frame))
+ (ediff-delete-frame ctl-frame))
+ (ediff-kill-buffer-carefully ctl-buf)
+
+ (delete-other-windows)
+
+ ;; display only if not visible
+ (condition-case nil
+ (or (ediff-get-visible-buffer-window buff-B)
+ (switch-to-buffer buff-B))
+ (error))
+ (condition-case nil
+ (or (ediff-get-visible-buffer-window buff-A)
+ (progn
+ (if (ediff-get-visible-buffer-window buff-B)
+ (split-window-vertically))
+ (switch-to-buffer buff-A)))
+ (error))
+ (if three-way-job
+ (condition-case nil
+ (or (ediff-get-visible-buffer-window buff-C)
+ (progn
+ (if (or (ediff-get-visible-buffer-window buff-A)
+ (ediff-get-visible-buffer-window buff-B))
+ (split-window-vertically))
+ (switch-to-buffer buff-C)
+ (balance-windows)))
+ (error)))
+ (message "")
+ ))
+
+;; The default way of suspending Ediff.
+;; Buries Ediff buffers, kills all windows.
+(defun ediff-default-suspend-hook ()
+ (let* ((buf-A ediff-buffer-A)
+ (buf-B ediff-buffer-B)
+ (buf-C ediff-buffer-C)
+ (buf-A-wind (ediff-get-visible-buffer-window buf-A))
+ (buf-B-wind (ediff-get-visible-buffer-window buf-B))
+ (buf-C-wind (ediff-get-visible-buffer-window buf-C))
+ (buf-patch ediff-patch-buf)
+ (buf-patch-diag ediff-patch-diagnostics)
+ (buf-err ediff-error-buffer)
+ (buf-diff ediff-diff-buffer)
+ (buf-custom-diff ediff-custom-diff-buffer)
+ (buf-fine-diff ediff-fine-diff-buffer))
+
+ ;; hide the control panel
+ (if (and window-system (ediff-frame-live-p ediff-control-frame))
+ (ediff-iconify-frame ediff-control-frame)
+ (bury-buffer))
+ (if buf-err (bury-buffer buf-err))
+ (if buf-diff (bury-buffer buf-diff))
+ (if buf-custom-diff (bury-buffer buf-custom-diff))
+ (if buf-fine-diff (bury-buffer buf-fine-diff))
+ (if buf-patch (bury-buffer buf-patch))
+ (if buf-patch-diag (bury-buffer buf-patch-diag))
+ (if (window-live-p buf-A-wind)
+ (progn
+ (select-window buf-A-wind)
+ (delete-other-windows)
+ (bury-buffer))
+ (if (ediff-buffer-live-p buf-A) (bury-buffer buf-A)))
+ (if (window-live-p buf-B-wind)
+ (progn
+ (select-window buf-B-wind)
+ (delete-other-windows)
+ (bury-buffer))
+ (if (ediff-buffer-live-p buf-B) (bury-buffer buf-B)))
+ (if (window-live-p buf-C-wind)
+ (progn
+ (select-window buf-C-wind)
+ (delete-other-windows)
+ (bury-buffer))
+ (if (ediff-buffer-live-p buf-C) (bury-buffer buf-C)))
+
+ ))
+
+
+(defun ediff-suspend ()
+ "Suspend Ediff.
+To resume, switch to the appropriate `Ediff Control Panel'
+buffer and then type \\[ediff-recenter]. Ediff will automatically set
+up an appropriate window config."
+ (interactive)
+ (let ((key (substitute-command-keys "\\[ediff-recenter]")))
+ (run-hooks 'ediff-suspend-hooks)
+ (message
+ "To resume, switch to Ediff Control Panel and hit `%s'" key)))
+
+
+(defun ediff-status-info ()
+ "Show the names of the buffers or files being operated on by Ediff.
+Hit \\[ediff-recenter] to reset the windows afterward."
+ (interactive)
+ (with-output-to-temp-buffer " *ediff-info*"
+ (princ (ediff-version))
+ (princ "\n\n")
+ (ediff-eval-in-buffer ediff-buffer-A
+ (if buffer-file-name
+ (princ
+ (format "File A = %S\n" buffer-file-name))
+ (princ
+ (format "Buffer A = %S\n" (buffer-name)))))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (if buffer-file-name
+ (princ
+ (format "File B = %S\n" buffer-file-name))
+ (princ
+ (format "Buffer B = %S\n" (buffer-name)))))
+ (if ediff-3way-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (if buffer-file-name
+ (princ
+ (format "File C = %S\n" buffer-file-name))
+ (princ
+ (format "Buffer C = %S\n" (buffer-name))))))
+
+ (let* ((A-line (ediff-eval-in-buffer ediff-buffer-A
+ (1+ (count-lines (point-min) (point)))))
+ (B-line (ediff-eval-in-buffer ediff-buffer-B
+ (1+ (count-lines (point-min) (point)))))
+ C-line)
+ (princ (format "\Buffer A's point is on line %d\n" A-line))
+ (princ (format "Buffer B's point is on line %d\n" B-line))
+ (if ediff-3way-job
+ (progn
+ (setq C-line (ediff-eval-in-buffer ediff-buffer-C
+ (1+ (count-lines (point-min) (point)))))
+ (princ (format "Buffer C's point is on line %d\n" C-line)))))
+
+ (princ (format "\nCurrent difference number = %S\n"
+ (cond ((< ediff-current-difference 0) 'start)
+ ((>= ediff-current-difference
+ ediff-number-of-differences) 'end)
+ (t (1+ ediff-current-difference)))))
+
+ (cond (ediff-ignore-similar-regions
+ (princ "\nSkipping regions that differ only in white space & line breaks"))
+ (t
+ (princ "\nNot skipping regions that differ in white space & line breaks")))
+
+ (cond ((eq ediff-skip-diff-region-function 'ediff-show-all-diffs)
+ (princ "\nSelective browsing by regexp is off.\n"))
+ ((eq ediff-skip-diff-region-function 'ediff-hide-regexp-matches)
+ (princ
+ "\nIgnoring regions that match")
+ (princ
+ (format
+ "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
+ ediff-regexp-hide-A ediff-hide-regexp-connective
+ ediff-regexp-hide-B)))
+ ((eq ediff-skip-diff-region-function 'ediff-focus-on-regexp-matches)
+ (princ
+ "\nFocusing on regions that match")
+ (princ
+ (format
+ "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
+ ediff-regexp-focus-A ediff-focus-regexp-connective
+ ediff-regexp-focus-B)))
+ (t (princ "\nSelective browsing via a user-defined method.\n")))
+
+ (princ
+ (format "\nBugs/suggestions: type `%s' while in Ediff Control Panel."
+ (substitute-command-keys "\\[ediff-submit-report]")))
+ ))
+
+
+
+
+;;; Support routines
+
+;; Select a difference by placing the ASCII flags around the appropriate
+;; group of lines in the A, B buffers
+;; This may have to be modified for buffer C, when it will be supported.
+(defun ediff-select-difference (n)
+ (if (and (ediff-buffer-live-p ediff-buffer-A)
+ (ediff-buffer-live-p ediff-buffer-B)
+ (ediff-valid-difference-p n))
+ (progn
+ (ediff-remember-buffer-characteristics)
+ (if (and window-system ediff-use-faces)
+ (progn
+ (ediff-highlight-diff n)
+ (setq ediff-highlighting-style 'face))
+ (setq ediff-highlighting-style 'ascii)
+ (ediff-place-flags-in-buffer 'A ediff-buffer-A
+ ediff-control-buffer n)
+ (ediff-place-flags-in-buffer 'B ediff-buffer-B
+ ediff-control-buffer n)
+ (if ediff-3way-job
+ (ediff-place-flags-in-buffer 'C ediff-buffer-C
+ ediff-control-buffer n))
+ )
+
+ (ediff-install-fine-diff-if-necessary n)
+
+ (ediff-restore-buffer-characteristics)
+ (run-hooks 'ediff-select-hooks))))
+
+
+;; Unselect a difference by removing the ASCII flags in the buffers.
+;; This may have to be modified for buffer C, when it will be supported.
+(defun ediff-unselect-difference (n)
+ (if (ediff-valid-difference-p n)
+ (progn
+ (ediff-remember-buffer-characteristics)
+
+ (cond ((and window-system ediff-use-faces)
+ (ediff-unhighlight-diff))
+ ((eq ediff-highlighting-style 'ascii)
+ (ediff-remove-flags-from-buffer
+ ediff-buffer-A
+ (ediff-get-diff-overlay n 'A)
+ (ediff-get-diff-posn 'A 'beg n)
+ (ediff-get-diff-posn 'A 'end n)
+ ediff-before-flag-A ediff-after-flag-A)
+ (ediff-remove-flags-from-buffer
+ ediff-buffer-B
+ (ediff-get-diff-overlay n 'B)
+ (ediff-get-diff-posn 'B 'beg n)
+ (ediff-get-diff-posn 'B 'end n)
+ ediff-before-flag-B ediff-after-flag-B)
+ (if ediff-3way-job
+ (ediff-remove-flags-from-buffer
+ ediff-buffer-C
+ (ediff-get-diff-overlay n 'C)
+ (ediff-get-diff-posn 'C 'beg n)
+ (ediff-get-diff-posn 'C 'end n)
+ ediff-before-flag-C ediff-after-flag-C))
+ ))
+
+ (ediff-restore-buffer-characteristics)
+ (setq ediff-highlighting-style nil)
+
+ ;; unhighlight fine diffs
+ (ediff-set-fine-diff-properties ediff-current-difference 'default)
+
+ (run-hooks 'ediff-unselect-hooks))))
+
+
+;; Unselects prev diff and selects a new one, if FLAG has value other than
+;; 'select-only or 'unselect-only. If FLAG is 'select-only, the
+;; next difference is selected, but the current selection is not
+;; unselected. If FLAG is 'unselect-only then the current selection is
+;; unselected, but the next one is not selected. If NO-RECENTER is non-nil,
+;; don't recenter buffers after selecting/unselecting.
+;;
+;; Don't use `ediff-select-difference' and `ediff-unselect-difference'
+;; directly, since this will screw up the undo info in the presence of
+;; ASCII flags.
+;; Instead, use `ediff-unselect-and-select-difference' with appropriate
+;; flags.
+
+(defun ediff-unselect-and-select-difference (n &optional flag no-recenter)
+ (let (;; save buf modified info
+ (control-buf ediff-control-buffer)
+ (buf-A-modified (buffer-modified-p ediff-buffer-A))
+ (buf-B-modified (buffer-modified-p ediff-buffer-B))
+ ;; temporarily disable undo so highlighting won't confuse the user
+ buf-C-modified buf-A-undo buf-B-undo buf-C-undo)
+
+ (let ((ediff-current-difference n))
+ (or no-recenter
+ (ediff-recenter 'no-rehighlight)))
+
+ (if (and (ediff-buffer-live-p ediff-buffer-A)
+ (ediff-buffer-live-p ediff-buffer-B))
+ (progn
+ (ediff-eval-in-buffer ediff-buffer-A
+ (setq buf-A-undo buffer-undo-list))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (setq buf-B-undo buffer-undo-list))
+ (buffer-disable-undo ediff-buffer-A)
+ (buffer-disable-undo ediff-buffer-B)))
+
+ (if (ediff-buffer-live-p ediff-buffer-C)
+ (progn
+ (setq buf-C-modified (buffer-modified-p ediff-buffer-C))
+ (ediff-eval-in-buffer ediff-buffer-C
+ (setq buf-C-undo buffer-undo-list))
+ (buffer-disable-undo ediff-buffer-C)))
+
+ (unwind-protect ; we don't want to lose undo info due to error
+ (progn
+ (or (eq flag 'select-only)
+ (ediff-unselect-difference ediff-current-difference))
+
+ ;; Auto-save buffers while Ediff flags are temporarily removed.
+ (ediff-eval-in-buffer ediff-buffer-A
+ (if buf-A-modified (do-auto-save)))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (if buf-B-modified (do-auto-save)))
+ (if (ediff-buffer-live-p ediff-buffer-C)
+ (ediff-eval-in-buffer ediff-buffer-C
+ (if buf-C-modified (do-auto-save))))
+
+ (or (eq flag 'unselect-only)
+ (ediff-select-difference n))
+ (setq ediff-current-difference n)
+ ) ; end protected section
+
+ (ediff-eval-in-buffer control-buf
+ (ediff-refresh-mode-lines)
+ ;; restore undo and buffer-modified info
+ (ediff-eval-in-buffer ediff-buffer-A
+ (set-buffer-modified-p buf-A-modified)
+ (setq buffer-undo-list buf-A-undo)))
+ (ediff-eval-in-buffer control-buf
+ (ediff-eval-in-buffer ediff-buffer-B
+ (set-buffer-modified-p buf-B-modified)
+ (setq buffer-undo-list buf-B-undo)))
+ (if (ediff-buffer-live-p ediff-buffer-C)
+ (ediff-eval-in-buffer control-buf
+ (ediff-eval-in-buffer ediff-buffer-C
+ (set-buffer-modified-p buf-C-modified)
+ (setq buffer-undo-list buf-C-undo))))
+ )))
+
+
+(defun ediff-read-file-name (prompt default-dir default-file)
+; This is a modified version of a similar function in `emerge.el'.
+; PROMPT should not have trailing ': ', so that it can be modified
+; according to context.
+; If default-file is set, it should be used as the default value.
+; If default-dir is non-nil, use it as the default directory.
+; Otherwise, use the value of Emacs' variable `default-directory.'
+
+ ;; hack default-dir if it is not set
+ (setq default-dir
+ (file-name-as-directory
+ (abbreviate-file-name
+ (expand-file-name (or default-dir
+ (and default-file
+ (file-name-directory default-file))
+ default-directory)))))
+
+ ;; strip the directory from default-file
+ (if default-file
+ (setq default-file (file-name-nondirectory default-file)))
+ (if (string= default-file "")
+ (setq default-file nil))
+
+ (let (f)
+ (setq f (expand-file-name
+ (read-file-name
+ (format "%s%s: "
+ prompt
+ (if default-file
+ (concat " (default " default-file ")")
+ ""))
+ default-dir
+ default-file
+ 'confirm
+ (if default-file (file-name-directory default-file))
+ )
+ default-dir
+ ))
+ ;; If user enters a directory name, expand the default file in that
+ ;; directory. This allows the user to enter a directory name for the
+ ;; B-file and diff against the default-file in that directory instead
+ ;; of a DIRED listing!
+ (if (and (file-directory-p f) default-file)
+ (setq f (expand-file-name
+ (file-name-nondirectory default-file) f)))
+ f))
+
+;; If `prefix' is given, then it is used as a prefix for the temp file
+;; name. Otherwise, `_buffer-name' is used. If `file' is given, use this
+;; file and don't create a new one.
+(defun ediff-make-temp-file (&optional prefix given-file start end)
+ (let ((f (or given-file
+ (make-temp-name (concat
+ ediff-temp-file-prefix
+ (if prefix
+ (concat prefix "_")
+ "ediff_"))))))
+ ;; create the file
+ (write-region (if start start (point-min))
+ (if end end (point-max))
+ f
+ nil ; don't append---erase
+ 'no-message)
+ (set-file-modes f ediff-temp-file-mode)
+ f))
+
+;; Quote metacharacters (using \) when executing diff in Unix, but not in
+;; EMX OS/2
+(defun ediff-protect-metachars (str)
+ (or (memq system-type '(emx vax-vms axp-vms))
+ (let ((limit 0))
+ (while (string-match ediff-metachars str limit)
+ (setq str (concat (substring str 0 (match-beginning 0))
+ "\\"
+ (substring str (match-beginning 0))))
+ (setq limit (1+ (match-end 0))))))
+ str)
+
+;; Make sure the current buffer (for a file) has the same contents as the
+;; file on disk, and attempt to remedy the situation if not.
+;; Signal an error if we can't make them the same, or the user doesn't want
+;; to do what is necessary to make them the same.
+;; If file has file handlers (indicated by the optional arg), then we
+;; offer to instead of saving. This is one difference with Emerge.
+;; Another is that we always offer to revert obsolete files, whether they
+;; are modified or not.
+(defun ediff-verify-file-buffer (&optional file-magic)
+ ;; First check if the file has been modified since the buffer visited it.
+ (if (verify-visited-file-modtime (current-buffer))
+ (if (buffer-modified-p)
+ ;; If buffer is not obsolete and is modified, offer to save
+ (if (yes-or-no-p
+ (format "Buffer out of sync with visited file. %s file %s? "
+ (if file-magic "Revert" "Save")
+ buffer-file-name))
+ (if (not file-magic)
+ (save-buffer)
+ ;; for some reason, file-name-handlers append instead of
+ ;; replacing, so we have to erase first.
+ (erase-buffer)
+ (revert-buffer t t))
+ (error "Buffer out of sync for file %s" buffer-file-name))
+ ;; If buffer is not obsolete and is not modified, do nothing
+ nil)
+ ;; If buffer is obsolete, offer to revert
+ (if (yes-or-no-p
+ (format "Buffer out of sync with visited file. Revert file %s? "
+ buffer-file-name))
+ (progn
+ (if file-magic
+ (erase-buffer))
+ (revert-buffer t t))
+ (error "Buffer out of sync for file %s" buffer-file-name))))
+
+
+;; to be deleted in due time
+(defun ediff-block-write-file ()
+ "Prevent writing files A and B directly."
+ (if (ediff-check-for-ascii-flags)
+ (error "Type `wa' and `wb' in Ediff Control Panel to save buffs A/B")))
+
+;; To be deleted in due time
+(defun ediff-before-change-guard (start end)
+ "If buffer is highlighted with ASCII flags, remove highlighting.
+Arguments, START and END are not used, but are provided
+because this is required by `before-change-function'."
+ (let (rehighlight-key)
+ (save-window-excursion
+ (mapcar
+ (function
+ (lambda (buf)
+ (ediff-eval-in-buffer buf
+ (if (eq ediff-highlighting-style 'ascii)
+ (progn
+ (ediff-unselect-and-select-difference
+ ediff-current-difference
+ 'unselect-only 'no-recenter)
+ (setq rehighlight-key
+ (substitute-command-keys "\\[ediff-recenter]"))
+ )))))
+ ediff-this-buffer-control-sessions)
+ (if rehighlight-key
+ (error
+ "ASCII flags removed. You can edit now. Hit `%s' to rehighlight"
+ rehighlight-key))
+ )))
+
+
+(defun ediff-check-for-ascii-flags ()
+ (eval
+ (cons 'or
+ (mapcar (function (lambda (buf)
+ (if (ediff-buffer-live-p buf)
+ (ediff-eval-in-buffer buf
+ (eq ediff-highlighting-style 'ascii)))))
+ ediff-this-buffer-control-sessions))))
+
+;; It would be nice to use these two functions as hooks instead of
+;; ediff-insert-in-front and ediff-move-disturbed-overlays.
+;; However, Emacs has a bug that causes BEG and END, below, to be
+;; the same, i.e., the end of inserted text is not passed correctly.
+;; Since the overlay doesn't move when these hooks run,
+;; there is no way to correctly determine the new (desired) position of
+;; the overlay end.
+;; Either this bug is fixed, or (better) use sticky overlays when they will
+;; be implemented in Emacs, like they are in XEmacs.
+;;(defun ediff-capture-inserts-in-front (overl beg end)
+;; (if (ediff-overlay-get overl 'ediff-diff-num)
+;; (ediff-move-overlay
+;; overl beg (+ (- end beg) (ediff-overlay-end overl)))
+;; ))
+;;(defun ediff-capture-inserts-behind (overl beg end)
+;; (if (ediff-overlay-get overl 'ediff-diff-num)
+;; (ediff-move-overlay overl (ediff-overlay-start overl) end))
+;; ))
+
+;; to be deleted in due time
+;; Capture overlays that had insertions in the front.
+;; Called when overlay OVERL gets insertion in front.
+(defun ediff-insert-in-front (overl &optional flag beg end length)
+ (if (ediff-overlay-get overl 'ediff-diff-num)
+ (setq ediff-disturbed-overlays
+ (cons overl ediff-disturbed-overlays))))
+
+;; to be deleted in due time
+;; Collects all extents at POS having property `ediff-diff-num'.
+;; XEmacs causes headache by detaching empty extents, so I have to save
+;; them before they disappear.
+(defun ediff-collect-extents-xemacs (pos)
+ (let (lis elt)
+ (while (setq elt (extent-at pos nil 'ediff-diff-num elt))
+ (setq lis (cons elt lis)))
+ (setq ediff-disturbed-overlays lis)))
+
+;; to be deleted in due time
+;; We can't move overlays directly in insert-in-front-hooks
+;; because when diff is highlighted with ascii flags, they will disturb
+;; overlays and so they will be included in them, which we don't want.
+(defun ediff-move-disturbed-overlays (posn)
+ (mapcar (function (lambda (overl)
+ (ediff-move-overlay overl
+ posn
+ (ediff-overlay-end overl))
+ ))
+ ediff-disturbed-overlays)
+ (setq ediff-disturbed-overlays nil))
+
+;; to be deleted in due time
+;; If XEmacs adds the ability to not detach extents, we should be able to
+;; delete this
+(defun ediff-adjust-disturbed-extents-xemacs (posn)
+ (mapcar (function (lambda (overl)
+ (if (equal (ediff-overlay-start overl)
+ (ediff-overlay-end overl))
+ (ediff-move-overlay overl posn posn))))
+ ediff-disturbed-overlays)
+ (setq ediff-disturbed-overlays nil))
+
+(defun ediff-save-buffer (arg)
+ "Safe way of saving buffers A, B, C, and the diff output.
+`wa' saves buffer A, `wb' saves buffer B, `wc' saves buffer C,
+and `wd' saves the diff output."
+ (interactive "P")
+ (let ((hooks local-write-file-hooks))
+ (ediff-unselect-and-select-difference ediff-current-difference
+ 'unselect-only)
+ (unwind-protect
+ (ediff-eval-in-buffer
+ (cond ((memq last-command-char '(?a ?b ?c))
+ (ediff-get-buffer
+ (ediff-char-to-buftype last-command-char)))
+ ((eq last-command-char ?d)
+ (message "Saving diff output ...")(sit-for 1)
+ (if arg ediff-diff-buffer ediff-custom-diff-buffer)
+ ))
+ ;; temporarily remove writing block
+ (setq hooks (delq 'ediff-block-write-file hooks))
+ (let ((local-write-file-hooks hooks))
+ (save-buffer)))
+ (ediff-unselect-and-select-difference ediff-current-difference
+ 'select-only)
+ )))
+
+
+;; will simplify it in due time, when emacs acquires before/after strings
+(defun ediff-remove-flags-from-buffer (buffer overlay before-posn after-posn
+ before-flag after-flag)
+ (ediff-eval-in-buffer buffer
+ (let ((before-flag-length (length before-flag))
+ (after-flag-length (length after-flag))
+ (inhibit-read-only t)
+ buffer-read-only
+ before-change-function)
+ (goto-char after-posn)
+ (setq after-posn (point-marker)) ; after-posn is now a marker
+ ;; remove the flags, if they're there
+ (goto-char (- before-posn before-flag-length))
+ (if ediff-xemacs-p
+ (ediff-overlay-put overlay 'begin-glyph nil)
+ ;; before-string is not yet implemented in emacs.
+ ;; when it will be, I will be able to delete much of the rest of
+ ;; this function
+ (ediff-overlay-put overlay 'before-string nil)
+ (if (looking-at (regexp-quote before-flag))
+ (delete-region (point) (+ (point) before-flag-length))
+ ;; flag isn't there
+ (ding)
+ (message "Trouble removing ASCII flag"))
+ )
+
+ (if ediff-xemacs-p
+ (ediff-overlay-put overlay 'end-glyph nil)
+ ;; after-string is not yet implemented in emacs.
+ (ediff-overlay-put overlay 'after-string nil)
+ (goto-char after-posn)
+ (if (looking-at (regexp-quote after-flag))
+ (delete-region (point) (+ (point) after-flag-length))
+ ;; flag isn't there
+ (ding)
+ (message "Trouble removing ASCII flag"))
+ (setq after-posn nil) ; after has become a marker--garbage-collect
+ )
+ )))
+
+
+
+;; will simplify it in due time, when emacs acquires before/after strings
+(defun ediff-place-flags-in-buffer (buf-type buffer ctl-buffer diff)
+ (ediff-eval-in-buffer buffer
+ (ediff-place-flags-in-buffer1 buf-type ctl-buffer diff)))
+
+
+(defun ediff-place-flags-in-buffer1 (buf-type ctl-buffer diff-no)
+ (let* ((before-flag-name (intern (format "ediff-before-flag-%S" buf-type)))
+ (after-flag-name (intern (format "ediff-after-flag-%S" buf-type)))
+ (curr-overl (ediff-eval-in-buffer ctl-buffer
+ (ediff-get-diff-overlay diff-no buf-type)))
+ (inhibit-read-only t)
+ (narrow-overlay (ediff-eval-in-buffer ctl-buffer
+ (ediff-get-value-according-to-buffer-type
+ buf-type ediff-narrow-bounds)))
+ (wide-overlay (ediff-eval-in-buffer ctl-buffer
+ (ediff-get-value-according-to-buffer-type
+ buf-type ediff-wide-bounds)))
+ (visibility-overlay (ediff-eval-in-buffer ctl-buffer
+ (ediff-get-value-according-to-buffer-type
+ buf-type ediff-visible-bounds)))
+ (visibility-min (ediff-overlay-start visibility-overlay))
+ (visibility-max (ediff-overlay-end visibility-overlay))
+ (before (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer))
+ after buffer-read-only before-change-function beg-of-line flag)
+
+ ;; we need it to be a marker
+ (setq visibility-max
+ (move-marker
+ (make-marker) (if (numberp visibility-max) visibility-max 1)))
+
+ (widen)
+
+ ;; insert flag before the difference
+ (goto-char before)
+ (setq beg-of-line (bolp))
+
+ (setq flag (ediff-eval-in-buffer ctl-buffer
+ (if beg-of-line
+ (set before-flag-name ediff-before-flag-bol)
+ (set before-flag-name ediff-before-flag-mol))))
+
+ ;; insert the flag itself
+ (if ediff-xemacs-p
+ (ediff-overlay-put curr-overl 'begin-glyph flag)
+ ;; before-string is not yet implemented in emacs.
+ ;; when it will, I will be able to delete much of the rest of this
+ ;; function
+ ;;(ediff-overlay-put curr-overl 'before-string flag)
+ (insert-before-markers flag)
+ (if (or (not (numberp visibility-min)) (< before visibility-min))
+ (setq visibility-min before))
+ )
+
+ ;; insert the flag after the difference
+ ;; `after' must be set here, after the before-flag was inserted
+ (setq after (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
+ (goto-char after)
+ (setq beg-of-line (bolp))
+
+ (setq flag (ediff-eval-in-buffer ctl-buffer
+ (if beg-of-line
+ (set after-flag-name ediff-after-flag-eol)
+ (set after-flag-name ediff-after-flag-mol))))
+
+ ;; insert the flag itself
+ (if ediff-xemacs-p
+ ;; In XEmacs, end-glyph of a 0-length overlay is not inserted.
+ ;; Hopefully, this bug will be fixed in 19.12.
+ (ediff-overlay-put curr-overl 'end-glyph flag)
+ ;; after-string is not yet implemented in emacs.
+ ;;(ediff-overlay-put curr-overl 'after-string flag)
+ (insert flag)
+ (if (> (point) visibility-max)
+ (move-marker visibility-max (point)))
+ )
+ (narrow-to-region visibility-min visibility-max)
+ (ediff-move-overlay wide-overlay
+ (min before
+ (ediff-overlay-start wide-overlay))
+ (max (point)
+ (ediff-overlay-end wide-overlay)))
+ (ediff-move-overlay narrow-overlay
+ (min before
+ (ediff-overlay-start narrow-overlay))
+ (max (point)
+ (ediff-overlay-end narrow-overlay)))
+
+ (setq visibility-max nil) ; garbage-collect it
+ ))
+
+
+(defun ediff-get-diff-posn (buf-type pos &optional n control-buf)
+ "Returns positions of difference sectors in the BUF-TYPE buffer.
+BUF-TYPE should be a symbol--either `A' or `B'.
+POS is either `beg' or `end'--it specifies whether you want the position at the
+beginning of a difference or at the end.
+
+The optional argument N says which difference \(default:
+`ediff-current-difference'\). The optional argument CONTROL-BUF says
+which control buffer is in effect in case it is not the current
+buffer."
+ (let (diff-overlay)
+ (or control-buf
+ (setq control-buf (current-buffer)))
+
+ (ediff-eval-in-buffer control-buf
+ (or n (setq n ediff-current-difference))
+ (if (or (< n 0) (>= n ediff-number-of-differences))
+ (if (> ediff-number-of-differences 0)
+ (error "There is no diff %d. Valid diffs are 1 to %d"
+ (1+ n) ediff-number-of-differences)
+ (error "No differences found")))
+ (setq diff-overlay (ediff-get-diff-overlay n buf-type)))
+
+ (if (eq pos 'beg)
+ (ediff-overlay-start diff-overlay)
+ (ediff-overlay-end diff-overlay))
+ ))
+
+
+
+(defun ediff-highlight-diff-in-one-buffer (n buf-type)
+ (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
+ (let* ((buff (ediff-get-buffer buf-type))
+ (last (ediff-eval-in-buffer buff (point-max)))
+ (begin (ediff-get-diff-posn buf-type 'beg n))
+ (end (ediff-get-diff-posn buf-type 'end n))
+ (xtra (if (equal begin end) 1 0))
+ (end-hilit (min last (+ end xtra)))
+ (current-diff-overlay
+ (symbol-value
+ (intern (format "ediff-current-diff-overlay-%S" buf-type))))
+ (odd-diff-face
+ (symbol-value
+ (intern (format "ediff-odd-diff-face-%S" buf-type))))
+ (even-diff-face
+ (symbol-value
+ (intern (format "ediff-even-diff-face-%S" buf-type))))
+ (odd-diff-face-var
+ (intern (format "ediff-odd-diff-face-%S-var" buf-type)))
+ (even-diff-face-var
+ (intern (format "ediff-even-diff-face-%S-var" buf-type)))
+ )
+
+ (if ediff-xemacs-p
+ (ediff-move-overlay
+ current-diff-overlay begin end-hilit)
+ ;; Emacs 19.22 has a bug, which requires that ediff-move-overlay will
+ ;; have the buffer as a parameter. Believed fixed in 19.23.
+ (ediff-move-overlay current-diff-overlay
+ begin end-hilit buff))
+ ;; giving priority of 0 and then changing it may look funny, but
+ ;; this overcomes an obscure Emacs bug.
+ (ediff-overlay-put current-diff-overlay 'priority 0)
+ (ediff-overlay-put current-diff-overlay 'priority
+ (ediff-highest-priority begin end-hilit buff))
+
+ (or (face-differs-from-default-p odd-diff-face-var)
+ (not ediff-highlight-all-diffs)
+ (progn
+ (copy-face odd-diff-face odd-diff-face-var)
+ (copy-face even-diff-face even-diff-face-var)))
+
+ ;; unhighlight the background overlay for diff n so they won't
+ ;; interfere with the current diff overlay
+ (ediff-overlay-put (ediff-get-diff-overlay n buf-type) 'face nil)
+ )))
+
+
+(defun ediff-unhighlight-diff-in-one-buffer (buf-type)
+ (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
+ (let ((current-diff-overlay
+ (symbol-value
+ (intern (format "ediff-current-diff-overlay-%S" buf-type))))
+ (odd-diff-face-var
+ (intern (format "ediff-odd-diff-face-%S-var" buf-type)))
+ (even-diff-face-var
+ (intern (format "ediff-even-diff-face-%S-var" buf-type)))
+ (overlay
+ (ediff-get-diff-overlay ediff-current-difference buf-type))
+ )
+
+ (ediff-move-overlay current-diff-overlay 1 1)
+
+ ;; rehighlight the overlay in the background of the
+ ;; current difference region
+ (ediff-overlay-put overlay
+ 'face (if (ediff-odd-p ediff-current-difference)
+ odd-diff-face-var
+ even-diff-face-var))
+ )))
+
+(defun ediff-unhighlight-diffs-totally-in-one-buffer (buf-type)
+ (let (buffer-read-only)
+ (ediff-unselect-and-select-difference -1)
+ (if (and window-system ediff-use-faces)
+ (let* ((inhibit-quit t)
+ (current-diff-overlay-var
+ (intern (format "ediff-current-diff-overlay-%S" buf-type)))
+ (current-diff-overlay (symbol-value current-diff-overlay-var))
+ (odd-diff-face-var
+ (intern (format "ediff-odd-diff-face-%S-var" buf-type)))
+ (even-diff-face-var
+ (intern (format "ediff-even-diff-face-%S-var" buf-type))))
+ (if (face-differs-from-default-p odd-diff-face-var)
+ (progn
+ (copy-face 'default odd-diff-face-var)
+ (copy-face 'default even-diff-face-var)))
+ (if (ediff-overlayp current-diff-overlay)
+ (ediff-delete-overlay current-diff-overlay))
+ (set current-diff-overlay-var nil)
+ ))
+ ))
+
+
+;; null out difference overlays so they won't slow down future
+;; editing operations
+;; VEC is either a difference vector or a fine-diff vector
+(defun ediff-clear-diff-vector (vec-var &optional fine-diffs-also)
+ (if (vectorp (symbol-value vec-var))
+ (mapcar (function
+ (lambda (elt)
+ (ediff-delete-overlay
+ (ediff-get-diff-overlay-from-diff-record elt))
+ (if fine-diffs-also
+ (ediff-clear-fine-diff-vector elt))
+ ))
+ (symbol-value vec-var)))
+ ;; allow them to be garbage collected
+ (set vec-var nil))
+
+(defun ediff-operate-on-flags (action)
+ "Re/unhighlights buffers A and B with all flags from all Ediff sessions.
+This is usually needed only when a
+buffer is involved in multiple Ediff sessions."
+ (let* ((A-sessions (ediff-eval-in-buffer ediff-buffer-A
+ ediff-this-buffer-control-sessions))
+ (B-sessions (ediff-eval-in-buffer ediff-buffer-B
+ ediff-this-buffer-control-sessions))
+ (C-sessions (if ediff-3way-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ ediff-this-buffer-control-sessions)))
+ (sessions (ediff-union
+ (ediff-union A-sessions B-sessions) C-sessions))
+ (flag (if (eq action 'remove) 'unselect-only 'select-only)))
+
+ (mapcar (function
+ (lambda (buf)
+ (if (ediff-buffer-live-p buf)
+ (ediff-eval-in-buffer buf
+ (or (if (eq action 'insert)
+ (memq ediff-highlighting-style '(ascii off))
+ (not (eq ediff-highlighting-style 'ascii)))
+ (ediff-unselect-and-select-difference
+ ediff-current-difference
+ flag 'no-recenter))
+ ))))
+ sessions)))
+
+
+
+
+;;; Misc
+
+;; These two functions are here to neutralize XEmacs unwillingless to
+;; handle overlays whose buffers were deleted.
+(defun ediff-move-overlay (overlay beg end &optional buffer)
+ "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
+Checks if overlay's buffer exists before actually doing the move."
+ (let ((buf (and overlay (ediff-overlay-buffer overlay))))
+ (if (ediff-buffer-live-p buf)
+ (if ediff-xemacs-p
+ (progn
+ (set-extent-endpoints overlay beg end)
+ (set-extent-property overlay 'ediff-marker beg))
+ (move-overlay overlay beg end buffer))
+ ;; buffer's dead
+ (if overlay
+ (ediff-delete-overlay overlay)))))
+
+(defun ediff-overlay-put (overlay prop value)
+ "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
+Checks if overlay's buffer exists."
+ (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
+ (if ediff-xemacs-p
+ (set-extent-property overlay prop value)
+ (overlay-put overlay prop value))
+ (ediff-delete-overlay overlay)))
+
+
+;; In Emacs 19.23 and XEmacs 19.10, the number of variables to
+;; file-name-handler has changed.
+(defun ediff-find-file-name-handler (file)
+ (let (newvers)
+ (setq newvers (if ediff-xemacs-p
+ (ediff-check-version '> 19 9)
+ (ediff-check-version '> 19 22)))
+ (if newvers
+ (find-file-name-handler file 'find-file-noselect)
+ (find-file-name-handler file))))
+
+;; In XEmacs, it checks if the overlay is detached. If so, it reattaches
+;; this overlay at position specified by ediff-marker.
+;; If extent is not detached, it simply returns the start point.
+;; In Emacs, this is the same as overlay-start.
+;; If arg is not overlay, retuns nil
+(defun ediff-overlay-start (overl)
+ (if (ediff-overlay-p overl)
+ (if ediff-emacs-p
+ (overlay-start overl)
+ (let ((pos (extent-property overl 'ediff-marker)))
+ (if (and (ediff-overlay-get overl 'detached)
+ (number-or-marker-p pos))
+ (ediff-move-overlay overl pos pos))
+ (extent-start-position overl)))))
+
+;; In XEmacs, it checks if the overlay is detached. If so, it reattaches
+;; this overlay at position specified by ediff-marker.
+;; If extent is not detached, it simply returns the end point.
+;; In Emacs, this is the same as overlay-end.
+(defun ediff-overlay-end (overl)
+ (if (ediff-overlay-p overl)
+ (if ediff-emacs-p
+ (overlay-end overl)
+ (let ((pos (extent-property overl 'ediff-marker)))
+ (if (and (ediff-overlay-get overl 'detached)
+ (number-or-marker-p pos))
+ (ediff-move-overlay overl pos pos))
+ (extent-end-position overl)))))
+
+;; Makes overlays that remember their position, even if detached in XEmacs.
+;; In Emacs, this just makes overlay. In the future, when Emacs will start
+;; supporting sticky overlays, this function will make a sticky overlay.
+;; BEG and END are expressions telling where overlay starts.
+;; If they are numbers or buffers, then all is well. Otherwise, they must
+;; be expressions to be evaluated in buffer BUF in order to get the overlay
+;; bounds.
+;; If BUFF is not a live buffer, then return nil; otherwise, return the
+;; newly created overlay.
+(defun ediff-make-bullet-proof-overlay (beg end buff)
+ (if (ediff-buffer-live-p buff)
+ (let (overl)
+ (ediff-eval-in-buffer buff
+ (or (number-or-marker-p beg)
+ (setq beg (eval beg)))
+ (or (number-or-marker-p end)
+ (setq end (eval end)))
+ (setq overl (ediff-make-overlay beg end buff))
+
+ (if ediff-xemacs-p
+ (progn
+ ;; take precautions against detached extents
+ (ediff-overlay-put
+ overl 'ediff-marker (move-marker (make-marker) beg buff))
+ ;; chars inserted at both ends will be inside extent
+ (ediff-overlay-put overl 'start-open nil)
+ (ediff-overlay-put overl 'end-open nil))
+ (ediff-overlay-put overl 'ediff-diff-num 0)
+ ;;(ediff-overlay-put overl 'insert-in-front-hooks
+ ;; (list 'ediff-capture-inserts-in-front))
+ ;;(ediff-overlay-put overl 'insert-behind-hooks
+ ;; (list 'ediff-capture-inserts-behind))
+ ;; These two are not yet implemented in Emacs
+ ;;(ediff-overlay-put overl 'rear-sticky t)
+ ;;(ediff-overlay-put overl 'front-sticky t)
+ )
+ overl))))
+
+
+;; Check the current version against the major and minor version numbers
+;; using op: cur-vers op major.minor If emacs-major-version or
+;; emacs-minor-version are not defined, we assume that the current version
+;; is hopelessly outdated. We assume that emacs-major-version and
+;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
+;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
+;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
+;; incorrect. However, this gives correct result in our cases, since we are
+;; testing for sufficiently high Emacs versions.
+(defun ediff-check-version (op major minor &optional type-of-emacs)
+ (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
+ (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p)
+ ((eq type-of-emacs 'emacs) ediff-emacs-p)
+ (t t))
+ (cond ((eq op '=) (and (= emacs-minor-version minor)
+ (= emacs-major-version major)))
+ ((memq op '(> >= < <=))
+ (and (or (funcall op emacs-major-version major)
+ (= emacs-major-version major))
+ (if (= emacs-major-version major)
+ (funcall op emacs-minor-version minor)
+ t)))
+ (t
+ (error "%S: Invalid op in ediff-check-version" op))))
+ (cond ((memq op '(= > >=)) nil)
+ ((memq op '(< <=)) t))))
+
+
+;; Like other-buffer, but prefers visible buffers and ignores temporary or
+;; other insignificant buffers (those beginning with "^[ *]").
+;; Gets one arg--buffer name or a list of buffer names (it won't return
+;; these buffers).
+(defun ediff-other-buffer (buff)
+ (if (not (listp buff)) (setq buff (list buff)))
+ (let* ((screen-buffers (buffer-list))
+ (significant-buffers
+ (mapcar
+ (function (lambda (x)
+ (cond ((member (buffer-name x) buff)
+ nil)
+ ((not (ediff-get-visible-buffer-window x))
+ nil)
+ ((string-match "^ " (buffer-name x))
+ nil)
+ (t x))))
+ screen-buffers))
+ (buffers (delq nil significant-buffers))
+ less-significant-buffers)
+
+ (cond (buffers (car buffers))
+ ;; try also buffers that are not displayed in windows
+ ((setq less-significant-buffers
+ (delq nil
+ (mapcar
+ (function
+ (lambda (x)
+ (cond ((member (buffer-name x) buff) nil)
+ ((string-match "^[ *]" (buffer-name x)) nil)
+ (t x))))
+ screen-buffers)))
+ (car less-significant-buffers))
+ (t (other-buffer (current-buffer))))
+ ))
+
+
+;; Construct a unique buffer name.
+;; The first one tried is prefixsuffix, then prefix<2>suffix,
+;; prefix<3>suffix, etc.
+(defun ediff-unique-buffer-name (prefix suffix)
+ (if (null (get-buffer (concat prefix suffix)))
+ (concat prefix suffix)
+ (let ((n 2))
+ (while (get-buffer (format "%s<%d>%s" prefix n suffix))
+ (setq n (1+ n)))
+ (format "%s<%d>%s" prefix n suffix))))
+
+
+;; Early versions of XEmacs didn't have window-live-p (or it didn't work right)
+(if (ediff-check-version '< 19 11 'xemacs)
+ (defun window-live-p (win)
+ (let (visible)
+ (walk-windows
+ '(lambda (walk-win)
+ (if(equal walk-win win)
+ (setq visible t)))
+ nil 'all-screens)
+ visible))
+ )
+
+(defun ediff-submit-report ()
+ "Submit bug report on Ediff."
+ (interactive)
+ (let ((reporter-prompt-for-summary-p t)
+ (ctl-buf ediff-control-buffer)
+ varlist salutation buffer-name)
+ (setq varlist '(ediff-diff-program ediff-diff-options
+ ediff-patch-program ediff-patch-options
+ ediff-shell
+ ediff-use-faces
+ ediff-auto-refine ediff-highlighting-style
+ ediff-buffer-A ediff-buffer-B ediff-control-buffer
+ ediff-forward-word-function
+ ediff-control-frame
+ ediff-control-frame-parameters
+ ediff-control-frame-position-function
+ ediff-prefer-iconified-control-frame
+ ediff-window-setup-function
+ ediff-split-window-function
+ ediff-job-name
+ ediff-word-mode
+ buffer-name
+ window-system
+ ))
+ (setq salutation "
+Congratulations! You may have unearthed a bug in Ediff!
+
+Please make a concise and accurate summary of what happened
+and mail it to the address above.
+-----------------------------------------------------------
+")
+
+ (ediff-skip-unsuitable-frames)
+ (if window-system
+ (set-mouse-position (ediff-selected-frame) 1 0))
+
+ (switch-to-buffer ediff-msg-buffer)
+ (erase-buffer)
+ (delete-other-windows)
+ (insert "
+Please read this first:
+----------------------
+
+Some ``bugs'' may actually be no bugs at all. For instance, if you are
+reporting that certain difference regions are not matched as you think they
+should, this is most likely due to the way Unix diff program decides what
+constitutes a difference region. Ediff is an Emacs interface to diff, and
+it has nothing to do with those decisions---it only takes the output from
+diff and presents it in a way that is better suited for human browsing and
+manipulation.
+
+If Emacs happens to dump core, this is NOT an Ediff problem---it is
+an Emacs bug. Report this to Emacs maintainers.
+
+Another popular topic for reports is compilation messages. Because Ediff
+interfaces to several other packages and runs under Emacs and XEmacs,
+byte-compilation may produce output like this:
+
+ While compiling toplevel forms in file ediff.el:
+ ** reference to free variable pm-color-alist
+ ........................
+ While compiling the end of the data:
+ ** The following functions are not known to be defined:
+ ediff-valid-color-p, ediff-display-color-p, ediff-set-face,
+ ........................
+
+These are NOT errors, but inevitable warnings, which ought to be ignored.
+
+Please do not report those and similar things. However, comments and
+suggestions are always welcome.
+
+Mail anyway? (y or n) ")
+
+ (if (y-or-n-p "Mail anyway? ")
+ (progn
+ (if (ediff-buffer-live-p ctl-buf)
+ (set-buffer ctl-buf))
+ (setq buffer-name (buffer-name))
+ (require 'reporter)
+ (reporter-submit-bug-report "kifer@cs.sunysb.edu"
+ (ediff-version)
+ varlist
+ nil
+ 'delete-other-windows
+ salutation))
+ (bury-buffer)
+ (beep 1)(message "Bug report aborted")
+ (if (ediff-buffer-live-p ctl-buf)
+ (ediff-eval-in-buffer ctl-buf
+ (ediff-recenter 'no-rehighlight))))
+ ))
+
+
+(defun ediff-union (list1 list2)
+ "Combine LIST1 and LIST2 using a set-union operation.
+The result list contains all items that appear in either LIST1 or LIST2.
+This is a non-destructive function; it makes a copy of the data if necessary
+to avoid corrupting the original LIST1 and LIST2.
+This is a slightly simplified version from `cl-seq.el'. Added here to
+avoid loading cl-*."
+ (cond ((null list1) list2) ((null list2) list1)
+ ((equal list1 list2) list1)
+ (t
+ (or (>= (length list1) (length list2))
+ (setq list1 (prog1 list2 (setq list2 list1))))
+ (while list2
+ (or (memq (car list2) list1)
+ (setq list1 (cons (car list2) list1)))
+ (setq list2 (cdr list2)))
+ list1)))
+
+(defun ediff-deactivate-mark ()
+ (if ediff-xemacs-p
+ (zmacs-deactivate-region)
+ (deactivate-mark)))
+
+(cond ((fboundp 'nuke-selective-display)
+ ;; XEmacs 19.12 has nuke-selective-display
+ (fset 'ediff-nuke-selective-display 'nuke-selective-display))
+ (t
+ (defun ediff-nuke-selective-display ()
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (point-min))
+ (let ((mod-p (buffer-modified-p))
+ (buffer-read-only nil)
+ end)
+ (and (eq t selective-display)
+ (while (search-forward "\^M" nil t)
+ (end-of-line)
+ (setq end (point))
+ (beginning-of-line)
+ (while (search-forward "\^M" end t)
+ (delete-char -1)
+ (insert "\^J"))))
+ (set-buffer-modified-p mod-p)
+ (setq selective-display nil)))))
+ ))
+
+
+;; The next two are simplified versions from emerge.el.
+;; VARS must be a list of symbols
+(defun ediff-save-variables (vars)
+ (mapcar (function (lambda (v) (symbol-value v)))
+ vars))
+(defun ediff-restore-variables (vars values)
+ (while vars
+ (set (car vars) (car values))
+ (setq vars (cdr vars)
+ values (cdr values))))
+
+;; When Emacs implements before/after-string properties in overlays,
+;; this function will be deleted
+(defun ediff-remember-buffer-characteristics (&optional arg)
+ "Record certain properties of the buffers being compared.
+Must be called in the control buffer. Saves `read-only', `modified',
+and `auto-save' properties in buffer local variables. Turns off
+`auto-save-mode'. These properties are restored via a call to
+`ediff-restore-buffer-characteristics'."
+
+ ;; remember and alter buffer characteristics
+ (set (if arg 'ediff-buffer-A-values-setup 'ediff-buffer-A-values)
+ (ediff-eval-in-buffer ediff-buffer-A
+ (prog1
+ (ediff-save-variables ediff-saved-variables)
+ (ediff-restore-variables ediff-saved-variables
+ ediff-working-values))))
+ (set (if arg 'ediff-buffer-B-values-setup 'ediff-buffer-B-values)
+ (ediff-eval-in-buffer ediff-buffer-B
+ (prog1
+ (ediff-save-variables ediff-saved-variables)
+ (ediff-restore-variables ediff-saved-variables
+ ediff-working-values))))
+ (if (ediff-buffer-live-p ediff-buffer-C)
+ (set (if arg 'ediff-buffer-C-values-setup 'ediff-buffer-C-values)
+ (ediff-eval-in-buffer ediff-buffer-C
+ (prog1
+ (ediff-save-variables ediff-saved-variables)
+ (ediff-restore-variables ediff-saved-variables
+ ediff-working-values)))))
+ )
+
+;; must execute in control buf
+(defun ediff-save-protected-variables ()
+ (setq ediff-buffer-A-values-orig
+ (ediff-eval-in-buffer ediff-buffer-A
+ (ediff-save-variables ediff-protected-variables)))
+ (setq ediff-buffer-B-values-orig
+ (ediff-eval-in-buffer ediff-buffer-B
+ (ediff-save-variables ediff-protected-variables)))
+ (if ediff-3way-comparison-job
+ (setq ediff-buffer-C-values-orig
+ (ediff-eval-in-buffer ediff-buffer-C
+ (ediff-save-variables ediff-protected-variables)))))
+
+;; must execute in control buf
+(defun ediff-restore-protected-variables ()
+ (let ((values-A ediff-buffer-A-values-orig)
+ (values-B ediff-buffer-B-values-orig)
+ (values-C ediff-buffer-C-values-orig))
+ (ediff-eval-in-buffer ediff-buffer-A
+ (ediff-restore-variables ediff-protected-variables values-A))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (ediff-restore-variables ediff-protected-variables values-B))
+ (if ediff-3way-comparison-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (ediff-restore-variables ediff-protected-variables values-C)))))
+
+;; When Emacs implements before/after-string properties in overlays, this
+;; function will be called only once, in ediff-really-quit.
+(defun ediff-restore-buffer-characteristics (&optional arg)
+ "Restore properties saved by `ediff-remember-buffer-characteristics'."
+ (let ((A-values (if arg ediff-buffer-A-values-setup ediff-buffer-A-values))
+ (B-values (if arg ediff-buffer-B-values-setup ediff-buffer-B-values))
+ (C-values (if arg ediff-buffer-C-values-setup ediff-buffer-C-values))
+ )
+
+ (ediff-eval-in-buffer ediff-buffer-A
+ (ediff-restore-variables ediff-saved-variables A-values))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (ediff-restore-variables ediff-saved-variables B-values))
+ (if (ediff-buffer-live-p ediff-buffer-C)
+ (ediff-eval-in-buffer ediff-buffer-C
+ (ediff-restore-variables ediff-saved-variables C-values)))
+ ))
+
+
+;;; Debug
+
+(ediff-defvar-local ediff-command-begin-time '(0 0 0) "")
+
+;; calculate time used by command
+(defun ediff-calc-command-time ()
+ (let ((end (current-time))
+ micro sec)
+ (setq micro
+ (if (>= (nth 2 end) (nth 2 ediff-command-begin-time))
+ (- (nth 2 end) (nth 2 ediff-command-begin-time))
+ (+ (nth 2 end) (- 1000000 (nth 2 ediff-command-begin-time)))))
+ (setq sec (- (nth 1 end) (nth 1 ediff-command-begin-time)))
+ (or (equal ediff-command-begin-time '(0 0 0))
+ (message "Elapsed time: %d second(s) + %d microsecond(s)" sec micro))))
+
+(defsubst ediff-save-time ()
+ (setq ediff-command-begin-time (current-time)))
+
+(defun ediff-profile ()
+ "Toggle profiling Ediff commands."
+ (interactive)
+ (or (ediff-buffer-live-p ediff-control-buffer)
+ (error "This command runs only out of Ediff Control Buffer"))
+ (make-local-variable 'pre-command-hook)
+ (make-local-variable 'post-command-hook)
+ (if (memq 'ediff-save-time pre-command-hook)
+ (progn (remove-hook 'pre-command-hook 'ediff-save-time)
+ (remove-hook 'post-command-hook 'ediff-calc-command-time)
+ (setq ediff-command-begin-time '(0 0 0))
+ (message "Ediff profiling disabled"))
+ (add-hook 'pre-command-hook 'ediff-save-time t)
+ (add-hook 'post-command-hook 'ediff-calc-command-time)
+ (message "Ediff profiling enabled")))
+
+(defun ediff-print-diff-vector (diff-vector-var)
+ (princ (format "\n*** %S ***\n" diff-vector-var))
+ (mapcar (function
+ (lambda (overl-vec)
+ (princ
+ (format
+ "Diff %d: \tOverlay: %S
+\t\tFine diffs: %s
+\t\tNo-fine-diff-flag: %S
+\t\tState-of-diff:\t %S
+\t\tState-of-merge:\t %S
+"
+ (1+ (ediff-overlay-get (aref overl-vec 0) 'ediff-diff-num))
+ (aref overl-vec 0)
+ ;; fine-diff-vector
+ (if (= (length (aref overl-vec 1)) 0)
+ "none\n"
+ (mapconcat 'prin1-to-string
+ (aref overl-vec 1) "\n\t\t\t "))
+ (aref overl-vec 2) ; no fine diff flag
+ (aref overl-vec 3) ; state-of-diff
+ (aref overl-vec 4) ; state-of-merge
+ ))))
+ (eval diff-vector-var)))
+
+
+
+(defun ediff-debug-info ()
+ (interactive)
+ (or (ediff-buffer-live-p ediff-control-buffer)
+ (error "This command runs only out of Ediff Control Buffer"))
+ (with-output-to-temp-buffer ediff-debug-buffer
+ (princ (format "\nCtl buffer: %S\n" ediff-control-buffer))
+ (ediff-print-diff-vector (intern (concat "ediff-difference-vector-" "A")))
+ (ediff-print-diff-vector (intern (concat "ediff-difference-vector-" "B")))
+ (ediff-print-diff-vector (intern (concat "ediff-difference-vector-" "C")))
+ ))
+
+;; don't report error if version control package wasn't found
+;;(ediff-load-version-control 'silent)
+
+(run-hooks 'ediff-load-hooks)
+
+;; to foil foul play
+(if (or (not window-system)
+ (ediff-check-version '< 19 11 'xemacs))
+ (fset 'ediff-setup-windows-multiframe 'ediff-setup-windows-plain))
+
+
+;;; Local Variables:
+;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
+;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
+;;; End:
+
+(provide 'ediff-util)
+
+;;; ediff-util.el ends here
diff --git a/lisp/ediff-wind.el b/lisp/ediff-wind.el
new file mode 100644
index 00000000000..9ccdc437c97
--- /dev/null
+++ b/lisp/ediff-wind.el
@@ -0,0 +1,1098 @@
+;;; ediff-wind.el --- window manipulation utilities
+;;; Copyright (C) 1994 Free Software Foundation, Inc.
+
+;; Author: Michael Kifer <kifer@cs.sunysb.edu>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+(require 'ediff-init)
+
+
+(defvar ediff-window-setup-function (if (not window-system)
+ 'ediff-setup-windows-plain
+ 'ediff-setup-windows-multiframe)
+ "*Function called to set up windows.
+Ediff provides a choice of two functions: ediff-setup-windows-plain, for
+doing everything in one frame, and ediff-setup-windows-multiframe,
+which sets the control panel in a separate frame. Also, if the latter
+function detects that one of the buffers A/B is seen in some other frame,
+it will try to keep that buffer in that frame.
+
+If you don't like the two functions provided---write your own one.
+The basic guidelines:
+ 1. It should leave the control buffer current and the control window
+ selected.
+ 2. It should set ediff-window-A, ediff-window-B, ediff-window-C,
+ and ediff-control-window to contain window objects that display
+ the corresponding buffers.
+ 3. It should accept the following arguments:
+ buffer-A, buffer-B, buffer-C, control-buffer
+ Buffer C may not be used in jobs that compare only two buffers.
+If you plan to do something fancy, take a close look at how the two
+provided functions are written.")
+
+;; indicates if we are in a multiframe setup
+(ediff-defvar-local ediff-multiframe nil "")
+
+;; Share of the frame occupied by the merge window (buffer C)
+(ediff-defvar-local ediff-merge-window-share 0.45 "")
+
+;; The control window.
+(ediff-defvar-local ediff-control-window nil "")
+;; Official window for buffer A
+(ediff-defvar-local ediff-window-A nil "")
+;; Official window for buffer B
+(ediff-defvar-local ediff-window-B nil "")
+;; Official window for buffer C
+(ediff-defvar-local ediff-window-C nil "")
+;; Ediff's window configuration.
+;; Used to minimize the need to rearrange windows.
+(ediff-defvar-local ediff-window-config-saved "" "")
+
+
+(defvar ediff-split-window-function 'split-window-vertically
+ "*The function used to split the main window between buffer-A and buffer-B.
+You can set it to a horizontal split instead of the default vertical split
+by setting this variable to `split-window-horizontally'.
+You can also have your own function to do fancy splits.
+This variable has no effect when buffer-A/B are shown in different frames.
+In this case, Ediff will use those frames to display these buffers.")
+
+(defvar ediff-merge-split-window-function 'split-window-horizontally
+ "*The function used to split the main window between buffer-A and buffer-B.
+You can set it to a vertical split instead of the default horizontal split
+by setting this variable to `split-window-vertically'.
+You can also have your own function to do fancy splits.
+This variable has no effect when buffer-A/B/C are shown in different frames.
+In this case, Ediff will use those frames to display these buffers.")
+
+(defconst ediff-control-frame-parameters
+ (if window-system
+ (list
+ '(name . "Ediff")
+ ;;'(unsplittable . t)
+ '(minibuffer . nil)
+ '(vertical-scroll-bars . nil) ; FSF only
+ '(scrollbar-width . 0) ; XEmacs only
+ '(menu-bar-lines . 0) ; FSF only
+ ;; don't lower and auto-raise
+ '(auto-lower . nil)
+ '(auto-raise . t)
+ ;; this blocks queries from window manager as to where to put
+ ;; ediff's control frame. we put the frame outside the display,
+ ;; so the initial frame won't jump all over the screen
+ (cons 'top (if (fboundp 'x-display-pixel-height)
+ (1+ (x-display-pixel-height))
+ 3000))
+ (cons 'left (if (fboundp 'x-display-pixel-width)
+ (1+ (x-display-pixel-width))
+ 3000))
+ ))
+ "Frame parameters for displaying Ediff Control Panel.
+Do not specify width and height here. These are computed automatically.")
+
+(defvar ediff-control-frame-position-function 'ediff-make-frame-position
+ "Function to call to determine the desired location for the control panel.
+Expects three parameters: the control buffer, the desired width and height
+of the control frame. It returns an association list
+of the form \(\(top . <position>\) \(left . <position>\)\)")
+
+(defvar ediff-control-frame-upward-shift (if ediff-xemacs-p 36 4)
+ "*The upward shift of control frame from the top of buffer A's frame.
+Measured in pixels.
+This is used by the default control frame positioning function,
+`ediff-make-frame-position'. This variable is provided for easy
+customization of the default.")
+
+(defvar ediff-narrow-control-frame-leftward-shift (if ediff-xemacs-p 7 3)
+ "*The leftward shift of control frame from the right edge of buf A's frame.
+Measured in characters.
+This is used by the default control frame positioning function,
+`ediff-make-frame-position' to adjust the position of the control frame
+when it shows the short menu. This variable is provided for easy
+customization of the default.")
+
+(defvar ediff-wide-control-frame-rightward-shift 7
+ "*The rightward shift of control frame from the left edge of buf A's frame.
+Measured in characters.
+This is used by the default control frame positioning function,
+`ediff-make-frame-position' to adjust the position of the control frame
+when it shows the full menu. This variable is provided for easy
+customization of the default.")
+
+
+;; Wide frame display
+
+;; t means Ediff is using wide display
+(ediff-defvar-local ediff-wide-display-p nil "")
+;; keeps frame config for toggling wide display
+(ediff-defvar-local ediff-wide-display-orig-parameters nil
+ "Frame parameters to be restored when the user wants to toggle the wide
+display off.")
+(ediff-defvar-local ediff-wide-display-frame nil
+ "Frame to be used for wide display.")
+(ediff-defvar-local ediff-make-wide-display-function 'ediff-make-wide-display
+ "The value is a function that is called to create a wide display.
+The function is called without arguments. It should resize the frame in
+which buffers A, B, and C are to be displayed, and it should save the old
+frame parameters in `ediff-wide-display-orig-parameters'.
+The variable `ediff-wide-display-frame' should be set to contain
+the frame used for the wide display.")
+
+;; Frame used for the control panel in a windowing system.
+(ediff-defvar-local ediff-control-frame nil "")
+
+(defvar ediff-prefer-iconified-control-frame nil
+ "*If t, keep control panel iconified when help message is off.
+This has effect only on a windowing system.
+If t, hiting `?' to toggle control panel off iconifies it.
+
+This is only useful in Emacs and only for certain kinds of window managers,
+such as TWM and its derivatives, since the window manager must permit
+keyboard input to go into icons. XEmacs completely ignores keyboard input
+into icons, regardless of the window manager.")
+
+;;; Functions
+
+(defun ediff-get-window-by-clicking (wind prev-wind wind-number)
+ (let (event)
+ (message
+ "Select windows by clicking. Please click on Window %d " wind-number)
+ (while (not (ediff-mouse-event-p (setq event (ediff-read-event))))
+ (if (sit-for 1) ; if sequence of events, wait till the final word
+ (beep 1))
+ (message "Please click on Window %d " wind-number))
+ (ediff-read-event) ; discard event
+ (setq wind (if ediff-xemacs-p
+ (event-window event)
+ (posn-window (event-start event))))
+ ))
+
+
+;; Select the lowest window on the frame.
+(defun ediff-select-lowest-window ()
+ (let* ((lowest-window (selected-window))
+ (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
+ ;;(last-window (previous-window))
+ (last-window (save-excursion
+ (other-window -1) (selected-window)))
+ (window-search t))
+ (while window-search
+ (let* ((this-window (next-window))
+ (next-bottom-edge (car (cdr (cdr (cdr
+ (window-edges this-window)))))))
+ (if (< bottom-edge next-bottom-edge)
+ (progn
+ (setq bottom-edge next-bottom-edge)
+ (setq lowest-window this-window)))
+
+ (select-window this-window)
+ (if (eq last-window this-window)
+ (progn
+ (select-window lowest-window)
+ (setq window-search nil)))))))
+
+
+
+;;; Common window setup routines
+
+;; Set up the window configuration. If POS is given, set the points to
+;; the beginnings of the buffers.
+;; When 3way comparison is added, this will have to choose the appropriate
+;; setup function based on ediff-job-name
+(defun ediff-setup-windows (buffer-A buffer-B buffer-C control-buffer)
+ ;; Make sure we are not in the minibuffer window when we try to delete
+ ;; all other windows.
+ (run-hooks 'ediff-before-setup-windows-hooks)
+ (if (eq (selected-window) (minibuffer-window))
+ (other-window 1))
+
+ ;; when support for buf C is added, the actual window setup function will
+ ;; depend on ediff-job-name
+ (or (ediff-keep-window-config control-buffer)
+ (funcall
+ (ediff-eval-in-buffer control-buffer ediff-window-setup-function)
+ buffer-A buffer-B buffer-C control-buffer))
+ (run-hooks 'ediff-after-setup-windows-hooks))
+
+;; Just set up 3 windows.
+;; Usually used without windowing systems
+;; With windowing, we want to use dedicated frames.
+(defun ediff-setup-windows-plain (buffer-A buffer-B buffer-C control-buffer)
+ (ediff-eval-in-buffer control-buffer
+ (setq ediff-multiframe nil))
+ (if ediff-merge-job
+ (ediff-setup-windows-plain-merge
+ buffer-A buffer-B buffer-C control-buffer)
+ (ediff-setup-windows-plain-compare
+ buffer-A buffer-B buffer-C control-buffer)))
+
+(defun ediff-setup-windows-plain-merge (buf-A buf-B buf-C control-buffer)
+ ;; skip dedicated and unsplittable frames
+ (ediff-eval-in-buffer control-buffer
+ (if (and window-system (ediff-frame-live-p ediff-control-frame))
+ (progn
+ (redraw-display)
+ (ediff-delete-frame ediff-control-frame)
+ (setq ediff-control-frame nil))))
+ (ediff-skip-unsuitable-frames)
+ (let ((window-min-height 1)
+ split-window-function
+ merge-window-share merge-window-lines
+ wind-A wind-B wind-C)
+ (ediff-eval-in-buffer control-buffer
+ (setq merge-window-share ediff-merge-window-share
+ ;; this lets us have local versions of ediff-split-window-function
+ split-window-function ediff-split-window-function))
+ (delete-other-windows)
+ (split-window-vertically)
+ (ediff-select-lowest-window)
+ (ediff-setup-control-buffer control-buffer)
+
+ ;; go to the upper window and split it betw A, B, and possibly C
+ (other-window 1)
+ (setq merge-window-lines
+ (max 2 (round (* (window-height) merge-window-share))))
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+
+ ;; XEmacs seems to have a lot of trouble with display
+ ;; It won't set things right unless we tell it to sit still
+ (if ediff-xemacs-p (sit-for 0))
+
+ (split-window-vertically (max 2 (- (window-height) merge-window-lines)))
+ (if (eq (selected-window) wind-A)
+ (other-window 1))
+ (setq wind-C (selected-window))
+ (switch-to-buffer buf-C)
+
+ (select-window wind-A)
+ (funcall split-window-function)
+
+ (if (eq (selected-window) wind-A)
+ (other-window 1))
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+
+ (ediff-eval-in-buffer control-buffer
+ (setq ediff-window-A wind-A
+ ediff-window-B wind-B
+ ediff-window-C wind-C))
+
+ (ediff-select-lowest-window)
+ (ediff-setup-control-buffer control-buffer)
+ ))
+
+
+;; This function handles all comparison jobs, including 3way jobs
+(defun ediff-setup-windows-plain-compare (buf-A buf-B buf-C control-buffer)
+ ;; skip dedicated and unsplittable frames
+ (ediff-eval-in-buffer control-buffer
+ (if (and window-system (ediff-frame-live-p ediff-control-frame))
+ (progn
+ (redraw-display)
+ (ediff-delete-frame ediff-control-frame)
+ (setq ediff-control-frame nil))))
+ (ediff-skip-unsuitable-frames)
+ (let ((window-min-height 1)
+ split-window-function wind-width-or-height
+ three-way-comparison
+ job wind-A-start wind-B-start wind-A wind-B wind-C)
+ (ediff-eval-in-buffer control-buffer
+ (setq wind-A-start (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ 'A ediff-narrow-bounds))
+ wind-B-start (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ 'B ediff-narrow-bounds))
+ job ediff-job-name
+ ;; this lets us have local versions of ediff-split-window-function
+ split-window-function ediff-split-window-function
+ three-way-comparison ediff-3way-comparison-job))
+ (delete-other-windows)
+ (split-window-vertically)
+ (ediff-select-lowest-window)
+ (ediff-setup-control-buffer control-buffer)
+
+ ;; go to the upper window and split it betw A, B, and possibly C
+ (other-window 1)
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+ (if three-way-comparison
+ (setq wind-width-or-height
+ (/ (if (eq split-window-function 'split-window-vertically)
+ (window-height wind-A)
+ (window-width wind-A))
+ 3)))
+
+ ;; XEmacs seems to have a lot of trouble with display
+ ;; It won't set things right unless we tell it to sit still
+ (if ediff-xemacs-p (sit-for 0))
+
+ (funcall split-window-function wind-width-or-height)
+
+ (if (eq (selected-window) wind-A)
+ (other-window 1))
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+
+ (if three-way-comparison
+ (progn
+ (funcall split-window-function) ; equally
+ (if (eq (selected-window) wind-B)
+ (other-window 1))
+ (switch-to-buffer buf-C)
+ (setq wind-C (selected-window))))
+
+ (ediff-eval-in-buffer control-buffer
+ (setq ediff-window-A wind-A
+ ediff-window-B wind-B
+ ediff-window-C wind-C))
+
+ ;; It is unlikely that we will want to implement 3way window comparison.
+ ;; So, only buffers A and B are used here.
+ (if (eq job 'ediff-windows)
+ (progn
+ (set-window-start wind-A wind-A-start)
+ (set-window-start wind-B wind-B-start)))
+
+ (ediff-select-lowest-window)
+ (ediff-setup-control-buffer control-buffer)
+ ))
+
+
+;; dispatch the appropriate window setup function
+(defun ediff-setup-windows-multiframe (buf-A buf-B buf-C control-buf)
+ (ediff-eval-in-buffer control-buf
+ (setq ediff-multiframe t))
+ (if ediff-merge-job
+ (ediff-setup-windows-multiframe-merge buf-A buf-B buf-C control-buf)
+ (ediff-setup-windows-multiframe-compare buf-A buf-B buf-C control-buf)))
+
+(defun ediff-setup-windows-multiframe-merge (buf-A buf-B buf-C control-buf)
+;;; Algorithm:
+;;; If A and B are in the same frame but C's frame is different--- use one
+;;; frame for A and B and use a separate frame for C.
+;;; If C's frame is non-existent, then: if the first suitable
+;;; non-dedicated frame is different from A&B's, then use it for C.
+;;; Otherwise, put A,B, and C in one frame.
+;;; If buffers A, B, C are is separate frames, use them to display these
+;;; buffers.
+
+ ;; Skip dedicated or iconified frames. Unsplittable frames are taken
+ ;; care of later.
+ (ediff-skip-unsuitable-frames 'ok-unsplittable)
+
+ (let* ((window-min-height 1)
+ (wind-A (ediff-get-visible-buffer-window buf-A))
+ (wind-B (ediff-get-visible-buffer-window buf-B))
+ (wind-C (ediff-get-visible-buffer-window buf-C))
+ (frame-A (if wind-A (ediff-window-frame wind-A)))
+ (frame-B (if wind-B (ediff-window-frame wind-B)))
+ (frame-C (if wind-C (ediff-window-frame wind-C)))
+ ;; on wide display, do things in one frame
+ (force-one-frame
+ (ediff-eval-in-buffer control-buf ediff-wide-display-p))
+ ;; this lets us have local versions of ediff-split-window-function
+ (split-window-function
+ (ediff-eval-in-buffer control-buf ediff-split-window-function))
+ (orig-wind (selected-window))
+ (orig-frame (ediff-selected-frame))
+ (use-same-frame (or force-one-frame
+ (eq frame-A (or frame-C orig-frame))
+ (eq frame-B (or frame-C orig-frame))
+ (not (ediff-frame-live-p frame-A))
+ (not (ediff-frame-live-p frame-B))
+ ))
+ (use-same-frame-for-AB (and (not use-same-frame)
+ (eq frame-A frame-B)))
+ (merge-window-share (ediff-eval-in-buffer control-buf
+ ediff-merge-window-share))
+ merge-window-lines
+ designated-minibuffer-frame
+ done-A done-B done-C)
+
+ ;; buf-A on its own
+ (if (and (window-live-p wind-A)
+ (null use-same-frame)
+ (null use-same-frame-for-AB))
+ (progn
+ (select-window wind-A)
+ (delete-other-windows)
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+ (setq done-A t)))
+
+ ;; buf-B on its own
+ (if (and (window-live-p wind-B) (null use-same-frame)) ; buf B on its own
+ (progn
+ (select-window wind-B)
+ (delete-other-windows)
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+ (setq done-B t)))
+
+ ;; buf-C on its own
+ (if (and (window-live-p wind-C) (null use-same-frame)) ; buf C on its own
+ (progn
+ (select-window wind-C)
+ (delete-other-windows)
+ (switch-to-buffer buf-C)
+ (setq wind-C (selected-window))
+ (setq done-C t)))
+
+ (if use-same-frame-for-AB
+ (progn
+ (ediff-select-frame frame-A)
+ (switch-to-buffer buf-A)
+ (delete-other-windows)
+ (setq wind-A (selected-window))
+
+ (funcall split-window-function)
+ (if (eq (selected-window) wind-A)
+ (other-window 1))
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+
+ (setq done-A t
+ done-B t)))
+
+ (if use-same-frame
+ (let ((curr-frame (ediff-selected-frame))
+ (window-min-height 1))
+ ;; avoid dedicated and non-splittable windows
+ (ediff-skip-unsuitable-frames)
+ (or (eq curr-frame (ediff-selected-frame))
+ (setq wind-A nil
+ wind-B nil
+ wind-C nil
+ orig-wind (selected-window)))
+
+ ;; set the right frame
+ (cond (wind-A (select-window wind-A))
+ (wind-B (select-window wind-B))
+ (wind-C (select-window wind-C))
+ (t (select-window orig-wind)))
+ (delete-other-windows)
+ (setq merge-window-lines
+ (max 2 (round (* (window-height) merge-window-share))))
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+
+ ;; XEmacs seems to have a lot of trouble with display
+ ;; It won't set things right unless we tell it to catch breath
+ (if ediff-xemacs-p (sit-for 0))
+
+ (split-window-vertically
+ (max 2 (- (window-height) merge-window-lines)))
+ (if (eq (selected-window) wind-A)
+ (other-window 1))
+ (setq wind-C (selected-window))
+ (switch-to-buffer buf-C)
+
+ (select-window wind-A)
+
+ (funcall split-window-function)
+ (if (eq (selected-window) wind-A)
+ (other-window 1))
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+
+ (setq done-A t
+ done-B t
+ done-C t)
+ ))
+
+ (or done-A ; Buf A to be set in its own frame
+ (progn ; It was not set up yet as it wasn't visible
+ (select-window orig-wind)
+ (delete-other-windows)
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+ ))
+ (or done-B ; Buf B to be set in its own frame
+ (progn ; It was not set up yet as it wasn't visible
+ (select-window orig-wind)
+ (delete-other-windows)
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+ ))
+
+ (or done-C ; Buf C to be set in its own frame.
+ (progn ; It was not set up yet as it wasn't visible
+ (select-window orig-wind)
+ (delete-other-windows)
+ (switch-to-buffer buf-C)
+ (setq wind-C (selected-window))
+ ))
+
+ (ediff-eval-in-buffer control-buf
+ (setq ediff-window-A wind-A
+ ediff-window-B wind-B
+ ediff-window-C wind-C)
+
+ (setq frame-A (ediff-window-frame ediff-window-A)
+ designated-minibuffer-frame (ediff-window-frame
+ (minibuffer-window frame-A)))
+ (if ediff-xemacs-p
+ ()
+ (if (not (eq designated-minibuffer-frame default-minibuffer-frame))
+ (progn
+ (setq default-minibuffer-frame designated-minibuffer-frame)
+ (if (ediff-frame-live-p ediff-control-frame)
+ (ediff-delete-frame ediff-control-frame)))
+ ))
+ )
+
+ (ediff-setup-control-frame control-buf)
+ ))
+
+
+;; Window setup for all comparison jobs, including 3way comparisons
+(defun ediff-setup-windows-multiframe-compare (buf-A buf-B buf-C control-buf)
+;;; Algorithm:
+;;; If a buffer is seen in a frame, use that frame for that buffer.
+;;; If it is not seen, use the current frame.
+;;; If both buffers are not seen, they share the current frame. If one
+;;; of the buffers is not seen, it is placed in the current frame (where
+;;; ediff started). If that frame is displaying the other buffer, it is
+;;; shared between the two buffers.
+;;; However, if we decide to put both buffers in one frame
+;;; and the selected frame isn't splittable, we create a new frame and
+;;; put both buffers there, event if one of this buffers is visible in
+;;; another frame.
+
+ ;; Skip dedicated or iconified frames.
+ ;; Unsplittable frames are taken care of later.
+ (ediff-skip-unsuitable-frames 'ok-unsplittable)
+
+ (let* ((window-min-height 1)
+ (wind-A (ediff-get-visible-buffer-window buf-A))
+ (wind-B (ediff-get-visible-buffer-window buf-B))
+ (wind-C (ediff-get-visible-buffer-window buf-C))
+ (frame-A (if wind-A (ediff-window-frame wind-A)))
+ (frame-B (if wind-B (ediff-window-frame wind-B)))
+ (frame-C (if wind-C (ediff-window-frame wind-C)))
+ (ctl-frame-exists-p (ediff-eval-in-buffer control-buf
+ (ediff-frame-live-p ediff-control-frame)))
+ ;; on wide display, do things in one frame
+ (force-one-frame
+ (ediff-eval-in-buffer control-buf ediff-wide-display-p))
+ ;; this lets us have local versions of ediff-split-window-function
+ (split-window-function
+ (ediff-eval-in-buffer control-buf ediff-split-window-function))
+ (three-way-comparison
+ (ediff-eval-in-buffer control-buf ediff-3way-comparison-job))
+ (orig-wind (selected-window))
+ (use-same-frame (or force-one-frame
+ (eq frame-A frame-B)
+ (if three-way-comparison
+ (or (eq frame-A frame-C)
+ (eq frame-B frame-C)
+ (not (ediff-frame-live-p frame-A))
+ (not (ediff-frame-live-p frame-B))
+ (not (ediff-frame-live-p frame-C))))
+ (and (not (ediff-frame-live-p frame-B))
+ (or ctl-frame-exists-p
+ (eq frame-A (ediff-selected-frame))))
+ (and (not (ediff-frame-live-p frame-A))
+ (or ctl-frame-exists-p
+ (eq frame-B (ediff-selected-frame))))))
+ wind-A-start wind-B-start job-name
+ designated-minibuffer-frame
+ done-A done-B done-C)
+
+ (ediff-eval-in-buffer control-buf
+ (setq wind-A-start (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ 'A ediff-narrow-bounds))
+ wind-B-start (ediff-overlay-start
+ (ediff-get-value-according-to-buffer-type
+ 'B ediff-narrow-bounds))
+ job-name ediff-job-name))
+
+ (if (and (window-live-p wind-A) (null use-same-frame)) ; buf-A on its own
+ (progn
+ (select-window wind-A)
+ (delete-other-windows)
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+ (setq done-A t)))
+
+ (if (and (window-live-p wind-B) (null use-same-frame)) ; buf B on its own
+ (progn
+ (select-window wind-B)
+ (delete-other-windows)
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+ (setq done-B t)))
+
+ (if (and (window-live-p wind-C) (null use-same-frame)) ; buf C on its own
+ (progn
+ (select-window wind-C)
+ (delete-other-windows)
+ (switch-to-buffer buf-C)
+ (setq wind-C (selected-window))
+ (setq done-C t)))
+
+ (if use-same-frame
+ (let ((curr-frame (ediff-selected-frame))
+ ;; this affects 3way setups only
+ wind-width-or-height)
+ ;; avoid dedicated and non-splittable windows
+ (ediff-skip-unsuitable-frames)
+ (or (eq curr-frame (ediff-selected-frame))
+ (setq wind-A nil
+ wind-B nil
+ wind-C nil
+ orig-wind (selected-window)))
+
+ ;; set the right frame
+ (cond (wind-A (select-window wind-A))
+ (wind-B (select-window wind-B))
+ (wind-C (select-window wind-C))
+ (t (select-window orig-wind)))
+ (delete-other-windows)
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+
+ ;; XEmacs seems to have a lot of trouble with display
+ ;; It won't set things right unless we tell it to catch breath
+ (if ediff-xemacs-p (sit-for 0))
+
+ (if three-way-comparison
+ (setq wind-width-or-height
+ (/
+ (if (eq split-window-function 'split-window-vertically)
+ (window-height wind-A)
+ (window-width wind-A))
+ 3)))
+
+ (funcall split-window-function wind-width-or-height)
+ (if (eq (selected-window) wind-A)
+ (other-window 1))
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+
+ (if three-way-comparison
+ (progn
+ (funcall split-window-function) ; equally
+ (if (memq (selected-window) (list wind-A wind-B))
+ (other-window 1))
+ (switch-to-buffer buf-C)
+ (setq wind-C (selected-window))))
+ (setq done-A t
+ done-B t
+ done-C t)
+ ))
+
+ (or done-A ; Buf A to be set in its own frame
+ (progn ; It was not set up yet as it wasn't visible
+ (select-window orig-wind)
+ (delete-other-windows)
+ (switch-to-buffer buf-A)
+ (setq wind-A (selected-window))
+ ))
+ (or done-B ; Buf B to be set in its own frame
+ (progn ; It was not set up yet as it wasn't visible
+ (select-window orig-wind)
+ (delete-other-windows)
+ (switch-to-buffer buf-B)
+ (setq wind-B (selected-window))
+ ))
+
+ (if three-way-comparison
+ (or done-C ; Buf C to be set in its own frame
+ (progn ; It was not set up yet as it wasn't visible
+ (select-window orig-wind)
+ (delete-other-windows)
+ (switch-to-buffer buf-C)
+ (setq wind-C (selected-window))
+ )))
+
+ (ediff-eval-in-buffer control-buf
+ (setq ediff-window-A wind-A
+ ediff-window-B wind-B
+ ediff-window-C wind-C)
+
+ (setq frame-A (ediff-window-frame ediff-window-A)
+ designated-minibuffer-frame (ediff-window-frame
+ (minibuffer-window frame-A)))
+ (if ediff-xemacs-p
+ ()
+ (if (not (eq designated-minibuffer-frame default-minibuffer-frame))
+ (progn
+ (setq default-minibuffer-frame designated-minibuffer-frame)
+ (if (ediff-frame-live-p ediff-control-frame)
+ (ediff-delete-frame ediff-control-frame)))
+ ))
+ )
+
+ ;; It is unlikely that we'll implement ediff-windows that would compare
+ ;; 3 windows at once. So, we don't use buffer C here.
+ (if (eq job-name 'ediff-windows)
+ (progn
+ (set-window-start wind-A wind-A-start)
+ (set-window-start wind-B wind-B-start)))
+
+ (ediff-setup-control-frame control-buf)
+ ))
+
+;; skip unsplittable and dedicated windows
+;; create a new splittable frame if none is found
+(defun ediff-skip-unsuitable-frames (&optional ok-unsplittable)
+ (if window-system
+ (let (last-window)
+ (while (and (not (eq (selected-window) last-window))
+ (or
+ (window-dedicated-p (selected-window))
+ (ediff-frame-iconified-p (ediff-selected-frame))
+ (if ok-unsplittable
+ nil
+ (ediff-frame-unsplittable-p (ediff-selected-frame)))))
+ ;; remember where started
+ (or last-window (setq last-window (selected-window)))
+ ;; try new window
+ (other-window 1 t))
+ (if (eq (selected-window) last-window)
+ ;; fed up, no appropriate frame
+ (progn
+ (redraw-display)
+ (ediff-select-frame (ediff-make-frame '((unsplittable)))))))))
+
+;; Prepare or refresh control frame
+(defun ediff-setup-control-frame (ctl-buffer)
+ (let ((window-min-height 1)
+ ctl-frame-iconified-p dont-iconify-ctl-frame deiconify-ctl-frame
+ ctl-frame old-ctl-frame lines
+ fheight fwidth adjusted-parameters)
+
+ (ediff-eval-in-buffer ctl-buffer
+ (run-hooks 'ediff-before-setup-control-frame-hooks))
+
+ (setq old-ctl-frame (ediff-eval-in-buffer ctl-buffer ediff-control-frame))
+ (if (ediff-frame-live-p old-ctl-frame)
+ (setq ctl-frame old-ctl-frame)
+ (redraw-display)
+ ;; frame should be made while ctl-buff is current, so that
+ ;; the local default-minibuffer-frame will be consulted and
+ ;; that ediff-control-frame-parameters will have the right value.
+ (ediff-eval-in-buffer ctl-buffer
+ (setq ctl-frame (ediff-make-frame
+ ediff-control-frame-parameters)))
+ (ediff-eval-in-buffer ctl-buffer (setq ediff-control-frame ctl-frame)))
+
+ (setq ctl-frame-iconified-p (ediff-frame-iconified-p ctl-frame))
+ (ediff-select-frame ctl-frame)
+ (if (window-dedicated-p (selected-window))
+ ()
+ (delete-other-windows)
+ (switch-to-buffer ctl-buffer))
+
+ ;; must be before ediff-setup-control-buffer
+ (if ediff-xemacs-p
+ ;; just a precaution--we should be in ctl-buffer already
+ (ediff-eval-in-buffer ctl-buffer
+ (make-local-variable 'screen-title-format)
+ (make-local-variable 'screen-icon-title-format)))
+
+ (ediff-setup-control-buffer ctl-buffer)
+ (setq dont-iconify-ctl-frame
+ (not (string= ediff-help-message ediff-brief-help-message)))
+ (setq deiconify-ctl-frame
+ (and (eq this-command 'ediff-toggle-help)
+ dont-iconify-ctl-frame))
+
+ ;; 1 more line for the modeline
+ (setq lines (if ediff-xemacs-p
+ (+ 2 (count-lines (point-min) (point-max)))
+ (1+ (count-lines (point-min) (point-max))))
+ fheight lines
+ fwidth (+ (ediff-help-message-line-length) 2)
+ adjusted-parameters (append (list
+ (cons 'width fwidth)
+ (cons 'height fheight))
+ (funcall
+ ediff-control-frame-position-function
+ ctl-buffer fwidth fheight)))
+
+ ;; In XEmacs, buffer menubar needs to be killed before frame parameters
+ ;; are changed XEmacs needs to redisplay, as it has trouble setting
+ ;; height correctly otherwise.
+ (if (and ediff-xemacs-p (ediff-frame-has-menubar))
+ (progn (set-buffer-menubar nil)(sit-for 0)))
+
+ ;; Under OS/2 (emx) we have to call modify frame parameters twice, in
+ ;; order to make sure that at least once we do it for non-iconified
+ ;; frame. If appears that in the OS/2 port of Emacs, one can't modify
+ ;; frame parameters of iconified frames.
+ (if (eq system-type 'emx)
+ (ediff-modify-frame-parameters ctl-frame adjusted-parameters))
+
+ (goto-char (point-min))
+
+ (cond ((and ediff-prefer-iconified-control-frame
+ (not ctl-frame-iconified-p)
+ (not dont-iconify-ctl-frame))
+ (ediff-iconify-frame ctl-frame))
+ ((or deiconify-ctl-frame
+ (not ctl-frame-iconified-p))
+ (ediff-raise-frame ctl-frame)))
+
+ ;; This works around a bug in 19.25 and earlier. There, if frame gets
+ ;; iconified, the current buffer changes to that of the frame that
+ ;; becomes exposed as a result of this iconification.
+ ;; So, we make sure the current buffer doesn't change.
+ (ediff-select-frame ctl-frame)
+ (ediff-refresh-control-frame)
+
+ (ediff-modify-frame-parameters ctl-frame adjusted-parameters)
+
+ (if ediff-xemacs-p
+ (set-window-buffer-dedicated (selected-window) ctl-buffer)
+ (set-window-dedicated-p (selected-window) t))
+
+ (or ediff-xemacs-p (sit-for 0 200)) ; emacs has trouble here, needs time
+ (or (ediff-frame-iconified-p ctl-frame)
+ (set-mouse-position ctl-frame 1 0))
+ (if (ediff-check-version '< 19 11 'xemacs) (sit-for 0))
+ (or ediff-xemacs-p (unfocus-frame))
+
+ (if ediff-xemacs-p
+ (ediff-eval-in-buffer ctl-buffer
+ (make-local-variable 'select-screen-hook)
+ (add-hook 'select-screen-hook 'ediff-xemacs-select-screen-hook)
+ ))
+
+ (ediff-eval-in-buffer ctl-buffer
+ (run-hooks 'ediff-after-setup-control-frame-hooks))
+
+ ))
+
+
+;; finds a good place to clip control frame
+(defun ediff-make-frame-position (ctl-buffer ctl-frame-width ctl-frame-height)
+ (ediff-eval-in-buffer ctl-buffer
+ (let* ((frame-A (ediff-window-frame ediff-window-A))
+ (frame-A-parameters (ediff-frame-parameters frame-A))
+ (frame-A-top (cdr (assoc 'top frame-A-parameters)))
+ (frame-A-left (cdr (assoc 'left frame-A-parameters)))
+ (frame-A-width (ediff-frame-width frame-A))
+ (ctl-frame ediff-control-frame)
+ horizontal-adjustment upward-adjustment
+ ctl-frame-top)
+
+ ;; Multiple control frames are clipped based on the value of
+ ;; ediff-control-buffer-number. This is done in order not to obscure
+ ;; other active control panels.
+ (setq horizontal-adjustment (* 2 ediff-control-buffer-number)
+ upward-adjustment (* -14 ediff-control-buffer-number))
+
+ (setq ctl-frame-top (- frame-A-top
+ upward-adjustment
+ ediff-control-frame-upward-shift))
+ (list
+ (cons 'top (if (> ctl-frame-top 0) ctl-frame-top 1))
+ (cons 'left (+ frame-A-left
+ (if ediff-prefer-long-help-message
+ (* (ediff-frame-char-width ctl-frame)
+ (+ ediff-wide-control-frame-rightward-shift
+ horizontal-adjustment))
+ (- (* frame-A-width
+ (ediff-frame-char-width frame-A))
+ (* (ediff-frame-char-width ctl-frame)
+ (+ ctl-frame-width
+ ediff-narrow-control-frame-leftward-shift
+ horizontal-adjustment))))))))))
+
+(defun ediff-xemacs-select-screen-hook ()
+ (if (equal (ediff-selected-frame) ediff-control-frame)
+ (ediff-raise-frame ediff-control-frame)))
+
+(defun ediff-make-wide-display ()
+ "Construct an alist of parameters for the wide display.
+Saves the old frame parameters in `ediff-wide-display-orig-parameters'.
+The frame to be resized is kept in `ediff-wide-display-frame'.
+This function modifies only the left margin and the width of the display.
+It assumes that it is called from within the control buffer."
+ (if (not (fboundp 'x-display-pixel-width))
+ (error
+ "Can't determine display width. Please upgrade your version of Emacs"))
+ (let* ((frame-A (ediff-window-frame ediff-window-A))
+ (frame-A-params (ediff-frame-parameters frame-A))
+ (cw (ediff-frame-char-width frame-A))
+ (wd (- (/ (x-display-pixel-width) cw) 5)))
+ (setq ediff-wide-display-orig-parameters
+ (list (cons 'left (max 0 (cdr (assoc 'left frame-A-params))))
+ (cons 'width (cdr (assoc 'width frame-A-params))))
+ ediff-wide-display-frame frame-A)
+ (ediff-modify-frame-parameters frame-A (list (cons 'left cw)
+ (cons 'width wd)))))
+
+
+
+;; Revise the mode line to display which difference we have selected
+;; Also resets modelines of buffers A/B, since they may be clobbered by
+;; anothe invocations of Ediff.
+(defun ediff-refresh-mode-lines ()
+ (let (buf-A-state-diff buf-B-state-diff buf-C-state-diff buf-C-state-merge)
+
+ (if (ediff-valid-difference-p)
+ (setq
+ buf-C-state-diff (ediff-get-state-of-diff ediff-current-difference 'C)
+ buf-C-state-merge (ediff-get-state-of-merge ediff-current-difference)
+ buf-A-state-diff (ediff-get-state-of-diff ediff-current-difference 'A)
+ buf-B-state-diff (ediff-get-state-of-diff ediff-current-difference 'B)
+ buf-A-state-diff (if buf-A-state-diff
+ (format "[%s] " buf-A-state-diff)
+ "")
+ buf-B-state-diff (if buf-B-state-diff
+ (format "[%s] " buf-B-state-diff)
+ "")
+ buf-C-state-diff (if (and (ediff-buffer-live-p ediff-buffer-C)
+ (or buf-C-state-diff buf-C-state-merge))
+ (format "[%s%s] "
+ (or buf-C-state-diff "")
+ (if buf-C-state-merge
+ (concat " " buf-C-state-merge)
+ ""))
+ ""))
+ (setq buf-A-state-diff ""
+ buf-B-state-diff ""
+ buf-C-state-diff ""))
+
+ ;; control buffer format
+ (setq mode-line-format
+ (list (if (ediff-narrow-control-frame-p) " " "-- ")
+ mode-line-buffer-identification
+ " Howdy!"))
+ ;; control buffer id
+ (setq mode-line-buffer-identification
+ (if (ediff-narrow-control-frame-p)
+ (ediff-make-narrow-control-buffer-id 'skip-name)
+ (ediff-make-wide-control-buffer-id)))
+ ;; Force mode-line redisplay
+ (force-mode-line-update)
+
+ (if (and window-system (ediff-frame-live-p ediff-control-frame))
+ (ediff-refresh-control-frame))
+
+ (ediff-eval-in-buffer ediff-buffer-A
+ (setq ediff-diff-status buf-A-state-diff)
+ (ediff-strip-mode-line-format)
+ (setq mode-line-format
+ (list " A: " 'ediff-diff-status mode-line-format))
+ (force-mode-line-update))
+ (ediff-eval-in-buffer ediff-buffer-B
+ (setq ediff-diff-status buf-B-state-diff)
+ (ediff-strip-mode-line-format)
+ (setq mode-line-format
+ (list " B: " 'ediff-diff-status mode-line-format))
+ (force-mode-line-update))
+ (if ediff-3way-job
+ (ediff-eval-in-buffer ediff-buffer-C
+ (setq ediff-diff-status buf-C-state-diff)
+ (ediff-strip-mode-line-format)
+ (setq mode-line-format
+ (list " C: " 'ediff-diff-status mode-line-format))
+ (force-mode-line-update)))
+ ))
+
+
+(defun ediff-refresh-control-frame ()
+ (if ediff-xemacs-p
+ (progn
+ (setq screen-title-format (ediff-make-narrow-control-buffer-id)
+ screen-icon-title-format (ediff-make-narrow-control-buffer-id))
+ ;; this forces update of the screen title
+ (ediff-modify-frame-parameters ediff-control-frame '(())))
+ (ediff-modify-frame-parameters
+ ediff-control-frame
+ (list (cons 'name (ediff-make-narrow-control-buffer-id))))
+ ))
+
+
+(defun ediff-make-narrow-control-buffer-id (&optional skip-name)
+ (concat
+ (if skip-name
+ " "
+ (concat
+ (cdr (assoc 'name ediff-control-frame-parameters))
+ ediff-control-buffer-suffix))
+ (cond ((< ediff-current-difference 0)
+ (format " _/%d" ediff-number-of-differences))
+ ((>= ediff-current-difference ediff-number-of-differences)
+ (format " $/%d" ediff-number-of-differences))
+ (t
+ (format " %d/%d"
+ (1+ ediff-current-difference)
+ ediff-number-of-differences)))))
+
+(defun ediff-make-wide-control-buffer-id ()
+ (cond ((< ediff-current-difference 0)
+ (list (format "%%b At start of %d diffs"
+ ediff-number-of-differences)))
+ ((>= ediff-current-difference ediff-number-of-differences)
+ (list (format "%%b At end of %d diffs"
+ ediff-number-of-differences)))
+ (t
+ (list (format "%%b diff %d of %d"
+ (1+ ediff-current-difference)
+ ediff-number-of-differences)))))
+
+
+
+;; If buff is not live, return nil
+(defun ediff-get-visible-buffer-window (buff)
+ (if (ediff-buffer-live-p buff)
+ (if ediff-xemacs-p
+ (get-buffer-window buff t)
+ (get-buffer-window buff 'visible))))
+
+;;; Functions to decide when to redraw windows
+
+
+(defun ediff-keep-window-config (control-buf)
+ (and (eq control-buf (current-buffer))
+ (/= (buffer-size) 0)
+ (ediff-eval-in-buffer control-buf
+ (let ((ctl-wind ediff-control-window)
+ (A-wind ediff-window-A)
+ (B-wind ediff-window-B)
+ (C-wind ediff-window-C))
+
+ (and
+ (ediff-window-visible-p A-wind)
+ (ediff-window-visible-p B-wind)
+ ;; if buffer C is defined then take it into account
+ (or (not ediff-3way-job)
+ (ediff-window-visible-p C-wind))
+ (eq (window-buffer A-wind) ediff-buffer-A)
+ (eq (window-buffer B-wind) ediff-buffer-B)
+ (or (not ediff-3way-job)
+ (eq (window-buffer C-wind) ediff-buffer-C))
+ (string= ediff-window-config-saved
+ (format "%S%S%S%S%S"
+ ctl-wind A-wind B-wind C-wind
+ ediff-split-window-function)))))))
+
+
+(provide 'ediff-wind)
+
+
+;;; ediff-wind.el ends here