changeset 65627:511f8e9d22ca

2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu> * ediff-ptch.el (ediff-file-name-sans-prefix): treat nil as an empty string. (ediff-fixup-patch-map): better heuristic for intuiting the file names to patch. (ediff-prompt-for-patch-file): more intuitive prompt. * ediff-util.el: use insert-buffer-substring. * ediff-vers.el (cvs-run-ediff-on-file-descriptor): bug fix. * viper-cmd.el (viper-change-state): don't move over the field boundaries in the minibuffer. (viper-set-minibuffer-style): add viper-minibuffer-post-command-hook. (viper-minibuffer-post-command-hook): new hook. (viper-line): don't move cursor at bolp. * viper-ex.el (ex-pwd, viper-info-on-file): fixed message * viper-init.el: add alias to make-variable-buffer-local to avoid compiler warnings. * viper-macs.el (ex-map): better messages. * viper-utils.el (viper-beginning-of-field): new function. * viper.el: replace make-variable-buffer-local with viper-make-variable-buffer-local everywhere, to avoid warnings.
author Michael Kifer <kifer@cs.stonybrook.edu>
date Tue, 20 Sep 2005 17:47:28 +0000
parents 69a9e146ef35
children a998f173b21a
files lisp/ChangeLog lisp/ediff-ptch.el lisp/ediff-util.el lisp/ediff-vers.el lisp/ediff.el lisp/emulation/viper-cmd.el lisp/emulation/viper-init.el lisp/emulation/viper-macs.el lisp/emulation/viper-util.el lisp/emulation/viper.el
diffstat 10 files changed, 158 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/ChangeLog	Tue Sep 20 17:47:28 2005 +0000
@@ -1,3 +1,33 @@
+2005-09-20  Michael Kifer  <kifer@cs.stonybrook.edu>
+	
+	* ediff-ptch.el (ediff-file-name-sans-prefix): treat nil as an empty
+	string.
+	(ediff-fixup-patch-map): better heuristic for intuiting the file names
+	to patch.
+	(ediff-prompt-for-patch-file): more intuitive prompt.
+	
+	* ediff-util.el: use insert-buffer-substring.
+	
+	* ediff-vers.el (cvs-run-ediff-on-file-descriptor): bug fix.
+	
+	* viper-cmd.el (viper-change-state): don't move over the field
+	boundaries in the minibuffer.
+	(viper-set-minibuffer-style): add viper-minibuffer-post-command-hook.
+	(viper-minibuffer-post-command-hook): new hook.
+	(viper-line): don't move cursor at bolp.
+	
+	* viper-ex.el (ex-pwd, viper-info-on-file): fixed message
+	
+	* viper-init.el: add alias to make-variable-buffer-local to avoid
+	compiler warnings.
+	
+	* viper-macs.el (ex-map): better messages.
+	
+	* viper-utils.el (viper-beginning-of-field): new function.
+	
+	* viper.el: replace make-variable-buffer-local with
+	viper-make-variable-buffer-local everywhere, to avoid warnings.
+	
 2005-09-19  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* mouse.el (mouse-drag-mode-line-1, mouse-drag-vertical-line):
--- a/lisp/ediff-ptch.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/ediff-ptch.el	Tue Sep 20 17:47:28 2005 +0000
@@ -163,10 +163,16 @@
 ;; strip prefix from filename
 ;; returns /dev/null, if can't strip prefix
 (defsubst ediff-file-name-sans-prefix (filename prefix)
-  (save-match-data
-    (if (string-match (concat "^" (regexp-quote prefix)) filename)
-	(substring filename (match-end 0))
-      (concat "/null/" filename))))
+  (if prefix
+      (save-match-data
+	(if (string-match (concat "^" (if (stringp prefix)
+					  (regexp-quote prefix)
+					""))
+			  filename)
+	    (substring filename (match-end 0))
+	  (concat "/null/" filename)))
+    filename)
+  )
 
 
 
@@ -260,11 +266,14 @@
       count)))
 
 ;; Fix up the file names in the list using the argument FILENAME
