changeset 20206:f44ff2c52fac

new version
author Michael Kifer <kifer@cs.stonybrook.edu>
date Sat, 01 Nov 1997 01:46:51 +0000
parents cdaddfc03fe8
children 38616c4cf58c
files lisp/ediff-diff.el lisp/ediff-hook.el lisp/ediff-init.el lisp/ediff-merg.el lisp/ediff-mult.el lisp/ediff-util.el lisp/ediff-vers.el lisp/ediff.el lisp/emulation/viper-ex.el lisp/emulation/viper-init.el lisp/emulation/viper-keym.el lisp/emulation/viper-mous.el lisp/emulation/viper.el
diffstat 13 files changed, 627 insertions(+), 249 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ediff-diff.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff-diff.el	Sat Nov 01 01:46:51 1997 +0000
@@ -59,6 +59,11 @@
   :type 'string
   :group 'ediff-diff)
 
+(defcustom ediff-cmp-program "cmp"
+  "*Utility to use to determine if two files are identical.
+It must return code 0, if its arguments are identical files."
+  :type 'string
+  :group 'ediff-diff)
 
 (defcustom ediff-diff-program "diff"
   "*Program to use for generating the differential of the two files."
@@ -1235,6 +1240,11 @@
 	  (funcall fwd-word-fun))
       (point))))
 
+(defun ediff-same-file-contents (f1 f2)
+  "T if F1 and F2 have identical contents."
+  (let ((res (call-process ediff-cmp-program nil nil nil f1 f2)))
+    (and (numberp res) (eq res 0))))
+
 
 ;;; Local Variables:
 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
--- a/lisp/ediff-hook.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff-hook.el	Sat Nov 01 01:46:51 1997 +0000
@@ -126,10 +126,11 @@
 	   ))
 
        ;; put these menus before Object-Oriented-Browser in Tools menu
-       (add-hook 'before-init-hook 'ediff-xemacs-init-menus)
-       (if (not purify-flag)
-	   (ediff-xemacs-init-menus))
-       )
+;;       (add-hook 'before-init-hook 'ediff-xemacs-init-menus)
+;;       (if (not purify-flag)
+;;	   (ediff-xemacs-init-menus))
+;;       )
+       (ediff-xemacs-init-menus))
       
       ;; Emacs--only if menu-bar is loaded
       ((featurep 'menu-bar)
--- a/lisp/ediff-init.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff-init.el	Sat Nov 01 01:46:51 1997 +0000
@@ -346,6 +346,21 @@
       (error "%S: This command runs in Ediff Control Buffer only!"
 	     this-command)))
 
