;;; ediff.el --- a comprehensive visual interface to diff & patch
-;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01 Free Software Foundation, Inc.
;; Author: Michael Kifer <kifer@cs.sunysb.edu>
;; Created: February 2, 1994
-;; Keywords: comparing, merging, patching, version control.
+;; Keywords: comparing, merging, patching, tools, unix
-(defconst ediff-version "2.74" "The current version of Ediff")
-(defconst ediff-date "October 31, 1999" "Date of last update")
+(defconst ediff-version "2.76" "The current version of Ediff")
+(defconst ediff-date "July 18, 2001" "Date of last update")
;; This file is part of GNU Emacs.
(toggle-read-only 1)))
;; Return a plausible default for ediff's first file:
-;; In dired, return the file name under the point, unless it is a directory
-;; If the buffer has a file name, return that file name.
-(defun ediff-get-default-file-name ()
+;; In dired, return the file number FILENO (or 0) in the list
+;; (all-selected-files, filename under the cursor), where directories are
+;; ignored. Otherwise, return DEFAULT file name, if non-nil. Else,
+;; if the buffer is visiting a file, return that file name.
+(defun ediff-get-default-file-name (&optional default fileno)
(cond ((eq major-mode 'dired-mode)
- (let ((f (dired-get-filename nil 'no-error)))
- (if (and (stringp f) (not (file-directory-p f)))
- f)))
+ (let ((current (dired-get-filename nil 'no-error))
+ (marked (condition-case nil
+ (dired-get-marked-files 'no-dir)
+ (error)))
+ aux-list choices result)
+ (or (integerp fileno) (setq fileno 0))
+ (if (stringp default)
+ (setq aux-list (cons default aux-list)))
+ (if (and (stringp current) (not (file-directory-p current)))
+ (setq aux-list (cons current aux-list)))
+ (setq choices (nconc marked aux-list))
+ (setq result (elt choices fileno))
+ (or result
+ default)))
+ ((stringp default) default)
((buffer-file-name (current-buffer))
(file-name-nondirectory (buffer-file-name (current-buffer))))
))
(file-name-nondirectory f)
dir-B))
file-name-history))
- f))
+ (ediff-get-default-file-name f 1)))
)))
(ediff-files-internal file-A
(if (file-directory-p file-B)
(file-name-nondirectory f)
dir-B))
file-name-history))
- f)))
+ (ediff-get-default-file-name f 1))))
(ediff-read-file-name "File C to compare"
(setq dir-C (if ediff-use-last-dir
ediff-last-dir-C
(file-name-nondirectory ff)
dir-C))
file-name-history))
- ff))
+ (ediff-get-default-file-name ff 2)))
)))
(ediff-files-internal file-A
(if (file-directory-p file-B)
(and (< beg-B end-A) (<= end-A end-B)))) ; b-B e-A e-B
(progn
(with-output-to-temp-buffer ediff-msg-buffer
+ (ediff-with-current-buffer standard-output
+ (fundamental-mode))
(princ "
You have requested to compare overlapping regions of the same buffer.
(file-name-nondirectory f)
dir-B))
file-name-history))
- f))
+ (ediff-get-default-file-name f 1)))
)))
(setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
(ediff-files-internal file-A
(file-name-nondirectory f)
dir-B))
file-name-history))
- f)))
+ (ediff-get-default-file-name f 1))))
(ediff-read-file-name "Ancestor file"
(setq dir-ancestor
(if ediff-use-last-dir
(file-name-nondirectory ff)
dir-ancestor))
file-name-history))
- ff))
+ (ediff-get-default-file-name ff 2)))
)))
(setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
(ediff-files-internal file-A
(buffer-file-name patch-buf))))
(t default-directory)))
(setq source-file
- ;; the default is the directory, not the visited file name
(read-file-name
"File to patch (directory, if multifile patch): "
- source-dir (ediff-get-default-file-name)))
+ ;; use an explicit initial file
+ source-dir nil nil (ediff-get-default-file-name)))
(ediff-dispatch-file-patching-job patch-buf source-file)))
;;;###autoload
(defun ediff-patch-buffer (&optional arg patch-buf)
- "Run Ediff by patching BUFFER-NAME."
+ "Run Ediff by patching BUFFER-NAME.
+Without prefix argument: asks if the patch is in some buffer and prompts for
+the buffer or a file, depending on the answer.
+With prefix arg=1: assumes the patch is in a file and prompts for the file.
+With prefix arg=2: assumes the patch is in a buffer and prompts for the buffer."
(interactive "P")
(require 'ediff-ptch)
(setq patch-buf
patch-buf
(read-buffer
"Which buffer to patch? "
- (ediff-prompt-for-patch-buffer))))
+ (current-buffer))))
;;;###autoload
;;;###autoload
(defun ediff-revision (&optional file startup-hooks)
"Run Ediff by comparing versions of a file.
-The file is an optional FILE argument or the file visited by the current
-buffer. Use `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
+The file is an optional FILE argument or the file entered at the prompt.
+Default: the file visited by the current buffer.
+Uses `vc.el' or `rcs.el' depending on `ediff-version-control-package'."
;; if buffer is non-nil, use that buffer instead of the current buffer
(interactive "P")
- (if (stringp file) (find-file file))
+ (if (not (stringp file))
+ (setq file
+ (ediff-read-file-name "Compare revisions for file"
+ (if ediff-use-last-dir
+ ediff-last-dir-A
+ default-directory)
+ (ediff-get-default-file-name))))
+ (find-file file)
+ (if (and (buffer-modified-p)
+ (y-or-n-p (message "Buffer %s is modified. Save buffer? "
+ (buffer-name))))
+ (save-buffer (current-buffer)))
(let (rev1 rev2)
(setq rev1
(read-string
(format "Version 1 to compare (default: %s's latest version): "
- (if (stringp file)
- (file-name-nondirectory file) "current buffer")))
+ (file-name-nondirectory file)))
rev2
(read-string
(format "Version 2 to compare (default: %s): "
- (if (stringp file)
- (file-name-nondirectory file) "current buffer"))))
+ (file-name-nondirectory file))))
(ediff-load-version-control)
(funcall
(intern (format "ediff-%S-internal" ediff-version-control-package))
(raise-frame (selected-frame)))
(error (beep 1)
(with-output-to-temp-buffer ediff-msg-buffer
+ (ediff-with-current-buffer standard-output
+ (fundamental-mode))
(princ ediff-BAD-INFO))
(if (window-live-p ctl-window)
(progn