-;; Algorithm: find the first file's directory and cut it out from each file
-;; name in the patch.  Prepend the directory of FILENAME to each file in the
-;; patch.  In addition, the first file in the patch is replaced by FILENAME.
-;; Each file is actually a file-pair of files found in the context diff header
-;; In the end, for each pair, we select the shortest existing file.
+;; Algorithm: find the files' directories in the patch and, if a directory is
+;; absolute, cut it out from the corresponding file name in the patch.
+;; Relative directories are not cut out.
+;; Prepend the directory of FILENAME to each resulting file (which came
+;; originally from the patch).
+;; In addition, the first file in the patch document is replaced by FILENAME.
+;; Each file is actually a pair of files found in the context diff header
+;; In the end, for each pair, we ask the user which file to patch.
 ;; Note: Ediff doesn't recognize multi-file patches that are separated
 ;; with the `Index:' line.  It treats them as a single-file patch.
 ;;
@@ -275,30 +284,41 @@
 			;; directory part of filename
 			(file-name-as-directory filename)
 		      (file-name-directory filename)))
-	;; Filename-spec is objA; at this point it is represented as
-	;; (file1 . file2). We get it using ediff-get-session-objA
-	;; directory part of the first file in the patch
-	(base-dir1 (file-name-directory
-		    (car (ediff-get-session-objA-name (car ediff-patch-map)))))
-	;; directory part of the 2nd file in the patch
-	(base-dir2 (file-name-directory
-		    (cdr (ediff-get-session-objA-name (car ediff-patch-map)))))
+	;; In case 2 files are possible patch targets, the user will be offered
+	;; to choose file1 or file2.  In a multifile patch, if the user chooses
+	;; 1 or 2, this choice is preserved to decide future alternatives.
+	chosen-alternative
 	)
 
     ;; chop off base-dirs
     (mapcar (lambda (session-info)
-	      (let ((proposed-file-names
-		     (ediff-get-session-objA-name session-info)))
+	      (let* ((proposed-file-names
+		      ;; Filename-spec is objA; it is represented as
+		      ;; (file1 . file2). Get it using ediff-get-session-objA.
+		      (ediff-get-session-objA-name session-info))
+		     ;; base-dir1 is  the dir part of the 1st file in the patch
+		     (base-dir1 (file-name-directory (car proposed-file-names)))
+		     ;; directory part of the 2nd file in the patch
+		     (base-dir2 (file-name-directory (cdr proposed-file-names)))
+		     )
+		;; If both base-dir1 and base-dir2 are relative, assume that
+		;; these dirs lead to the actual files starting at the present
+		;; directory. So, we don't strip these relative dirs from the
+		;; file names. This is a heuristic intended to improve guessing
+		(unless (or (file-name-absolute-p base-dir1)
+			    (file-name-absolute-p base-dir2))
+		  (setq base-dir1 ""
+			base-dir2 ""))
 		(or (string= (car proposed-file-names) "/dev/null")
 		    (setcar proposed-file-names
 			    (ediff-file-name-sans-prefix
 			     (car proposed-file-names) base-dir1)))
-	      (or (string=
-		   (cdr proposed-file-names) "/dev/null")
-		  (setcdr proposed-file-names
-			  (ediff-file-name-sans-prefix
-			   (cdr proposed-file-names) base-dir2)))
-	      ))
+		(or (string=
+		     (cdr proposed-file-names) "/dev/null")
+		    (setcdr proposed-file-names
+			    (ediff-file-name-sans-prefix
+			     (cdr proposed-file-names) base-dir2)))
+		))
 	    ediff-patch-map)
 
     ;; take the given file name into account
@@ -314,8 +334,8 @@
 		     (ediff-get-session-objA-name session-info)))
 		(if (and (string-match "^/null/" (car proposed-file-names))
 			 (string-match "^/null/" (cdr proposed-file-names)))
-		    ;; couldn't strip base-dir1 and base-dir2
-		    ;; hence, something is wrong
+		    ;; couldn't intuit the file name to patch, so
+		    ;; something is amiss
 		    (progn
 		      (with-output-to-temp-buffer ediff-msg-buffer
 			(ediff-with-current-buffer standard-output
@@ -367,17 +387,29 @@
 		     (f1-exists (file-exists-p file1))
 		     (f2-exists (file-exists-p file2)))
 		(cond
-		 ((and (< (length file2) (length file1))
-		       f2-exists)
+		 ((and
+		   ;; The patch program prefers the shortest file as the patch
+		   ;; target. However, this is a questionable heuristic. In an
+		   ;; interactive program, like ediff, we can offer the user a
+		   ;; choice.
+		   ;; (< (length file2) (length file1))
+		   (not f1-exists)
+		   f2-exists)
 		  ;; replace file-pair with the winning file2
 		  (setcar session-file-object file2))
-		 ((and (< (length file1) (length file2))
-		       f1-exists)
+		 ((and
+		   ;; (< (length file1) (length file2))
+		   (not f2-exists)
+		   f1-exists)
 		  ;; replace file-pair with the winning file1
 		  (setcar session-file-object file1))
 		 ((and f1-exists f2-exists
 		       (string= file1 file2))
 		  (setcar session-file-object file1))
+		 ((and f1-exists f2-exists (eq chosen-alternative 1))
+		  (setcar session-file-object file1))
+		 ((and f1-exists f2-exists (eq chosen-alternative 2))
+		  (setcar session-file-object file2))
 		 ((and f1-exists f2-exists)
 		  (with-output-to-temp-buffer ediff-msg-buffer
 		    (ediff-with-current-buffer standard-output
@@ -393,10 +425,15 @@
     Type `y' to use %s as the target;
     Type `n' to use %s as the target.
 "
-				   file1 file2 file2 file1)))
+				   file1 file2 file1 file2)))
 		  (setcar session-file-object
-			  (if (y-or-n-p (format "Use %s ? " file2))
-			      file2 file1)))
+			  (if (y-or-n-p (format "Use %s ? " file1))
+			      (progn
+				(setq chosen-alternative 1)
+				file1)
+			    (setq chosen-alternative 2)
+			    file2))
+		  )
 		 (f2-exists (setcar session-file-object file2))
 		 (f1-exists (setcar session-file-object file1))
 		 (t
@@ -407,7 +444,7 @@
 		    (if (string= file1 file2)
 			(princ (format "
 	%s
-is the target for this patch.  However, this file does not exist."
+is assumed to be the target for this patch.  However, this file does not exist."
 				       file1))
 		      (princ (format "
 	%s
@@ -441,22 +478,26 @@
 
 ;; prompt for file, get the buffer
 (defun ediff-prompt-for-patch-file ()
-  (let ((dir (cond (ediff-patch-default-directory) ; try patch default dir
-		   (ediff-use-last-dir ediff-last-dir-patch)
+  (let ((dir (cond (ediff-use-last-dir ediff-last-dir-patch)
+		   (ediff-patch-default-directory) ; try patch default dir
 		   (t default-directory)))
-	(coding-system-for-read ediff-coding-system-for-read))
-    (find-file-noselect
-     (read-file-name
-      (format "Patch is in file:%s "
-	      (cond ((and buffer-file-name
-			  (equal (expand-file-name dir)
-				 (file-name-directory buffer-file-name)))
-		     (concat
-		      " (default "
-		      (file-name-nondirectory buffer-file-name)
-		      ")"))
-		    (t "")))
-      dir buffer-file-name 'must-match))
+	(coding-system-for-read ediff-coding-system-for-read)
+	patch-file-name)
+    (setq patch-file-name
+	  (read-file-name
+	   (format "Patch is in file:%s "
+		   (cond ((and buffer-file-name
+			       (equal (expand-file-name dir)
+				      (file-name-directory buffer-file-name)))
+			  (concat
+			   " (default "
+			   (file-name-nondirectory buffer-file-name)
+			   ")"))
+			 (t "")))
+	   dir buffer-file-name 'must-match))
+    (if (file-directory-p patch-file-name)
+	(error "Patch file cannot be a directory: %s" patch-file-name)
+      (find-file-noselect patch-file-name))
     ))
 
 
@@ -647,7 +688,7 @@
     (ediff-maybe-checkout buf-to-patch)
 
     (ediff-with-current-buffer patch-diagnostics
-      (insert-buffer patch-buf)
+      (insert-buffer-substring patch-buf)
       (message "Applying patch ... ")
       ;; fix environment for gnu patch, so it won't make numbered extensions
       (setq backup-style (getenv "VERSION_CONTROL"))
--- a/lisp/ediff-util.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/ediff-util.el	Tue Sep 20 17:47:28 2005 +0000
@@ -367,7 +367,7 @@
 		   (ediff-unique-buffer-name "*ediff-merge" "*")))
 	    (save-excursion
 	      (set-buffer buffer-C)
-	      (insert-buffer buf)
+	      (insert-buffer-substring buf)
 	      (funcall (ediff-with-current-buffer buf major-mode))
 	      (widen) ; merge buffer is always widened
 	      (add-hook 'local-write-file-hooks 'ediff-set-merge-mode nil t)
--- a/lisp/ediff-vers.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/ediff-vers.el	Tue Sep 20 17:47:28 2005 +0000
@@ -299,7 +299,10 @@
 	  ((eq type 'MODIFIED)
 	   (ediff-buffers
 	    (find-file-noselect tmp-file)
-	    (find-file-noselect (cvs-fileinfo->full-path fileinfo))
+	    (if (featurep 'xemacs)
+		;; XEmacs doesn't seem to have cvs-fileinfo->full-name
+		(find-file-noselect (cvs-fileinfo->full-path fileinfo))
+	      (find-file-noselect (cvs-fileinfo->full-name fileinfo)))
 	    nil ; startup-hooks
 	    'ediff-revisions)))
     (if (stringp tmp-file) (delete-file tmp-file))
--- a/lisp/ediff.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/ediff.el	Tue Sep 20 17:47:28 2005 +0000
@@ -7,8 +7,8 @@
 ;; Created: February 2, 1994
 ;; Keywords: comparing, merging, patching, tools, unix
 
-(defconst ediff-version "2.80" "The current version of Ediff")
-(defconst ediff-date "July 8, 2005" "Date of last update")
+(defconst ediff-version "2.80.1" "The current version of Ediff")
+(defconst ediff-date "September 19, 2005" "Date of last update")
 
 
 ;; This file is part of GNU Emacs.
--- a/lisp/emulation/viper-cmd.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/emulation/viper-cmd.el	Tue Sep 20 17:47:28 2005 +0000
@@ -358,7 +358,7 @@
 					  'viper-insertion-ring))
 
 		(if viper-ESC-moves-cursor-back
-		    (or (bolp) (backward-char 1))))
+		    (or (bolp) (viper-beginning-of-field) (backward-char 1))))
 	       ))
 
 	;; insert or replace
@@ -1996,7 +1996,8 @@
 ;;; Minibuffer business
 
 (defsubst viper-set-minibuffer-style ()
-  (add-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel))
+  (add-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel)
+  (add-hook 'post-command-hook 'viper-minibuffer-post-command-hook))
 
 
 (defun viper-minibuffer-setup-sentinel ()
@@ -2039,6 +2040,11 @@
       (minibuffer-prompt-end)
     (point-min)))
 
+(defun viper-minibuffer-post-command-hook()
+  (when (active-minibuffer-window)
+    (when (< (point) (viper-minibuffer-real-start))
+      (goto-char (viper-minibuffer-real-start)))))
+
 
 ;; Interpret last event in the local map first; if fails, use exit-minibuffer.
 ;; Run viper-minibuffer-exit-hook before exiting.
@@ -2570,7 +2576,7 @@
     ;; last line of buffer when this line has no \n.
     (viper-add-newline-at-eob-if-necessary)
     (viper-execute-com 'viper-line val com))
-  (if (and (eobp) (not (bobp))) (forward-line -1))
+  (if (and (eobp) (bolp) (not (bobp))) (forward-line -1))
   )
 
 (defun viper-yank-line (arg)
--- a/lisp/emulation/viper-init.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/emulation/viper-init.el	Tue Sep 20 17:47:28 2005 +0000
@@ -115,6 +115,11 @@
 
 ;;; Macros
 
+;; Fool the compiler to avoid warnings.
+;; Viper calls make-variable-buffer-local from within other functions, which
+;; triggers compiler warnings.
+(defalias 'viper-make-variable-buffer-local 'make-variable-buffer-local)
+
 (defmacro viper-deflocalvar (var default-value &optional documentation)
   `(progn
     (defvar ,var ,default-value
--- a/lisp/emulation/viper-macs.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/emulation/viper-macs.el	Tue Sep 20 17:47:28 2005 +0000
@@ -118,7 +118,7 @@
       (define-key viper-vi-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro)
       (define-key viper-insert-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro)
       (define-key viper-emacs-intercept-map "\C-x)" 'viper-end-mapping-kbd-macro)
-      (message "Mapping %S in %s state.  Hit `C-x )' to complete the mapping"
+      (message "Mapping %S in %s state.  Type macro definition followed by `C-x )'"
 	       (viper-display-macro macro-name)
 	       (if ins "Insert" "Vi")))
     ))
@@ -170,7 +170,7 @@
 	      ((stringp macro-name)
 	       (setq macro-name (vconcat macro-name)))
 	      (t (setq macro-name (vconcat (prin1-to-string macro-name)))))
