Commits

steveb  committed a35f247

viper 3.02

  • Participants
  • Parent commits 715861a

Comments (0)

Files changed (8)

 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-VERSION = 1.05
-AUTHOR_VERSION = 3.005
+VERSION = 1.06
+AUTHOR_VERSION = 3.02
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = viper
 PKG_TYPE = regular

File viper-cmd.el

 
 ;; Runs viper-after-change-functions inside after-change-functions
 (defun viper-after-change-sentinel (beg end len)
-  (let ((list viper-after-change-functions))
-    (while list
-      (funcall (car list) beg end len)
-      (setq list (cdr list)))))
+  (run-hook-with-args 'viper-after-change-functions beg end len))
       
 ;; Runs viper-before-change-functions inside before-change-functions
 (defun viper-before-change-sentinel (beg end)
-  (let ((list viper-before-change-functions))
-    (while list
-      (funcall (car list) beg end)
-      (setq list (cdr list)))))
+  (run-hook-with-args 'viper-before-change-functions beg end))
 
 (defsubst viper-post-command-sentinel ()
   (run-hooks 'viper-post-command-hooks))
   ;; We remove then add viper-post/pre-command-sentinel since it is very
   ;; desirable that viper-pre-command-sentinel is the last hook and
   ;; viper-post-command-sentinel is the first hook.
+
+  (make-local-hook 'viper-after-change-functions)
+  (make-local-hook 'viper-before-change-functions)
+  (make-local-hook 'viper-post-command-hooks)
+  (make-local-hook 'viper-pre-command-hooks)
+
   (remove-hook 'post-command-hook 'viper-post-command-sentinel)
   (add-hook 'post-command-hook 'viper-post-command-sentinel)
   (remove-hook 'pre-command-hook 'viper-pre-command-sentinel)
   (add-hook 'pre-command-hook 'viper-pre-command-sentinel t)
   ;; These hooks will be added back if switching to insert/replace mode
-  (viper-remove-hook 'viper-post-command-hooks
-		     'viper-insert-state-post-command-sentinel)
-  (viper-remove-hook 'viper-pre-command-hooks
-		     'viper-insert-state-pre-command-sentinel)
+  (remove-hook 'viper-post-command-hooks
+	       'viper-insert-state-post-command-sentinel 'local)
+  (remove-hook 'viper-pre-command-hooks
+	       'viper-insert-state-pre-command-sentinel 'local)
   (setq viper-intermediate-command nil)
   (cond ((eq new-state 'vi-state)
 	 (cond ((member viper-current-state '(insert-state replace-state))
 	     (viper-move-marker-locally 'viper-insert-point (point)))
 	 (viper-move-marker-locally
 	  'viper-last-posn-while-in-insert-state (point))
-	 (viper-add-hook 'viper-post-command-hooks
-			 'viper-insert-state-post-command-sentinel t)
-	 (viper-add-hook 'viper-pre-command-hooks
-			 'viper-insert-state-pre-command-sentinel t))
+	 (add-hook 'viper-post-command-hooks
+		   'viper-insert-state-post-command-sentinel t 'local)
+	 (add-hook 'viper-pre-command-hooks
+		   'viper-insert-state-pre-command-sentinel t 'local))
 	) ; outermost cond
   
   ;; Nothing needs to be done to switch to emacs mode! Just set some
   (setq viper-began-as-replace t
 	viper-sitting-in-replace t
 	viper-replace-chars-to-delete 0)
-  (viper-add-hook
-   'viper-after-change-functions 'viper-replace-mode-spy-after t)
-  (viper-add-hook
-   'viper-before-change-functions 'viper-replace-mode-spy-before t)
+  (add-hook
+   'viper-after-change-functions 'viper-replace-mode-spy-after t 'local)
+  (add-hook
+   'viper-before-change-functions 'viper-replace-mode-spy-before t 'local)
   ;; this will get added repeatedly, but no harm
   (add-hook 'after-change-functions 'viper-after-change-sentinel t)
   (add-hook 'before-change-functions 'viper-before-change-sentinel t)
-  (viper-move-marker-locally 'viper-last-posn-in-replace-region
-			     (viper-replace-start))
-  (viper-add-hook
-   'viper-post-command-hooks 'viper-replace-state-post-command-sentinel t)
-  (viper-add-hook
-   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t)
+  (viper-move-marker-locally
+   'viper-last-posn-in-replace-region (viper-replace-start))
+  (add-hook
+   'viper-post-command-hooks 'viper-replace-state-post-command-sentinel
+   t 'local)
+  (add-hook
+   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t 'local)
   ;; guard against a smartie who switched from R-replace to normal replace
-  (viper-remove-hook
-   'viper-post-command-hooks 'viper-R-state-post-command-sentinel)
+  (remove-hook
+   'viper-post-command-hooks 'viper-R-state-post-command-sentinel 'local)
   (if overwrite-mode (overwrite-mode nil))
   )
   
 ;; the overlay and current point is before the end of the overlay.
 ;; Don't delete anything if current point is past the end of the overlay.
 (defun viper-finish-change ()
-  (viper-remove-hook
-   'viper-after-change-functions 'viper-replace-mode-spy-after)
-  (viper-remove-hook
-   'viper-before-change-functions 'viper-replace-mode-spy-before)
-  (viper-remove-hook
-   'viper-post-command-hooks 'viper-replace-state-post-command-sentinel) 
-  (viper-remove-hook
-   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel) 
+  (remove-hook
+   'viper-after-change-functions 'viper-replace-mode-spy-after 'local)
+  (remove-hook
+   'viper-before-change-functions 'viper-replace-mode-spy-before 'local)
+  (remove-hook
+   'viper-post-command-hooks 'viper-replace-state-post-command-sentinel 'local) 
+  (remove-hook
+   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel 'local) 
   (viper-restore-cursor-color-after-replace)
   (setq viper-sitting-in-replace nil) ; just in case we'll need to know it
   (save-excursion
   (setq kill-ring-yank-pointer kill-ring))
 
 (defun viper-finish-R-mode ()
-  (viper-remove-hook
-   'viper-post-command-hooks 'viper-R-state-post-command-sentinel)
-  (viper-remove-hook
-   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel)
+  (remove-hook
+   'viper-post-command-hooks 'viper-R-state-post-command-sentinel 'local)
+  (remove-hook
+   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel 'local)
   (viper-downgrade-to-insert))
   
 (defun viper-start-R-mode ()
   ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number
   (overwrite-mode 1)
-  (viper-add-hook
-   'viper-post-command-hooks 'viper-R-state-post-command-sentinel t)
-  (viper-add-hook
-   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t)
+  (add-hook
+   'viper-post-command-hooks 'viper-R-state-post-command-sentinel t 'local)
+  (add-hook
+   'viper-pre-command-hooks 'viper-replace-state-pre-command-sentinel t 'local)
   ;; guard against a smartie who switched from R-replace to normal replace
-  (viper-remove-hook
-   'viper-post-command-hooks 'viper-replace-state-post-command-sentinel)
+  (remove-hook
+   'viper-post-command-hooks 'viper-replace-state-post-command-sentinel 'local)
   )
 
 
 ;;; viper-ex.el --- functions implementing the Ex commands for Viper
 
-;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
 		     "\\|" "jo.*"
 		     "\\|" "^[ \t]*ta.*"
 		     "\\|" "^[ \t]*una.*"
-		     "\\|" "^[ \t]*su.*"
+		     ;; don't jump up in :s command
+		     "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*su.*"
+		     "\\|" "^[ \t]*\\([`'][a-z]\\|[.,%]\\)*[ \t]*s[^a-z].*"
 		     "\\|" "['`][a-z][ \t]*"
 		     ;; r! assumes that the next one is a shell command
 		     "\\|" "\\(r\\|re\\|rea\\|read\\)[ \t]*!"
     (set-buffer viper-ex-work-buf)
     (skip-chars-forward " \t")
     (if (looking-at "!")
+	;; this is probably a variant command r!
 	(progn
 	  (setq ex-g-variant (not ex-g-variant)
 		ex-g-flag (not ex-g-flag))
 	  (forward-char 1)
 	  (skip-chars-forward " \t")))
     (let ((c (following-char)))
-      (if (string-match "[0-9A-Za-z]" (format "%c" c))
-	  (error
-	   "Global regexp must be inside matching non-alphanumeric chars"))
+      (cond ((string-match "[0-9A-Za-z]" (format "%c" c))
+	     (error
+	      "Global regexp must be inside matching non-alphanumeric chars"))
+	    ((= c ??) (error "`?' is not an allowed pattern delimiter here")))
       (if (looking-at "[^\\\\\n]")
 	  (progn
 	    (forward-char 1)
 	    (set-mark (point))
 	    (let ((cont t))
-	      (while (and (not (eolp)) cont)
+	      ;; the use of eobp instead of eolp permits the use of newlines in
+	      ;; pat2 in s/pat1/pat2/
+	      (while (and (not (eobp)) cont)
 		(if (not (re-search-forward (format "[^%c]*%c" c c) nil t))
 		    (if (member ex-token '("global" "vglobal"))
-			(error
-			 "Missing closing delimiter for global regexp")
+			(error "Missing closing delimiter for global regexp")
 		      (goto-char (point-max))))
 		(if (not (viper-looking-back
 			  (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)))
-		    (setq cont nil))))
+		    (setq cont nil)
+		  ;; we are at an escaped delimiter: unescape it and continue
+		  (delete-backward-char 2)
+		  (insert c)
+		  (if (eolp)
+		      ;; if at eol, exit loop and go to next line
+		      ;; later, delim will be inserted at the end
+		      (progn
+			(setq cont nil)
+			(forward-char))))
+		))
 	    (setq ex-token
 		  (if (= (mark t) (point)) ""
 		    (buffer-substring (1- (point)) (mark t))))
 	    (backward-char 1)
-	    ;; if the user doesn't specify the final pattern delimiter, we're
+	    ;; if the user didn't insert the final pattern delimiter, we're
 	    ;; at newline now. In this case, insert the initial delimiter
 	    ;; specified in variable c
-	    (if (looking-at "\n")
+	    (if (eolp)
 		(progn
-		    (insert c)
-		      (backward-char 1)))
+		  (insert c)
+		  (backward-char 1)))
 	    )
 	(setq ex-token nil))
       c)))
     (while cont
       (setq viper-keep-reading-filename nil
 	    val (read-file-name (concat prompt str) nil default-directory))
-      (if (string-match " " val)
-	  (setq val (concat "\\\"" val "\\\"")))
+      (setq val (expand-file-name val))
+      (if (and (string-match " " val)
+	       (ex-cmd-accepts-multiple-files-p ex-token))
+	  (setq val (concat "\"" val "\"")))
       (setq str  (concat str (if (equal val "") "" " ")
 			 val (if (equal val "") "" " ")))
 			 
 	((string= ex-file "")
 	 (error viper-NoFileSpecified)))
       
-  (let (msg do-edit)
-    (if buffer-file-name
-	(cond ((buffer-modified-p)
-	       (setq msg
-		     (format "Buffer %s is modified. Discard changes? "
-			     (buffer-name))
-		     do-edit t))
-	      ((not (verify-visited-file-modtime (current-buffer)))
-	       (setq msg
-		     (format "File %s changed on disk.  Reread from disk? "
-			     buffer-file-name)
-		     do-edit t))
-	      (t (setq do-edit nil))))
-      
-    (if do-edit
-	(if (yes-or-no-p msg)
-	    (progn
-	      (set-buffer-modified-p nil)
-	      (kill-buffer (current-buffer)))
-	  (message "Buffer %s was left intact" (buffer-name))))
-    ) ; let
+;;;  (let (msg do-edit)
+;;;    (if buffer-file-name
+;;;	(cond ((buffer-modified-p)
+;;;	       (setq msg
+;;;		     (format "Buffer %s is modified. Discard changes? "
+;;;			     (buffer-name))
+;;;		     do-edit t))
+;;;	      ((not (verify-visited-file-modtime (current-buffer)))
+;;;	       (setq msg
+;;;		     (format "File %s changed on disk.  Reread from disk? "
+;;;			     buffer-file-name)
+;;;		     do-edit t))
+;;;	      (t (setq do-edit nil))))
+;;;      
+;;;    (if do-edit
+;;;	(if (yes-or-no-p msg)
+;;;	    (progn
+;;;	      (set-buffer-modified-p nil)
+;;;	      (kill-buffer (current-buffer)))
+;;;	  (message "Buffer %s was left intact" (buffer-name))))
+;;;    ) ; let
   
   (if (null (setq file (get-file-buffer ex-file)))
       (progn 
   (ex-fixup-history viper-last-ex-prompt ex-file))
 
 ;; Find-file FILESPEC if it appears to specify a single file.
-;; Otherwise, assume that FILES{EC is a wildcard.
+;; 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.
 (defun ex-find-file (filespec)
 	(ask-if-save t)
 	(auto-cmd-label "; don't touch or else...")
 	(delete-turn-on-auto-fill-pattern
-	 "([ \t]*add-hook[ \t]+'viper-insert-state-hooks[ \t]+'turn-on-auto-fill.*)")
+	 "([ \t]*add-hook[ \t]+'viper-insert-state-hook[ \t]+'turn-on-auto-fill.*)")
 	actual-lisp-cmd lisp-cmd-del-pattern
 	val2 orig-var)
     (setq orig-var var)
 	      (if (> val2 0)
 		  (viper-save-string-in-file
 		   (concat
-		    "(add-hook 'viper-insert-state-hooks 'turn-on-auto-fill) "
+		    "(add-hook 'viper-insert-state-hook 'turn-on-auto-fill) "
 		    auto-cmd-label)
 		   viper-custom-file-name
 		   delete-turn-on-auto-fill-pattern)
 		       (point-marker))))
 	  (goto-char (min (point) (mark t)))
 	  (while (< (point) limit)
-	    (end-of-line)
-	    (setq eol-mark (point-marker))
+	    (save-excursion
+	      (end-of-line)
+	      ;; This move allows the use of newline as the last character in
+	      ;; the substitution pattern
+	      (viper-forward-char-carefully)
+	      (setq eol-mark (point-marker)))
 	    (beginning-of-line)
 	    (if opt-g
 		(progn
 		    (if (not (stringp repl))
 			(error "Can't perform Ex substitution: No previous replacement pattern"))
 		    (replace-match repl t)))
-	      (end-of-line)
-	      (viper-forward-char-carefully))))))
+	      ;;(end-of-line)
+	      ;;(viper-forward-char-carefully)
+	      (goto-char eol-mark)
+	      )))))
     (if matched-pos (goto-char matched-pos))
     (beginning-of-line)
     (if opt-c (message "done"))))

File viper-init.el

 (defvar viper-current-state)
 (defvar viper-version)
 (defvar viper-expert-level)
+(defvar current-input-method)
+(defvar default-input-method)
+(defvar describe-current-input-method-function)
 ;; end pacifier
 
 
 			     (or current-input-method default-input-method))
 		   "")))
     ))
+
 ;; viper hook to run on input-method deactivation
 (defun viper-inactivate-input-method-action ()
   (if (null viper-mule-hook-flag)
 
 ;; Replace mode and changing text
 
-;; Viper's own after/before change functions, which get viper-add-hook'ed to
-;; Emacs's
-(viper-deflocalvar viper-after-change-functions nil "")
-(viper-deflocalvar viper-before-change-functions nil "")
-(viper-deflocalvar viper-post-command-hooks nil "")
-(viper-deflocalvar viper-pre-command-hooks nil "")
-
-;; Can be used to pass global states around for short period of time
+;; Hack used to pass global states around for short period of time
 (viper-deflocalvar viper-intermediate-command nil "")
 
 ;; This is used to pass the right Vi command key sequence to
   :group 'viper)
 
 (defcustom viper-shift-width 8
-  "*The shiftwidth variable."
+  "*The value of the shiftwidth.
+This determines the number of columns by which the Ctl-t moves the cursor in
+the Insert state."
   :type 'integer
   :group 'viper)
 
 (viper-deflocalvar viper-minibuffer-overlay nil)
 
 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer.
-;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run
-;; *after* exiting the minibuffer
-(defvar viper-minibuffer-exit-hook '(viper-minibuffer-trim-tail))
+;; This is needed because beginning with Emacs 19.26, the standard
+;; `minibuffer-exit-hook' is run *after* exiting the minibuffer
+(defvar viper-minibuffer-exit-hook nil)
        
 
 ;; Mode line

File viper-keym.el

     ;; 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
-    ;; function is actually called from within the right buffer.
+    ;; function is actually called from within the affected buffer.
     (viper-normalize-minor-mode-map-alist)
     
     (viper-set-mode-vars-for viper-current-state)))

File viper-util.el

   (let ((buf (find-file-noselect (substitute-in-file-name custom-file))))
     (save-excursion
       (set-buffer buf)
-      (goto-char (point-min))
-      (if pattern (delete-matching-lines pattern))
-      (goto-char (point-max))
-      (if string (insert string))
-      (save-buffer))
+      (let (buffer-read-only)
+	(goto-char (point-min))
+	(if pattern (delete-matching-lines pattern))
+	(goto-char (point-max))
+	(if string (insert string))
+	(save-buffer)))
     (kill-buffer buf)
     ))
 
 
 
 (defsubst viper-is-in-minibuffer ()
-  (string-match "\*Minibuf-" (buffer-name)))
+  (save-match-data
+    (string-match "\*Minibuf-" (buffer-name))))
   
 
 
   (cond (viper-xemacs-p (events-to-keys events))
 	(t events)))
 		  
-	
-;; This is here because Emacs changed the way local hooks work.
-;;
-;;Add to the value of HOOK the function FUNCTION.
-;;FUNCTION is not added if already present.
-;;FUNCTION is added (if necessary) at the beginning of the hook list
-;;unless the optional argument APPEND is non-nil, in which case
-;;FUNCTION is added at the end.
-;;
-;;HOOK should be a symbol, and FUNCTION may be any valid function.  If
-;;HOOK is void, it is first set to nil.  If HOOK's value is a single
-;;function, it is changed to a list of functions."
-(defun viper-add-hook (hook function &optional append)
-  (if (not (boundp hook)) (set hook nil))
-  ;; If the hook value is a single function, turn it into a list.
-  (let ((old (symbol-value hook)))
-    (if (or (not (listp old)) (eq (car old) 'lambda))
-	(setq old (list old)))
-    (if (member function old)
-	nil
-      (set hook (if append
-		    (append old (list function)) ; don't nconc
-		  (cons function old))))))
-
-;; This is here because of Emacs's changes in the semantics of add/remove-hooks
-;; and due to the bugs they introduced.
-;;
-;; Remove from the value of HOOK the function FUNCTION.
-;; HOOK should be a symbol, and FUNCTION may be any valid function.  If
-;; FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
-;; list of hooks to run in HOOK, then nothing is done.  See `viper-add-hook'."
-(defun viper-remove-hook (hook function)
-  (if (or (not (boundp hook))		;unbound symbol, or
-	  (null (symbol-value hook))	;value is nil, or
-	  (null function))		;function is nil, then
-      nil				;Do nothing.
-    (let ((hook-value (symbol-value hook)))
-      (if (consp hook-value)
-	  ;; don't side-effect the list
-	  (setq hook-value (delete function (copy-sequence hook-value)))
-	(if (equal hook-value function)
-	    (setq hook-value nil)))
-      (set hook hook-value))))
-
     
 ;; it is suggested that an event must be copied before it is assigned to
 ;; last-command-event in XEmacs
 ;;  Keywords: emulations
 ;;  Author: Michael Kifer <kifer@cs.sunysb.edu>
 
-;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
 
-(defconst viper-version "3.005 (Polyglot) of December 15, 1997"
+(defconst viper-version "3.02 (Polyglot) of March 7, 1998"
   "The current version of Viper")
 
 ;; This file is part of GNU Emacs.
 (defvar quail-mode)
 (defvar viper-expert-level)
 (defvar viper-mode-string)
+(defvar viper-major-mode-modifier-list)
 
 ;; loading happens only in non-interactive compilation
 ;; in order to spare non-viperized emacs from being viperized
   :tag "Set Viper Mode on Loading"
   :group 'viper-misc)
 
-(defcustom viper-non-vi-major-modes
-  '(custom-mode dired-mode efs-mode internal-ange-ftp-mode tar-mode
-		mh-folder-mode gnus-group-mode gnus-summary-mode Info-mode
-		Buffer-menu-mode view-mode vm-mode vm-summary-mode)
-  "*A list of major modes that should never come up in Vi command mode.
-Viper automatically augments this list with some obvious modes, such as
-`dired-mode', `tar-mode', etc.  So, don't put a mode on this list, unless 
-it comes up in a wrong Viper state."
+(defcustom viper-vi-state-mode-list
+  '(fundamental-mode
+    makefile-mode
+    help-mode
+    
+    awk-mode
+    m4-mode
+    
+    html-mode html-helper-mode
+    emacs-lisp-mode lisp-mode lisp-interaction-mode
+				  
+    java-mode cc-mode c-mode c++-mode-hook
+    fortran-mode f90-mode
+    basic-mode
+    bat-mode
+    asm-mode
+    prolog-mode
+
+    text-mode indented-text-mode
+    tex-mode latex-mode bibtex-mode
+				  
+    completion-list-mode
+    compilation-mode
+    
+    perl-mode
+    javascript-mode
+    tcl-mode
+    python-mode
+				  
+    sh-mode ksh-mode csh-mode
+				  
+    gnus-article-mode
+    mh-show-mode
+    )
+  "Major modes that require Vi command state."
   :type '(repeat symbol)
   :group 'viper-misc)
 
+(defcustom viper-emacs-state-mode-list
+  '(custom-mode
+
+    dired-mode
+    efs-mode
+    tar-mode
+
+    mh-folder-mode
+    gnus-group-mode
+    gnus-summary-mode
+    
+    Info-mode
+    Buffer-menu-mode
+    
+    view-mode
+    vm-mode
+    vm-summary-mode)
+  "*A list of major modes that should come up in Emacs state.
+Normally, Viper would bring buffers up in Emacs state, unless the corresponding
+major mode has been placed on `viper-vi-state-mode-list' or
+`viper-insert-state-mode-list'. So, don't place a new mode on this list, unless
+it is coming up in a wrong Viper state."
+  :type '(repeat symbol)
+  :group 'viper-misc)
+
+(defcustom viper-insert-state-mode-list
+  '(internal-ange-ftp-mode comint-mode shell-mode)
+  "*A list of major modes that should come up in Vi Insert state."
+  :type '(repeat symbol)
+  :group 'viper-misc)
+
+
+;; used to set viper-major-mode-modifier-list in defcustom
+(defun viper-apply-major-mode-modifiers (&optional symbol value)
+  (if symbol
+      (set symbol value))
+  (mapcar (function
+	   (lambda (triple)
+	     (viper-modify-major-mode
+	      (nth 0 triple) (nth 1 triple) (eval (nth 2 triple)))))
+	  viper-major-mode-modifier-list))
+
+(defcustom viper-major-mode-modifier-list
+  '((help-mode emacs-state viper-slash-and-colon-map)
+    (comint-mode insert-state viper-comint-mode-modifier-map)
+    (comint-mode vi-state viper-comint-mode-modifier-map)
+    (shell-mode insert-state viper-comint-mode-modifier-map)
+    (shell-mode vi-state viper-comint-mode-modifier-map)
+    (ange-ftp-shell-mode insert-state viper-comint-mode-modifier-map)
+    (ange-ftp-shell-mode vi-state viper-comint-mode-modifier-map)
+    (internal-ange-ftp-mode insert-state viper-comint-mode-modifier-map)
+    (internal-ange-ftp-mode vi-state viper-comint-mode-modifier-map)
+    (dired-mode emacs-state viper-dired-modifier-map)
+    (tar-mode emacs-state viper-slash-and-colon-map)
+    (mh-folder-mode emacs-state viper-slash-and-colon-map)
+    (gnus-group-mode emacs-state viper-slash-and-colon-map)
+    (gnus-summary-mode emacs-state viper-slash-and-colon-map)
+    (Info-mode emacs-state viper-slash-and-colon-map)
+    (Buffer-menu-mode emacs-state viper-slash-and-colon-map)
+    )
+  "List specifying how to modify the various major modes to enable some Viperisms.
+The list has the structure: ((mode viper-state keymap) (mode viper-state
+keymap) ...). If `mode' is on the list, the `kemap' will be made active (on the
+minor-mode-map-alist) in the specified viper state.
+If you change this list, have to restart emacs for the change to take effect.
+However, if you did the change through the customization widget, then emacs
+needs to be restarted only if you deleted a triple mode-state-keymap from the
+list. No need to restart emacs in case of insertion or modification of an
+existing triple."
+  :type '(repeat
+	  (list symbol
+		(choice (const emacs-state)
+			(const vi-state)
+			(const insert-state))
+		symbol))
+  :set 'viper-apply-major-mode-modifiers
+  :group 'viper-misc)
+
+
 
 
 
 		    ))
 	      (viper-set-expert-level 'dont-change-unless)))
 
-	(or (memq major-mode viper-non-vi-major-modes) ; don't switch to Vi
+	(or (memq major-mode viper-emacs-state-mode-list) ; don't switch to Vi
+	    (memq major-mode viper-insert-state-mode-list) ; don't switch
 	    (viper-change-state-to-vi)))))
    
 
 
   ;; restore non-viper vars
   (setq-default
-   default-major-mode
-   (viper-standard-value 'default-major-mode viper-saved-non-viper-variables) 
    next-line-add-newlines
    (viper-standard-value 
     'next-line-add-newlines viper-saved-non-viper-variables) 
   (mapatoms 'viper-remove-hooks)
   (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)
 
   ;; unbind Viper mouse bindings
   (viper-unbind-mouse-search-key)
   ) ; end viper-go-away
 
 
+;; list of buffers that just changed their major mode
+;; used in a hack that triggers vi command mode whenever needed
+(defvar viper-new-major-mode-buffer-list nil)
+
+;; set appropriate Viper state in buffers that changed major mode
+(defun set-viper-state-in-major-mode ()
+  (mapcar
+   (function
+    (lambda (buf)
+      (if (viper-buffer-live-p buf)
+	  (with-current-buffer buf
+	    (cond ((and (memq major-mode viper-vi-state-mode-list)
+			(eq viper-current-state 'emacs-state))
+		   (viper-mode))
+		  ((memq major-mode viper-emacs-state-mode-list)
+		   ;; not checking (eq viper-current-state 'emacs-state)
+		   ;; because viper-current-state could have gotten it by
+		   ;; default. we need viper-change-state-to-emacs here to have
+		   ;; the keymaps take effect.
+		   (viper-change-state-to-emacs))
+		  ((and (memq major-mode viper-insert-state-mode-list)
+			(not (eq viper-current-state 'insert-state)))
+		   (viper-change-state-to-insert))
+		  )) ; with-current-buffer
+	))) ; function
+   viper-new-major-mode-buffer-list)
+  ;; clear the list of bufs that changed major mode
+  (setq viper-new-major-mode-buffer-list nil)
+  ;; change the global value of hook
+  (remove-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode))
+
+;; sets up post-command-hook to turn viper-mode, if the current mode is
+;; fundamental
+(defun viper-major-mode-change-sentinel ()
+  (save-match-data
+    (or (string-match "\*Minibuf-" (buffer-name))
+	(setq viper-new-major-mode-buffer-list 
+	      (cons (current-buffer) viper-new-major-mode-buffer-list))))
+  ;; change the global value of hook
+  (add-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode t))
+
 
 
 ;; This sets major mode hooks to make them come up in vi-state.
 (defun viper-set-hooks ()
-  
   ;; It is of course a misnomer to call viper-mode a `major mode'.
   ;; However, this has the effect that if the user didn't specify the
   ;; default mode, new buffers that fall back on the default will come up
   ;; in Fundamental Mode and Vi state.
-  (setq default-major-mode 'viper-mode)
+  (if (eq default-major-mode 'fundamental-mode)
+      (setq default-major-mode 'viper-mode))
   
-  ;; The following major modes should come up in vi-state
-  (defadvice fundamental-mode (after viper-fundamental-mode-ad activate)
-    "Run `viper-change-state-to-vi' on entry."
-    (viper-change-state-to-vi))
+  (add-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
 
-  (defvar makefile-mode-hook)
-  (add-hook 'makefile-mode-hook 'viper-mode)
-
-  ;; Help mode is now for viewing only
-  (defvar help-mode-hook)
-  (add-hook 'help-mode-hook 'viper-change-state-to-emacs)
-  (viper-modify-major-mode 'help-mode 'emacs-state viper-slash-and-colon-map)
-
-  (defvar awk-mode-hook)
-  (add-hook 'awk-mode-hook 'viper-mode)
-  
-  (defvar html-mode-hook)
-  (add-hook 'html-mode-hook 'viper-mode)
-  (defvar html-helper-mode-hook)
-  (add-hook 'html-helper-mode-hook 'viper-mode)
-
-  (defvar java-mode-hook)
-  (add-hook 'java-mode-hook 'viper-mode)
-  
-  (defvar javascript-mode-hook)
-  (add-hook 'javascript-mode-hook 'viper-mode)
-  
-  (defvar emacs-lisp-mode-hook)
-  (add-hook 'emacs-lisp-mode-hook 'viper-mode)
-  (defvar lisp-mode-hook)
-  (add-hook 'lisp-mode-hook 'viper-mode)
-  (defvar lisp-interaction-mode-hook)
-  (add-hook 'lisp-interaction-mode-hook 'viper-mode)
-  
-  (defvar bibtex-mode-hook)
-  (add-hook 'bibtex-mode-hook 'viper-mode) 	  
-      
-  (defvar m4-mode-hook)
-  (add-hook 'm4-mode-hook 'viper-mode)
-      
-  (defvar cc-mode-hook)
-  (add-hook 'cc-mode-hook 'viper-mode)
-      
-  (defvar c-mode-hook)
-  (add-hook 'c-mode-hook 'viper-mode)
-      
-  (defvar c++-mode-hook)
-  (add-hook 'c++-mode-hook 'viper-mode)
-
-  (defvar fortran-mode-hook)
-  (add-hook 'fortran-mode-hook 'viper-mode)
-  (defvar f90-mode-hook)
-  (add-hook 'f90-mode-hook 'viper-mode)
-
-  (defvar basic-mode-hook)
-  (add-hook 'basic-mode-hook 'viper-mode)
-  (defvar bat-mode-hook)
-  (add-hook 'bat-mode-hook 'viper-mode)
-  
-  (defvar asm-mode-hook)
-  (add-hook 'asm-mode-hook 'viper-mode)
-
-  (defvar prolog-mode-hook)
-  (add-hook 'prolog-mode-hook 'viper-mode)
-      
+  ;; keep this because many modes we don't know about use this hook
   (defvar text-mode-hook)
   (add-hook 'text-mode-hook 'viper-mode)
       
-  (add-hook 'completion-list-mode-hook 'viper-mode)  
-  (add-hook 'compilation-mode-hook     'viper-mode)  
-
-  (defvar perl-mode-hook)
-  (add-hook 'perl-mode-hook 'viper-mode)  
-
-  (defvar tcl-mode-hook)
-  (add-hook 'tcl-mode-hook 'viper-mode)  
-  
-  (defvar python-mode-hook)
-  (add-hook 'python-mode-hook 'viper-mode)  
-  
   (defvar emerge-startup-hook)
   (add-hook 'emerge-startup-hook 'viper-change-state-to-emacs)
 
       (viper-change-state-to-emacs)))
   
   ;; Emacs shell, ange-ftp, and comint-based modes
-  (defvar comint-mode-hook)
-  (viper-modify-major-mode 
-   'comint-mode 'insert-state viper-comint-mode-modifier-map)
-  (viper-modify-major-mode 
-   'comint-mode 'vi-state viper-comint-mode-modifier-map)
-  (viper-modify-major-mode 
-   'shell-mode 'insert-state viper-comint-mode-modifier-map)
-  (viper-modify-major-mode 
-   'shell-mode 'vi-state viper-comint-mode-modifier-map)
-  ;; ange-ftp in XEmacs
-  (viper-modify-major-mode 
-   'ange-ftp-shell-mode 'insert-state viper-comint-mode-modifier-map)
-  (viper-modify-major-mode 
-   'ange-ftp-shell-mode 'vi-state viper-comint-mode-modifier-map)
-  ;; ange-ftp in Emacs
-  (viper-modify-major-mode 
-   'internal-ange-ftp-mode 'insert-state viper-comint-mode-modifier-map)
-  (viper-modify-major-mode 
-   'internal-ange-ftp-mode 'vi-state viper-comint-mode-modifier-map)
-  ;; set hook
-  (add-hook 'comint-mode-hook 'viper-comint-mode-hook)
-  
-  ;; Shell scripts
-  (defvar sh-mode-hook)
-  (add-hook 'sh-mode-hook 'viper-mode)
-  (defvar ksh-mode-hook)
-  (add-hook 'ksh-mode-hook 'viper-mode)
-  
-  ;; Dired
-  (viper-modify-major-mode 'dired-mode 'emacs-state viper-dired-modifier-map)
-  (viper-set-emacs-state-searchstyle-macros nil 'dired-mode)
-  (add-hook 'dired-mode-hook 'viper-change-state-to-emacs)
+  (add-hook 'comint-mode-hook 'viper-comint-mode-hook) ; comint
 
-  ;; Tar
-  (viper-modify-major-mode 'tar-mode 'emacs-state viper-slash-and-colon-map)
-  (viper-set-emacs-state-searchstyle-macros nil 'tar-mode)
+  (viper-set-emacs-state-searchstyle-macros nil 'dired-mode) ; dired
+  (viper-set-emacs-state-searchstyle-macros nil 'tar-mode) ; tar
+  (viper-set-emacs-state-searchstyle-macros nil 'mh-folder-mode) ; mhe
+  (viper-set-emacs-state-searchstyle-macros nil 'gnus-group-mode) ; gnus
+  (viper-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode)
+  (viper-set-emacs-state-searchstyle-macros nil 'Info-mode) ; info
+  (viper-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode) ;buffer-menu
 
-  ;; MH-E
-  (viper-modify-major-mode 
-   'mh-folder-mode 'emacs-state viper-slash-and-colon-map)
-  (viper-set-emacs-state-searchstyle-macros nil 'mh-folder-mode)
-  ;; changing state to emacs is needed so the preceding will take hold
-  (add-hook 'mh-folder-mode-hook 'viper-change-state-to-emacs)
-  (add-hook 'mh-show-mode-hook 'viper-mode)
-
-  ;; Gnus
-  (viper-modify-major-mode
-   'gnus-group-mode 'emacs-state viper-slash-and-colon-map)
-  (viper-set-emacs-state-searchstyle-macros nil 'gnus-group-mode)
-  (viper-modify-major-mode 
-   'gnus-summary-mode 'emacs-state viper-slash-and-colon-map)
-  (viper-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode)
-  ;; changing state to emacs is needed so the preceding will take hold
-  (add-hook 'gnus-group-mode-hook 'viper-change-state-to-emacs)
-  (add-hook 'gnus-summary-mode-hook 'viper-change-state-to-emacs)
-  (add-hook 'gnus-article-mode-hook 'viper-mode)
-
-  ;; Info
-  (viper-modify-major-mode 'Info-mode 'emacs-state viper-slash-and-colon-map)
-  (viper-set-emacs-state-searchstyle-macros nil 'Info-mode)
-  ;; Switching to emacs is needed  so the above will take hold
-  (defadvice Info-mode (after viper-Info-ad activate)
-    "Switch to emacs mode."
-    (viper-change-state-to-emacs))
-
-  ;; Buffer menu
-  (viper-modify-major-mode 
-   'Buffer-menu-mode 'emacs-state viper-slash-and-colon-map)
-  (viper-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode)
-  ;; Switching to emacs is needed  so the above will take hold
-  (defadvice Buffer-menu-mode (after viper-Buffer-menu-ad activate)
-    "Switch to emacs mode."
-    (viper-change-state-to-emacs))
-
-  ;; View mode
-  (defvar view-mode-hook)
-  (defvar view-hook)
-  (add-hook 'view-hook 'viper-change-state-to-emacs)
-  (add-hook 'view-mode-hook 'viper-change-state-to-emacs)
-  
-  ;; For VM users.
-  ;; Put summary and other VM buffers in Emacs state.
-  (defvar vm-mode-hooks)
-  (defvar vm-summary-mode-hooks)
-  (add-hook 'vm-mode-hooks   'viper-change-state-to-emacs)
-  (add-hook 'vm-summary-mode-hooks   'viper-change-state-to-emacs)
+  ;; Modify major modes according to viper-major-mode-modifier-list
+  (viper-apply-major-mode-modifiers)
   
   ;; For RMAIL users.
   ;; Put buf in Emacs state after edit.
 			(read-key-sequence "Describe key briefly: ")))))
   
   
-  ;; This is now done in viper-minibuffer-exit-hook
-  ;;;; Advice for use in find-file and read-file-name commands.
-  ;;(defadvice exit-minibuffer (before viper-exit-minibuffer-advice activate)
-  ;;  "Run `viper-minibuffer-exit-hook' just before exiting the minibuffer."
-  ;;  (run-hooks 'viper-minibuffer-exit-hook))
-  
   (defadvice find-file (before viper-add-suffix-advice activate)
     "Use `read-file-name' for reading arguments."
     (interactive (cons (read-file-name "Find file: " nil default-directory)
   (defadvice read-file-name (around viper-suffix-advice activate)
     "Tell `exit-minibuffer' to run `viper-file-add-suffix' as a hook."
     (let ((viper-minibuffer-exit-hook
-	   (append viper-minibuffer-exit-hook '(viper-file-add-suffix))))
+	   (append viper-minibuffer-exit-hook
+		   '(viper-minibuffer-trim-tail viper-file-add-suffix))))
       ad-do-it))
   
   (defadvice start-kbd-macro (after viper-kbd-advice activate)
 
       ;; If viper-mode is t, then just continue. Viper will kick in.
       ((eq viper-mode t))
-      ;; Otherwise, it was asking mode and Viper was not loaded through .emacs
+      ;; Otherwise, it was asking Viper was not loaded through .emacs
       ;; In this case, it was either through M-x viper-mode or via something
       ;; else, like the custom widget. If Viper was loaded through 
       ;; M-x viper-mode, then viper will kick in anyway.
 (if (null viper-saved-non-viper-variables)
     (setq viper-saved-non-viper-variables
 	  (list
-	   (cons 'default-major-mode (list default-major-mode))
 	   (cons 'next-line-add-newlines (list next-line-add-newlines))
 	   (cons 'require-final-newline (list require-final-newline))
 	   (cons 'scroll-step (list scroll-step))
       (viper-harness-minor-mode "russian")
       (viper-harness-minor-mode "view-less")
       (viper-harness-minor-mode "view")
+      (viper-harness-minor-mode "reftex")
       ))
 
 
       (viper-change-state-to-emacs)
       (setq-default minor-mode-map-alist minor-mode-map-alist)
       ))
-    
 
+(if (and viper-mode (memq major-mode viper-vi-state-mode-list))
+    (viper-mode))
 
 (run-hooks 'viper-load-hook) ; the last chance to change something
 
 @titlepage
 @title Viper Is a Package for Emacs Rebels
 @subtitle a Vi emulator for GNU Emacs 20 and XEmacs 20
-@subtitle November 1997, Viper Version 3.004 (Polyglot)
+@subtitle March 1998, Viper Version 3.02 (Polyglot)
 
 @author Michael Kifer (Viper)
 @author Aamod Sane (VIP 4.4)
 @end example
 
 @noindent
-in @file{~/.viper}. To do the same in Vi and Insert states, one should use
+in @file{~/.viper}. To do the same in Vi and Insert states, you should use
 @code{vi-state} and @code{insert-state}. Changes in Insert state are also
 in effect in Replace state.  For instance, suppose that the user wants to
 use @kbd{dd} in Vi state under Dired mode to delete files, @kbd{u} to unmark
 (viper-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)
 @end example
 
-Similar effect can be achieved by defining Vi keyboard macros using the
-Ex commands @kbd{:map} and @kbd{:map!}. The difference is that multi-key
-Vi macros do not override the keys they are bound to, unless these keys are
-typed in quick succession. So, with macros, one can use the normal keys
-alongside with the macros. If per-mode modifications are needed, the user
-can try both ways and see which one is more convenient.
+Yet another way to customize key bindings in a major mode is to edit the
+list @code{viper-major-mode-modifier-list} using the customization widget.
+@vindex @code{viper-major-mode-modifier-list}
+(This variable is in the Viper-misc customization group.)
+The elements of this list are triples of the form: (major-mode viper-state
+keymap), where the keymap contains bindings that are supposed to be active
+in the given major mode and the given viper-state.
+
+Effects similar to key binding changes can be achieved by defining Vi
+keyboard macros using the Ex commands @kbd{:map} and @kbd{:map!}. The
+difference is that multi-key Vi macros do not override the keys they are
+bound to, unless these keys are typed in quick succession. So, with macros,
+one can use the normal keys alongside with the macros. If per-mode
+modifications are needed, the user can try both ways and see which one is
+more convenient.
 @findex @kbd{:map}
 @xref{Vi Macros}, for details.
 
 packages. Fortunately, these modes operate on read-only buffers and are
 designed not for editing files, but for special-purpose browsing, reading
 news, mail, etc., and Vi commands are meaningless in these situations. For
-this reason, Viper doesn't force Vi state on such major modes.  Rather, it
+this reason, Viper doesn't force Vi state on such major modes---it
 brings them in Emacs state. You can switch to Vi state by typing @kbd{C-z}
 if, for instance, you want to do Vi-style search in a buffer (although,
 usually, incremental search, which is bound to @kbd{C-s}, is sufficient in
 
 If you would like certain major modes to come up in Emacs state rather than
 Vi state (but Viper thinks otherwise), you should put these major modes
-on the @code{viper-non-vi-major-modes} list and also add
-@code{viper-change-state-to-emacs} to these modes' hooks.
-@vindex @code{viper-non-vi-major-modes}
-
-It is also possible to harness some major modes, even though they may bind
-common keys to specialized commands. Harnessing can make sense for modes
-that bind only a small number of common keys.  For instance, if
-@code{viper-always} is set to @code{t} in your @file{~/.viper} file, Viper will
-harness Shell mode by changing the bindings for @kbd{C-m} and @kbd{C-d}
-using @code{viper-add-local-keys} described in section on customization
-(@xref{Customization}). In general, there is no single recipe for
-harnessing modes. It can be as simple as adding the function
-@code{viper-mode} to a hook associated with the mode, or it can be more
-complex, as in the case of Shell mode and Emerge. Take a look at
-@code{viper-set-hooks} function for some examples.
-
-Conversely, it may be the case that most of the major modes harnessed 
-by @code{viper-set-hooks} function fit your working style, except one or two
-cases. In this case, you may still be able to set @code{viper-always} to
-@code{t} and then remove a hook that forces Vi command state. For instance,
-to unharness @code{lisp-interaction-mode}, you can execute the following line
-in @code{viper-load-hook}:
-@lisp
-(remove-hook 'lisp-interaction-mode-hook 'viper-mode)
-@end lisp
-Note: this type of customization cannot be done in @code{.viper}!
-
-In some rare cases, some minor modes may override certain essential
-bindings in Vi command state.  This is not really catastrophic because this
-may happen only in the beginning, when the minor mode kicks in. Typing
+on the @code{viper-emacs-state-mode-list} list and delete them from
+@code{viper-vi-state-mode-list}.
+Likewise, you can force Viper's Insert state on a major mode by putting it
+in @code{viper-insert-state-mode-list}.
+@vindex @code{viper-emacs-state-mode-list}
+@vindex @code{viper-insert-state-mode-list}
+@vindex @code{viper-vi-state-mode-list}
+
+It is also possible to impose Vi on some major modes, even though they may
+bind common keys to specialized commands. This might make sense for modes
+that bind only a small number of common keys.  For instance, Viper subverts
+the Shell mode by changing the bindings for @kbd{C-m} and @kbd{C-d} using
+@code{viper-add-local-keys} described in section on customization
+(@xref{Customization}).
+
+In some cases, some @emph{minor} modes might override certain essential
+bindings in Vi command state.  This is not a big priblem because this
+can happen only in the beginning, when the minor mode kicks in. Typing
 @code{M-x viper-mode} will correct the situation.  Viper knows about
-several such minor modes and takes care of them, so that the above trick
+several such minor modes and takes care of them, so the above trick
 is usually not necessary.  If you find that some minor mode, e.g.,
 @code{nasty-mode.el} interferes with Viper, putting the following in
 @file{.viper} should fix the problem:
 The argument to @code{viper-harness-minor-mode} is the name of the file for the
 offending minor mode with the suffixes @file{.el} and @file{.elc} removed.
 
-It may be tricky, however, to find out which minor mode is at fault. The
-only guidance here is to look into the file that defines the minor mode you
-are suspecting, say @code{nasty-mode.el}, and see if it has a variable
-called @code{nasty-mode-map}. Then check if there is a statement of the form
+It may not be always obvious which minor mode is at fault. The only
+guidance here is to look into the file that defines the minor mode you are
+suspecting, say @code{nasty-mode.el}, and see if it has a variable called
+@code{nasty-mode-map}. Then check if there is a statement of the form
 @lisp
 (define-key nasty-mode-map key function)
 @end lisp
 @item %
 @cindex % (Ex address)
 For the whole file, same as (1,$).
-@item /pat/
-@item ?pat?
-Next or previous line with pattern pat
+@item /<pat>/
+@item ?<pat>?
+Next or previous line with pattern <pat>.
+
+Note that the pattern is allowed to contain newline character (inserted as 
+@kbd{C-qC-j}). Therefore, one can search for patterns that span several
+lines.
 @end table
 
 @cindex % (Current file)
 Switch lower and upper cases.
 @item <count>  J
 Join <count> lines (default 2).
-@item  :[x,y]s/<p>/<r>/<f>
+@item  :[x,y]s/<pat>/<repl>/<f>
 Substitute (on lines x through y) the pattern
-<p> (default the last pattern) with <r>.  Useful
+<pat> (default the last pattern) with <repl>.  Useful
 flags <f> are @samp{g} for @samp{global} (i.e. change every
-non-overlapping occurrence of <p>) and @samp{c} for
+non-overlapping occurrence of <pat>) and @samp{c} for
 @samp{confirm} (type @samp{y} to confirm a particular
 substitution, else @samp{n} ).  Instead of @kbd{/} any
 punctuation CHAR unequal to <space> <tab> and <lf> can be used as
 In Emacs, @samp{\&} stands for the last matched expression, so
 @kbd{s/[ab]+/\&\&/} will double the string matched by @kbd{[ab]}.
 Viper doesn't treat @samp{&} specially, unlike Vi: use @samp{\&} instead.
+
+Note: @emph{The newline character (inserted as @kbd{C-qC-j})
+can be used in <repl>}.
 @item  :[x,y]copy [z]
 Copy text between @kbd{x} and @kbd{y} to the position after @kbd{z}.
 @item  :[x,y]t [z]
 @kindex @kbd{#c<move>}
 @kindex @kbd{&}
 @kindex @kbd{\&}
-@findex @kbd{:substitute/<p>/<r>/<f>}
-@findex @kbd{:s/<p>/<r>/<f>}
+@findex @kbd{:substitute/<pat>/<repl>/<f>}
+@findex @kbd{:s/<pat>/<repl>/<f>}
 @findex @kbd{:copy [z]}
 @findex @kbd{:t [z]}
 @findex @kbd{:move [z]}
 Query Replace.
 @item :ta <name>
 Search in the tags file where <name> is defined (file, line), and go to it.
-@item  :[x,y]s/<p>/<r>/<f>
-Substitute (on lines x through y) the pattern <p> (default the last
-pattern) with <r>.  Useful
+@item  :[x,y]s/<pat>/<repl>/<f>
+Substitute (on lines x through y) the pattern <pat> (default the last
+pattern) with <repl>.  Useful
 flags <f> are @samp{g} for @samp{global} (i.e. change every
-non-overlapping occurrence of <p>) and @samp{c} for
+non-overlapping occurrence of <pat>) and @samp{c} for
 @samp{confirm} (type @samp{y} to confirm a particular
 substitution, else @samp{n}).  Instead of @kbd{/} any
 punctuation character other than <space> <tab> and <lf> can be used as
 delimiter. 
+
+Note: @emph{The newline character (inserted as @kbd{C-qC-j})
+can be used in <repl>}.
 @item  &
 Repeat latest Ex substitute command, e.g. @kbd{:s/wrong/right}.
 @item :global /<pattern>/<ex-command>
 Execute <ex-command> on all lines that do not match <pattern>.
 @end table
 @kindex @kbd{&}
-@findex @kbd{:substitute/<p>/<r>/<f>}
+@findex @kbd{:substitute/<pat>/<repl>/<f>}
 @kindex @kbd{Q}
 @kindex @kbd{#g<move>}
 @findex @kbd{:v}
 cook@@biostat.wisc.edu (Tom Cook),
 csdayton@@midway.uchicago.edu (Soren Dayton),
 dave@@hellgate.utah.edu,
+dominik@@strw.LeidenUniv.nl (Carsten Dominik),
 dwallach@@cs.princeton.edu (Dan Wallach),
 dwight@@toolucky.llnl.gov (Dwight Shih),
 edmonds@@edmonds.home.cs.ubc.ca (Brian Edmonds),