Commits

michaelk  committed 82d096c

Wed Oct 14 03:22:47 1998 Michael Kifer <kifer@cs.sunysb.edu>

* viper-keym.el: Fixed calls to viper-ex.

* viper-util.el (viper-nontrivial-find-file-function): deleted.
(viper-glob-unix-files, viper-glob-mswindows-files): new functions.

* viper-ex.el (ex-read,ex-edit):
fixes for correct interpretation of #,%.
(viper-ex): now works correctly when called from other functions.
(viper-glob-function): new variable.

* viper-mous.el (viper-counting-clicks-p): bug fixes.

* viper-cmd.el (viper-replace-mode-spy-after):
include hippie-expand in the list of
exceptions.
(viper-put-back, viper-Put-back, viper-exec-Delete,
viper-exec-delete): issue message only if changes are larger than
viper-change-notification-threshold.
(viper-skip-separators, viper-switch-to-buffer,
viper-switch-to-buffer-other-window): bug fixes.
(viper-backward-Word, viper-skip-separators,
viper-switch-to-buffer, viper-switch-to-buffer-other-window): bug
fixes.

* viper.el, viper-util.el, viper-macs.el, viper-keym.el,
viper-ex.el, viper-cmd.el: Removed function quotes around lambdas.

* viper-init.el (viper-change-notification-threshold): new variable.

* viper-cmd.el (viper-backward-Word): bug fix.

* viper-util.el (viper-skip-syntax): bug fix for eob/bob cases.
(viper-skip-syntax): bug fix for eob/bob cases.

* viper-mous.el (viper-surrounding-word): added '_' to alpha modifiers.

  • Participants
  • Parent commits de62a54

Comments (0)

Files changed (12)