-      (message ":map%s <Name>" variant)(sit-for 2)
+      (message ":map%s <Macro Name>" variant)(sit-for 2)
       (while
 	  (not (member key
 		       '(?\C-m ?\n (control m) (control j) return linefeed)))
@@ -442,10 +442,6 @@
 		       scope)
 	       viper-custom-file-name))
 
-	  ;; 2005-09-18 T06:41:22-0400 (Sunday)    D. Goel
-	  ;; From careful parsing of the above code, it looks like msg
-	  ;; couldn't be nil when we reach here. Since it is a string,
-	  ;; and a complicated one too, we might as well provide it a "%s"
 	  (message "%s" msg)
 	  ))
 
--- a/lisp/emulation/viper-util.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/emulation/viper-util.el	Tue Sep 20 17:47:28 2005 +0000
@@ -1405,6 +1405,7 @@
 		       viper-SEP-char-class
 		       (or within-line "\n")
 		       (if within-line (viper-line-pos 'end)))))
+
 (defsubst viper-skip-all-separators-backward (&optional within-line)
   (if (eq viper-syntax-preference 'strict-vi)
       (if within-line
@@ -1433,6 +1434,7 @@
      ;; Emacs may consider some of these as words, but we don't want them
      viper-non-word-characters
      (viper-line-pos 'end))))
+
 (defun viper-skip-nonalphasep-backward ()
   (if (eq viper-syntax-preference 'strict-vi)
       (skip-chars-backward
@@ -1502,6 +1504,12 @@
     total
     ))
 
+;; tells when point is at the beginning of field
+(defun viper-beginning-of-field ()
+  (or (bobp)
+      (not (eq (get-char-property (point) 'field)
+	       (get-char-property (1- (point)) 'field)))))
+
 
 ;; this is copied from cl-extra.el
 ;; Return the subsequence of SEQ from START to END.
--- a/lisp/emulation/viper.el	Tue Sep 20 13:19:29 2005 +0000
+++ b/lisp/emulation/viper.el	Tue Sep 20 17:47:28 2005 +0000
@@ -9,7 +9,7 @@
 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
 ;; Keywords: emulations
 
-(defconst viper-version "3.11.5 of August 6, 2005"
+(defconst viper-version "3.11.5 of September 19, 2005"
   "The current version of Viper")
 
 ;; This file is part of GNU Emacs.
@@ -606,7 +606,7 @@
 	      (viper-set-expert-level 'dont-change-unless)))
 
 	(if viper-xemacs-p
-	    (make-variable-buffer-local 'bar-cursor))
+	    (viper-make-variable-buffer-local 'bar-cursor))
 	(if (eq major-mode 'viper-mode)
 	    (setq major-mode 'fundamental-mode))
 
@@ -769,6 +769,7 @@
   (remove-hook 'comint-mode-hook 'viper-comint-mode-hook)
   (remove-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel)
   (remove-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
+  (remove-hook 'post-command-hook 'viper-minibuffer-post-command-hook)
 
   ;; unbind Viper mouse bindings
   (viper-unbind-mouse-search-key)
@@ -1008,7 +1009,7 @@
   ;; ***This is needed only in case emulation-mode-map-alists is not defined
   (unless
       (and (fboundp 'add-to-ordered-list) (boundp 'emulation-mode-map-alists))
-    (make-variable-buffer-local 'minor-mode-map-alist))
+    (viper-make-variable-buffer-local 'minor-mode-map-alist))
 
   ;; Viper changes the default mode-line-buffer-identification
   (setq-default mode-line-buffer-identification '(" %b"))
@@ -1017,7 +1018,7 @@
   (setq next-line-add-newlines nil
 	require-final-newline t)
 
-  (make-variable-buffer-local 'require-final-newline)
+  (viper-make-variable-buffer-local 'require-final-newline)
 
   ;; don't bark when mark is inactive
   (if viper-emacs-p