Merge from emacs--rel--22
[bpt/emacs.git] / lisp / emulation / viper-init.el
index af9fb31..2b0e886 100644 (file)
@@ -1,12 +1,15 @@
 ;;; viper-init.el --- some common definitions for Viper
 
-;; Copyright (C) 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
+
+;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
 
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
 
-;; Code
+;;; Code:
 
 (provide 'viper-init)
 
 (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)
+(defvar bar-cursor)
+(defvar default-cursor-type)
+(defvar cursor-type)
 ;; end pacifier
 
 
 ;; Viper version
 (defun viper-version ()
   (interactive)
-  (message "Viper version is %s" viper-version)) 
+  (message "Viper version is %s" viper-version))
 
 ;; Is it XEmacs?
 (defconst viper-xemacs-p (string-match "XEmacs" emacs-version))
 ;; Is it Emacs?
 (defconst viper-emacs-p (not viper-xemacs-p))
 ;; Tell whether we are running as a window application or on a TTY
+
+;; This is used to avoid compilation warnings. When emacs/xemacs forms can
+;; generate compile time warnings, we use this macro.
+;; In this case, the macro will expand into the form that is appropriate to the
+;; compiler at hand.
+;; Suggested by rms.
+(defmacro viper-cond-compile-for-xemacs-or-emacs (xemacs-form emacs-form)
+  (if (string-match "XEmacs" emacs-version)
+      xemacs-form emacs-form))
+
+
 (defsubst viper-device-type ()
-  (if viper-emacs-p
-      window-system
-    (device-type (selected-device))))
+  (viper-cond-compile-for-xemacs-or-emacs
+   (device-type (selected-device))
+   window-system
+   ))
+
+(defun viper-color-display-p ()
+  (condition-case nil
+      (viper-cond-compile-for-xemacs-or-emacs
+       (eq (device-class (selected-device)) 'color) ; xemacs form
+       (if (fboundp 'display-color-p) ; emacs form
+          (display-color-p)
+        (x-display-color-p))
+       )
+    (error nil)))
+
 ;; in XEmacs: device-type is tty on tty and stream in batch.
 (defun viper-window-display-p ()
   (and (viper-device-type) (not (memq (viper-device-type) '(tty stream pc)))))
   :tag "Is it VMS?"
   :group 'viper-misc)
 
+(defcustom viper-suppress-input-method-change-message nil
+  "If t, the message notifying about changes in the input method is not displayed.
+Normally, a message is displayed each time on enters the vi, insert or replace
+state."
+  :type 'boolean
+  :group 'viper-misc)
+
 (defcustom viper-force-faces nil
   "If t, Viper will think that it is running on a display that supports faces.
 This is provided as a temporary relief for users of graphics-capable terminals
@@ -74,6 +115,7 @@ In all likelihood, you don't need to bother with this setting."
 (defun viper-has-face-support-p ()
   (cond ((viper-window-display-p))
        (viper-force-faces)
+       ((viper-color-display-p))
        (viper-emacs-p (memq (viper-device-type) '(pc)))
        (viper-xemacs-p (memq (viper-device-type) '(tty pc)))))
 
@@ -81,52 +123,48 @@ In all likelihood, you don't need to bother with this setting."
 ;;; Macros
 
 (defmacro viper-deflocalvar (var default-value &optional documentation)
-  (` (progn
-       (defvar (, var) (, default-value)
-              (, (format "%s\n\(buffer local\)" documentation)))
-       (make-variable-buffer-local '(, var))
-     )))
+  `(progn
+    (defvar ,var ,default-value
+      ,(format "%s\n\(buffer local\)" documentation))
+    (make-variable-buffer-local ',var)))
 
 ;; (viper-loop COUNT BODY) Execute BODY COUNT times.
 (defmacro viper-loop (count &rest body)
-  (` (let ((count (, count)))
-       (while (> count 0)
-        (progn
-          (,@ body)
-          (setq count (1- count))
-          ))
-       )))
+  `(let ((count ,count))
+    (while (> count 0)
+      ,@body
+      (setq count (1- count)))))
 
 (defmacro viper-buffer-live-p (buf)
-  (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf))))))
-  
+  `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
+
 ;; return buffer-specific macro definition, given a full macro definition
 (defmacro viper-kbd-buf-alist (macro-elt)
-  (` (nth 1 (, macro-elt))))
+  `(nth 1 ,macro-elt))
 ;; get a pair: (curr-buffer . macro-definition)
 (defmacro viper-kbd-buf-pair (macro-elt)
-  (` (assoc (buffer-name) (viper-kbd-buf-alist (, macro-elt)))))
+  `(assoc (buffer-name) (viper-kbd-buf-alist ,macro-elt)))
 ;; get macro definition for current buffer
 (defmacro viper-kbd-buf-definition (macro-elt)
-  (` (cdr (viper-kbd-buf-pair (, macro-elt)))))
-  
+  `(cdr (viper-kbd-buf-pair ,macro-elt)))
+
 ;; return mode-specific macro definitions, given a full macro definition
 (defmacro viper-kbd-mode-alist (macro-elt)
-  (` (nth 2 (, macro-elt))))
+  `(nth 2 ,macro-elt))
 ;; get a pair: (major-mode . macro-definition)
 (defmacro viper-kbd-mode-pair (macro-elt)
-  (` (assoc major-mode (viper-kbd-mode-alist (, macro-elt)))))
+  `(assoc major-mode (viper-kbd-mode-alist ,macro-elt)))
 ;; get macro definition for the current major mode
 (defmacro viper-kbd-mode-definition (macro-elt)
-  (` (cdr (viper-kbd-mode-pair (, macro-elt)))))
-  
+  `(cdr (viper-kbd-mode-pair ,macro-elt)))
+
 ;; return global macro definition, given a full macro definition
 (defmacro viper-kbd-global-pair (macro-elt)
-  (` (nth 3 (, macro-elt))))
+  `(nth 3 ,macro-elt))
 ;; get global macro definition from an elt of macro-alist
 (defmacro viper-kbd-global-definition (macro-elt)
-  (` (cdr (viper-kbd-global-pair (, macro-elt)))))
-  
+  `(cdr (viper-kbd-global-pair ,macro-elt)))
+
 ;; last elt of a sequence
 (defsubst viper-seq-last-elt (seq)
   (elt seq (1- (length seq))))
@@ -143,12 +181,12 @@ In all likelihood, you don't need to bother with this setting."
   (if (eq direction 'forward)
       (char-after (+ (point) offset))
     (char-before (- (point) offset))))
-  
+
 \f
 (defvar viper-minibuffer-overlay-priority 300)
 (defvar viper-replace-overlay-priority 400)
 (defvar viper-search-overlay-priority 500)
-  
+
 \f
 ;;; Viper minor modes
 
@@ -157,7 +195,7 @@ In all likelihood, you don't need to bother with this setting."
 
 (viper-deflocalvar viper-vi-basic-minor-mode nil
   "Viper's minor mode for Vi bindings.")
-  
+
 (viper-deflocalvar viper-vi-local-user-minor-mode nil
   "Auxiliary minor mode for user-defined local bindings in Vi state.")
 
@@ -205,24 +243,24 @@ the Ex command :map!.")
   "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
   "Minor mode for local user bindings effective in Emacs state.
 Users can use it to override Emacs bindings when Viper is in its Emacs
-state.")  
-  
+state.")
+
 (viper-deflocalvar viper-emacs-global-user-minor-mode nil
   "Minor mode for global user bindings in effect in Emacs state.
 Users can use it to override Emacs bindings when Viper is in its Emacs
-state.")  
+state.")
 
 (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
@@ -235,7 +273,7 @@ that deletes a file.")
 
 (viper-deflocalvar viper-insert-minibuffer-minor-mode nil
    "Minor mode that forces Vi-style when the Minibuffer is in Insert state.")
-  
+
 \f
 
 ;; Some common error messages
@@ -253,7 +291,7 @@ that deletes a file.")
 (defconst viper-FirstAddrExceedsSecond "First address exceeds second"   "")
 (defconst viper-NoFileSpecified "No file specified"   "")
 
-;; Is t until viper-mode executes for the very first time. 
+;; Is t until viper-mode executes for the very first time.
 ;; Prevents recursive descend into startup messages.
 (defvar viper-first-time t)
 
@@ -265,7 +303,7 @@ The minor mode viper-insert-diehard-minor-mode is in effect when
 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)
 
@@ -274,19 +312,19 @@ Use `M-x viper-set-expert-level' to change this.")
 
 ;; 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
 (defun viper-activate-input-method-action ()
   (if (null viper-mule-hook-flag)
@@ -295,19 +333,22 @@ Use `M-x viper-set-expert-level' to change this.")
     ;; turn off special input methods in vi-state
     (if (eq viper-current-state 'vi-state)
        (viper-set-input-method nil))
-    (if (memq viper-current-state '(vi-state insert-state replace-state))
+    (if (and (memq viper-current-state '(vi-state insert-state replace-state))
+            (not viper-suppress-input-method-change-message))
        (message "Viper special input method%s: on"
                 (if (or current-input-method default-input-method)
-                    (format " %S" 
+                    (format " %S"
                             (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)
       ()
     (setq viper-special-input-method nil)
-    (if (memq viper-current-state '(vi-state insert-state replace-state))
+    (if (and (memq viper-current-state '(vi-state insert-state replace-state))
+            (not viper-suppress-input-method-change-message))
        (message "Viper special input method%s: off"
                 (if (or current-input-method default-input-method)
                     (format " %S"
@@ -319,7 +360,7 @@ Use `M-x viper-set-expert-level' to change this.")
         (inactivate-input-method))
        ((and viper-xemacs-p (boundp 'current-input-method))
         ;; XEmacs had broken quil-mode for some time, so we are working around
-        ;; it here 
+        ;; it here
         (setq quail-mode nil)
         (if (featurep 'quail)
             (quail-delete-overlays))
@@ -331,13 +372,13 @@ Use `M-x viper-set-expert-level' to change this.")
 (defun viper-activate-input-method ()
   (cond ((and viper-emacs-p (fboundp 'activate-input-method))
         (activate-input-method default-input-method))
-       ((and viper-xemacs-p (fboundp 'quail-mode))
-        (quail-mode 1))))
+       ((featurep 'xemacs)
+        (if (fboundp 'quail-mode) (quail-mode 1)))))
 
 ;; Set quail-mode to ARG
 (defun viper-set-input-method (arg)
   (setq viper-mule-hook-flag t) ; just a precaution
-  (let (viper-mule-hook-flag) ; temporarily inactivate viper mule hooks
+  (let (viper-mule-hook-flag) ; temporarily deactivate viper mule hooks
     (cond ((and arg (> (prefix-numeric-value arg) 0) default-input-method)
           ;; activate input method
           (viper-activate-input-method))
@@ -353,34 +394,28 @@ Use `M-x viper-set-expert-level' to change this.")
 (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"
-  :group 'viper)  
+  :group 'viper)
 
 ;; 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
 ;; 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.
@@ -398,14 +433,31 @@ delete the text being replaced, as in standard Vi."
   "*Cursor color when Viper is in Replace state."
   :type 'string
   :group 'viper)
+(if (fboundp 'make-variable-frame-local)
+    (make-variable-frame-local 'viper-replace-overlay-cursor-color))
+
 (defcustom viper-insert-state-cursor-color "Green"
   "Cursor color when Viper is in insert state."
   :type 'string
   :group 'viper)
+(if (fboundp 'make-variable-frame-local)
+    (make-variable-frame-local 'viper-insert-state-cursor-color))
+
+;; viper-emacs-state-cursor-color doesn't work well. Causes cursor colors to be
+;; confused in some cases. So, this var is nulled for now.
+;; (defcustom viper-emacs-state-cursor-color "Magenta"
+(defcustom viper-emacs-state-cursor-color nil
+  "Cursor color when Viper is in Emacs state."
+  :type 'string
+  :group 'viper)
+(if (fboundp 'make-variable-frame-local)
+    (make-variable-frame-local 'viper-emacs-state-cursor-color))
+
+;; internal var, used to remember the default cursor color of emacs frames
+(defvar viper-vi-state-cursor-color nil)
+(if (fboundp 'make-variable-frame-local)
+    (make-variable-frame-local 'viper-vi-state-cursor-color))
 
-;; place to save cursor colow when switching to insert mode
-(viper-deflocalvar viper-saved-cursor-color nil "")
-  
 (viper-deflocalvar viper-replace-overlay nil "")
 (put 'viper-replace-overlay 'permanent-local t)
 
@@ -421,27 +473,35 @@ It is used only with TTYs or if `viper-use-replace-region-delimiters'
 is non-nil."
   :type 'string
   :group 'viper)
-(defcustom viper-use-replace-region-delimiters 
+(defcustom viper-use-replace-region-delimiters
   (or (not (viper-has-face-support-p))
       (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)
-  
+
+(defcustom viper-read-buffer-function 'read-buffer
+  "Function to use for prompting the user for a buffer name."
+  :type 'symbol
+  :group 'viper)
+
 ;; XEmacs requires glyphs
-(if viper-xemacs-p
-    (progn
-      (or (glyphp viper-replace-region-end-delimiter)
-         (setq viper-replace-region-end-delimiter
-               (make-glyph viper-replace-region-end-delimiter)))
-      (or (glyphp viper-replace-region-start-delimiter)
-         (setq viper-replace-region-start-delimiter
-               (make-glyph viper-replace-region-start-delimiter)))
-      ))
-      
-  
+(viper-cond-compile-for-xemacs-or-emacs
+ (progn ; xemacs
+   (or (glyphp viper-replace-region-end-delimiter)
+       (setq viper-replace-region-end-delimiter
+            (make-glyph viper-replace-region-end-delimiter)))
+   (or (glyphp viper-replace-region-start-delimiter)
+       (setq viper-replace-region-start-delimiter
+            (make-glyph viper-replace-region-start-delimiter)))
+   )
+  nil ; emacs
+ )
+
+
+
 ;; These are local marker that must be initialized to nil and moved with
 ;; `viper-move-marker-locally'
 ;;
@@ -454,12 +514,12 @@ color displays. By default, the delimiters are used only on TTYs."
 
 (viper-deflocalvar viper-sitting-in-replace nil "")
 (put 'viper-sitting-in-replace 'permanent-local t)
-  
+
 ;; Remember the number of characters that have to be deleted in replace
 ;; 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).
@@ -474,7 +534,7 @@ text."
   :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 "")
@@ -485,27 +545,40 @@ text."
   :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
-will make it hard to use Vi-stile timeout macros."
+Setting this too high may slow down your typing.  Setting this value too low
+will make it hard to use Vi-style 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
   :group 'viper-misc)
 
+(defcustom viper-translate-all-ESC-keysequences (not (viper-window-display-p))
+  "Allow translation of all key sequences into commands.
+Normally, Viper lets Emacs translate only those ESC key sequences that are
+defined in the low-level key-translation-map or function-key-map, such as those
+emitted by the arrow and function keys. Other sequences, e.g., \\e/, are
+treated as ESC command followed by a `/'. This is done for people who type fast
+and tend to hit other characters right after they hit ESC. Other people like
+Emacs to translate ESC sequences all the time.
+The default is to translate all sequences only when using a dumb terminal.
+This permits you to use ESC as a meta key in insert mode."
+  :type 'boolean
+  :group 'viper-misc)
+
 ;; Modes and related variables
 
 ;; Current mode.  One of: `emacs-state', `vi-state', `insert-state'
@@ -536,13 +609,15 @@ This is a buffer-local variable."
 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)
 
 (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)
 
@@ -554,7 +629,7 @@ This is useful for doing repeated changes with the '.' key.
 The user can change this to nil, if she likes when the cursor moves
 to a new place after repeating previous Vi command."
   :type 'boolean
-  :group 'viper) 
+  :group 'viper)
 
 ;; Remember insert point as a marker.  This is a local marker that must be
 ;; initialized to nil and moved with `viper-move-marker-locally'.
@@ -566,17 +641,17 @@ to a new place after repeating previous Vi command."
 ;; 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)
@@ -584,12 +659,12 @@ to a new place after repeating previous Vi command."
 
 ;; This is used for saving inserted text.
 (defvar viper-last-insertion  nil)
-  
+
 ;; Remembers the last replaced region.
 (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)
@@ -667,7 +742,7 @@ negative number."
   :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)
@@ -690,7 +765,7 @@ If nil, these commands cross line boundaries."
 `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
@@ -711,7 +786,7 @@ If nil, the cursor will move backwards without deleting anything."
   :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)
 
@@ -720,7 +795,7 @@ If nil, the cursor will move backwards without deleting anything."
   :type 'boolean
   :tag "Search Wraps Around"
   :group 'viper-search)
-  
+
 (viper-deflocalvar viper-related-files-and-buffers-ring nil "")
 (defcustom viper-related-files-and-buffers-ring nil
   "*List of file and buffer names that are considered to be related to the current buffer.
@@ -738,22 +813,22 @@ Related buffers can be cycled through via :R and :P commands."
 (viper-deflocalvar viper-search-overlay nil)
 
 
-(defvar viper-heading-start 
+(defvar viper-heading-start
   (concat "^\\s-*(\\s-*defun\\s-\\|"                           ; lisp
          "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|"         ; C/C++
          "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|"
          "^\\\\[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 
+(defvar viper-heading-end
   (concat "^}\\|"                                              ; C/C++
          "^\\\\end{\\|"                                        ; latex
          "^@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 `.
@@ -782,7 +857,7 @@ Related buffers can be cycled through via :R and :P commands."
 (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.
@@ -791,189 +866,72 @@ Related buffers can be cycled through via :R and :P commands."
 \f
 ;;; Face-saving tricks
 
-;;(defcustom viper-replace-overlay-pixmap "gray3"
-;;  "Pixmap to use for search face on non-color displays."
-;;  :type 'string
-;;  :group 'viper)
-;;(defcustom viper-search-face-pixmap "gray3"
-;;  "Pixmap to use for search face on non-color displays."
-;;  :type 'string
-;;  :group 'viper)
-
-(defun viper-hide-face (face)
-  (if (and (viper-has-face-support-p) viper-emacs-p)
-      (add-to-list 'facemenu-unlisted-faces face)))
-
-
 (defgroup viper-highlighting nil
   "Hilighting of replace region, search pattern, minibuffer, etc."
   :prefix "viper-"
   :group 'viper)
 
-;;(defvar viper-search-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;     (make-face 'viper-search-face)
-;;     (or (face-differs-from-default-p 'viper-search-face)
-;;         ;; face wasn't set in .viper or .Xdefaults
-;;         (if (viper-can-use-colors "Black" "khaki")
-;;             (progn
-;;               (set-face-background 'viper-search-face "khaki")
-;;               (set-face-foreground 'viper-search-face "Black"))
-;;           (set-face-underline-p 'viper-search-face t)
-;;           (viper-set-face-pixmap 'viper-search-face
-;;                                  viper-search-face-pixmap))) 
-;;     'viper-search-face))
-;;  "*Face used to flash out the search pattern.")
-
-(defface viper-search-face
+
+(defface viper-search
   '((((class color)) (:foreground "Black" :background "khaki"))
     (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.
-(defvar viper-search-face 'viper-search-face
+;; An internal variable.  Viper takes the face from here.
+(defvar viper-search-face 'viper-search
   "Face used to flash out the search pattern.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-search-face'
+DO NOT CHANGE this variable.  Instead, use the customization widget
+to customize the actual face object `viper-search'
 this variable represents.")
-(viper-hide-face 'viper-search-face)
-  
-;;(defvar viper-replace-overlay-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;     (make-face 'viper-replace-overlay-face)
-;;     (or (face-differs-from-default-p 'viper-replace-overlay-face)
-;;         (progn
-;;           (if (viper-can-use-colors "darkseagreen2" "Black")
-;;               (progn
-;;                 (set-face-background
-;;                  'viper-replace-overlay-face "darkseagreen2")
-;;                 (set-face-foreground 'viper-replace-overlay-face "Black")))
-;;           (set-face-underline-p 'viper-replace-overlay-face t)
-;;           (viper-set-face-pixmap
-;;            'viper-replace-overlay-face viper-replace-overlay-pixmap)))
-;;     'viper-replace-overlay-face))
-;;  "*Face for highlighting replace regions on a window display.")
-
-(defface viper-replace-overlay-face
+
+(defface viper-replace-overlay
   '((((class color)) (:foreground "Black" :background "darkseagreen2"))
     (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.
-(defvar viper-replace-overlay-face 'viper-replace-overlay-face
+;; An internal variable.  Viper takes the face from here.
+(defvar viper-replace-overlay-face 'viper-replace-overlay
   "Face for highlighting replace regions on a window display.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-replace-overlay-face'
+DO NOT CHANGE this variable.  Instead, use the customization widget
+to customize the actual face object `viper-replace-overlay'
 this variable represents.")
-(viper-hide-face 'viper-replace-overlay-face)
-
-;;(defvar viper-minibuffer-emacs-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;     (make-face 'viper-minibuffer-emacs-face)
-;;     (or (face-differs-from-default-p 'viper-minibuffer-emacs-face)
-;;         ;; face wasn't set in .viper or .Xdefaults
-;;         (if viper-vi-style-in-minibuffer
-;;             ;; emacs state is an exception in the minibuffer
-;;             (if (viper-can-use-colors "darkseagreen2" "Black")
-;;                 (progn
-;;                   (set-face-background
-;;                    'viper-minibuffer-emacs-face "darkseagreen2")
-;;                   (set-face-foreground
-;;                    'viper-minibuffer-emacs-face "Black"))
-;;               (copy-face 'modeline 'viper-minibuffer-emacs-face))
-;;           ;; emacs state is the main state in the minibuffer
-;;           (if (viper-can-use-colors "Black" "pink")
-;;               (progn
-;;                 (set-face-background 'viper-minibuffer-emacs-face "pink") 
-;;                 (set-face-foreground
-;;                  'viper-minibuffer-emacs-face "Black"))
-;;             (copy-face 'italic 'viper-minibuffer-emacs-face))
-;;           ))
-;;     'viper-minibuffer-emacs-face))
-;;  "Face used in the Minibuffer when it is in Emacs state.")
-
-(defface viper-minibuffer-emacs-face
+
+(defface viper-minibuffer-emacs
   '((((class color)) (:foreground "Black" :background "darkseagreen2"))
-    (t (:bold t)))
+    (t (:weight bold)))
   "Face used in the Minibuffer when it is in Emacs state."
   :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
-(defvar viper-minibuffer-emacs-face 'viper-minibuffer-emacs-face
+;; An internal variable.  Viper takes the face from here.
+(defvar viper-minibuffer-emacs-face 'viper-minibuffer-emacs
   "Face used in the Minibuffer when it is in Emacs state.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-minibuffer-emacs-face'
+DO NOT CHANGE this variable.  Instead, use the customization widget
+to customize the actual face object `viper-minibuffer-emacs'
 this variable represents.")
-(viper-hide-face 'viper-minibuffer-emacs-face)
-    
-;;(defvar viper-minibuffer-insert-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;     (make-face 'viper-minibuffer-insert-face)
-;;     (or (face-differs-from-default-p 'viper-minibuffer-insert-face)
-;;         (if viper-vi-style-in-minibuffer
-;;             (if (viper-can-use-colors "Black" "pink")
-;;                 (progn
-;;                   (set-face-background 'viper-minibuffer-insert-face "pink") 
-;;                   (set-face-foreground
-;;                    'viper-minibuffer-insert-face "Black"))
-;;               (copy-face 'italic 'viper-minibuffer-insert-face))
-;;           ;; If Insert state is an exception
-;;           (if (viper-can-use-colors "darkseagreen2" "Black")
-;;               (progn
-;;                 (set-face-background
-;;                  'viper-minibuffer-insert-face "darkseagreen2")
-;;                 (set-face-foreground
-;;                  'viper-minibuffer-insert-face "Black"))
-;;             (copy-face 'modeline 'viper-minibuffer-insert-face))
-;;           (viper-italicize-face 'viper-minibuffer-insert-face)))
-;;     'viper-minibuffer-insert-face))
-;;  "Face used in the Minibuffer when it is in Insert state.")
-
-(defface viper-minibuffer-insert-face
+
+(defface viper-minibuffer-insert
   '((((class color)) (:foreground "Black" :background "pink"))
-    (t (:italic t)))
+    (t (:slant italic)))
   "Face used in the Minibuffer when it is in Insert state."
   :group 'viper-highlighting)
-;; An internal variable. Viper takes the face from here.
-(defvar viper-minibuffer-insert-face 'viper-minibuffer-insert-face
+;; An internal variable.  Viper takes the face from here.
+(defvar viper-minibuffer-insert-face 'viper-minibuffer-insert
   "Face used in the Minibuffer when it is in Insert state.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-minibuffer-insert-face'
+DO NOT CHANGE this variable.  Instead, use the customization widget
+to customize the actual face object `viper-minibuffer-insert'
 this variable represents.")
-(viper-hide-face 'viper-minibuffer-insert-face)
-    
-;;(defvar viper-minibuffer-vi-face
-;;  (if (viper-has-face-support-p)
-;;      (progn
-;;     (make-face 'viper-minibuffer-vi-face)
-;;     (or (face-differs-from-default-p 'viper-minibuffer-vi-face)
-;;         (if viper-vi-style-in-minibuffer
-;;             (if (viper-can-use-colors "Black" "grey")
-;;                 (progn
-;;                   (set-face-background 'viper-minibuffer-vi-face "grey")
-;;                   (set-face-foreground 'viper-minibuffer-vi-face "Black"))
-;;               (copy-face 'bold 'viper-minibuffer-vi-face))
-;;           (copy-face 'bold 'viper-minibuffer-vi-face)
-;;           (invert-face 'viper-minibuffer-vi-face)))
-;;     'viper-minibuffer-vi-face))
-;;  "Face used in the Minibuffer when it is in Vi state.")
-
-(defface viper-minibuffer-vi-face
+
+(defface viper-minibuffer-vi
   '((((class color)) (:foreground "DarkGreen" :background "grey"))
     (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.
-(defvar viper-minibuffer-vi-face 'viper-minibuffer-vi-face
+;; An internal variable.  Viper takes the face from here.
+(defvar viper-minibuffer-vi-face 'viper-minibuffer-vi
   "Face used in the Minibuffer when it is in Vi state.
-DO NOT CHANGE this variable. Instead, use the customization widget
-to customize the actual face object `viper-minibuffer-vi-face'
+DO NOT CHANGE this variable.  Instead, use the customization widget
+to customize the actual face object `viper-minibuffer-vi'
 this variable represents.")
-(viper-hide-face 'viper-minibuffer-vi-face)
-    
+
 ;; the current face to be used in the minibuffer
 (viper-deflocalvar
   viper-minibuffer-current-face viper-minibuffer-emacs-face "")
@@ -994,6 +952,14 @@ this variable represents.")
   :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
@@ -1001,15 +967,16 @@ this variable represents.")
 Should be set in `~/.viper' file."
   :type 'boolean
   :group 'viper)
-  
+
 ;; 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.
-;; 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
 (defconst viper-vi-state-id    "<V> "
@@ -1027,31 +994,44 @@ Should be set in `~/.viper' file."
   :prefix "viper-"
   :group 'viper)
 
-(defcustom viper-vi-state-hook nil
+(defcustom viper-vi-state-hook 'viper-restore-cursor-type
   "*Hooks run just before the switch to Vi mode is completed."
   :type 'hook
   :group 'viper-hooks)
-(defcustom viper-insert-state-hook nil
+(defcustom viper-insert-state-hook 'viper-set-insert-cursor-type
   "*Hooks run just before the switch to Insert mode is completed."
   :type 'hook
   :group 'viper-hooks)
-(defcustom viper-replace-state-hook nil
+(defcustom viper-replace-state-hook 'viper-restore-cursor-type
   "*Hooks run just before the switch to Replace mode is completed."
   :type 'hook
   :group 'viper-hooks)
-(defcustom viper-emacs-state-hook nil
+(defcustom viper-emacs-state-hook 'viper-restore-cursor-type
   "*Hooks run just before the switch to Emacs mode is completed."
   :type 'hook
   :group 'viper-hooks)
-  
+
 (defcustom viper-load-hook nil
   "Hooks run just after loading Viper."
   :type 'hook
   :group 'viper-hooks)
-  
 
-;;; Local Variables:
-;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
-;;; End:
+(defun viper-restore-cursor-type ()
+  (condition-case nil
+      (if viper-xemacs-p
+         (set (make-local-variable 'bar-cursor) nil)
+       (setq cursor-type default-cursor-type))
+    (error nil)))
+
+(defun viper-set-insert-cursor-type ()
+  (if viper-xemacs-p
+      (set (make-local-variable 'bar-cursor) 2)
+    (setq cursor-type '(bar . 2))))
+
+
+;; Local Variables:
+;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
+;; End:
 
-;;;  viper-ex.el ends here
+;; arch-tag: 4efa2416-1fcb-4690-be10-1a2a0248d250
+;;; viper-init.el ends here