+Fri Oct  2 00:22:47 1998  Michael Kifer  <kifer@cs.sunysb.edu> 
+ 
+        * viper-keym.el: Fixed calls to viper-ex. 
+ 
+        * viper-util.el (viper-nontrivial-find-file-function): deleted. 
+        (viper-glob-unix-files, viper-glob-mswindows-files): new functions. 
+ 
+        * viper-ex.el (ex-read,ex-edit): 
+        fixes for correct interpretation of #,%. 
+        (viper-ex): now works correctly when called from other functions. 
+        (viper-glob-function): new variable. 
+ 
+        * viper-mous.el (viper-counting-clicks-p): bug fixes. 
+
+1998-07-18  Michael Kifer  <kifer@cs.sunysb.edu>
+
+	* viper-cmd.el (viper-replace-mode-spy-after):
+	include hippie-expand in the list of
+	exceptions.
+	(viper-put-back, viper-Put-back, viper-exec-Delete,
+	viper-exec-delete): issue message only if changes are larger than
+	viper-change-notification-threshold. 
+	(viper-skip-separators, viper-switch-to-buffer,
+	viper-switch-to-buffer-other-window): bug fixes.
+	(viper-backward-Word, viper-skip-separators,
+	viper-switch-to-buffer, viper-switch-to-buffer-other-window): bug
+	fixes.
+
+	* viper.el, viper-util.el, viper-macs.el, viper-keym.el,
+	viper-ex.el, viper-cmd.el: Removed function quotes around lambdas.
+
+	* viper-init.el (viper-change-notification-threshold): new variable.
+
+	* viper-cmd.el (viper-backward-Word): bug fix.
+
+	* viper-util.el (viper-skip-syntax): bug fix for eob/bob cases.
+	(viper-skip-syntax): bug fix for eob/bob cases.
+
+	* viper-mous.el (viper-surrounding-word): added '_' to alpha modifiers.
+
+
 1998-02-25  SL Baur  <steve@altair.xemacs.org>
 
 	* viper.texi: Add direntry section (so installation can
 # Boston, MA 02111-1307, USA.
 
 VERSION = 1.10
-AUTHOR_VERSION = 3.03
+AUTHOR_VERSION = 3.05
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = viper
 PKG_TYPE = regular
-REQUIRES = xemacs-base
+REQUIRES = advice cl ring xemacs-base
 CATEGORY = wp
 
 ELCS = viper-cmd.elc viper-ex.elc viper-init.elc viper-keym.elc \
-**** Viper requires Emacs 19.23 or later.
 
 This directory:
 
    You also need to have a write permission for all directories
    mentioned in LISPDIR, INFODIR, and ETCDIR.
    
-6. XEmacs users must invoke make with the parameter EMACS=xemacs
-   or whatever name is used to invoke XEmacs (some backward sites
-   still use xemacs for Emacs 18). An even better thing would be to
-   edit Makefile directly as indicated in the comments there.
+6. XEmacs users must invoke make with the parameter EMACS=xemacs.
+   Even better: edit Makefile directly as indicated in the comments there.
 

File viper-cmd.el

 (defconst viper-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l
 				     ?H ?M ?L ?n ?t ?T ?w ?W ?$ ?%
 				     ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?`
-				     ?; ?, ?0 ?? ?/ ?\C-m ?\ 
+				     ?\; ?, ?0 ?? ?/ ?\  ?\C-m
 				     space return
 				     delete backspace
 				     )
 	(if (stringp viper-saved-cursor-color)
 	    (viper-change-cursor-color viper-insert-state-cursor-color))
 	))
-  (if (and (eq this-command 'dabbrev-expand)
+  (if (and (memq this-command '(dabbrev-expand hippie-expand))
 	   (integerp viper-pre-command-point)
 	   (markerp viper-insert-point)
 	   (marker-position viper-insert-point)
 	    '(up down left right (meta f) (meta b)
 		 (control n) (control p) (control f) (control b)))
       (viper-restore-cursor-color-after-insert))
-  (if (and (eq this-command 'dabbrev-expand)
+  (if (and (memq this-command '(dabbrev-expand hippie-expand))
 	   (markerp viper-insert-point)
 	   (marker-position viper-insert-point))
       (setq viper-pre-command-point (marker-position viper-insert-point))))
   ;; in another frame, the pre-command hook won't change cursor color to
   ;; default in that other frame.  So, if the second frame cursor was red and
   ;; we set the point outside the replacement region, then the cursor color
-  ;; will remain red. Restoring the default, below, prevents this.
+  ;; will remain red.  Restoring the default, below, prevents this.
   (if (and (<= (viper-replace-start) (point))
 	   (<=  (point) (viper-replace-end)))
       (viper-change-cursor-color viper-replace-overlay-cursor-color)
   ;; in another frame, the pre-command hook won't change cursor color to
   ;; default in that other frame.  So, if the second frame cursor was red and
   ;; we set the point outside the replacement region, then the cursor color
-  ;; will remain red. Restoring the default, below, fixes this problem.
+  ;; will remain red.  Restoring the default, below, fixes this problem.
   ;;
   ;; We optimize for self-insert-command's here, since they either don't change
   ;; cursor color or, if they terminate replace mode, the color will be changed
 		    
 		;; move viper-last-posn-while-in-insert-state
 		;; This is a normal hook that is executed in insert/replace
-		;; states after each command. In Vi/Emacs state, it does
-		;; nothing. We need to execute it here to make sure that
+		;; states after each command.  In Vi/Emacs state, it does
+		;; nothing.  We need to execute it here to make sure that
 		;; the last posn was recorded when we hit ESC.
 		;; It may be left unrecorded if the last thing done in
 		;; insert/repl state was dabbrev-expansion or abbrev
       (string= (viper-get-cursor-color) viper-insert-state-cursor-color)
       (setq viper-saved-cursor-color (viper-get-cursor-color)))
   ;; Commented out, because if viper-change-state-to-insert is executed
-  ;; non-interactively then the old cursor color may get lost. Same old Emacs
+  ;; non-interactively then the old cursor color may get lost.  Same old Emacs
   ;; bug related to local variables?
 ;;;(if (stringp viper-saved-cursor-color)
 ;;;      (viper-change-cursor-color viper-insert-state-cursor-color))
 
     
   
-;; Change to replace state. When the end of replacement region is reached,
+;; Change to replace state.  When the end of replacement region is reached,
 ;; replace state changes to insert state.
 (defun viper-change-state-to-replace (&optional non-R-cmd)
   (viper-change-state 'replace-state)
 (defun viper-escape-to-vi (arg)
   "Escape from Emacs state to Vi state for one Vi 1-character command.
 If the Vi command that the user types has a prefix argument, e.g., `d2w', then
-Vi's prefix argument will be used. Otherwise, the prefix argument passed to
+Vi's prefix argument will be used.  Otherwise, the prefix argument passed to
 `viper-escape-to-vi' is used."
   (interactive "P")
   (message "Switched to VI state for the next command...")
 		(while (vectorp com) (setq com (key-binding com))))
 	    nil)
 	  ;; Execute command com in the original Viper state, not in state
-	  ;; `state'. Otherwise, if we switch buffers while executing the
+	  ;; `state'.  Otherwise, if we switch buffers while executing the
 	  ;; escaped to command, Viper's mode vars will remain those of
-	  ;; `state'. When we return to the orig buffer, the bindings will be
+	  ;; `state'.  When we return to the orig buffer, the bindings will be
 	  ;; screwed up.
 	  (viper-set-mode-vars-for viper-current-state)
 	  
 
   
 ;; This is needed because minor modes sometimes override essential Viper
-;; bindings. By letting Viper know which files these modes are in, it will
+;; bindings.  By letting Viper know which files these modes are in, it will
 ;; arrange to reorganize minor-mode-map-alist so that things will work right.
 (defun viper-harness-minor-mode (load-file)
   "Familiarize Viper with a minor mode defined in LOAD_FILE.
 Prevents multiple escape keystrokes if viper-no-multiple-ESC is true.
 If viper-no-multiple-ESC is 'twice double ESC would ding in vi-state.
 Other ESC sequences are emulated via the current Emacs's major mode
-keymap. This is more convenient on TTYs, since this won't block
-function keys such as up,down, etc. ESC will also will also work as
-a Meta key in this case. When viper-no-multiple-ESC is nil, ESC functions
+keymap.  This is more convenient on TTYs, since this won't block
+function keys such as up,down, etc.  ESC will also will also work as
+a Meta key in this case.  When viper-no-multiple-ESC is nil, ESC functions
 as a Meta key and any number of multiple escapes is allowed."
   (interactive "P")
   (let (char)
 		;;
 		;; If `first-key' is not an ESC event, we make it into the
 		;; last-command-event in order to pretend that this key was
-		;; pressed. This is needed to allow arrow keys to be bound to
-		;; macros. Otherwise, viper-exec-mapped-kbd-macro will think
+		;; pressed.  This is needed to allow arrow keys to be bound to
+		;; macros.  Otherwise, viper-exec-mapped-kbd-macro will think
 		;; that the last event was ESC and so it'll execute whatever is
 		;; bound to ESC. (Viper macros can't be bound to
 		;; ESC-sequences).
 
 
 ;; Compute numeric prefix arg value. 
-;; Invoked by EVENT. COM is the command part obtained so far.
+;; Invoked by EVENT.  COM is the command part obtained so far.
 (defun viper-prefix-arg-value (event-char com)
   (let ((viper-intermediate-command 'viper-digit-argument)
 	value func)
 	;; confuse subsequent commands
 	(progn
 	  ;; last-command-char is the char we want emacs to think was typed
-	  ;; last. If com is not nil, the viper-digit-argument command was
+	  ;; last.  If com is not nil, the viper-digit-argument command was
 	  ;; called from within viper-prefix-arg command, such as `d', `w',
-	  ;; etc., i.e., the user typed, say, d2. In this case, `com' would be
+	  ;; etc., i.e., the user typed, say, d2.  In this case, `com' would be
 	  ;; `d', `w', etc.  If viper-digit-argument was invoked by
 	  ;; viper-escape-to-vi (which is indicated by the fact that the
 	  ;; current state is not vi-state), then `event-char' represents the
-	  ;; vi command to be executed (e.g., `d', `w', etc). Again,
+	  ;; vi command to be executed (e.g., `d', `w', etc).  Again,
 	  ;; last-command-char must make emacs believe that this is the command
 	  ;; we typed.
 	  (cond ((eq event-char 'return) (setq event-char ?\C-m))
       (setq prefix-arg nil)
       (cond 
        ;; If we change ?C to ?c here, then cc will enter replacement mode
-       ;; rather than deleting lines. However, it will affect 1 less line than
-       ;; normal. We decided to not use replacement mode here and follow Vi,
+       ;; rather than deleting lines.  However, it will affect 1 less line than
+       ;; normal.  We decided to not use replacement mode here and follow Vi,
        ;; since replacement mode on n full lines can be achieved with nC.
        ((equal com '(?c . ?c)) (viper-line (cons value ?C)))
        ((equal com '(?d . ?d)) (viper-line (cons value ?D)))
 (defun viper-exec-delete (m-com com)
   (or (and (markerp viper-com-point) (marker-position viper-com-point))
       (set-marker viper-com-point (point) (current-buffer)))
-  (if viper-use-register
-      (progn
-	(cond ((viper-valid-register viper-use-register '(letter digit))
-	       (copy-to-register
-		viper-use-register viper-com-point (point) nil))
-	      ((viper-valid-register viper-use-register '(Letter))
-	       (viper-append-to-register
-		(downcase viper-use-register) viper-com-point (point)))
-	      (t (setq viper-use-register nil)
+  (let (chars-deleted)
+    (if viper-use-register
+	(progn
+	  (cond ((viper-valid-register viper-use-register '(letter digit))
+		 (copy-to-register
+		  viper-use-register viper-com-point (point) nil))
+		((viper-valid-register viper-use-register '(Letter))
+		 (viper-append-to-register
+		  (downcase viper-use-register) viper-com-point (point)))
+		(t (setq viper-use-register nil)
 		 (error viper-InvalidRegister viper-use-register)))
-	(setq viper-use-register nil)))
-  (setq last-command
-	(if (eq last-command 'd-command) 'kill-region nil))
-  (message "Deleted %d characters" (abs (- (point) viper-com-point)))
-  (kill-region viper-com-point (point))
-  (setq this-command 'd-command)
-  (if viper-ex-style-motion
-      (if (and (eolp) (not (bolp))) (backward-char 1))))
+	  (setq viper-use-register nil)))
+    (setq last-command
+	  (if (eq last-command 'd-command) 'kill-region nil))
+    (setq chars-deleted (abs (- (point) viper-com-point)))
+    (if (> chars-deleted viper-change-notification-threshold)
+	(message "Deleted %d characters" chars-deleted))
+    (kill-region viper-com-point (point))
+    (setq this-command 'd-command)
+    (if viper-ex-style-motion
+	(if (and (eolp) (not (bolp))) (backward-char 1)))))
 
 (defun viper-exec-Delete (m-com com)
   (save-excursion
     (set-mark viper-com-point)
     (viper-enlarge-region (mark t) (point))
+    (let (lines-deleted)
+      (if viper-use-register
+	  (progn
+	    (cond ((viper-valid-register viper-use-register '(letter digit))
+		   (copy-to-register
+		    viper-use-register (mark t) (point) nil))
+		  ((viper-valid-register viper-use-register '(Letter))
+		   (viper-append-to-register
+		    (downcase viper-use-register) (mark t) (point)))
+		  (t (setq viper-use-register nil)
+		     (error viper-InvalidRegister viper-use-register)))
+	    (setq viper-use-register nil)))
+      (setq last-command
+	    (if (eq last-command 'D-command) 'kill-region nil))
+      (setq lines-deleted (count-lines (point) viper-com-point))
+      (if (> lines-deleted viper-change-notification-threshold)
+	  (message "Deleted %d lines" lines-deleted))
+      (kill-region (mark t) (point))
+      (if (eq m-com 'viper-line) (setq this-command 'D-command)))
+    (back-to-indentation)))
+
+;; save region
+(defun viper-exec-yank (m-com com)
+  (or (and (markerp viper-com-point) (marker-position viper-com-point))
+      (set-marker viper-com-point (point) (current-buffer)))
+  (let (chars-saved)
     (if viper-use-register
 	(progn
 	  (cond ((viper-valid-register viper-use-register '(letter digit))
 		 (copy-to-register
-		  viper-use-register (mark t) (point) nil))
+		  viper-use-register viper-com-point (point) nil))
 		((viper-valid-register viper-use-register '(Letter))
 		 (viper-append-to-register
-		  (downcase viper-use-register) (mark t) (point)))
+		  (downcase viper-use-register) viper-com-point (point)))
 		(t (setq viper-use-register nil)
 		   (error viper-InvalidRegister viper-use-register)))
 	  (setq viper-use-register nil)))
-    (setq last-command
-	  (if (eq last-command 'D-command) 'kill-region nil))
-    (message "Deleted %d lines" (count-lines (point) viper-com-point))
-    (kill-region (mark t) (point))
-    (if (eq m-com 'viper-line) (setq this-command 'D-command)))
-  (back-to-indentation))
-
-;; save region
-(defun viper-exec-yank (m-com com)
-  (or (and (markerp viper-com-point) (marker-position viper-com-point))
-      (set-marker viper-com-point (point) (current-buffer)))
-  (if viper-use-register
-      (progn
-	(cond ((viper-valid-register viper-use-register '(letter digit))
-	       (copy-to-register
-		viper-use-register viper-com-point (point) nil))
-	      ((viper-valid-register viper-use-register '(Letter))
-	       (viper-append-to-register
-		(downcase viper-use-register) viper-com-point (point)))
-	      (t (setq viper-use-register nil)
-		 (error viper-InvalidRegister viper-use-register)))
-	(setq viper-use-register nil)))
-  (setq last-command nil)
-  (copy-region-as-kill viper-com-point (point))
-  (message "Saved %d characters" (abs (- (point) viper-com-point)))
-  (goto-char viper-com-point))
+    (setq last-command nil)
+    (copy-region-as-kill viper-com-point (point))
+    (setq chars-saved (abs (- (point) viper-com-point)))
+    (if (> chars-saved viper-change-notification-threshold)
+	(message "Saved %d characters" chars-saved))
+    (goto-char viper-com-point)))
 
 ;; save lines
 (defun viper-exec-Yank (m-com com)
   (save-excursion
     (set-mark viper-com-point)
     (viper-enlarge-region (mark t) (point))
-    (if viper-use-register
-	(progn
-	  (cond ((viper-valid-register viper-use-register '(letter digit))
-		 (copy-to-register
-		  viper-use-register (mark t) (point) nil))
-		((viper-valid-register viper-use-register '(Letter))
-		 (viper-append-to-register
-		  (downcase viper-use-register) (mark t) (point)))
-		(t (setq viper-use-register nil)
-		   (error viper-InvalidRegister  viper-use-register)))
-	  (setq viper-use-register nil)))
-    (setq last-command nil)
-    (copy-region-as-kill (mark t) (point))
-    (message "Saved %d lines" (count-lines (mark t) (point))))
+    (let (lines-saved)
+      (if viper-use-register
+	  (progn
+	    (cond ((viper-valid-register viper-use-register '(letter digit))
+		   (copy-to-register
+		    viper-use-register (mark t) (point) nil))
+		  ((viper-valid-register viper-use-register '(Letter))
+		   (viper-append-to-register
+		    (downcase viper-use-register) (mark t) (point)))
+		  (t (setq viper-use-register nil)
+		     (error viper-InvalidRegister  viper-use-register)))
+	    (setq viper-use-register nil)))
+      (setq last-command nil)
+      (copy-region-as-kill (mark t) (point))
+      (setq lines-saved (count-lines (mark t) (point)))
+      (if (> lines-saved viper-change-notification-threshold)
+	  (message "Saved %d lines" lines-saved))))
   (viper-deactivate-mark)
   (goto-char viper-com-point))
 
 (defvar viper-exec-array (make-vector 128 nil))
 
 ;; Using a dispatch array allows adding functions like buffer search
-;; without affecting other functions. Buffer search can now be bound
+;; without affecting other functions.  Buffer search can now be bound
 ;; to any character.
 
 (aset viper-exec-array ?c 'viper-exec-change)
 
 
 ;; This function is called by various movement commands to execute a
-;; destructive command on the region specified by the movement command. For
+;; destructive command on the region specified by the movement command.  For
 ;; instance, if the user types cw, then the command viper-forward-word will
 ;; call viper-execute-com to execute viper-exec-change, which eventually will
 ;; call viper-change to invoke the replace mode on the region.
      ))
   (viper-adjust-undo) ; take care of undo
   ;; If the prev cmd was rotating the command ring, this means that `.' has
-  ;; just executed a command from that ring. So, push it on the ring again.
+  ;; just executed a command from that ring.  So, push it on the ring again.
   ;; If we are just executing previous command , then don't push viper-d-com
   ;; because viper-d-com is not fully constructed in this case (its keys and
-  ;; the inserted text may be nil). Besides, in this case, the command
+  ;; the inserted text may be nil).  Besides, in this case, the command
   ;; executed by `.' is already on the ring.
   (if (eq last-command 'viper-display-current-destructive-command)
       (viper-push-onto-ring viper-d-com 'viper-command-ring))
 Doesn't change viper-command-ring in any way, so `.' will work as before
 executing this command.
 This command is supposed to be bound to a two-character Vi macro where
-the second character is a digit 0 to 9. The digit indicates which
+the second character is a digit 0 to 9.  The digit indicates which
 history command to execute. `<char>0' is equivalent to `.', `<char>1'
 invokes the command before that, etc."
   (interactive)
     ))
       
 
-;; The hash-command. It is invoked interactively by the key sequence #<char>.
+;; The hash-command.  It is invoked interactively by the key sequence #<char>.
 ;; The chars that can follow `#' are determined by viper-hash-command-p
 (defun viper-special-prefix-com (char)
   (cond ((= char ?c)
   '("" "tex" "c" "cc" "C" "el" "java" "html" "htm" "pl" "P" "p")
   "*List of suffixes that Viper tries to append to filenames ending with a `.'.
 This is useful when you the current directory contains files with the same
-prefix and many different suffixes. Usually, only one of the suffixes
-represents an editable file. However, file completion will stop at the `.'
+prefix and many different suffixes.  Usually, only one of the suffixes
+represents an editable file.  However, file completion will stop at the `.'
 The smart suffix feature lets you hit RET in such a case, and Viper will
 select the appropriate suffix.
 
 Suffixes are tried in the order given and the first suffix for which a
-corresponding file exists is selected. If no file exists for any of the
+corresponding file exists is selected.  If no file exists for any of the
 suffixes, the user is asked to confirm.
 
 To turn this feature off, set this variable to nil."
 					      history-var default keymap
 					      init-message)
   ;; Read string, prompting with PROMPT and inserting the INITIAL
-  ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
+  ;; value.  Uses HISTORY-VAR.  DEFAULT is the default value to accept if the
   ;; input is an empty string.
   ;; Default value is displayed until the user types something in the
   ;; minibuffer. 
   ;; INIT-MESSAGE is the message temporarily displayed after entering the
   ;; minibuffer.
   (let ((minibuffer-setup-hook 
-	 (function
-	  (lambda ()
-	    (if (stringp init-message)
-		(viper-tmp-insert-at-eob init-message))
-	    (if (stringp initial)
-		(progn
-		  ;; don't wait if we have unread events or in kbd macro
-		  (or unread-command-events
-		      executing-kbd-macro
-		      (sit-for 840))
-		  (erase-buffer)
-		  (insert initial)))
-	    (viper-minibuffer-setup-sentinel))))
+	 (lambda ()
+	   (if (stringp init-message)
+	       (viper-tmp-insert-at-eob init-message))
+	   (if (stringp initial)
+	       (progn
+		 ;; don't wait if we have unread events or in kbd macro
+		 (or unread-command-events
+		     executing-kbd-macro
+		     (sit-for 840))
+		 (erase-buffer)
+		 (insert initial)))
+	   (viper-minibuffer-setup-sentinel)))
 	(val "")
 	(padding "")
 	temp-msg)
 	(set history-var (cdr (eval history-var))))
     ;; If the user enters nothing but the prev cmd wasn't viper-ex,
     ;; viper-command-argument, or `! shell-command', this probably means 
-    ;; that the user typed something then erased. Return "" in this case, not
+    ;; that the user typed something then erased.  Return "" in this case, not
     ;; the default---the default is too confusing in this case.
     (cond ((and (string= val "")
 		(not (string= prompt "!")) ; was a `! shell-command'
   )
 
 ;; Invoked as an after-change-function to calculate how many chars have to be
-;; deleted. This function may be called several times within a single command,
-;; if this command performs several separate buffer changes. Therefore, if adds
-;; up the number of chars inserted and subtracts the number of chars deleted.
+;; deleted.  This function may be called several times within a single command,
+;; if this command performs several separate buffer changes.  Therefore, if
+;; adds up the number of chars inserted and subtracts the number of chars
+;; deleted. 
 (defun viper-replace-mode-spy-after (beg end length)
   (if (memq viper-intermediate-command 
-	    '(dabbrev-expand repeating-insertion-from-ring))
+	    '(dabbrev-expand hippie-expand repeating-insertion-from-ring))
       ;; Take special care of text insertion from insertion ring inside
       ;; replacement overlays.
       (progn
 		;; column-shift instead of the number of inserted chars
 		(max (viper-chars-in-region beg real-end)
 		     ;; This test accounts for Chinese/Japanese/...  chars,
-		     ;; which occupy 2 columns instead of one. If we use
+		     ;; which occupy 2 columns instead of one.  If we use
 		     ;; column-shift here, we may delete two chars instead of
-		     ;; one when the user types one Chinese character. Deleting
-		     ;; two would be OK, if they were European chars, but it is
-		     ;; not OK if they are Chinese chars. Since it is hard to
+		     ;; one when the user types one Chinese character.
+		     ;; Deleting two would be OK, if they were European chars,
+		     ;; but it is not OK if they are Chinese chars.
+		     ;; Since it is hard to
 		     ;; figure out which characters are being deleted in any
 		     ;; given region, we decided to treat Eastern and European
 		     ;; characters equally, even though Eastern chars may
   (interactive)
   ;; If Emacs start supporting overlay maps, as it currently supports
   ;; text-property maps, we could do away with viper-replace-minor-mode and
-  ;; just have keymap attached to replace overlay. Then the "if part" of this
+  ;; just have keymap attached to replace overlay.  Then the "if part" of this
   ;; statement can be deleted.
   (if (or (< (point) (viper-replace-start))
 	  (> (point) (viper-replace-end)))
     (viper-move-marker-locally 'viper-com-point (point))
     (if (not (eobp))
 	(viper-next-line-carefully (1- val)))
-    ;; this ensures that dd, cc, D, yy will do the right thing on the last
-    ;; line of buffer when this line has no \n.
+    ;; the following ensures that dd, cc, D, yy will do the right thing on the
+    ;; 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))
 ;;; Word command
 
 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators for
-;; word movement. When executed with a destructive command, \n is usually left
+;; word movement.  When executed with a destructive command, \n is usually left
 ;; untouched for the last word.  Viper uses syntax table to determine what is a
-;; word and what is a separator. However, \n is always a separator. Also, if
+;; word and what is a separator.  However, \n is always a separator.  Also, if
 ;; viper-syntax-preference is 'vi, then `_' is part of the word.
 
 ;; skip only one \n
 	    (progn
 	      (forward-char)
 	      (viper-skip-all-separators-forward  'within-line))))
-    ;; check for eob and white space before it. move off of eob
+    ;; check for eob and white space before it.  move off of eob
     (if (and (eobp) (save-excursion
 		      (viper-backward-char-carefully)
 		      (viper-looking-at-separator)))
 	   (viper-skip-separators t)))
     (setq val (1- val))))
 
-;; first skip non-newline separators backward, then skip \n. Then, if TWICE is
+;; first skip non-newline separators backward, then skip \n.  Then, if TWICE is
 ;; non-nil, skip non-\n back again, but don't overshoot the limit LIM.
 (defun viper-separator-skipback-special (twice lim)
   (let ((prev-char (viper-char-at-pos 'backward))
 
 ;; If point is within viper-search-scroll-threshold of window top or bottom,
 ;; scroll up or down 1/7 of window height, depending on whether we are at the
-;; bottom or at the top of the  window. This function is called by viper-search
-;; (which is called from viper-search-forward/backward/next). If the value of
+;; bottom or at the top of the  window.  This function is called by viper-search
+;; (which is called from viper-search-forward/backward/next).  If the value of
 ;; viper-search-scroll-threshold is negative - don't scroll.
 (defun viper-adjust-window ()
   (let ((win-height (if viper-emacs-p
 
 
 ;; paren match
-;; must correct this to only match ( to ) etc. On the other hand
+;; must correct this to only match ( to ) etc.  On the other hand
 ;; it is good that paren match gets confused, because that way you
 ;; catch _all_ imbalances. 
 
     
 (defun viper-toggle-search-style (arg) 
   "Toggle the value of viper-case-fold-search/viper-re-search.
-Without prefix argument, will ask which search style to toggle. With prefix
+Without prefix argument, will ask which search style to toggle.  With prefix
 arg 1,toggles viper-case-fold-search; with arg 2 toggles viper-re-search.
 
 Although this function is bound to \\[viper-toggle-search-style], the most
 convenient way to use it is to bind `//' to the macro
 `1 M-x viper-toggle-search-style' and `///' to
-`2 M-x viper-toggle-search-style'. In this way, hitting `//' quickly will
+`2 M-x viper-toggle-search-style'.  In this way, hitting `//' quickly will
 toggle case-fold-search and hitting `/' three times witth toggle regexp
-search. Macros are more convenient in this case because they don't affect
+search.  Macros are more convenient in this case because they don't affect
 the Emacs binding of `/'."
   (interactive "P")
   (let (msg)
     (cond ((or (eq arg 1)
 	       (and (null arg)
-		    (y-or-n-p (format "Search style: '%s'. Want '%s'? "
+		    (y-or-n-p (format "Search style: '%s'.  Want '%s'? "
 				      (if viper-case-fold-search
 					  "case-insensitive" "case-sensitive")
 				      (if viper-case-fold-search
 	     (setq msg "Search becomes case-sensitive")))
 	  ((or (eq arg 2)
 	       (and (null arg)
-		    (y-or-n-p (format "Search style: '%s'. Want '%s'? "
+		    (y-or-n-p (format "Search style: '%s'.  Want '%s'? "
 				      (if viper-re-search
 					  "regexp-search" "vanilla-search")
 				      (if viper-re-search
 toggles regexp search is bound to `///'.
 With a prefix argument, this function unsets the macros. 
 If the optional prefix argument is non-nil and specifies a valid major mode,
-this sets the macros only in the macros in that major mode. Otherwise,
+this sets the macros only in the macros in that major mode.  Otherwise,
 the macros are set in the current major mode.
 \(When unsetting the macros, the second argument has no effect.\)"
   (interactive "P")
 ;; yank and pop
 
 (defsubst viper-yank (text)
-  "Yank TEXT silently. This works correctly with Emacs's yank-pop command."
+  "Yank TEXT silently.  This works correctly with Emacs's yank-pop command."
     (insert text)
     (setq this-command 'yank))
 
 			 (get-register (downcase viper-use-register)))
 			(t (error viper-InvalidRegister viper-use-register)))
 		(current-kill 0)))
-	sv-point)
+	sv-point chars-inserted lines-inserted)
     (if (null text)
 	(if viper-use-register
 	    (let ((reg viper-use-register))
      (list 'viper-put-back val nil viper-use-register nil nil))
     (setq sv-point (point))
     (viper-loop val (viper-yank text))
-    (message "Inserted %d character(s), %d line(s)"
-	     (abs (- (point) sv-point)) 
-	     (abs (count-lines (point) sv-point))))
+    (setq chars-inserted (abs (- (point) sv-point))
+	  lines-inserted (abs (count-lines (point) sv-point)))
+    (if (or (> chars-inserted viper-change-notification-threshold)
+	    (> lines-inserted viper-change-notification-threshold))
+	(message "Inserted %d character(s), %d line(s)"
+		 chars-inserted lines-inserted)))
   ;; Vi puts cursor on the last char when the yanked text doesn't contain a
   ;; newline; it leaves the cursor at the beginning when the text contains 
   ;; a newline
 			((viper-valid-register viper-use-register)
 			 (get-register (downcase viper-use-register)))
 			(t (error viper-InvalidRegister viper-use-register)))
-		(current-kill 0))))
+		(current-kill 0)))
+	sv-point chars-inserted lines-inserted)
     (if (null text)
 	(if viper-use-register
 	    (let ((reg viper-use-register))
     (viper-set-destructive-command
      (list 'viper-Put-back val nil viper-use-register nil nil))
     (set-marker (viper-mark-marker) (point) (current-buffer))
-    (viper-loop val (viper-yank text)))
+    (setq sv-point (point))
+    (viper-loop val (viper-yank text))
+    (setq chars-inserted (abs (- (point) sv-point))
+	  lines-inserted (abs (count-lines (point) sv-point)))
+    (if (or (> chars-inserted viper-change-notification-threshold)
+	    (> lines-inserted viper-change-notification-threshold))
+	(message "Inserted %d character(s), %d line(s)"
+		 chars-inserted lines-inserted)))
   ;; Vi puts cursor on the last char when the yanked text doesn't contain a
   ;; newline; it leaves the cursor at the beginning when the text contains 
   ;; a newline
     ))
 
 (defun viper-delete-backward-char (arg)
-  "Delete previous character. On reaching beginning of line, stop and beep."
+  "Delete previous character.  On reaching beginning of line, stop and beep."
   (interactive "P")
   (let ((val (viper-p-val arg))
 	end-del-pos)
 (defun viper-del-backward-char-in-replace ()
   "Delete one character in replace mode.
 If `viper-delete-backwards-in-replace' is t, then DEL key actually deletes
-charecters. If it is nil, then the cursor just moves backwards, similarly
-to Vi. The variable `viper-ex-style-editing', if t, doesn't let the
+charecters.  If it is nil, then the cursor just moves backwards, similarly
+to Vi.  The variable `viper-ex-style-editing', if t, doesn't let the
 cursor move past the beginning of line."
   (interactive)
   (cond (viper-delete-backwards-in-replace
 	     viper-replace-region-start-delimiter
 	     viper-replace-region-end-delimiter)
 	    ;; this move takes care of the last posn in the overlay, which
-	    ;; has to be shifted because of insert. We can't simply insert
+	    ;; has to be shifted because of insert.  We can't simply insert
 	    ;; "$" before-markers because then overlay-start will shift the
 	    ;; beginning of the overlay in case we are replacing a single
-	    ;; character. This fixes the bug with `s' and `cl' commands.
+	    ;; character.  This fixes the bug with `s' and `cl' commands.
 	    (viper-move-replace-overlay (viper-replace-start) (point))
 	    (goto-char (viper-replace-start))
 	    (viper-change-state-to-replace t))
 ;; So, if you hit '' or `` then you can return to p1.
 ;;
 ;; If repeated command, pop top elt from the ring into mark and
-;; jump there. This forgets the position, p1, and puts M1 back into mark.
+;; jump there.  This forgets the position, p1, and puts M1 back into mark.
 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from
 ;; the ring into mark.  Push M2 back on the ring and set mark to M0.
 ;; etc.
 One can use `` and '' to temporarily jump 1 step back."
   (let* ((sv-pt (point)))
        ;; if repeated `m,' command, pop the previously saved mark.
-       ;; Prev saved mark is actually prev saved point. It is used if the
+       ;; Prev saved mark is actually prev saved point.  It is used if the
        ;; user types `` or '' and is discarded 
        ;; from the mark ring by the next `m,' command. 
        ;; In any case, go to the previous or previously saved mark.
        ;; Then push the current mark (popped off the ring) and set current
-       ;; point to be the mark. Current pt as mark is discarded by the next
+       ;; point to be the mark.  Current pt as mark is discarded by the next
        ;; m, command.
        (if (eq last-command 'viper-cycle-through-mark-ring)
 	   ()
 ;; Viewing registers
 
 (defun viper-ket-function (arg)
-  "Function called by \], the ket. View registers and call \]\]."
+  "Function called by \], the ket.  View registers and call \]\]."
   (interactive "P")
   (let ((reg (read-char)))
     (cond ((viper-valid-register reg '(letter Letter))
 	      viper-InvalidRegister reg)))))
 
 (defun viper-brac-function (arg)
-  "Function called by \[, the brac. View textmarkers and call \[\["
+  "Function called by \[, the brac.  View textmarkers and call \[\["
   (interactive "P")
   (let ((reg (read-char)))
     (cond ((= ?\[ reg)
 You can change it at any time by typing `M-x viper-set-expert-level RET'
 	
  1 -- BEGINNER: Almost all Emacs features are suppressed.
-       Feels almost like straight Vi. File name completion and
+       Feels almost like straight Vi.  File name completion and
        command history in the minibuffer are thrown in as a bonus. 
        To use Emacs productively, you must reach level 3 or higher.
  2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state,
        in Viper's insert state.
  4 -- GURU: Like 3, but user settings are respected for viper-no-multiple-ESC,
        viper-ex-style-motion, viper-ex-style-editing, and
-       viper-re-search variables. Adjust these settings to your taste.
+       viper-re-search variables.  Adjust these settings to your taste.
  5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
        viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi,
-       and viper-want-emacs-keys-in-insert. Adjust these to your taste.
+       and viper-want-emacs-keys-in-insert.  Adjust these to your taste.
       
 Please, specify your level now: ")
 	  
 not cause by other packages you are using.
 
 Don't report compilation warnings, unless you are certain that there is a
-problem. These warnings are normal and unavoidable.
+problem.  These warnings are normal and unavoidable.
 
 Please note that users should not modify variables and keymaps other than
-those advertised in the manual. Such `customization' is likely to crash
+those advertised in the manual.  Such `customization' is likely to crash
 Viper, as it would any other improperly customized Emacs package.
 
 If you are reporting an error message received while executing one of the
 
     M-x set-variable <Return> debug-on-error <Return> t <Return>
 	
-Then reproduce the error. The above command will cause Emacs to produce a
-back trace of the execution that leads to the error. Please include this
+Then reproduce the error.  The above command will cause Emacs to produce a
+back trace of the execution that leads to the error.  Please include this
 trace in your bug report.
 
 If you believe that one of Viper's commands goes into an infinite loop
 
     M-x set-variable <Return> debug-on-quit <Return> t <Return>
 	
-Then reproduce the problem. Wait for a few seconds, then type C-g to abort
-the current command. Include the resulting back trace in the bug report.
+Then reproduce the problem.  Wait for a few seconds, then type C-g to abort
+the current command.  Include the resulting back trace in the bug report.
 
 Mail anyway (y or n)? ")
 	    (if (y-or-n-p "Mail anyway? ")
     
 		
 ;; Smoothes out the difference between Emacs' unread-command-events
-;; and XEmacs unread-command-event. Arg is a character, an event, a list of
+;; and XEmacs unread-command-event.  Arg is a character, an event, a list of
 ;; events or a sequence of keys.
 ;;
 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event
 ;; symbol in unread-command-events list may cause Emacs to turn this symbol
-;; into an event. Below, we delete nil from event lists, since nil is the most
+;; into an event.  Below, we delete nil from event lists, since nil is the most
 ;; common symbol that might appear in this wrong context.
 (defun viper-set-unread-command-events (arg)
   (if viper-emacs-p
 ;; list is assumed to be a list of events of characters
 (defun viper-eventify-list-xemacs (lis)
   (mapcar
-   (function (lambda (elt)
-	       (cond ((viper-characterp elt) (character-to-event elt))
-		     ((eventp elt)  elt)
-		     (t (error
-			 "viper-eventify-list-xemacs: can't convert to event, %S"
-			 elt)))))
+   (lambda (elt)
+     (cond ((viper-characterp elt) (character-to-event elt))
+	   ((eventp elt)  elt)
+	   (t (error
+	       "viper-eventify-list-xemacs: can't convert to event, %S"
+	       elt))))
    lis))
   
   
 
 ;;; Variable completion in :set command
   
-;; The list of Ex commands. Used for completing command names.
+;; The list of Ex commands.  Used for completing command names.
 (defconst ex-token-alist
   '(("!") ("=") (">") ("&") ("~")
     ("yank") ("xit") ("WWrite") ("Write") ("write") ("wq") ("visual") 
 (defvar ex-addresses nil)
 
 ;; This flag is supposed to be set only by `#', `print', and `list',
-;; none of which is implemented. So, it and the pices of the code it
-;; controls are dead weight. We keep it just in case this might be
+;; none of which is implemented.  So, it and the pices of the code it
+;; controls are dead weight.  We keep it just in case this might be
 ;; needed in the future.
 (defvar ex-flag nil)
 
   :type 'string
   :group 'viper-ex)
 
-(defvar ex-nontrivial-find-file-function
-  (cond (ex-unix-type-shell 'viper-ex-nontrivial-find-file-unix)
-	((eq system-type 'emx) 'viper-ex-nontrivial-find-file-ms) ; OS/2
-	(viper-ms-style-os-p 'viper-ex-nontrivial-find-file-ms) ; Microsoft OS
-	(viper-vms-os-p 'viper-ex-nontrivial-find-file-unix) ; VMS
-	(t  'viper-ex-nontrivial-find-file-unix) ; presumably UNIX
-	))
+(defcustom viper-glob-function
+  "Expand the file spec containing wildcard symbols.
+The default tries to set this variable to work with Unix, Windows,
+OS/2, and VMS.
+
+However, if it doesn't work right for some types of Unix shells or some OS, 
+the user should supply the appropriate function and set this variable to the
+corresponding function symbol."
+  (cond (ex-unix-type-shell 'viper-glob-unix-files)
+	((eq system-type 'emx) 'viper-glob-mswindows-files) ; OS/2
+	(viper-ms-style-os-p 'viper-glob-mswindows-files) ; Microsoft OS
+	(viper-vms-os-p 'viper-glob-unix-files) ; VMS
+	(t  'viper-glob-unix-files) ; presumably UNIX
+	)
+  :type 'symbol
+  :group 'viper-ex)
+
 
 ;; Remembers the previous Ex tag.
 (defvar ex-tag 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
+;; multiple file names.  Used for :edit and :next
 (defvar viper-keep-reading-filename nil)
 
 (defcustom ex-cycle-other-window t
   "*If t, :n and :b cycles through files and buffers in other window.
-Then :N and :B cycles in the current window. If nil, this behavior is
+Then :N and :B cycles in the current window.  If nil, this behavior is
 reversed."
   :type 'boolean
   :group 'viper-ex)
 	    (t
 	     (error viper-BadExCommand))))))
 
-;; Reads Ex command. Tries to determine if it has to exit because command
-;; is complete or invalid. If not, keeps reading command.
+;; Reads Ex command.  Tries to determine if it has to exit because command
+;; is complete or invalid.  If not, keeps reading command.
 (defun ex-cmd-read-exit ()
   (interactive)
   (setq viper-incomplete-ex-cmd t)
     
 
 ;; Read Ex commands 
+;; ARG is a prefix argument. If given, the ex command runs on the region
+;;(without the user having to specify the address :a,b
+;; STRING is the command to execute. If nil, then Viper asks you to enter the
+;; command. 
 (defun viper-ex (arg &optional string)
   (interactive "P")
   (or string
 		    (buffer-substring (1- (point)) (mark t))))
 	    (backward-char 1)
 	    ;; if the user didn't insert the final pattern delimiter, we're
-	    ;; at newline now. In this case, insert the initial delimiter
+	    ;; at newline now.  In this case, insert the initial delimiter
 	    ;; specified in variable c
 	    (if (eolp)
 		(progn
 	      (setq ex-file (buffer-substring (point)  (1- (point-max))))
 	      (setq ex-file
 		    ;; For :e, match multiple non-white strings separated
-		    ;; by white. For others, find the first non-white string
+		    ;; by white.  For others, find the first non-white string
 		    (if (string-match
 			 (if (string= ex-token "edit")
 			     "[^ \t\n]+\\([ \t]+[^ \t\n]+\\)*"
     ))
 
 
-;; Completes file name or exits minibuffer. If Ex command accepts multiple
+;; Completes file name or exits minibuffer.  If Ex command accepts multiple
 ;; file names, arranges to re-enter the minibuffer.
 (defun viper-complete-filename-or-exit ()
   (interactive)
 	((or (string= ex-token "abbreviate")
 	     (string= ex-token "unabbreviate"))
 	 (error
-	  "`%s': Vi abbrevs are obsolete. Use the more powerful Emacs abbrevs"
+	  "`%s': Vi abbrevs are obsolete.  Use the more powerful Emacs abbrevs"
 	  ex-token))
 	((or (string= ex-token "list")
 	     (string= ex-token "print")
 
 (defun viper-undisplayed-files ()
   (mapcar
-   (function 
-    (lambda (b) 
-      (if (null (get-buffer-window b))
-	  (let ((f (buffer-file-name b)))
-	    (if f f
-	      (if ex-cycle-through-non-files 
-		  (let ((s (buffer-name b)))
-		    (if (string= " " (substring s 0 1))
-			nil
-		      s))
-		nil)))
-	nil)))
+   (lambda (b) 
+     (if (null (get-buffer-window b))
+	 (let ((f (buffer-file-name b)))
+	   (if f f
+	     (if ex-cycle-through-non-files 
+		 (let ((s (buffer-name b)))
+		   (if (string= " " (substring s 0 1))
+		       nil
+		     s))
+	       nil)))
+       nil))
    (buffer-list)))
 
 
 	    (princ "\n\nPress any key to continue...\n\n"))
 	  (viper-read-event))))))
 
-;; Ex cd command. Default directory of this buffer changes
+;; Ex cd command.  Default directory of this buffer changes
 (defun ex-cd ()
   (viper-get-ex-file)
   (if (string= ex-file "")
 
 
 ;; Ex edit command
-;; In Viper, `e' and `e!' behave identically. In both cases, the user is
+;; In Viper, `e' and `e!' behave identically.  In both cases, the user is
 ;; asked if current buffer should really be discarded.
-;; This command can take multiple file names. It replaces the current buffer
+;; This command can take multiple file names.  It replaces the current buffer
 ;; with the first file in its argument list
 (defun ex-edit (&optional file)
   (if (not file)
 ;;;    (if buffer-file-name
 ;;;	(cond ((buffer-modified-p)
 ;;;	       (setq msg
-;;;		     (format "Buffer %s is modified. Discard changes? "
+;;;		     (format "Buffer %s is modified.  Discard changes? "
 ;;;			     (buffer-name))
 ;;;		     do-edit t))
 ;;;	      ((not (verify-visited-file-modtime (current-buffer)))
   
   (if (null (setq file (get-file-buffer ex-file)))
       (progn 
-	(ex-find-file ex-file)
+	;; this also does shell-style globbing
+	(ex-find-file
+	 ;; replace # and % with the previous/current file
+	 (ex-expand-filsyms ex-file (current-buffer)))
 	(or (eq major-mode 'dired-mode)
 	    (viper-change-state-to-vi))
 	(goto-char (point-min)))
 ;; Find-file FILESPEC if it appears to specify a single file.
 ;; Otherwise, assume that FILESPEC is a wildcard.
 ;; In this case, split it into substrings separated by newlines.
-;; Each line is assumed to be a file name. find-file's each file thus obtained.
+;; Each line is assumed to be a file name.
 (defun ex-find-file (filespec)
   (let ((nonstandard-filename-chars "[^-a-zA-Z0-9_./,~$\\]"))
     (cond ((file-exists-p filespec) (find-file filespec))
 	  ((string-match nonstandard-filename-chars  filespec)
-	   (funcall ex-nontrivial-find-file-function filespec))
+	   (mapcar 'find-file (funcall viper-glob-function filespec)))
 	  (t (find-file filespec)))
     ))
 
     (save-window-excursion
       (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) 
       (set-buffer viper-ex-work-buf)
+      ;; com-str is the command string, i.e., g/pattern/ or v/pattern'
       (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
     (while marks
       (goto-char (car marks))
-      (viper-ex com-str)
+      (viper-ex nil com-str)
       (setq mark-count (1- mark-count))
       (setq marks (cdr marks)))))
 
 
 ;; Ex quit command
 (defun ex-quit ()
-  ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
+  ;; skip "!", if it is q!.  In Viper q!, w!, etc., behave as q, w, etc.
   (save-excursion
     (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) 
     (set-buffer viper-ex-work-buf)
 
 
 ;; Ex read command
+;; ex-read doesn't support wildcards, because file completion is a better
+;; mechanism. We also don't support # and % (except in :r <shell-command>
+;; because file history is a better mechanism.
 (defun ex-read ()
   (viper-get-ex-file)
   (let ((point (if (null ex-addresses) (point) (car ex-addresses)))
     (if ex-cmdfile
 	(progn
 	  (setq command 
-		(concat (ex-expand-filsyms ex-file (current-buffer))
-			ex-cmdfile-args))
+		;; replace # and % with the previous/current file
+		(ex-expand-filsyms (concat ex-file ex-cmdfile-args)
+				   (current-buffer)))
 	  (shell-command command t))
       (insert-file-contents ex-file)))
   (ex-fixup-history viper-last-ex-prompt ex-file ex-cmdfile-args))
 ;; Tell that `rewind' is obsolete and to use `:next count' instead
 (defun ex-rewind ()
   (message
-   "Use `:n <count>' instead. Counts are obtained from the `:args' command"))
+   "Use `:n <count>' instead.  Counts are obtained from the `:args' command"))
 
 
 ;; read variable name for ex-set
 (defun ex-shell ()
   (shell))
   
-;; Viper help. Invokes Info
+;; Viper help.  Invokes Info
 (defun ex-help ()
   (condition-case nil
       (progn
 			    (if viper-xemacs-p "X" "")
 			    ))))))
 
-;; Ex source command. Loads the file specified as argument or `~/.viper'
+;; Ex source command.  Loads the file specified as argument or `~/.viper'
 (defun ex-source ()
   (viper-get-ex-file)
   (if (string= ex-file "")
        (viper-message-conditions conds)))))
 
 ;; Ex write command
+;; ex-write doesn't support wildcards, because file completion is a better
+;; mechanism. We also don't support # and % 
+;; because file history is a better mechanism.
 (defun ex-write (q-flag)
   (viper-default-ex-addresses t)
   (viper-get-ex-file)
       (if (and (string= ex-file "") (not (buffer-file-name)))
 	  (setq ex-file
 		(read-file-name
-		 (format "Buffer %s isn't visiting any file. File to save in: "
+		 (format "Buffer %s isn't visiting any file.  File to save in: "
 			 (buffer-name)))))
       
       (setq writing-whole-file (and (= (point-min) beg) (= (point-max) end))
 	;; writing to non-visited file and it already exists
 	(if (and file-exists (not writing-same-file)
 		 (not (yes-or-no-p
-		       (format "File %s exists. Overwrite? " ex-file))))
+		       (format "File %s exists.  Overwrite? " ex-file))))
 	    (error "Quit"))
 	;; writing a region or whole buffer to non-visited file
 	(unwind-protect 
 	      ;; create temp buffer for the region
 	      (setq temp-buf (get-buffer-create " *ex-write*"))
 	      (set-buffer temp-buf)
-	      (set-visited-file-name ex-file 'noquerry)
+	      (if viper-xemacs-p
+		  (set-visited-file-name ex-file)
+		(set-visited-file-name ex-file 'noquerry))
 	      (erase-buffer)
 	      (if (and file-exists ex-append)
 		  (insert-file-contents ex-file))
       (skip-chars-forward " \t")
       (setq command (buffer-substring (point) (point-max)))
       (end-of-line))
+    ;; replace # and % with the previous/current file
     (setq command (ex-expand-filsyms command (current-buffer)))
     (if (and (> (length command) 0) (string= "!" (substring command 0 1)))
 	(if viper-ex-last-shell-com

File viper-init.el

   "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 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
+;; 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 nil
 (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
+`viper-record-kbd-macro' command.  There is no Ex-level command to do this
 interactively.")
 
 (viper-deflocalvar viper-emacs-state-modifier-minor-mode nil
 viper-expert-level is 1 or 2 or if viper-want-emacs-keys-in-insert is t.
 Use `M-x viper-set-expert-level' to change this.")
 
-;; Max expert level supported by Viper. This is NOT a user option.
+;; Max expert level supported by Viper.  This is NOT a user option.
 ;; It is here to make it hard for the user from resetting it.
 (defconst viper-max-expert-level 5)
 
 
 ;; If non-nil, ISO accents will be turned on in insert/replace emacs states and
 ;; turned off in vi-state.  For some users, this behavior may be too
-;; primitive. In this case, use insert/emacs/vi state hooks.
+;; primitive.  In this case, use insert/emacs/vi state hooks.
 (viper-deflocalvar viper-automatic-iso-accents nil "")
-;; Set iso-accents-mode to ARG. Check if it is bound first
+;; Set iso-accents-mode to ARG.  Check if it is bound first
 (defsubst viper-set-iso-accents-mode (arg)
   (if (boundp 'iso-accents-mode)
       (setq iso-accents-mode arg)))
 ;; Internal flag used to control when viper mule hooks are run.
 ;; Don't change this!
 (defvar viper-mule-hook-flag t)
-;; If non-nil, the default intl. input method is turned on.
+;; If non-nil, the default intl.  input method is turned on.
 (viper-deflocalvar viper-special-input-method nil "")
   
 ;; viper hook to run on input-method activation
 (put 'viper-undo-needs-adjustment 'permanent-local t)
 
 ;; A mark that Viper puts on buffer-undo-list.  Marks the beginning of a
-;; complex command that must be undone atomically. If inserted, it is
+;; complex command that must be undone atomically.  If inserted, it is
 ;; erased by viper-change-state-to-vi and viper-repeat.
 (defconst viper-buffer-undo-list-mark 'viper)
 
 (defcustom viper-keep-point-on-undo nil
   "*Non-nil means not to move point while undoing commands.
-This style is different from Emacs and Vi. Try it to see if
+This style is different from Emacs and Vi.  Try it to see if
 it better fits your working style."
   :type 'boolean
   :tag "Preserve Position of Point After Undo"
 
 ;; This is used to pass the right Vi command key sequence to
 ;; viper-set-destructive-command whenever (this-command-keys) doesn't give the
-;; right result. For instance, in commands like c/bla<RET>, (this-command-keys)
-;; will return ^M, which invoked exit-minibuffer, while we need "c/"
+;; right result.  For instance, in commands like c/bla<RET>,
+;; (this-command-keys) will return ^M, which invoked exit-minibuffer, while we
+;; need "c/" 
 (defconst viper-this-command-keys nil)
 
 ;; Indicates that the current destructive command has started in replace mode.
   :type 'string
   :group 'viper)
 
-;; place to save cursor colow when switching to insert mode
+;; place to save cursor color when switching to insert mode
 (viper-deflocalvar viper-saved-cursor-color nil "")
+(put 'viper-saved-cursor-color 'permanent-local t)
   
 (viper-deflocalvar viper-replace-overlay nil "")
 (put 'viper-replace-overlay 'permanent-local t)
       (and viper-xemacs-p (eq (viper-device-type) 'tty)))
   "*If non-nil, Viper will always use `viper-replace-region-end-delimiter' and
 `viper-replace-region-start-delimiter' to delimit replacement regions, even on
-color displays. By default, the delimiters are used only on TTYs."
+color displays.  By default, the delimiters are used only on TTYs."
   :type 'boolean
   :group 'viper)
   
 ;; mode to compensate for the inserted characters.
 (viper-deflocalvar viper-replace-chars-to-delete 0 "")
 ;; This variable is used internally by the before/after changed functions to
-;; determine how many chars were deleted by the change. This can't be
+;; determine how many chars were deleted by the change.  This can't be
 ;; determined inside after-change-functions because those get the length of the
 ;; deleted region, not the number of chars deleted (which are two different
 ;; things under MULE).
   :group 'viper-misc)
 ;; The insertion ring.
 (defvar viper-insertion-ring nil)
-;; This is temp insertion ring. Used to do rotation for display purposes.
+;; This is temp insertion ring.  Used to do rotation for display purposes.
 ;; When rotation just started, it is initialized to viper-insertion-ring.
 (defvar viper-temp-insertion-ring nil)
 (defvar viper-last-inserted-string-from-insertion-ring "")
   :group 'viper-misc)
 ;; The command ring.
 (defvar viper-command-ring nil)
-;; This is temp command ring. Used to do rotation for display purposes.
+;; This is temp command ring.  Used to do rotation for display purposes.
 ;; When rotation just started, it is initialized to viper-command-ring.
 (defvar viper-temp-command-ring nil)
 
 ;; Fast keyseq and ESC keyseq timeouts
 (defcustom viper-fast-keyseq-timeout 200
   "*Key sequence separated by no more than this many milliseconds is viewed as a Vi-style macro, if such a macro is defined.
-Setting this too high may slow down your typing. Setting this value too low
+Setting this too high may slow down your typing.  Setting this value too low
 will make it hard to use Vi-stile timeout macros."
   :type 'integer
   :group 'viper-misc)
 (defcustom viper-ESC-keyseq-timeout (if (viper-window-display-p)
 				      0 viper-fast-keyseq-timeout)
   "*Key sequence beginning with ESC and separated by no more than this many milliseconds is considered to be generated by a keyboard function key.
-Setting this too high may slow down switching from insert to vi state. Setting
+Setting this too high may slow down switching from insert to vi state.  Setting
 this value too low will make it impossible to use function keys in insert mode
 on a dumb terminal."
   :type 'integer
 Currently, this only electrifies auto-indentation, making it appropriate to the
 mode of the buffer.
 This means that auto-indentation will depart from standard Vi and will indent
-appropriate to the mode of the buffer. This is especially useful for editing
+appropriate to the mode of the buffer.  This is especially useful for editing
 programs and LaTeX documents."
   :type 'boolean
   :group 'viper)
 ;; back to viper-pre-command-point.
 ;; The reason this is needed is because dabbrev-expand (and possibly
 ;; others) may jump to before the insertion point, delete something and
-;; then reinsert a bigger piece. For instance:  bla^blo
+;; then reinsert a bigger piece.  For instance:  bla^blo
 ;; If dabbrev-expand is called after `blo' and ^ undicates viper-insert-point,
-;; then point jumps to the beginning of `blo'. If expansion is found, `blablo'
-;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand
+;; then point jumps to the beginning of `blo'.  If expansion is found, `blablo'
+;; is deleted, and we have |^, where | denotes point.  Next, dabbrev-expand
 ;; will insert the expansion, and we get: blablo^
 ;; Whatever we insert next goes before the ^, i.e., before the
-;; viper-insert-point marker. So, Viper will think that nothing was
-;; inserted. Remembering the orig position of the marker circumvents the
+;; viper-insert-point marker.  So, Viper will think that nothing was
+;; inserted.  Remembering the orig position of the marker circumvents the
 ;; problem.
 ;; We don't know of any command, except dabbrev-expand, that has the same
-;; problem. However, the same trick can be used if such a command is
+;; problem.  However, the same trick can be used if such a command is
 ;; discovered later.
 ;;
 (viper-deflocalvar viper-pre-command-point nil)
 (defvar viper-last-replace-region "")
   
 ;; Remember com point as a marker.
-;; This is a local marker. Should be moved with `viper-move-marker-locally'
+;; This is a local marker.  Should be moved with `viper-move-marker-locally'
 (viper-deflocalvar viper-com-point nil)
 
 ;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys)
   :group 'viper-search)
 
 (defcustom viper-re-replace t
-  "*If t, do regexp replace. nil means do string replace."
+  "*If t, do regexp replace.  nil means do string replace."
   :type 'boolean
   :tag "Regexp Replace"
   :group 'viper-search)
 `Backspace' and `Delete' don't cross line boundaries in insert.
 `X' and `x' can't delete characters across line boundary in Vi, etc.
 Note: this doesn't preclude `Backspace' and `Delete' from deleting characters
-by moving past the insertion point. This is a feature, not a bug.
+by moving past the insertion point.  This is a feature, not a bug.
 
 If nil, the above commands can work across lines."
   :type 'boolean
   :group 'viper)
 
 (defcustom viper-buffer-search-char nil
-  "*Key used for buffer-searching. Must be a character type, e.g., ?g."
+  "*Key used for buffer-searching.  Must be a character type, e.g., ?g."
   :type '(choice (const nil) character)
   :group 'viper-search)
 
 	  "^\\\\[sb][a-z]*{.*}\\s-*$\\|"	    		; latex
 	  "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|"	; texinfo
 	  "^.+:-")			                        ; prolog
-  "*Regexps for Headings. Used by \[\[ and \]\].")
+  "*Regexps for Headings.  Used by \[\[ and \]\].")
 
 (defvar viper-heading-end 
   (concat "^}\\|"						; C/C++
 	  "^@end \\|"						; texinfo
 	  ")\n\n[ \t\n]*\\|"					; lisp
 	  "\\.\\s-*$")						; prolog
-      "*Regexps to end Headings/Sections. Used by \[\].")
+      "*Regexps to end Headings/Sections.  Used by \[\].")
 
 
 ;; These two vars control the interaction of jumps performed by ' and `.
 (defvar viper-shell-history nil)
 
 
-;; Last shell command. There are two of these, one for Ex (in viper-ex)
+;; Last shell command.  There are two of these, one for Ex (in viper-ex)
 ;; and one for Vi.
 
 ;; Last shell command executed with ! command.
     (t (:underline t :stipple "gray3")))
   "*Face used to flash out the search pattern."
   :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
+;; An internal variable.  Viper takes the face from here.
 (defvar viper-search-face 'viper-search-face
   "Face used to flash out the search pattern.
-DO NOT CHANGE this variable. Instead, use the customization widget
+DO NOT CHANGE this variable.  Instead, use the customization widget
 to customize the actual face object `viper-search-face'
 this variable represents.")
 (viper-hide-face 'viper-search-face)
     (t (:underline t :stipple "gray3")))
   "*Face for highlighting replace regions on a window display."
   :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
+;; An internal variable.  Viper takes the face from here.
 (defvar viper-replace-overlay-face 'viper-replace-overlay-face
   "Face for highlighting replace regions on a window display.
-DO NOT CHANGE this variable. Instead, use the customization widget
+DO NOT CHANGE this variable.  Instead, use the customization widget
 to customize the actual face object `viper-replace-overlay-face'
 this variable represents.")
 (viper-hide-face 'viper-replace-overlay-face)
     (t (:bold t)))
   "Face used in the Minibuffer when it is in Emacs state."
   :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
+;; An internal variable.  Viper takes the face from here.
 (defvar viper-minibuffer-emacs-face 'viper-minibuffer-emacs-face
   "Face used in the Minibuffer when it is in Emacs state.
-DO NOT CHANGE this variable. Instead, use the customization widget
+DO NOT CHANGE this variable.  Instead, use the customization widget
 to customize the actual face object `viper-minibuffer-emacs-face'
 this variable represents.")
 (viper-hide-face 'viper-minibuffer-emacs-face)
     (t (:italic t)))
   "Face used in the Minibuffer when it is in Insert state."
   :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
+;; An internal variable.  Viper takes the face from here.
 (defvar viper-minibuffer-insert-face 'viper-minibuffer-insert-face
   "Face used in the Minibuffer when it is in Insert state.
-DO NOT CHANGE this variable. Instead, use the customization widget
+DO NOT CHANGE this variable.  Instead, use the customization widget
 to customize the actual face object `viper-minibuffer-insert-face'
 this variable represents.")
 (viper-hide-face 'viper-minibuffer-insert-face)
     (t (:inverse-video t)))
   "Face used in the Minibuffer when it is in Vi state."
   :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
+;; An internal variable.  Viper takes the face from here.
 (defvar viper-minibuffer-vi-face 'viper-minibuffer-vi-face
   "Face used in the Minibuffer when it is in Vi state.
-DO NOT CHANGE this variable. Instead, use the customization widget
+DO NOT CHANGE this variable.  Instead, use the customization widget
 to customize the actual face object `viper-minibuffer-vi-face'
 this variable represents.")
 (viper-hide-face 'viper-minibuffer-vi-face)
   :type 'string
   :group 'viper-misc)
 
+(defcustom viper-change-notification-threshold 1
+  "Notify the user when this many lines or characters have been deleted/yanked.
+For line-deleting/yanking commands (like `dd', `yy'), the value denotes the
+number of lines.  For character-based commands (such as `x', `dw', etc.), the
+value refers to the number of characters affected."
+  :type 'integer
+  :group 'viper-misc)
+
 ;; Minibuffer
 
 (defcustom viper-vi-style-in-minibuffer t
   
 ;; overlay used in the minibuffer to indicate which state it is in
 (viper-deflocalvar viper-minibuffer-overlay nil)
+(put 'viper-minibuffer-overlay 'permanent-local t)
 
 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer.
 ;; This is needed because beginning with Emacs 19.26, the standard

File viper-keym.el

 (defcustom viper-no-multiple-ESC  t
   "*If true, multiple ESC in Vi mode will cause bell to ring.
 This is set to t on a windowing terminal and to 'twice on a dumb
-terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this
+terminal (unless the user level is 1, 2, or 5).  On a dumb terminal, this
 enables cursor keys and is generally more convenient, as terminals usually
 don't have a convenient Meta key.
 Setting viper-no-multiple-ESC to nil will allow as many multiple ESC,
   "Keymap for user-defined local bindings.
 Useful for changing bindings such as ZZ in certain major modes.
 For instance, in letter-mode, one may want to bind ZZ to
-mh-send-letter. In a newsreader such as gnus, tin, or rn, ZZ could be bound
+mh-send-letter.  In a newsreader such as gnus, tin, or rn, ZZ could be bound
 to save-buffers-kill-emacs then post article, etc.")
 (put 'viper-vi-local-user-map 'permanent-local t)	
 
 
 (defvar viper-vi-diehard-map (make-sparse-keymap)
   "This keymap is in use when the user asks Viper to simulate Vi very closely.
-This happens when viper-expert-level is 1 or 2. See viper-set-expert-level.")
+This happens when viper-expert-level is 1 or 2.  See viper-set-expert-level.")
   
 
 (viper-deflocalvar viper-insert-local-user-map (make-sparse-keymap)
 
 (defvar viper-insert-diehard-map (make-keymap)
   "Map used when user wants vi-style keys in insert mode.
-Most of the Emacs keys are suppressed. This map overshadows
-viper-insert-basic-map. Not recommended, except for novice users.")
+Most of the Emacs keys are suppressed.  This map overshadows
+viper-insert-basic-map.  Not recommended, except for novice users.")
 
 (defvar  viper-insert-kbd-map  (make-sparse-keymap)
   "This keymap keeps VI-style kbd macros for insert mode.")
 (defvar viper-empty-keymap (make-sparse-keymap))
 
 ;; This was the main Vi mode in old versions of VIP which may have been
-;; extensively used by VIP users. We declare it as a global var
+;; extensively used by VIP users.  We declare it as a global var
 ;; and, after .viper is loaded, we add this keymap to viper-vi-basic-map.
 (defvar viper-mode-map (make-sparse-keymap))
 
 (defvar viper-emacs-state-modifier-alist nil)
 
 ;; Tells viper-add-local-keys to create a new viper-vi-local-user-map for new
-;; buffers. Not a user option.
+;; buffers.  Not a user option.
 (viper-deflocalvar viper-need-new-vi-local-map t "")
 (put 'viper-need-new-vi-local-map  'permanent-local t)
 
 ;; Tells viper-add-local-keys to create a new viper-insert-local-user-map for
-;; new buffers. Not a user option.
+;; new buffers.  Not a user option.
 (viper-deflocalvar viper-need-new-insert-local-map t "")
 (put 'viper-need-new-insert-local-map  'permanent-local t)
 
 ;; Tells viper-add-local-keys to create a new viper-emacs-local-user-map for
-;; new buffers. Not a user option.
+;; new buffers.  Not a user option.
 (viper-deflocalvar viper-need-new-emacs-local-map t "")
 (put 'viper-need-new-emacs-local-map  'permanent-local t)
 
 
 ;; Vi keymaps
 
-(define-key viper-vi-basic-map "\C-^" 
-  (function (lambda () (interactive) (viper-ex "e#"))))
+(define-key viper-vi-basic-map "\C-^" (lambda ()
+					(interactive) (viper-ex nil "e#")))
 (define-key viper-vi-basic-map "\C-b" 'viper-scroll-screen-back)
 (define-key viper-vi-basic-map "\C-d" 'viper-scroll-up)
 (define-key viper-vi-basic-map "\C-e" 'viper-scroll-up-one)
 (define-key viper-vi-basic-map "#" 'viper-command-argument)
 (define-key viper-vi-basic-map "$" 'viper-goto-eol)
 (define-key viper-vi-basic-map "%" 'viper-paren-match)
-(define-key viper-vi-basic-map "&"
-  (function (lambda () (interactive) (viper-ex "&"))))
+(define-key viper-vi-basic-map "&" (lambda ()
+				     (interactive) (viper-ex nil "&")))
 (define-key viper-vi-basic-map "'" 'viper-goto-mark-and-skip-white)
 (define-key viper-vi-basic-map "(" 'viper-backward-sentence)
 (define-key viper-vi-basic-map ")" 'viper-forward-sentence)
 (define-key viper-vi-basic-map "\C-?" 'viper-backward-char)
 (define-key viper-vi-basic-map "_" 'viper-nil)
 
-;;; This is viper-vi-diehard-map. Used when viper-vi-diehard-minor-mode is on.
+;;; This is viper-vi-diehard-map.  Used when viper-vi-diehard-minor-mode is on.
 
 (define-key viper-vi-diehard-map "\C-a" 'viper-nil)
 (define-key viper-vi-diehard-map "\C-c" 'viper-nil)
 		 map viper-emacs-local-user-map))
 	  (t 
 	   (error
-	    "Invalid state in viper-add-local-keys: %S. Valid states: vi-state, insert-state or emacs-state" state)))
+	    "Invalid state in viper-add-local-keys: %S.  Valid states: vi-state, insert-state or emacs-state" state)))
 
     (viper-modify-keymap map alist)
     (viper-normalize-minor-mode-map-alist)
 
 If the default for a major mode is emacs-state, then modifications to this
 major mode may not take effect until the buffer switches state to Vi,
-Insert or Emacs. If this happens, add viper-change-state-to-emacs to this
-major mode's hook. If no such hook exists, you may have to put an advice on
-the function that invokes the major mode. See viper-set-hooks for hints.
+Insert or Emacs.  If this happens, add viper-change-state-to-emacs to this
+major mode's hook.  If no such hook exists, you may have to put an advice on
+the function that invokes the major mode.  See viper-set-hooks for hints.
 
 The above needs not to be done for major modes that come up in Vi or Insert
 state by default.
     
     ;; Normalization usually doesn't help here, since one needs to
     ;; normalize in the actual buffer where changes to the keymap are
-    ;; to take place. However, it doesn't hurt, and it helps whenever this
+    ;; to take place.  However, it doesn't hurt, and it helps whenever this
     ;; function is actually called from within the affected buffer.
     (viper-normalize-minor-mode-map-alist)
     
 ;;; Keymap utils
 	     
 (defun viper-add-keymap (mapsrc mapdst) 
-  "Add contents of mapsrc to mapdst. It is assumed that mapsrc is sparse."
+  "Add contents of mapsrc to mapdst.  It is assumed that mapsrc is sparse."
   (if viper-xemacs-p
-      (map-keymap (function (lambda (key binding)
-			      (define-key mapdst key binding)))
+      (map-keymap (lambda (key binding) (define-key mapdst key binding))
 		  mapsrc)
-    (mapcar 
-     (function (lambda (p) 
-		 (define-key mapdst (vector (car p)) (cdr p))
-		 ))
-     (cdr mapsrc))))
+    (mapcar (lambda (p) (define-key mapdst (vector (car p)) (cdr p)))
+	    (cdr mapsrc))))
   
 (defun viper-modify-keymap (map alist)
-   "Modifies MAP with bindings specified in the ALIST. The alist has the
+   "Modifies MAP with bindings specified in the ALIST.  The alist has the
 form ((key . function) (key . function) ... )."
-   (mapcar (function (lambda (p)
-		       (define-key map (eval (car p)) (cdr p)))) 
+   (mapcar (lambda (p) (define-key map (eval (car p)) (cdr p))) 
 	   alist))
 
 

File viper-macs.el

 (defcustom viper-repeat-from-history-key 'f12
   "Prefix key for accessing previously typed Vi commands.
 
-The previous command is accessible, as usual, via `.'. The command before this
+The previous command is accessible, as usual, via `.'.  The command before this
 can be invoked as `<this key> 1', and the command before that, and the command
 before that one is accessible as `<this key> 2'.
-The notation for these keys is borrowed from XEmacs. Basically,
+The notation for these keys is borrowed from XEmacs.  Basically,
 a key is a symbol, e.g., `a', `\\1', `f2', etc., or a list, e.g.,
 `(meta control f1)'."
   :type 'sexp
       (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.  Hit `C-x )' to complete the mapping"
 	       (viper-display-macro macro-name)
 	       (if ins "Insert" "Vi")))
     ))
     
     ;; We expect macro-name to be a vector, a string, or a quoted string.
     ;; In the second case, it will emerge as a symbol when read from
-    ;; the above read-from-string. So we need to convert it into a string
+    ;; the above read-from-string.  So we need to convert it into a string
     (if macro-name
         (cond ((vectorp macro-name) nil)
 	      ((stringp macro-name) 
 
 ;;; Recording, unrecording, executing
 
-;; accepts as macro names: strings and vectors.
+;; Accepts as macro names: strings and vectors.
 ;; strings must be strings of characters; vectors must be vectors of keys
-;; in canonic form. the canonic form is essentially the form used in XEmacs
+;; in canonic form.  The canonic form is essentially the form used in XEmacs
 (defun viper-record-kbd-macro (macro-name state macro-body &optional scope)
-  "Record a Vi macro. Can be used in `.viper' file to define permanent macros.
-MACRO-NAME is a string of characters or a vector of keys. STATE is
-either `vi-state' or `insert-state'. It specifies the Viper state in which to
-define the macro. MACRO-BODY is a string that represents the keyboard macro.
+  "Record a Vi macro.  Can be used in `.viper' file to define permanent macros.
+MACRO-NAME is a string of characters or a vector of keys.  STATE is
+either `vi-state' or `insert-state'.  It specifies the Viper state in which to
+define the macro.  MACRO-BODY is a string that represents the keyboard macro.
 Optional SCOPE says whether the macro should be global \(t\), mode-specific
 \(a major-mode symbol\), or buffer-specific \(buffer name, a string\).
 If SCOPE is nil, the user is asked to specify the scope."
     (if (= (length macro-name) 0)
 	(error "Can't map an empty macro name"))
 	
-    ;; Macro-name is usually a vector. However, command history or macros
-    ;; recorded in ~/.viper may be recorded as strings. So, convert to vectors.
+    ;; Macro-name is usually a vector.  However, command history or macros
+    ;; recorded in ~/.viper may be recorded as strings.  So, convert to
+    ;; vectors. 
     (setq macro-name (viper-fixup-macro macro-name))
     (if (viper-char-array-p macro-name)
 	(setq macro-name (viper-char-array-to-macro macro-name)))
 ;; macro name must be a vector of viper-style keys
 (defun viper-unrecord-kbd-macro (macro-name state)
   "Delete macro MACRO-NAME from Viper STATE.
-MACRO-NAME must be a vector of viper-style keys. This command is used by Viper
+MACRO-NAME must be a vector of viper-style keys.  This command is used by Viper
 internally, but the user can also use it in ~/.viper to delete pre-defined
-macros supplied with Viper. The best way to avoid mistakes in macro names to be
-passed to this function is to use viper-describe-kbd-macros and copy the name
-from there."
+macros supplied with Viper.  The best way to avoid mistakes in macro names to
+be passed to this function is to use viper-describe-kbd-macros and copy the
+name from there."
   (let* (state-name keymap 
 	 (macro-alist-var
 	  (cond ((eq state 'vi-state)
 	 buf-mapping mode-mapping global-mapping
 	 macro-pair macro-entry)
 	 	
-    ;; Macro-name is usually a vector. However, command history or macros
-    ;; recorded in ~/.viper may appear as strings. So, convert to vectors.
+    ;; Macro-name is usually a vector.  However, command history or macros
+    ;; recorded in ~/.viper may appear as strings.  So, convert to vectors.
     (setq macro-name (viper-fixup-macro macro-name))
     (if (viper-char-array-p macro-name)
 	(setq macro-name (viper-char-array-to-macro macro-name)))
     ))
     
 ;; Check if MACRO-ALIST has an entry for a macro name starting with
-;; CHAR. If not, this indicates that the binding for this char
+;; CHAR.  If not, this indicates that the binding for this char
 ;; in viper-vi/insert-kbd-map can be released.
 (defun viper-can-release-key (char macro-alist)
   (let ((lis macro-alist)
       (viper-set-unread-command-events event-seq)
       ;; if the user typed arg, then use it if prefix arg is not set by
       ;; some other command (setting prefix arg can happen if we do, say,
-      ;; 2dw and there is a macro starting with 2. Then control will go to
+      ;; 2dw and there is a macro starting with 2.  Then control will go to
       ;; this routine
       (or prefix-arg (setq  prefix-arg count)) 
       (setq command (key-binding (read-key-sequence nil)))
   (let ((converted-seq (viper-events-to-macro seq)))
     (eval (cons 'or 
 		(mapcar
-		 (function (lambda (elt)
-			     (viper-prefix-subseq-p converted-seq elt)))
+		 (lambda (elt) (viper-prefix-subseq-p converted-seq elt))
 		 (viper-this-buffer-macros alist))))))
 		 
 ;; whether SEQ1 is a prefix of SEQ2
       (setq len (apply 'min (mapcar 'length seqs))))
     (while (< idx len)
       (if (eval (cons 'and 
-		      (mapcar (function (lambda (s)
-					  (equal (elt first idx)
-						 (elt s idx))))
+		      (mapcar (lambda (s) (equal (elt first idx) (elt s idx)))
 			      rest)))
 	  (setq pref (vconcat pref (vector (elt first idx)))))
       (setq idx (1+ idx)))
     
 ;; get all sequences that match PREFIX from a given A-LIST
 (defun viper-extract-matching-alist-members (pref alist)
-  (delq nil (mapcar (function (lambda (elt)
-				(if (viper-prefix-subseq-p pref elt)
-				    elt)))
+  (delq nil (mapcar (lambda (elt) (if (viper-prefix-subseq-p pref elt) elt))
 		    (viper-this-buffer-macros alist))))
 		    
 (defun viper-do-sequence-completion (seq alist compl-message)
 (defun viper-this-buffer-macros (macro-alist)
   (let (candidates)
     (setq candidates
-	  (mapcar (function
-		   (lambda (elt)
-		     (if (or (viper-kbd-buf-definition elt)
-			     (viper-kbd-mode-definition elt)
-			     (viper-kbd-global-definition elt))
-			 (car elt))))
+	  (mapcar (lambda (elt)
+		    (if (or (viper-kbd-buf-definition elt)
+			    (viper-kbd-mode-definition elt)
+			    (viper-kbd-global-definition elt))
+			(car elt)))
 		  macro-alist))
     (setq candidates (delq nil candidates))))
     
   
 ;; if seq of Viper key symbols (representing a macro) can be converted to a
-;; string--do so. Otherwise, do nothing.
+;; string--do so.  Otherwise, do nothing.
 (defun viper-display-macro (macro-name-or-body)
   (cond ((viper-char-symbol-sequence-p macro-name-or-body)
 	 (mapconcat 'symbol-name macro-name-or-body ""))
 ;; Viper's macro, which is a vector of the form
 ;; [ desc desc ... ]
 ;; Each desc is either a symbol of (meta symb), (shift symb), etc.
-;; Here we purge events that happen to be lists. In most cases, these events
+;; Here we purge events that happen to be lists.  In most cases, these events
 ;; got into a macro definition unintentionally; say, when the user moves mouse
 ;; during a macro definition, then something like (switch-frame ...) might get
-;; in. Another reason for purging lists-events is that we can't store them in
+;; in.  Another reason for purging lists-events is that we can't store them in
 ;; textual form (say, in .emacs) and then read them back.
 (defun viper-events-to-macro (event-seq)
-  (vconcat (delq nil (mapcar (function (lambda (elt)
-					 (if (consp elt)
-					     nil
-					   (viper-event-key elt))))
+  (vconcat (delq nil (mapcar (lambda (elt) (if (consp elt)
+					       nil
+					     (viper-event-key elt)))
 			     event-seq))))
   
 ;; convert strings or arrays of characters to Viper macro form
    (sequencep vec)
    (eval
     (cons 'and
-	  (mapcar
-	   (function (lambda (elt)
-		       (and (symbolp elt) (= (length (symbol-name elt)) 1))))
-	   vec)))))
+	  (mapcar (lambda (elt)
+		    (and (symbolp elt) (= (length (symbol-name elt)) 1)))
+		  vec)))))
 	       
 
 ;; Check if vec is a vector of key-press events representing characters
 ;;; Reading fast key sequences
     
 ;; Assuming that CHAR was the first character in a fast succession of key
-;; strokes, read the rest. Return the vector of keys that was entered in
+;; strokes, read the rest.  Return the vector of keys that was entered in
 ;; this fast succession of key strokes.
 ;; A fast keysequence is one that is terminated by a pause longer than
 ;; viper-fast-keyseq-timeout.
 ;; sets register to last-kbd-macro carefully.
 (defun viper-set-register-macro (reg)
   (if (get-register reg)
-      (if (y-or-n-p "Register contains data. Overwrite? ")
+      (if (y-or-n-p "Register contains data.  Overwrite? ")
 	  ()
 	(error
-	 "Macro not saved in register. Can still be invoked via `C-x e'")))
+	 "Macro not saved in register.  Can still be invoked via `C-x e'")))
   (set-register reg last-kbd-macro))
 
 (defun viper-register-macro (count)

File viper-mous.el

   
 ;; Variable used for catching the switch-frame event.
 ;; If non-nil, indicates that previous-frame should be the selected
-;; one. Used by viper-mouse-click-get-word. Not a user option.
+;; one.  Used by viper-mouse-click-get-word.  Not a user option.
 (defvar viper-frame-of-focus nil)
     
 ;; Frame that was selected before the switch-frame event.
 Takes two parameters: a COUNT, indicating how many words to return, 
 and CLICK-COUNT, telling whether this is the first click, a double-click,
 or a tripple-click."
-  :type 'boolean
+  :type 'symbol
   :group 'viper-mouse)
        
 ;; time interval in millisecond within which successive clicks are
 If CLICK-COUNT is 2,then `word' is a Word in Vi sense.
 If the character clicked on is a non-separator and is non-alphanumeric but
 is adjacent to an alphanumeric symbol, then it is considered alphanumeric
-for the purpose of this command. If this character has a matching
+for the purpose of this command.  If this character has a matching
 character, such as `\(' is a match for `\)', then the matching character is
 also considered alphanumeric.
 For convenience, in Lisp modes, `-' is considered alphanumeric.
 
 If CLICK-COUNT is 3 or more, returns the line clicked on with leading and
-trailing space and tabs removed. In that case, the first argument, COUNT,
+trailing space and tabs removed.  In that case, the first argument, COUNT,
 is ignored."
    (let ((modifiers "_")
 	 beg skip-flag result
 
 (defun viper-mouse-click-get-word (click count click-count)
   "Returns word surrounding the position of a mouse click.
-Click may be in another window. Current window and buffer isn't changed.
+Click may be in another window.  Current window and buffer isn't changed.
 On single or double click, returns the word as determined by
 `viper-surrounding-word-function'."
      
   (interactive "e\nP")
   (if viper-frame-of-focus	;; to handle clicks in another frame
       (select-frame viper-frame-of-focus))
-  (if (or (not (eq (key-binding viper-mouse-down-insert-key-parsed)
-		   'viper-mouse-catch-frame-switch))
-	  (not (eq (key-binding viper-mouse-up-insert-key-parsed)
-		   'viper-mouse-click-insert-word))
-	  (and viper-xemacs-p (not (event-over-text-area-p click))))
+  (if (save-excursion
+	(or (not (eq (key-binding viper-mouse-down-insert-key-parsed)
+		     'viper-mouse-catch-frame-switch))
+	    (not (eq (key-binding viper-mouse-up-insert-key-parsed)
+		     'viper-mouse-click-insert-word))
+	    (and viper-xemacs-p (not (event-over-text-area-p click)))))
       () ; do nothing, if binding isn't right or not over text
     ;; turn arg into a number
     (cond ((integerp arg) nil)
 	      (viper-set-unread-command-events interrupting-event))
 	  )))))
   
-;; arg is an event. accepts symbols and numbers, too
+;; Arg is an event.  Accepts symbols and numbers, too
 (defun viper-mouse-event-p (event)
   (if (eventp event)
       (string-match "\\(mouse-\\|frame\\|screen\\|track\\)"
 		    (prin1-to-string (viper-event-key event)))))
   
-;; XEmacs has no double-click events. So, we must simulate.
+;; XEmacs has no double-click events.  So, we must simulate.
 ;; So, we have to simulate event-click-count.
 (defun viper-event-click-count (click)
   (if viper-xemacs-p
-      (progn
-	;; if more than 1 second
-	(if (> (- (event-timestamp click) viper-last-click-event-timestamp)
-	       viper-multiclick-timeout)
-	    (setq viper-current-click-count 0))
-	(setq viper-last-click-event-timestamp (event-timestamp click)
-	      viper-current-click-count (1+ viper-current-click-count)))
+      (viper-event-click-count-xemacs click)
     (event-click-count click)))
     
-
+;; kind of semaphore for updating viper-current-click-count
+(defvar viper-counting-clicks-p nil)
+(defun viper-event-click-count-xemacs (click)
+  (let ((time-delta (- (event-timestamp click)
+		       viper-last-click-event-timestamp))
+	inhibit-quit)
+    (while viper-counting-clicks-p
+      (ignore))
+    (setq viper-counting-clicks-p t)
+    (if (> time-delta viper-multiclick-timeout)
+	(setq viper-current-click-count 0))
+    (discard-input)
+    (setq viper-current-click-count (1+ viper-current-click-count)
+	  viper-last-click-event-timestamp (event-timestamp click))
+    (setq viper-counting-clicks-p nil)
+    (if (viper-sit-for-short viper-multiclick-timeout t)
+	viper-current-click-count
+      0)
+    ))
+    
 
 (defun viper-mouse-click-search-word (click arg)
-   "Find the word clicked or double-clicked on. Word may be in another window.
+   "Find the word clicked or double-clicked on.  Word may be in another window.
 With prefix argument, N, search for N-th occurrence.
-This command must be bound to a mouse click. The double-click action of the
+This command must be bound to a mouse click.  The double-click action of the
 same button must not be bound \(or it must be bound to the same function\).
 See `viper-surrounding-word' for the details on what constitutes a word for
 this command."
   (interactive "e\nP")
   (if viper-frame-of-focus	;; to handle clicks in another frame
       (select-frame viper-frame-of-focus))
-  (if (or (not (eq (key-binding viper-mouse-down-search-key-parsed)
-		   'viper-mouse-catch-frame-switch))
-	  (not (eq (key-binding viper-mouse-up-search-key-parsed)
-		   'viper-mouse-click-search-word))
-	  (and viper-xemacs-p (not (event-over-text-area-p click))))
+  (if (save-excursion
+	(or (not (eq (key-binding viper-mouse-down-search-key-parsed)
+		     'viper-mouse-catch-frame-switch))
+	    (not (eq (key-binding viper-mouse-up-search-key-parsed)
+		     'viper-mouse-click-search-word))
+	    (and viper-xemacs-p (not (event-over-text-area-p click)))))
       () ; do nothing, if binding isn't right or not over text
     (let ((previous-search-string viper-s-string)
 	  click-word click-count)
 	     (viper-read-event)
 	     (viper-mouse-event-p last-input-event)))
 	  (progn ; interrupted wait
-	    (setq viper-global-prefix-argument 
-		  (or viper-global-prefix-argument arg))
-	    ;; remember command that was before the multiclick
-	    (setq this-command last-command)
+	    (setq viper-global-prefix-argument (or viper-global-prefix-argument
+						   arg)
+		  ;; remember command that was before the multiclick
+		  this-command last-command)
 	    ;; make sure we counted this event---needed for XEmacs only
 	    (viper-event-click-count click))
 	;; uninterrupted wait
 		       (message "`%s': String not found in %s"
 				viper-s-string (buffer-name (current-buffer)))
 		     (message
-		      "`%s': Last occurrence in %s. Back to beginning of search"
+		      "`%s': Last occurrence in %s.  Back to beginning of search"
 		      click-word (buffer-name (current-buffer)))
 		     (setq arg 1) ;; to terminate the loop
 		     (sit-for 2))
   
 (defun viper-mouse-catch-frame-switch (event arg)
   "Catch the event of switching frame.
-Usually is bound to a `down-mouse' event to work properly. See sample
+Usually is bound to a `down-mouse' event to work properly.  See sample
 bindings in the Viper manual."
   (interactive "e\nP")
   (setq viper-frame-of-focus nil)
   ;; make Emacs forget that it executed viper-mouse-catch-frame-switch
   (setq this-command last-command))
       
-;; Called just before switching frames. Saves the old selected frame.
+;; Called just before switching frames.  Saves the old selected frame.
 ;; Sets last-command to handle-switch-frame (this is done automatically in
 ;; Emacs. 
 ;; The semantics of switching frames is different in Emacs and XEmacs.
 ;; In Emacs, if you select-frame A while mouse is over frame B and then
 ;; start typing, input goes to frame B, which becomes selected.
-;; In XEmacs, input will go to frame A. This may be a bug in one of the
+;; In XEmacs, input will go to frame A.  This may be a bug in one of the
 ;; Emacsen, but also may be a design decision.
 ;; Also, in Emacs sending input to frame B generates handle-switch-frame
 ;; event, while in XEmacs it doesn't.
 ;; All this accounts for the difference in the behavior of
 ;; viper-mouse-click-* commands when you click in a frame other than the one
-;; that was the last to receive input. In Emacs, focus will be in frame A
+;; that was the last to receive input.  In Emacs, focus will be in frame A
 ;; until you do something other than viper-mouse-click-* command.
 ;; In XEmacs, you have to manually select frame B (with the mouse click) in
 ;; order to shift focus to frame B.
 
 ;; The key is of the form (MODIFIER ... BUTTON-NUMBER)
 ;; Converts into a valid mouse button spec for the appropriate version of
-;; Emacs. EVENT-TYPE is either `up' or `down'. Up returns button-up key; down
+;; Emacs.  EVENT-TYPE is either `up' or `down'.  Up returns button-up key; down
 ;; returns button-down key.
 (defun viper-parse-mouse-key (key-var event-type)
   (let ((key (eval key-var))
 	      (not (eq (key-binding viper-mouse-up-search-key-parsed)
 		       'viper-mouse-click-search-word)))