+(defgroup ediff-highlighting nil
+  "Hilighting of difference regions in Ediff"
+  :prefix "ediff-"
+  :group 'ediff)
+
+(defgroup ediff-merge nil
+  "Merging utilities"
+  :prefix "ediff-"
+  :group 'ediff)
+
+(defgroup ediff-hook nil
+  "Hooks called by Ediff"
+  :prefix "ediff-"
+  :group 'ediff)
+
 ;; Hook variables
 
 (defcustom ediff-before-setup-windows-hook nil
@@ -353,74 +368,74 @@
 This can be used to save the previous window config, which can be restored
 on ediff-quit or ediff-suspend."
   :type 'hook
-  :group 'ediff) 
+  :group 'ediff-hook) 
 (defcustom ediff-after-setup-windows-hook nil
   "*Hooks to run after Ediff sets its window configuration. 
 This can be used to set up control window or icon in a desired place."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-before-setup-control-frame-hook 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."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-after-setup-control-frame-hook nil
   "*Hooks run after setting up the frame to display Ediff Control Panel.
 Can be used to move the frame where it is desired."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-startup-hook nil
   "*Hooks to run in the control buffer after Ediff has been set up."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-select-hook nil
   "*Hooks to run after a difference has been selected."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-unselect-hook nil
   "*Hooks to run after a difference has been unselected."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-prepare-buffer-hook  nil
   "*Hooks called after buffers A, B, and C are set up."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-load-hook nil
   "*Hook run after Ediff is loaded.  Can be used to change defaults."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
   
 (defcustom ediff-mode-hook 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."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-keymap-setup-hook nil
   "*Hook run just after the default bindings in Ediff keymap are set up."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
   
 (defcustom ediff-display-help-hook nil
   "*Hooks run after preparing the help message."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 
 (defcustom ediff-suspend-hook (list 'ediff-default-suspend-function)
   "*Hooks to run in the Ediff control buffer when Ediff is suspended."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 (defcustom ediff-quit-hook (list 'ediff-cleanup-mess)
   "*Hooks to run in the Ediff control buffer after finishing Ediff."
   :type 'hook
-  :group 'ediff) 
+  :group 'ediff-hook) 
 (defcustom ediff-cleanup-hook nil
   "*Hooks to run on exiting Ediff but before killing the control buffer.
 This is a place to do various cleanups, such as deleting the variant buffers.
 Ediff provides a function, `ediff-janitor', as one such possible hook."
   :type 'hook
-  :group 'ediff)
+  :group 'ediff-hook)
 
 ;; Error messages
 (defconst ediff-KILLED-VITAL-BUFFER
@@ -847,10 +862,6 @@
   (if (and (ediff-has-face-support-p) ediff-emacs-p)
       (add-to-list 'facemenu-unlisted-faces face)))
       
-(defgroup ediff-highlighting nil
-  "Hilighting of difference regions in Ediff"
-  :prefix "ediff-"
-  :group 'ediff)
 
 ;;(defvar ediff-current-diff-face-A
 ;;  (if (ediff-has-face-support-p)
@@ -1523,11 +1534,14 @@
 ;; if nil, this silences some messages
 (defconst ediff-verbose-p t)
 
-(ediff-defvar-local ediff-autostore-merges  'group-jobs-only
+(defcustom ediff-autostore-merges  'group-jobs-only
   "*Save the results of merge jobs automatically.
 Nil means don't save automatically. t means always save. Anything but nil or t
 means save automatically only if the merge job is part of a group of jobs, such
-as `ediff-merge-directory' or `ediff-merge-directory-revisions'.")
+as `ediff-merge-directory' or `ediff-merge-directory-revisions'."
+  :type '(choice (const nil) (const t) (const group-jobs-only))
+  :group 'ediff-merge)
+(make-variable-buffer-local 'ediff-autostore-merges)
 
 ;; file where the result of the merge is to be saved. used internally
 (ediff-defvar-local ediff-merge-store-file nil "")
@@ -1538,7 +1552,7 @@
   :type 'boolean
   :group 'ediff)
   
-(defvar ediff-temp-file-prefix
+(defcustom ediff-temp-file-prefix
   (let ((env (or (getenv "TMPDIR")
 		 (getenv "TMP")
 		 (getenv "TEMP")))
@@ -1549,20 +1563,26 @@
  		    ((eq system-type 'ms-dos) "c:/")
  		    (t "/tmp"))))
     ;; The following is to make sure we get something to which we can
-    ;; add directory levels on VMS.
+    ;; add directory levels under VMS.
     (setq d (file-name-as-directory (directory-file-name d)))
     )
   "*Prefix to put on Ediff temporary file names.
-Do not start with `~/' or `~user-name/'.")  
+Do not start with `~/' or `~user-name/'."
+  :type 'string
+  :group 'ediff)
 
-(defvar ediff-temp-file-mode 384	; u=rw only
-  "*Mode for Ediff temporary files.")
+(defcustom ediff-temp-file-mode 384	; u=rw only
+  "*Mode for Ediff temporary files."
+  :type 'integer
+  :group 'ediff)
   
 ;; 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.")
+(defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
+  "Regexp that matches characters that must be quoted with `\\' in shell command line.
+This default should work without changes."
+  :type 'string
+  :group 'ediff)
 
 ;; needed to simulate frame-char-width in XEmacs.
 (defvar ediff-H-glyph (if ediff-xemacs-p (make-glyph "H")))
--- a/lisp/ediff-merg.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff-merg.el	Sat Nov 01 01:46:51 1997 +0000
@@ -25,12 +25,6 @@
 
 (provide 'ediff-merg)
 
-(defgroup ediff-merge nil
-  "Merging utilities"
-  :prefix "ediff-"
-  :group 'ediff)
-
-
 ;; compiler pacifier
 (defvar ediff-window-A)
 (defvar ediff-window-B)
@@ -138,7 +132,6 @@
     ))
     
 (defun ediff-set-merge-mode ()
-  ;; by Stig@hackvan.com
   (normal-mode t)
   (remove-hook 'local-write-file-hooks 'ediff-set-merge-mode))
 
--- a/lisp/ediff-mult.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff-mult.el	Sat Nov 01 01:46:51 1997 +0000
@@ -120,16 +120,17 @@
 (defconst ediff-meta-buffer-message "This is an Ediff Session Group Panel: %s
 
 Useful commands:
-     button2, `v', RET over a session line:   start that Ediff session
-     `M':\tin any session invoked from here, brings back this group panel
-     `R':\tdisplay the registry of active Ediff sessions
-     `h':\tmark session for hiding (toggle)
-     `x':\thide marked sessions; with prefix arg--unhide hidden sessions
-     `m':\tmark session for a non-hiding operation (toggle)
-     SPC:\tnext session
-     DEL:\tprevious session
-     `E':\tbrowse Ediff on-line manual
-     `q':\tquit this session group
+     button2, v, or RET over session record:   start that Ediff session
+     M:\tin sessions invoked from here, brings back this group panel
+     R:\tdisplay the registry of active Ediff sessions
+     h:\tmark session for hiding (toggle)
+     x:\thide marked sessions; with prefix arg: unhide
+     m:\tmark session for a non-hiding operation (toggle)
+ n,SPC:\tnext session
+ p,DEL:\tprevious session
+     E:\tbrowse Ediff on-line manual
+     T:\ttoggle truncation of long file names
+     q:\tquit this session group
 ")
 
 (ediff-defvar-local ediff-meta-buffer-map nil
@@ -166,6 +167,8 @@
 ;; group.
 (ediff-defvar-local ediff-meta-list nil "")
 
+(ediff-defvar-local ediff-meta-session-number nil "")
+
 
 ;; the difference list between directories in a directory session group
 (ediff-defvar-local ediff-dir-difference-list nil "")
@@ -174,6 +177,11 @@
 ;; The registry of Ediff sessions. A list of control buffers.
 (defvar ediff-session-registry nil)
 
+(defcustom ediff-meta-truncate-filenames t
+  "*If non-nil, truncate long file names in the session group buffers.
+This can be toggled with `ediff-toggle-filename-truncation'."
+  :type 'hook
+  :group 'ediff-mult)
 (defcustom ediff-registry-setup-hook nil
   "*Hooks run just after the registry control panel is set up."
   :type 'hook
@@ -250,6 +258,15 @@
 (defsubst ediff-set-file-eqstatus (elt value)
   (setcar (cdr elt) value))
 
+;; The activity marker is either or + (active session, i.e., ediff is currently
+;; run in it), or - (finished session, i.e., we've ran ediff in it and then
+;; exited). Return nil, if session is neither active nor finished
+(defun ediff-get-session-activity-marker (session)
+  (let ((session-buf (ediff-get-session-buffer session)))
+    (cond ((null session-buf) nil) ; virgin session
+	  ((ediff-buffer-live-p session-buf) ?+) ;active session
+	  (t ?-))))
+
 ;; checks if the session is a meta session
 (defun ediff-meta-session-p (session-info)
   (and (stringp (ediff-get-session-objA-name session-info))
@@ -264,12 +281,15 @@
   (setq ediff-meta-buffer-map (make-sparse-keymap))
   (suppress-keymap ediff-meta-buffer-map)
   (define-key ediff-meta-buffer-map "q" 'ediff-quit-meta-buffer)
+  (define-key ediff-meta-buffer-map "T" 'ediff-toggle-filename-truncation)
   (define-key ediff-meta-buffer-map "R" 'ediff-show-registry)
   (define-key ediff-meta-buffer-map "E" 'ediff-documentation)
   (define-key ediff-meta-buffer-map "v" ediff-meta-action-function)
   (define-key ediff-meta-buffer-map "\C-m" ediff-meta-action-function)
   (define-key ediff-meta-buffer-map  " "  'ediff-next-meta-item)
+  (define-key ediff-meta-buffer-map  "n"  'ediff-next-meta-item)
   (define-key ediff-meta-buffer-map  "\C-?"  'ediff-previous-meta-item)
+  (define-key ediff-meta-buffer-map  "p"  'ediff-previous-meta-item)
   (define-key ediff-meta-buffer-map  [delete]  'ediff-previous-meta-item)
   (define-key ediff-meta-buffer-map  [backspace]  'ediff-previous-meta-item)
   (or (ediff-one-filegroup-metajob)
@@ -313,7 +333,9 @@
 (suppress-keymap ediff-dir-diffs-buffer-map)
 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
+(define-key ediff-dir-diffs-buffer-map "n" 'next-line)
 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
+(define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line)
 (define-key ediff-dir-diffs-buffer-map [backspace] 'previous-line)
 
@@ -322,20 +344,20 @@
 Moves in circular fashion. With numeric prefix arg, skip this many items."
   (interactive "p")
   (or count (setq count 1))
-  (while (< 0 count)
-    (setq count (1- count))
-    (ediff-next-meta-item1)))
+  (let (overl)
+    (while (< 0 count)
+      (setq count (1- count))
+      (ediff-next-meta-item1)
+      (setq overl (ediff-get-meta-overlay-at-pos (point)))
+      ;; skip invisible ones
+      (while (and overl (ediff-overlay-get overl 'invisible))
+	(ediff-next-meta-item1)
+	(setq overl (ediff-get-meta-overlay-at-pos (point)))))))
 
 ;; Move to the next meta item
 (defun ediff-next-meta-item1 ()
   (let (pos)
     (setq pos (ediff-next-meta-overlay-start (point)))
-;;;	;; skip deleted
-;;;    (while (memq (ediff-get-session-status
-;;;	          (ediff-get-meta-info (current-buffer) pos 'noerror))
-;;;		 '(?H ?I))
-;;;      (setq pos (ediff-next-meta-overlay-start pos)))
-    
     (if pos (goto-char pos))
     (if (eq ediff-metajob-name 'ediff-registry)
 	(if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
@@ -350,9 +372,15 @@
 Moves in circular fashion. With numeric prefix arg, skip this many items."
   (interactive "p")
   (or count (setq count 1))
-  (while (< 0 count)
-    (setq count (1- count))
-    (ediff-previous-meta-item1)))
+  (let (overl)
+    (while (< 0 count)
+      (setq count (1- count))
+      (ediff-previous-meta-item1)
+      (setq overl (ediff-get-meta-overlay-at-pos (point)))
+      ;; skip invisible ones
+      (while (and overl (ediff-overlay-get overl 'invisible))
+	(ediff-previous-meta-item1)
+	(setq overl (ediff-get-meta-overlay-at-pos (point)))))))
 
 (defun ediff-previous-meta-item1 ()
   (let (pos)
@@ -376,6 +404,14 @@
       (file-name-as-directory file)
     file))
 
+(defun ediff-toggle-filename-truncation ()
+  "Toggle truncation of long file names in session group buffers.
+Set `ediff-meta-truncate-filenames' variable if you want to change the default
+behavior."
+  (interactive)
+  (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
+  (ediff-update-meta-buffer (current-buffer) 'must-redraw))
+
 
 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
@@ -490,11 +526,10 @@
 	   common))
     ))
 
-;; find directory files that are under revision.
-;; Include subdirectories, since we may visit them recursively.
-;; DIR1 is the directory to inspect.
-;; OUTPUT-DIR is the directory where to auto-store the results of merges. Can
-;; be nil.
+;; find directory files that are under revision.  Include subdirectories, since
+;; we may visit them recursively.  DIR1 is the directory to inspect.
+;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
+;; merges. Can be nil.
 (defun ediff-get-directory-files-under-revision (jobname
 						 regexp dir1
 						 &optional merge-autostore-dir)
@@ -511,7 +546,8 @@
 	    lis1 (cdr lis1))
       ;; take files under revision control
       (cond ((file-directory-p (concat auxdir1 elt))
-	     (setq common (cons elt common)))
+	     (setq common
+		   (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
 	    ((file-exists-p (concat auxdir1 elt ",v"))
 	     (setq common (cons elt common)))
 	    ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
@@ -519,8 +555,8 @@
 	    ) ; cond
       ) ; while
 
-    (setq common (delete "."  common)
-	  common (delete ".." common)
+    (setq common (delete "./"  common)
+	  common (delete "../" common)
 	  common (delete "RCS" common))
 
     ;; copying is needed because sort sorts via side effects
@@ -665,6 +701,74 @@
       ) ; eval in meta-buffer
     meta-buffer))
 
+;; Insert the activity marker for session SESSION in the meta buffer at point
+;; The activity marker is either SPC (untouched session), or + (active session,
+;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
+;; ediff in it and then exited)
+(defun ediff-insert-session-activity-marker-in-meta-buffer (session)
+  (insert
+   (cond ((ediff-get-session-activity-marker session))
+	 ;; virgin session
+	 (t " "))))
+
+;; Insert session status at point. Status is either ?H (marked for hiding), or
+;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
+;; such op can only be checking for equality)), or SPC (meaning neither marked
+;; nor invalid) 
+(defun ediff-insert-session-status-in-meta-buffer (session)
+  (insert
+   (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
+	 ;; normal session, no marks or hidings
+	 (t " "))))
+
+;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
+;; in the meta buffer. If nil, use SPC
+(defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
+  (let* ((overl (ediff-get-meta-overlay-at-pos point))
+	 (session-info (ediff-overlay-get overl 'ediff-meta-info))
+	 (activity-marker (ediff-get-session-activity-marker session-info))
+	 buffer-read-only)
+    (or new-marker activity-marker (setq new-marker ?\ ))
+    (goto-char (ediff-overlay-start overl))
+    (if (eq (char-after (point)) new-marker)
+	() ; if marker shown in buffer is the same as new-marker, do nothing
+      (insert new-marker)
+      (delete-char 1)
+      (set-buffer-modified-p nil))))
+
+;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
+;; the meta buffer. If nil, use SPC
+(defun ediff-replace-session-status-in-meta-buffer (point new-status)
+  (let* ((overl (ediff-get-meta-overlay-at-pos point))
+	 (session-info (ediff-overlay-get overl 'ediff-meta-info))
+	 (status (ediff-get-session-status session-info))
+	 buffer-read-only)
+    (setq new-status (or new-status status ?\ ))
+    (goto-char (ediff-overlay-start overl))
+    (forward-char 1) ; status is the second char in session record
+    (if (eq (char-after (point)) new-status)
+	() ; if marker shown in buffer is the same as new-marker, do nothing
+      (insert new-status)
+      (delete-char 1)
+      (set-buffer-modified-p nil))))
+
+;; insert all file info in meta buffer for a given session
+(defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
+  (let ((f1 (ediff-get-session-objA session-info))
+	(f2 (ediff-get-session-objB session-info))
+	(f3 (ediff-get-session-objC session-info))
+	(pt (point))
+	(hidden (eq (ediff-get-session-status session-info) ?I)))
+    ;; insert activity marker, i.e., SPC, - or +
+    (ediff-insert-session-activity-marker-in-meta-buffer session-info)
+    ;; insert session status, i.e., *, H
+    (ediff-insert-session-status-in-meta-buffer session-info)
+    (insert "  Session " (int-to-string sessionNum) ":\n")
+    (ediff-meta-insert-file-info1 f1)
+    (ediff-meta-insert-file-info1 f2)
+    (ediff-meta-insert-file-info1 f3)
+    (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
+
 
 ;; this is a setup function for ediff-directories
 ;; must return meta-buffer
@@ -673,42 +777,50 @@
   (let ((meta-buf (ediff-get-group-buffer meta-list))
 	(empty t)
 	(sessionNum 0)
-	regexp elt session-buf f1 f2 f3 pt 
-	merge-autostore-dir
+	regexp elt merge-autostore-dir
 	point tmp-list buffer-read-only)
     (ediff-with-current-buffer meta-buf
       (setq point (point))
       (erase-buffer)
+      ;; delete phony overlays that used to represent sessions before the buff
+      ;; was redrawn
+      (if ediff-emacs-p
+	  (mapcar 'delete-overlay (overlays-in 1 1))
+	(map-extents 'delete-extent))
+      
       (insert (format ediff-meta-buffer-message
 		      (ediff-abbrev-jobname ediff-metajob-name)))
 
       (setq regexp (ediff-get-group-regexp meta-list)
-	    merge-autostore-dir (ediff-get-group-merge-autostore-dir meta-list))
+	    merge-autostore-dir
+	    (ediff-get-group-merge-autostore-dir meta-list))
       
       (cond ((ediff-collect-diffs-metajob)
 	     (insert
-	      "     `P':\tcollect custom diffs of all marked sessions\n"))
+	      "     P:\tcollect custom diffs of all marked sessions\n"))
 	    ((ediff-patch-metajob)
 	     (insert
-	      "     `P':\tshow patch appropriately for the context (session or group)\n")))
+	      "     P:\tshow patch appropriately for the context (session or group)\n")))
       (insert
-       "     `u':\tshow parent session group\n")
+       "     u:\tshow parent session group\n")
       (or (ediff-one-filegroup-metajob)
 	  (insert
-	   "     `D':\tshow differences among directories\n"
-	   "     `=':\tmark identical files in each session\n\n"))
+	   "     D:\tshow differences among directories\n"
+	   "     =:\tmark identical files in each session\n\n"))
 
+      (insert "\n")
       (if (and (stringp regexp) (> (length regexp) 0))
 	  (insert
-	   (format "\n*** Filter-through regular expression: %s\n" regexp)))
+	   (format "*** Filter-through regular expression: %s\n" regexp)))
+      (ediff-insert-dirs-in-meta-buffer meta-list)
       (if (and ediff-autostore-merges (ediff-merge-metajob)
 	       (stringp merge-autostore-dir))
 	  (insert (format
-		   "\nMerges are automatically stored in directory: %s\n"
+		   "\nMerge results are automatically stored in:\n\t%s\n"
 		   merge-autostore-dir)))
       (insert "\n
         Size   Last modified           Name
-    -----------------------------------------------------------------------
+    ----------------------------------------------
 
 ")
       
@@ -734,27 +846,87 @@
 	      sessionNum (1+ sessionNum))
 	(if (eq (ediff-get-session-status elt) ?I)
 	    ()
-	  (setq session-buf (ediff-get-session-buffer elt)
-		f1 (ediff-get-session-objA elt)
-		f2 (ediff-get-session-objB elt)
-		f3 (ediff-get-session-objC elt))
-	  (setq pt (point))
-	  ;; insert markers
-	  (insert (cond ((null session-buf) " ") ; virgin session
-			((ediff-buffer-live-p session-buf) "+") ;active session
-			(t "-"))) ; finished session
-	  (insert (cond ((ediff-get-session-status elt)) ; session has status,
-						       ;;; e.g., ?H, ?I
-			(t " "))) ; normal session
-	  (insert "  Session " (int-to-string sessionNum) ":\n")
-	  (ediff-meta-insert-file-info f1)
-	  (ediff-meta-insert-file-info f2)
-	  (ediff-meta-insert-file-info f3)
-	  (ediff-set-meta-overlay pt (point) elt)))
+	  (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
       (set-buffer-modified-p nil)
       (goto-char point)
       meta-buf)))
 
+(defun ediff-update-markers-in-dir-meta-buffer (meta-list)
+  (let ((meta-buf (ediff-get-group-buffer meta-list))
+	session-info point overl buffer-read-only)
+    (ediff-with-current-buffer meta-buf
+      (setq point (point))
+      (goto-char (point-min))
+      (ediff-next-meta-item1)
+      (while (not (bobp))
+	(setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
+	      overl (ediff-get-meta-overlay-at-pos (point)))
+	(if session-info
+	    (progn
+	      (cond ((eq (ediff-get-session-status session-info) ?I)
+		     ;; Do hiding
+		     (if overl (ediff-overlay-put overl 'invisible t)))
+		    ((and (eq (ediff-get-session-status session-info) ?H)
+			  overl (ediff-overlay-get overl 'invisible))
+		     ;; Do unhiding
+		     (ediff-overlay-put overl 'invisible nil))
+		    (t (ediff-replace-session-activity-marker-in-meta-buffer
+			(point)
+			(ediff-get-session-activity-marker session-info))
+		       (ediff-replace-session-status-in-meta-buffer
+			(point)
+			(ediff-get-session-status session-info))))))
+	(ediff-next-meta-item1) ; advance to the next item
+	) ; end while
+      (set-buffer-modified-p nil)
+      (goto-char point))
+    meta-buf))
+
+(defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
+  (let (buffer-meta-overlays session-info overl buffer-read-only)
+    (setq overl
+	  (if ediff-xemacs-p
+	      (map-extents
+	       (function
+		(lambda (ext maparg)
+		  (if (and
+		       (ediff-overlay-get ext 'ediff-meta-info)
+		       (eq (ediff-overlay-get ext 'ediff-meta-session-number)
+			   session-num))
+		      ext))))
+	    ;; Emacs doesn't have map-extents, so try harder
+	    ;; Splice overlay lists to get all buffer overlays
+	    (setq buffer-meta-overlays (overlay-lists)
+		  buffer-meta-overlays (append (car buffer-meta-overlays)
+					       (cdr buffer-meta-overlays)))
+	    (car
+	     (delq nil
+		   (mapcar
+		    (function
+		     (lambda (overl)
+		       (if (and
+			    (ediff-overlay-get overl 'ediff-meta-info)
+			    (eq (ediff-overlay-get
+				 overl 'ediff-meta-session-number)
+				session-num))
+			   overl)))
+		    buffer-meta-overlays)))))
+    (or overl
+	(error
+	 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
+	 session-num))
+    (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
+    (goto-char (ediff-overlay-start overl))
+    (ediff-replace-session-activity-marker-in-meta-buffer
+     (point)
+     (ediff-get-session-activity-marker session-info))
+    (ediff-replace-session-status-in-meta-buffer
+     (point)
+     (ediff-get-session-status session-info)))
+  (ediff-next-meta-item1))
+
+
+
 ;; Check if this is a problematic session.
 ;; Return nil if not. Otherwise, return symbol representing the problem
 ;; At present, problematic sessions occur only in -with-ancestor comparisons
@@ -773,11 +945,13 @@
 	   'ancestor-is-dir)
 	  (t nil))))
 
-(defun ediff-meta-insert-file-info (fileinfo)
+(defun ediff-meta-insert-file-info1 (fileinfo)
   (let ((fname (car fileinfo))
 	(feq (ediff-get-file-eqstatus fileinfo))
+	(max-filename-width (if ediff-meta-truncate-filenames
+				(- (window-width) 41)
+			      500))
 	file-modtime file-size)
-
     (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
 	  ((not (ediff-file-remote-p fname))
 	   (if (file-exists-p fname)
@@ -802,7 +976,9 @@
 	  ;; abbreviate the file name, if file exists
 	  (if (and (not (stringp fname)) (< file-size -1))
 	      "-------"		; file doesn't exist
-	    (ediff-abbreviate-file-name fname)))))))
+	    (ediff-truncate-string-left
+	     (ediff-abbreviate-file-name fname)
+	     max-filename-width)))))))
 
 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
 			(5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
@@ -826,6 +1002,18 @@
 	  (ediff-fill-leading-zero (nth 0 time)) ; sec
 	  ))
 
+;; Draw the directories
+(defun ediff-insert-dirs-in-meta-buffer (meta-list)
+  (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
+	 (dir2 (ediff-get-group-objB meta-list))
+	 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
+	 (dir3 (ediff-get-group-objC meta-list))
+	 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
+    (insert "*** Directory A: " dir1 "\n")
+    (if dir2 (insert "*** Directory B: " dir2 "\n"))
+    (if dir3 (insert "*** Directory C: " dir3 "\n"))
+    (insert "\n")))
+
 (defun ediff-draw-dir-diffs (diff-list)
   (if (null diff-list) (error "Lost difference info on these directories"))
   (let* ((buf-name (ediff-unique-buffer-name
@@ -850,8 +1038,8 @@
       (insert "
 Useful commands:
      `q': hide this buffer
-     SPC: next line
-     DEL: previous line\n\n")
+   n,SPC: next line
+   p,DEL: previous line\n\n")
 
       (if (and (stringp regexp) (> (length regexp) 0))
 	  (insert
@@ -946,7 +1134,8 @@
   "Go to the parent session group buffer."
   (interactive)
   (if (ediff-buffer-live-p ediff-parent-meta-buffer)
-      (ediff-show-meta-buffer ediff-parent-meta-buffer)
+      (ediff-show-meta-buffer
+       ediff-parent-meta-buffer ediff-meta-session-number)
     (error "This session group has no parent")))
   
 
@@ -957,16 +1146,22 @@
 	  elt bufAname bufBname bufCname cur-diff total-diffs pt
 	  job-name meta-list registry-list buffer-read-only)
       (erase-buffer)
+      ;; delete phony overlays that used to represent sessions before the buff
+      ;; was redrawn
+      (if ediff-emacs-p
+	  (mapcar 'delete-overlay (overlays-in 1 1))
+	(map-extents 'delete-extent))
+
       (insert "This is a registry of all active Ediff sessions.
 
 Useful commands:
      button2, `v', RET over a session record:  switch to that session
-     `M' over a session record:  display the associated session group
-     `R' in any Ediff session:   display session registry
-     SPC:\tnext session
-     DEL:\tprevious session
-     `E':\tbrowse Ediff on-line manual
-     `q':\tbury registry
+     M over a session record:  display the associated session group
+     R in any Ediff session:   display session registry
+     n,SPC: next session
+     p,DEL: previous session
+         E: browse Ediff on-line manual
+         q: bury registry
 
 
 \t\tActive Ediff Sessions:
@@ -1048,14 +1243,19 @@
       (goto-char point)
       )))
 
-;; sets overlay around a meta record with 'ediff-meta-info property PROP
-(defun ediff-set-meta-overlay (b e prop)
+;; Sets overlay around a meta record with 'ediff-meta-info property PROP
+;; If optional SESSION-NUMBER, make it a property of the overlay,
+;; ediff-meta-session-number
+(defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
   (let (overl)
     (setq overl (ediff-make-overlay b e))
     (if ediff-emacs-p
 	(ediff-overlay-put overl 'mouse-face 'highlight)
       (ediff-overlay-put overl 'highlight t))
-    (ediff-overlay-put overl 'ediff-meta-info prop)))
+    (ediff-overlay-put overl 'ediff-meta-info prop)
+    (ediff-overlay-put overl 'invisible hidden)
+    (if (numberp session-number)
+	(ediff-overlay-put overl 'ediff-meta-session-number session-number))))
 
 (defun ediff-mark-for-hiding (unmark)
   "Mark session for hiding. With prefix arg, unmark."
@@ -1064,8 +1264,8 @@
 	 (meta-buf (ediff-event-buffer last-command-event))
 	 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
 	 (info (ediff-get-meta-info meta-buf pos))
-	 (session-buf (ediff-get-session-buffer info)))
-
+	 (session-buf (ediff-get-session-buffer info))
+	 (session-number (ediff-get-session-number-at-pos pos)))
     (if (eq (ediff-get-session-status info) ?H)
 	(setq unmark t))
     (if unmark
@@ -1075,7 +1275,7 @@
       (ediff-set-session-status info ?H))
     (or unmark
 	(ediff-next-meta-item 1))
-    (ediff-update-meta-buffer meta-buf)
+    (ediff-update-meta-buffer meta-buf nil session-number)
     ))
 
 (defun ediff-mark-for-operation (unmark)
@@ -1084,8 +1284,8 @@
   (let* ((pos (ediff-event-point last-command-event))
 	 (meta-buf (ediff-event-buffer last-command-event))
 	 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
-	 (info (ediff-get-meta-info meta-buf pos)))
-
+	 (info (ediff-get-meta-info meta-buf pos))
+	 (session-number (ediff-get-session-number-at-pos pos)))
     (if (eq (ediff-get-session-status info) ?*)
 	(setq unmark t))
     (if unmark
@@ -1093,7 +1293,7 @@
       (ediff-set-session-status info ?*))
     (or unmark
 	(ediff-next-meta-item 1))
-    (ediff-update-meta-buffer meta-buf)
+    (ediff-update-meta-buffer meta-buf nil session-number)
     ))
 
 (defun ediff-hide-marked-sessions (unhide)
@@ -1124,7 +1324,7 @@
 	  (message "Nothing to reveal...")
 	(message "Nothing to hide...")))
     (if active-sessions-exist
-	(message "Note: didn't hide active sessions!"))
+	(message "Note: Ediff didn't hide active sessions!"))
     ))
 
 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
@@ -1156,7 +1356,7 @@
 			(setq ediff-meta-diff-buffer diff-buffer)
 			;; collect diffs in child group
 			(ediff-operate-on-marked-sessions operation)))))))
-    (ediff-update-meta-buffer grp-buf) ; just in case
+    (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
     numMarked
     ))
 
@@ -1255,11 +1455,11 @@
 	 (meta-buf (ediff-event-buffer last-command-event))
 	 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
 	 (info (ediff-get-meta-info meta-buf pos))
-	 merge-autostore-dir
-	 session-buf file1 file2 file3 regexp)
+	 (session-buf (ediff-get-session-buffer info))
+	 (session-number (ediff-get-session-number-at-pos pos))
+	 merge-autostore-dir file1 file2 file3 regexp)
 
-    (setq session-buf (ediff-get-session-buffer info)
-	  file1 (ediff-get-session-objA-name info)
+    (setq file1 (ediff-get-session-objA-name info)
 	  file2 (ediff-get-session-objB-name info)
 	  file3 (ediff-get-session-objC-name info))
 
@@ -1271,7 +1471,7 @@
 	  (if (y-or-n-p "This session is marked as hidden, unmark? ")
 	      (progn
 		(ediff-set-session-status info nil)
-		(ediff-update-meta-buffer meta-buf))
+		(ediff-update-meta-buffer meta-buf nil session-number))
 	    (error "Aborted"))))
 
     (ediff-with-current-buffer meta-buf
@@ -1295,7 +1495,9 @@
 		(` (list (lambda () 
 			   ;; child session group should know its parent
 			   (setq ediff-parent-meta-buffer
-				 (quote (, ediff-meta-buffer)))
+				 (quote (, ediff-meta-buffer))
+				 ediff-meta-session-number
+				 (, session-number))
 			   ;; and parent will know its child
 			   (setcar (quote (, info)) ediff-meta-buffer)))))))
 
@@ -1312,9 +1514,12 @@
 		ediff-session-action-function ediff-metajob-name
 		;; make it update car info after startup
 		(` (list (lambda () 
-			   ;; child session group should know its parent
+			   ;; child session group should know its parent and
+			   ;; its number
 			   (setq ediff-parent-meta-buffer
-				 (quote (, ediff-meta-buffer)))
+				 (quote (, ediff-meta-buffer))
+				 ediff-meta-session-number
+				 (, session-number))
 			   ;; and parent will know its child
 			   (setcar (quote (, info)) ediff-meta-buffer)))))))
 
@@ -1334,11 +1539,13 @@
 		  file1 file2
 		  ;; provide startup hooks 
 		  (` (list (lambda () 
-			     (setq ediff-meta-buffer (, (current-buffer)))
+			     (setq ediff-meta-buffer (, (current-buffer))
+				   ediff-meta-session-number
+				   (, session-number))
 			     (setq ediff-merge-store-file
 				   (, (concat
 				       merge-autostore-dir
-				       "mrg_"
+				       "merge_"
 				       (file-name-nondirectory file1))))
 			     ;; make ediff-startup pass
 			     ;; ediff-control-buffer back to the meta
@@ -1351,11 +1558,13 @@
 		      file1
 		      ;; provide startup hooks 
 		      (` (list (lambda () 
-				 (setq ediff-meta-buffer (, (current-buffer)))
+				 (setq ediff-meta-buffer (, (current-buffer))
+				       ediff-meta-session-number
+				       (, session-number))
 				 (setq ediff-merge-store-file
 				       (, (concat
 					   merge-autostore-dir
-					   "mrg_"
+					   "merge_"
 					   (file-name-nondirectory file1))))
 				 ;; make ediff-startup pass
 				 ;; ediff-control-buffer back to the meta
@@ -1367,11 +1576,13 @@
 		      file1 file2
 		      ;; provide startup hooks 
 		      (` (list (lambda () 
-				 (setq ediff-meta-buffer (, (current-buffer)))
+				 (setq ediff-meta-buffer (, (current-buffer))
+				       ediff-meta-session-number
+				       (, session-number))
 				 (setq ediff-merge-store-file
 				       (, (concat
 					   merge-autostore-dir
-					   "mrg_"
+					   "merge_"
 					   (file-name-nondirectory file1))))
 				 ;; make ediff-startup pass
 				 ;; ediff-control-buffer back to the meta
@@ -1386,9 +1597,11 @@
 				 (setq ediff-merge-store-file
 				       (, (concat
 					   merge-autostore-dir
-					   "mrg_"
+					   "merge_"
 					   (file-name-nondirectory file1))))
-				 (setq ediff-meta-buffer (, (current-buffer)))
+				 (setq ediff-meta-buffer (, (current-buffer))
+				       ediff-meta-session-number
+				       (, session-number))
 				 ;; this arranges that ediff-startup will pass
 				 ;; the value of ediff-control-buffer back to
 				 ;; the meta level, to the record in the meta
@@ -1413,7 +1626,7 @@
 	(if (ediff-with-current-buffer ctl-buf
 	      (eq (key-binding "q") 'ediff-quit-meta-buffer))
 	    ;; it's a meta-buffer -- last action should just display it
-	    (ediff-show-meta-buffer ctl-buf)
+	    (ediff-show-meta-buffer ctl-buf t)
 	  ;; it's a session buffer -- invoke go back to session
 	  (ediff-with-current-buffer ctl-buf
 	    (setq ediff-mouse-pixel-position (mouse-pixel-position))
@@ -1426,7 +1639,8 @@
     ))
 
 
-(defun ediff-show-meta-buffer (&optional meta-buf)
+;; If session number is t, means don't update meta buffer
+(defun ediff-show-meta-buffer (&optional meta-buf session-number)
   "Show the session group buffer."
   (interactive)
   (let (wind frame silent)
@@ -1439,7 +1653,12 @@
 	   (error
 	    "Can't find this session's group panel -- session itself is ok")))
 
-    (ediff-cleanup-meta-buffer meta-buf)
+    (cond ((numberp session-number)
+	   (ediff-update-meta-buffer meta-buf nil session-number))
+	  ;; if session-number is t, don't update
+	  (session-number)
+	  (t (ediff-cleanup-meta-buffer meta-buf)))
+
     (ediff-with-current-buffer meta-buf
       (save-excursion
 	(cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
@@ -1477,6 +1696,10 @@
     (run-hooks 'ediff-show-session-group-hook)
     ))
 
+(defun ediff-show-current-session-meta-buffer ()
+  (interactive)
+  (ediff-show-meta-buffer nil ediff-meta-session-number))
+
 (defun ediff-show-meta-buff-from-registry ()
   "Display the session group buffer for a selected session group."
   (interactive)
@@ -1485,7 +1708,7 @@
 	 (info (ediff-get-meta-info meta-buf pos))
 	 (meta-or-session-buf info))
     (ediff-with-current-buffer meta-or-session-buf
-      (ediff-show-meta-buffer))))
+      (ediff-show-meta-buffer nil t))))
 
 ;;;###autoload
 (defun ediff-show-registry ()
@@ -1538,12 +1761,20 @@
 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
 ;; parent meta-buf
 ;; Check if META-BUF exists before calling this function
-(defun ediff-update-meta-buffer (meta-buf)
-  (ediff-with-current-buffer (current-buffer)
-    (if (ediff-buffer-live-p meta-buf)
-	(ediff-with-current-buffer meta-buf
-	  (funcall ediff-meta-redraw-function ediff-meta-list))
-      )))
+;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
+;; buffer. Otherwise, it will just go over the buffer and update activity marks
+;; and session status.
+;; SESSION-NUMBER, if specified, says which session caused the update.
+(defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
+  (if (ediff-buffer-live-p meta-buf)
+      (ediff-with-current-buffer meta-buf
+	(cond (must-redraw ; completely redraw the meta buffer
+	       (funcall ediff-meta-redraw-function ediff-meta-list))
+	      ((numberp session-number) ; redraw only for the given session
+	       (ediff-update-session-marker-in-dir-meta-buffer session-number))
+	      (t ; update only what's changed, but scan the entire meta buffer
+	       (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
+	)))
 
 (defun ediff-update-registry ()
   (ediff-with-current-buffer (current-buffer)
@@ -1564,15 +1795,16 @@
       (ediff-with-current-buffer meta-buffer
 	(ediff-update-meta-buffer meta-buffer)
 	(if (ediff-buffer-live-p ediff-parent-meta-buffer)
-	    (ediff-update-meta-buffer ediff-parent-meta-buffer)))))
+	    (ediff-update-meta-buffer
+	     ediff-parent-meta-buffer nil ediff-meta-session-number)))))
 
-;; t if no session in progress
+;; t if no session is in progress
 (defun ediff-safe-to-quit (meta-buffer)
   (if (ediff-buffer-live-p meta-buffer)
       (let ((lis ediff-meta-list)
 	    (cont t)
 	    buffer-read-only)
-	(ediff-update-meta-buffer meta-buffer)
+	;;(ediff-update-meta-buffer meta-buffer)
 	(ediff-with-current-buffer meta-buffer
 	  (setq lis (cdr lis)) ; discard the description part of meta-list
 	  (while (and cont lis)
@@ -1591,11 +1823,12 @@
   (let* ((buf (current-buffer))
 	 (dir-diffs-buffer ediff-dir-diffs-buffer)
 	 (meta-diff-buffer ediff-meta-diff-buffer)
+	 (session-number ediff-meta-session-number)
 	 (parent-buf ediff-parent-meta-buffer)
 	 (dont-show-registry (eq buf ediff-registry-buffer)))
     (if dont-show-registry
 	(bury-buffer)
-      (ediff-cleanup-meta-buffer buf)
+      ;;(ediff-cleanup-meta-buffer buf)
       (cond ((and (ediff-safe-to-quit buf)
 		  (y-or-n-p "Quit this session group? "))
 	     (run-hooks 'ediff-quit-session-group-hook)
@@ -1606,13 +1839,13 @@
 	    (t
 	     (error
 	      "This session group has active sessions---cannot exit")))
-      (ediff-cleanup-meta-buffer parent-buf)
+      (ediff-update-meta-buffer parent-buf nil session-number)
       (ediff-kill-buffer-carefully dir-diffs-buffer)
       (ediff-kill-buffer-carefully meta-diff-buffer)
       (if (ediff-buffer-live-p parent-buf)
 	  (progn
 	    (setq dont-show-registry t)
-	    (ediff-show-meta-buffer parent-buf)))
+	    (ediff-show-meta-buffer parent-buf session-number)))
       )
     (or dont-show-registry
 	(ediff-show-registry))))
@@ -1653,46 +1886,58 @@
 	(ediff-update-registry)
 	(error "No session info in this line")))))
 
-;; return location of the next meta overlay after point
+
+(defun ediff-get-meta-overlay-at-pos (point)
+  (if ediff-xemacs-p
+      (extent-at point (current-buffer) 'ediff-meta-info)
+    (let* ((overl-list (overlays-at point))
+	   (overl (car overl-list)))
+      (while (and overl (null (overlay-get overl 'ediff-meta-info)))
+	(setq overl-list (cdr overl-list)
+	      overl (car overl-list)))
+      overl)))
+
+(defsubst ediff-get-session-number-at-pos (point)
+  (ediff-overlay-get
+   (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number))
+
+
+;; Return location of the next meta overlay after point
 (defun ediff-next-meta-overlay-start (point)
   (if (eobp)
       (goto-char (point-min))
-    (let (overl)
+    (let ((overl (ediff-get-meta-overlay-at-pos point)))
       (if ediff-xemacs-p
 	  (progn
-	    (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
 	    (if overl
 		(setq overl (next-extent overl))
 	      (setq overl (next-extent (current-buffer))))
 	    (if overl
 		(extent-start-position overl)
 	      (point-max)))
-	(setq overl (car (overlays-at point)))
-	(if (and overl (overlay-get overl 'ediff-meta-info))
+	(if overl
 	    ;; note: end of current overlay is the beginning of the next one
 	    (overlay-end overl)
 	  (next-overlay-change point))))
     ))
 
+
 (defun ediff-previous-meta-overlay-start (point)
   (if (bobp)
       (goto-char (point-max))
-    (let (overl)
+    (let ((overl (ediff-get-meta-overlay-at-pos point)))
       (if ediff-xemacs-p
 	  (progn
-	    (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
 	    (if overl
 		(setq overl (previous-extent overl))
 	      (setq overl (previous-extent (current-buffer))))
 	    (if overl
 		(extent-start-position overl)
 	      (point-min)))
-	(setq overl (car (overlays-at point)))
-	(if (and overl (overlay-get overl 'ediff-meta-info))
-	    (setq point (overlay-start overl)))
+	(if overl (setq point (overlay-start overl)))
 	;; to get to the beginning of prev overlay
 	(if (not (bobp))
-	    ;; trickery to overcome an emacs bug--doesn't always find previous
+	    ;; trick to overcome an emacs bug--doesn't always find previous
 	    ;; overlay change correctly
 	    (setq point (1- point)))
 	(setq point (previous-overlay-change point))
@@ -1701,8 +1946,7 @@
 	;; goto the top of the registry buffer.
 	(or (car (overlays-at point))
 	    (setq point (point-min)))
-	point
-	))))
+	point))))
 
 ;; this is the action invoked when the user selects a patch from the meta
 ;; buffer.
@@ -1752,19 +1996,18 @@
 	    (ediff-mark-if-equal fileinfo1 fileinfo3)
 	    (ediff-mark-if-equal fileinfo2 fileinfo3)))
       (setq list (cdr list))))
-  (ediff-update-meta-buffer (current-buffer)))
+  (ediff-update-meta-buffer (current-buffer) 'must-redraw))
 
 ;; mark files 1 and 2 as equal, if they are.
 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
-  (get-buffer-create ediff-tmp-buffer)
-  (or (file-directory-p (car fileinfo1))
-      (file-directory-p (car fileinfo2))
-      (if (= (ediff-make-diff2-buffer
-	      ediff-tmp-buffer (car fileinfo1) (car fileinfo2))
-	     0)
-	  (progn
-	    (ediff-set-file-eqstatus fileinfo1 t)
-	    (ediff-set-file-eqstatus fileinfo2 t)))))
+  (let ((f1 (car fileinfo1))
+	(f2 (car fileinfo2)))
+    (or (file-directory-p f1)
+	(file-directory-p f2)
+	(if (ediff-same-file-contents f1 f2)
+	    (progn
+	      (ediff-set-file-eqstatus fileinfo1 t)
+	      (ediff-set-file-eqstatus fileinfo2 t))))))
 
 
 
--- a/lisp/ediff-util.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff-util.el	Sat Nov 01 01:46:51 1997 +0000
@@ -178,7 +178,7 @@
   (define-key ediff-mode-map "E" 'ediff-documentation)
   (define-key ediff-mode-map "?" 'ediff-toggle-help)
   (define-key ediff-mode-map "!" 'ediff-update-diffs)
-  (define-key ediff-mode-map "M" 'ediff-show-meta-buffer)
+  (define-key ediff-mode-map "M" 'ediff-show-current-session-meta-buffer)
   (define-key ediff-mode-map "R" 'ediff-show-registry)
   (or ediff-word-mode
       (define-key ediff-mode-map "*" 'ediff-make-or-kill-fine-diffs))
@@ -251,7 +251,8 @@
 ;; STARTUP-HOOKS, but these parameters are set in the new control buffer right
 ;; after this buf is created and before any windows are set and such.
 (defun ediff-setup (buffer-A file-A buffer-B file-B buffer-C file-C
-			     startup-hooks setup-parameters)
+			     startup-hooks setup-parameters
+			     &optional merge-buffer-file)
   ;; ediff-convert-standard-filename puts file names in the form appropriate
   ;; for the OS at hand.
   (setq file-A (ediff-convert-standard-filename (expand-file-name file-A)))
@@ -259,6 +260,21 @@
   (if (stringp file-C)
       (setq file-C
 	    (ediff-convert-standard-filename (expand-file-name file-C))))
+  (if (stringp merge-buffer-file)
+      (progn
+	(setq merge-buffer-file 
+	      (ediff-convert-standard-filename
+	       (expand-file-name merge-buffer-file)))
+	;; check the directory exists
+	(or (file-exists-p (file-name-directory merge-buffer-file))
+	    (error "Directory %s given as place to save the merge doesn't exist."
+		   (abbreviate-file-name 
+		    (file-name-directory merge-buffer-file))))
+	(if (and (file-exists-p merge-buffer-file)
+		 (file-directory-p merge-buffer-file))
+	    (error "The merge buffer file %s must not be a directory"
+		   (abbreviate-file-name merge-buffer-file)))
+	))
   (let* ((control-buffer-name 
 	  (ediff-unique-buffer-name "*Ediff Control Panel" "*"))
 	 (control-buffer (ediff-with-current-buffer buffer-A
@@ -327,7 +343,6 @@
 	      (set-buffer buffer-C)
 	      (insert-buffer buf)
 	      (funcall (ediff-with-current-buffer buf major-mode))
-	      ;; after Stig@hackvan.com
 	      (add-hook 'local-write-file-hooks 'ediff-set-merge-mode nil t)
 	      )))
       (setq buffer-read-only nil    
@@ -489,13 +504,16 @@
       (ediff-visible-region)
       
       (run-hooks 'startup-hooks)
+      (ediff-arrange-autosave-in-merge-jobs merge-buffer-file)
+
       (ediff-refresh-mode-lines)
       (setq buffer-read-only t)
       (setq ediff-session-registry
 	    (cons control-buffer ediff-session-registry))
       (ediff-update-registry)
       (if (ediff-buffer-live-p ediff-meta-buffer)
-	  (ediff-update-meta-buffer ediff-meta-buffer))
+	  (ediff-update-meta-buffer
+	   ediff-meta-buffer nil ediff-meta-session-number))
       (run-hooks 'ediff-startup-hook)
       ) ; eval in control-buffer
     control-buffer))
@@ -536,7 +554,25 @@
     (goto-char (point-min))
     (skip-chars-forward ediff-whitespace)))
     
-    
+;; This executes in control buffer and sets auto-save, visited file name, etc,
+;; in the merge buffer
+(defun ediff-arrange-autosave-in-merge-jobs (merge-buffer-file)
+  (if (not ediff-merge-job)
+      ()
+    (if (stringp merge-buffer-file)
+	(setq ediff-autostore-merges t
+	      ediff-merge-store-file merge-buffer-file))
+    (if (stringp ediff-merge-store-file)
+	(progn
+	  ;; save before leaving ctl buffer
+	  (setq merge-buffer-file ediff-merge-store-file) 
+	  (ediff-with-current-buffer ediff-buffer-C
+	    (set-visited-file-name merge-buffer-file))))
+    (ediff-with-current-buffer ediff-buffer-C
+      (setq buffer-offer-save t) ; ask before killing buffer
+      ;; make sure the contents is auto-saved
+      (auto-save-mode 1))
+    ))
 
 
 ;;; Commands for working with Ediff
@@ -1330,13 +1366,15 @@
 		    'C  ediff-visible-bounds))
 	  )
       (ediff-with-current-buffer ediff-buffer-A
-	(narrow-to-region
-	 (ediff-overlay-start overl-A) (ediff-overlay-end overl-A)))
+	(if (ediff-overlay-buffer overl-A)
+	    (narrow-to-region
+	     (ediff-overlay-start overl-A) (ediff-overlay-end overl-A))))
       (ediff-with-current-buffer ediff-buffer-B
-	(narrow-to-region
-	 (ediff-overlay-start overl-B) (ediff-overlay-end overl-B)))
+	(if (ediff-overlay-buffer overl-B)
+	    (narrow-to-region
+	     (ediff-overlay-start overl-B) (ediff-overlay-end overl-B))))
       
-      (if ediff-3way-job
+      (if (and ediff-3way-job (ediff-overlay-buffer overl-C))
 	  (ediff-with-current-buffer ediff-buffer-C
 	    (narrow-to-region
 	     (ediff-overlay-start overl-C) (ediff-overlay-end overl-C))))
@@ -2291,6 +2329,7 @@
   ;; restore buffer mode line id's in buffer-A/B/C
   (let ((control-buffer ediff-control-buffer)
 	(meta-buffer ediff-meta-buffer)
+	(session-number ediff-meta-session-number)
 	;; suitable working frame
 	(warp-frame (if (and (ediff-window-display-p) (eq ediff-grab-mouse t))
 			(cond ((window-live-p ediff-window-A) 
@@ -2355,7 +2394,7 @@
     (or ediff-keep-variants (ediff-janitor 'ask)))
 
   (run-hooks 'ediff-quit-hook)
-  (ediff-cleanup-meta-buffer meta-buffer)
+  (ediff-update-meta-buffer meta-buffer nil session-number)
 
   ;; warp mouse into a working window
   (setq warp-frame  ; if mouse is over a reasonable frame, use it
@@ -2368,7 +2407,7 @@
 			  2 1))
 
   (if (ediff-buffer-live-p meta-buffer)
-      (ediff-show-meta-buffer meta-buffer))
+      (ediff-show-meta-buffer meta-buffer session-number))
   ))
 
 ;; Returns frame under mouse, if this frame is not a minibuffer
@@ -2391,11 +2430,11 @@
   
   
 (defun ediff-delete-temp-files ()
-  (if (stringp ediff-temp-file-A)
+  (if (and (stringp ediff-temp-file-A) (file-exists-p ediff-temp-file-A))
       (delete-file ediff-temp-file-A))
-  (if (stringp ediff-temp-file-B)
+  (if (and (stringp ediff-temp-file-B) (file-exists-p ediff-temp-file-B))
       (delete-file ediff-temp-file-B))
-  (if (stringp ediff-temp-file-C)
+  (if (and (stringp ediff-temp-file-C) (file-exists-p ediff-temp-file-C))
       (delete-file ediff-temp-file-C)))
   
 
@@ -2538,6 +2577,7 @@
 	  (if show-file
 	      (progn
 		(message "Merge buffer saved in: %s" file)
+		(set-buffer-modified-p nil)
 		(sit-for 2)))
 	  (if (and
 	       (not save-and-continue)
--- a/lisp/ediff-vers.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff-vers.el	Sat Nov 01 01:46:51 1997 +0000
@@ -146,7 +146,8 @@
 
 ;;; Merge with Version Control
 
-(defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev &optional startup-hooks)
+(defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev 
+				     &optional startup-hooks merge-buffer-file)
 ;; If ANCESTOR-REV non-nil, merge with ancestor
   (let (buf1 buf2 ancestor-buf)
     (save-excursion
@@ -175,12 +176,14 @@
     (if ancestor-rev
 	(ediff-merge-buffers-with-ancestor
 	 buf1 buf2 ancestor-buf
-	 startup-hooks 'ediff-merge-revisions-with-ancestor)
-      (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions))
+	 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file)
+      (ediff-merge-buffers
+       buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file))
     ))
 
 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
-				      &optional startup-hooks)
+				      &optional
+				      startup-hooks merge-buffer-file)
   ;; If ANCESTOR-REV non-nil, merge with ancestor
   (let (buf1 buf2 ancestor-buf)
     (setq buf1 (rcs-ediff-view-revision rev1)
@@ -196,11 +199,13 @@
     (if ancestor-rev
 	(ediff-merge-buffers-with-ancestor
 	 buf1 buf2 ancestor-buf
-	 startup-hooks 'ediff-merge-revisions-with-ancestor)
-      (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions))))
+	 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file)
+      (ediff-merge-buffers
+       buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file))))
 
 (defun ediff-generic-sc-merge-internal (rev1 rev2 ancestor-rev
-					     &optional startup-hooks)
+					     &optional
+					     startup-hooks merge-buffer-file)
   ;; If ANCESTOR-REV non-nil, merge with ancestor
   (let (buf1 buf2 ancestor-buf)
     (save-excursion
@@ -220,8 +225,9 @@
     (if ancestor-rev
 	(ediff-merge-buffers-with-ancestor
 	 buf1 buf2 ancestor-buf
-	 startup-hooks 'ediff-merge-revisions-with-ancestor)
-      (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions))))
+	 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file)
+      (ediff-merge-buffers
+       buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file))))
 
 
 ;; PCL-CVS.el support
@@ -254,7 +260,8 @@
 ;; Works like with other interfaces: runs ediff on versions of the file in the
 ;; current buffer.
 (defun ediff-pcl-cvs-merge-internal (rev1 rev2 ancestor-rev
-					  &optional startup-hooks)
+					  &optional
+					  startup-hooks merge-buffer-file)
 ;; Ediff-merge appropriate revisions of the selected file.
 ;; If REV1 is "" then use the latest revision.
 ;; If REV2 is "" then merge current buffer's file with REV1.
@@ -292,9 +299,9 @@
     (if ancestor-buf
 	(ediff-merge-buffers-with-ancestor
 	 buf1 buf2 ancestor-buf startup-hooks 
-	 'ediff-merge-revisions-with-ancestor)
+	 'ediff-merge-revisions-with-ancestor merge-buffer-file)
       (ediff-merge-buffers
-       buf1 buf2 startup-hooks 'ediff-merge-revisions))
+       buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file))
     ))
 
 (defun ediff-pcl-cvs-view-revision (file rev)
@@ -324,7 +331,7 @@
 
 (defun cvs-run-ediff-on-file-descriptor (tin)
 ;; This is a replacement for cvs-emerge-mode
-;; Run after cvs-update.
+;; Runs after cvs-update.
 ;; Ediff-merge appropriate revisions of the selected file.
   (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
 	 (type (cvs-fileinfo->type fileinfo))
--- a/lisp/ediff.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/ediff.el	Sat Nov 01 01:46:51 1997 +0000
@@ -6,8 +6,8 @@
 ;; Created: February 2, 1994
 ;; Keywords: comparing, merging, patching, version control.
 
-(defconst ediff-version "2.671" "The current version of Ediff")
-(defconst ediff-date "September 23, 1997" "Date of last update")  
+(defconst ediff-version "2.69" "The current version of Ediff")
+(defconst ediff-date "October 10, 1997" "Date of last update")  
 
 
 ;; This file is part of GNU Emacs.
@@ -314,7 +314,9 @@
 	     (ediff-verify-file-buffer))))
     (set file-var file)))
 
-(defun ediff-files-internal (file-A file-B file-C startup-hooks job-name)
+;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
+(defun ediff-files-internal (file-A file-B file-C startup-hooks job-name
+				    &optional merge-buffer-file)
   (let (buf-A buf-B buf-C)
     (message "Reading file %s ... " file-A)
     ;;(sit-for 0)
@@ -335,7 +337,8 @@
 		 buf-B file-B
 		 buf-C file-C
 		 startup-hooks
-		 (list (cons 'ediff-job-name job-name)))))
+		 (list (cons 'ediff-job-name job-name))
+		 merge-buffer-file)))
   
 
 ;;;###autoload
@@ -394,7 +397,9 @@
       
 
 			
-(defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name)
+;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
+(defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name
+				     &optional merge-buffer-file)
   (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A)))
 	 (buf-B-file-name (buffer-file-name (get-buffer buf-B)))
 	 (buf-C-is-alive (ediff-buffer-live-p buf-C))
@@ -432,7 +437,7 @@
 			    ))
 		       startup-hooks)
 		 (list (cons 'ediff-job-name job-name))
-		 )))
+		 merge-buffer-file)))
 
 
 ;;; Directory and file group operations
@@ -938,8 +943,7 @@
 		  (list (cons 'ediff-word-mode  word-mode)
 			(cons 'ediff-narrow-bounds (list overl-A overl-B))
 			(cons 'ediff-job-name job-name))
-		  setup-parameters)
-		 )
+		  setup-parameters))
     ))
     
  
@@ -954,7 +958,10 @@
     (set-buffer-modified-p nil)))
 
 ;;;###autoload
-(defun ediff-merge-files (file-A file-B &optional startup-hooks)
+(defun ediff-merge-files (file-A file-B
+				 ;; MERGE-BUFFER-FILE is the file to be
+				 ;; associated with the merge buffer 
+				 &optional startup-hooks merge-buffer-file)
   "Merge two files without ancestor."
   (interactive
    (let ((dir-A (if ediff-use-last-dir
@@ -986,11 +993,17 @@
 			  file-B)
 			  nil ; file-C
 			  startup-hooks
-			  'ediff-merge-files))
+			  'ediff-merge-files
+			  merge-buffer-file))
 			  
 ;;;###autoload
 (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor
-					       &optional startup-hooks)
+					       &optional
+					       startup-hooks
+					       ;; MERGE-BUFFER-FILE is the file
+					       ;; to be associated with the
+					       ;; merge buffer
+					       merge-buffer-file)
   "Merge two files with ancestor."
   (interactive
    (let ((dir-A (if ediff-use-last-dir
@@ -1036,13 +1049,18 @@
 			  file-B)
 			  file-ancestor
 			  startup-hooks
-			  'ediff-merge-files-with-ancestor))
+			  'ediff-merge-files-with-ancestor
+			  merge-buffer-file))
 			  
 ;;;###autoload
 (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor)
 			  
 ;;;###autoload
-(defun ediff-merge-buffers (buffer-A buffer-B &optional startup-hooks job-name)
+(defun ediff-merge-buffers (buffer-A buffer-B
+				     &optional
+				     ;; MERGE-BUFFER-FILE is the file to be
+				     ;; associated with the merge buffer
+				     startup-hooks job-name merge-buffer-file)
   "Merge buffers without ancestor."
   (interactive 
    (let (bf)
@@ -1059,12 +1077,17 @@
   (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
   (or job-name (setq job-name 'ediff-merge-buffers))
   (ediff-buffers-internal
-   buffer-A buffer-B nil startup-hooks job-name))
+   buffer-A buffer-B nil startup-hooks job-name merge-buffer-file))
    
 ;;;###autoload
-(defun ediff-merge-buffers-with-ancestor (buffer-A 
-					  buffer-B buffer-ancestor
-					  &optional startup-hooks job-name)
+(defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
+						   &optional
+						   startup-hooks
+						   job-name
+						   ;; MERGE-BUFFER-FILE is the
+						   ;; file to be associated
+						   ;; with the merge buffer
+						   merge-buffer-file)
   "Merge buffers with ancestor."
   (interactive 
    (let (bf bff)
@@ -1089,11 +1112,12 @@
   (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks))
   (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor))
   (ediff-buffers-internal
-   buffer-A buffer-B buffer-ancestor startup-hooks job-name))
+   buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file))
       
 
 ;;;###autoload
-(defun ediff-merge-revisions (&optional file startup-hooks)
+(defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file)
+  ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer
   "Run Ediff by merging two revisions of a file.
 The file is the optional FILE argument or the file visited by the current
 buffer."
@@ -1116,11 +1140,16 @@
     ;; ancestor-revision=nil
     (funcall
      (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
-     rev1 rev2 nil startup-hooks)))
+     rev1 rev2 nil startup-hooks merge-buffer-file)))
     
 
 ;;;###autoload
-(defun ediff-merge-revisions-with-ancestor (&optional file startup-hooks)
+(defun ediff-merge-revisions-with-ancestor (&optional
+					    file startup-hooks
+					    ;; MERGE-BUFFER-FILE is the file to
+					    ;; be associated with the merge
+					    ;; buffer
+					    merge-buffer-file)
   "Run Ediff by merging two revisions of a file with a common ancestor.
 The file is the the optional FILE argument or the file visited by the current
 buffer."
@@ -1148,7 +1177,7 @@
     (ediff-load-version-control)
     (funcall
      (intern (format "ediff-%S-merge-internal" ediff-version-control-package))
-     rev1 rev2 ancestor-rev startup-hooks)))
+     rev1 rev2 ancestor-rev startup-hooks merge-buffer-file)))
 
 ;;;###autoload
 (defun run-ediff-from-cvs-buffer (pos)
--- a/lisp/emulation/viper-ex.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/emulation/viper-ex.el	Sat Nov 01 01:46:51 1997 +0000
@@ -195,6 +195,7 @@
 ;; File containing the shell command to be executed at Ex prompt,
 ;; e.g., :r !date
 (defvar ex-cmdfile nil)
+(defvar ex-cmdfile-args "")
   
 ;; flag used in viper-ex-read-file-name to indicate that we may be reading
 ;; multiple file names. Used for :edit and :next
@@ -457,7 +458,11 @@
 		     "\\|" "^[ \t]*ta.*"
 		     "\\|" "^[ \t]*una.*"
 		     "\\|" "^[ \t]*su.*"
-		     "\\|['`][a-z][ \t]*"
+		     "\\|" "['`][a-z][ \t]*"
+		     ;; r! assumes that the next one is a shell command
+		     "\\|" "\\(r\\|re\\|rea\\|read\\)[ \t]*!"
+		     ;; w ! assumes that the next one is a shell command
+		     "\\|" "\\(w\\|wr\\|wri\\|writ.?\\)[ \t]+!"
 		     "\\|" "![ \t]*[a-zA-Z].*"
 		     "\\)"
 		     "!*")))
@@ -851,14 +856,16 @@
       (message "%s" ret))
     ret))
 
-;; Get a file name and set ex-variant, `ex-append' and `ex-offset' if found
+;; Get a file name and set `ex-variant', `ex-append' and `ex-offset' if found
+;; If it is r!, then get the command name and whatever args
 (defun viper-get-ex-file ()
   (let (prompt)
     (setq ex-file nil
 	  ex-variant nil
 	  ex-append nil
 	  ex-offset nil
-	  ex-cmdfile nil)
+	  ex-cmdfile nil
+	  ex-cmdfile-args "")
     (save-excursion
       (save-window-excursion
 	(setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) 
@@ -908,6 +915,8 @@
 			  ;; if file name comes from history, don't leave
 			  ;; minibuffer when the user types space
 			  (setq viper-incomplete-ex-cmd nil)
+			  (setq ex-cmdfile-args
+				(substring ex-file (match-end 0) nil))
 			  ;; this must be the last clause in this progn
 			  (substring ex-file (match-beginning 0) (match-end 0))
 			  )
@@ -958,6 +967,7 @@
 (defun ex-cmd-accepts-multiple-files-p (token)
   (member token '("edit" "next" "Next")))
 
+;; Read file name from the minibuffer in an ex command.
 ;; If user doesn't enter anything, then "" is returned, i.e., the
 ;; prompt-directory is not returned.
 (defun viper-ex-read-file-name (prompt)
@@ -1548,10 +1558,12 @@
 	  (setq ex-file buffer-file-name)))
     (if ex-cmdfile
 	(progn
-	  (setq command (ex-expand-filsyms ex-file (current-buffer)))
+	  (setq command 
+		(concat (ex-expand-filsyms ex-file (current-buffer))
+			ex-cmdfile-args))
 	  (shell-command command t))
       (insert-file-contents ex-file)))
-  (ex-fixup-history viper-last-ex-prompt ex-file))
+  (ex-fixup-history viper-last-ex-prompt ex-file ex-cmdfile-args))
   
 ;; this function fixes ex-history for some commands like ex-read, ex-edit
 (defun ex-fixup-history (&rest args)  
@@ -1935,7 +1947,8 @@
     (if ex-cmdfile
 	(progn
 	  (viper-enlarge-region beg end)
-	  (shell-command-on-region (point) (mark t) ex-file))
+	  (shell-command-on-region (point) (mark t) 
+				   (concat ex-file ex-cmdfile-args)))
       (if (and (string= ex-file "") (not (buffer-file-name)))
 	  (setq ex-file
 		(read-file-name
--- a/lisp/emulation/viper-init.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/emulation/viper-init.el	Sat Nov 01 01:46:51 1997 +0000
@@ -204,28 +204,28 @@
 (viper-deflocalvar viper-replace-minor-mode nil
   "Minor mode in effect in replace state (cw, C, and the like commands).")
 
-;; Mode for vital things like \C-z and \C-x)
-;; This is t, by default. So, any new buffer will have C-z defined as
-;; switch to Vi, unless we switched states in this buffer
-(viper-deflocalvar viper-emacs-intercept-minor-mode t)
+;; Mode for vital things like \C-z and \C-x) This is set to t, when viper-mode
+;; is invoked. So, any new buffer will have C-z defined as switch to Vi, unless
+;; we switched states in this buffer
+(viper-deflocalvar viper-emacs-intercept-minor-mode nil)
   
-(viper-deflocalvar viper-emacs-local-user-minor-mode t
+(viper-deflocalvar viper-emacs-local-user-minor-mode nil
   "Minor mode for local user bindings effective in Emacs state.
 Users can use it to override Emacs bindings when Viper is in its Emacs
 state.")  
   
-(viper-deflocalvar viper-emacs-global-user-minor-mode t
+(viper-deflocalvar viper-emacs-global-user-minor-mode nil
   "Minor mode for global user bindings in effect in Emacs state.
 Users can use it to override Emacs bindings when Viper is in its Emacs
 state.")  
 
-(viper-deflocalvar viper-emacs-kbd-minor-mode t
+(viper-deflocalvar viper-emacs-kbd-minor-mode nil
   "Minor mode for Vi style macros in Emacs state.
 The corresponding keymap stores key bindings of Vi macros defined with
 `viper-record-kbd-macro' command. There is no Ex-level command to do this
 interactively.")
 
-(viper-deflocalvar viper-emacs-state-modifier-minor-mode t
+(viper-deflocalvar viper-emacs-state-modifier-minor-mode nil
   "Minor mode used to make major-mode-specific modification to Emacs state.
 For instance, a Vi purist may want to bind `dd' in Dired mode to a function
 that deletes a file.")
--- a/lisp/emulation/viper-keym.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/emulation/viper-keym.el	Sat Nov 01 01:46:51 1997 +0000
@@ -389,9 +389,6 @@
 (define-key viper-vi-basic-map "~" 'viper-toggle-case)
 (define-key viper-vi-basic-map "\C-?" 'viper-backward-char)
 (define-key viper-vi-basic-map "_" 'viper-nil)
-  
-;;; Escape from Emacs to Vi for one command
-(global-set-key "\C-c\\" 'viper-escape-to-vi)  ; everywhere
 
 ;;; This is viper-vi-diehard-map. Used when viper-vi-diehard-minor-mode is on.
 
--- a/lisp/emulation/viper-mous.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/emulation/viper-mous.el	Sat Nov 01 01:46:51 1997 +0000
@@ -116,10 +116,13 @@
   (not (viper-sit-for-short viper-multiclick-timeout t)))
 
 ;; Returns window where click occurs
-(defsubst viper-mouse-click-window (click)
-  (if viper-xemacs-p
-      (event-window click)
-    (posn-window (event-start click))))
+(defun viper-mouse-click-window (click)
+  (let ((win (if viper-xemacs-p
+		(event-window click)
+	      (posn-window (event-start click)))))
+    (if (window-live-p win)
+	win
+      (error "Click was not over a live window"))))
 
 ;; Returns window where click occurs
 (defsubst viper-mouse-click-frame (click)
--- a/lisp/emulation/viper.el	Fri Oct 31 23:17:17 1997 +0000
+++ b/lisp/emulation/viper.el	Sat Nov 01 01:46:51 1997 +0000
@@ -8,7 +8,7 @@
 
 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
 
-(defconst viper-version "3.001 (Polyglot) of September 23, 1997"
+(defconst viper-version "3.002 (Polyglot) of October 23, 1997"
   "The current version of Viper")
 
 ;; This file is part of GNU Emacs.
@@ -385,6 +385,8 @@
 
 ;;;###autoload
 (defun toggle-viper-mode ()
+  "Toggle Viper on/off.
+If Viper is enabled, turn it off. Otherwise, turn it on."
   (interactive)
   (if (eq viper-mode t)
       (viper-go-away)
@@ -1208,6 +1210,26 @@
 (define-key viper-vi-intercept-map viper-toggle-key 'viper-toggle-key-action)
 (define-key
   viper-emacs-intercept-map viper-toggle-key 'viper-change-state-to-vi)
+  
+;;; Escape from Emacs and Insert modes to Vi for one command
+(define-key 
+  viper-emacs-intercept-map "\C-c\\" 'viper-escape-to-vi)
+(define-key 
+  viper-insert-intercept-map "\C-c\\" 'viper-escape-to-vi)
+
+(if viper-mode
+    (progn
+      (setq viper-emacs-intercept-minor-mode t
+	    viper-emacs-local-user-minor-mode t
+	    viper-emacs-global-user-minor-mode t
+	    viper-emacs-kbd-minor-mode t
+	    viper-emacs-state-modifier-minor-mode t)
+      (setq-default viper-emacs-intercept-minor-mode t
+		    viper-emacs-local-user-minor-mode t
+		    viper-emacs-global-user-minor-mode t
+		    viper-emacs-kbd-minor-mode t
+		    viper-emacs-state-modifier-minor-mode t)
+      ))
 
 
 (if (and viper-mode
@@ -1219,7 +1241,7 @@
 ;; this may not be enough, so we also set default minor-mode-alist.
 ;; Without setting the default, new buffers that come up in emacs mode have
 ;; minor-mode-map-alist = nil, unless we call viper-change-state-*
-(if (eq viper-current-state 'emacs-state)
+(if (and viper-mode (eq viper-current-state 'emacs-state))
     (progn
       (viper-change-state-to-emacs)
       (setq-default minor-mode-map-alist minor-mode-map-alist)