]> code.delx.au - gnu-emacs/blobdiff - lisp/vcursor.el
(normal-splash-screen, fancy-splash-screens-1): Add a reference to the Lisp
[gnu-emacs] / lisp / vcursor.el
index d4c13f4610330d682cb588dcf1fbc5c136be3b90..a9d3fd68d74a59ea44f141644cb9ffdcf554645b 100644 (file)
@@ -1,9 +1,11 @@
-;;; vcursor.el --- manipulate an alternative ("virtual") cursor.
+;;; vcursor.el --- manipulate an alternative ("virtual") cursor
 
-;; Copyright (C) 1994, 1996, 1998 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1996, 1998, 2002, 2003,
+;;   2004, 2005, 2006 Free Software Foundation, Inc.
 
-;; Author:   Peter Stephenson <pws@ifh.de>
-;; Keywords: virtual cursor, display, copying
+;; Author:   Peter Stephenson <pws@ibmth.df.unipi.it>
+;; Maintainer: FSF
+;; Keywords: virtual cursor, convenience
 
 ;; This file is part of GNU Emacs.
 
 
 ;; 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:
 
-;; Latest changes (1.6)
-;; ====================
+;; Latest changes
+;; ==============
 ;;
+;; - *IMPORTANT* vcursor-key-bindings is now nil by default, to avoid
+;;   side-effects when the package is loaded.  This means no keys are
+;;   bound by default.  Use customize to change it to t to restore
+;;   the old behaviour.  (If you do it by hand in .emacs, it
+;;   must come before vcursor is loaded.)
+;; - You can alter the main variables and the vcursor face via
+;;   M-x customize: go to the Editing group and find Vcursor.
+;; - vcursor-auto-disable can now be 'copy (actually any value not nil
+;;   or t), which means that copying from the vcursor will be turned
+;;   off after any operation not involving the vcursor, but the
+;;   vcursor itself will be left alone.
 ;; - works on dumb terminals with Emacs 19.29 and later
 ;; - new keymap vcursor-map for binding to a prefix key
 ;; - vcursor-compare-windows substantially improved
 ;; for more information.
 ;;
 ;; This is much easier to use than the instructions are to read.
-;; I suggest you simply load it and play around with holding down Ctrl
-;; and Shift and pressing up, down, left, right, tab, return, and see
-;; what happens.  (Find a scratch buffer before using C-S-tab: that
-;; toggles copying.)
+;; First, you need to let vcursor define some keys: setting
+;; vcursor-key-bindings to t before loading, or by customize, will
+;; define various keys with the prefix C-S.  You'll have to read
+;; further if you don't want this.  Then I suggest you simply load it
+;; and play around with holding down Ctrl and Shift and pressing up,
+;; down, left, right, tab, return, and see what happens.  (Find a
+;; scratch buffer before using C-S-tab: that toggles copying.)
 ;;
 ;; Most of the functions described in this documentation are in
 ;; parentheses so that if you have the package loaded you can type C-h
 ;; other alternatives (search for "Oemacs").  There is also a keymap
 ;; which you can bind to a prefix key, which may give some more
 ;; intuitive alternatives in some cases, see `The vcursor keymap' below.
-;; 
+;;
 ;; Holding down control and shift and pressing insert (vcursor-copy)
 ;; copies one character from wherever the virtual cursor is to point;
 ;; point and the virtual cursor advance in the separate and equal
 ;; station to which... (etc.).  M-C-S-return (vcursor-copy-line)
 ;; copies to the end of the line instead of just one character,
 ;; C-S-delete or C-S-remove (vcursor-copy-word) copies a word.
-;; 
+;;
 ;; A more general way of copying is to use C-S-tab, which is a toggle.
 ;; In the "on" state, moving the virtual cursor will copy the
 ;; moved-over text to the normal cursor position (including when going
 ;; window.  (See the function (vcursor-find-window) for details of how
 ;; this window is chosen.)  This gives you fingertip control over two
 ;; windows at once.
-;; 
+;;
 ;; C-S-return (vcursor-disable) disables the virtual cursor, removing
 ;; it so that it starts from point whenever you move it again --- note
 ;; that simply moving the cursor and virtual cursor on top of one
 ;; another does not have this effect.
-;; 
+;;
 ;; If you give C-S-return a positive prefix arg, it will also delete the
 ;; window (unless it's the current one).  Whenever the virtual cursor
 ;; goes off-screen in its own window, point in that window is moved as
 ;; remember the current cursor location for examining or copying from
 ;; that buffer.  (I just hit C-S-right C-S-left, but I'm a hopeless
 ;; lowbrow.)
-;; 
+;;
 ;; There is also C-S-f6 (vcursor-other-window) which behaves like
 ;; C-x o on the virtual rather than the real cursor, except that it
 ;; will create another window if necessary.
 ;;
 ;; If you set the variable vcursor-auto-disable, then any command
 ;; which does not involve moving or copying from the virtual cursor
-;; causes the virtual cursor to be disabled.  If you don't intend to
-;; use this, you can comment out the `add-hook' line at the bottom of
-;; this file.  (This feature partially emulates the way the "copy" key
-;; on the BBC micro worked; actually, the copy cursor was homed when
-;; you hit return.  This was in keeping with the line-by-line way of
-;; entering BASIC, but is less appropriate here.)
+;; causes the virtual cursor to be disabled.  If you set it to non-nil
+;; but not t, then the vcursor itself will remain active, but copying
+;; will be turned off, so that the next time the vcursor is moved no
+;; text is copied over.  Experience shows that this setting is
+;; particularly useful.  If you don't intend to use this, you can
+;; comment out the `add-hook' line at the bottom of this file.  (This
+;; feature partially emulates the way the "copy" key on the BBC micro
+;; worked; actually, the copy cursor was homed when you hit return.
+;; This was in keeping with the line-by-line way of entering BASIC,
+;; but is less appropriate here.)
 ;;
 ;; vcursor-compare-windows is now a reliable adaption of
 ;; compare-windows, which compares between point in the current buffer
 ;;
 ;; Key bindings
 ;; ============
-;; 
+;;
 ;; There is an alternative set of key bindings which will be used
 ;; automatically for a PC if Oemacs is detected.  This set uses separate
 ;; control, shift and meta keys with function keys 1 to 10.  In
 ;;
 ;; If Emacs has set the variable window-system to nil, vcursor will
 ;; assume that overlays cannot be displayed in a different face,
-;; and will instead use an string (the variable vcursor-string, by
+;; and will instead use a string (the variable vcursor-string, by
 ;; default "**>") to show its position.  This was first implemented
 ;; in Emacs 19.29.  Unlike the old-fashioned overlay arrow (as used
 ;; by debuggers), this appears between existing text, which can
 ;; get an easy key binding for the vcursor keys on a generic terminal.
 ;; Consequently a special keymap is defined for you to use traditional
 ;; methods: the keymap, however, is available on any terminal type.
-;; 
+;;
 ;; The vcursor keymap
 ;; ==================
 ;;
 ;; does something else.  To get this effect, set
 ;; vcursor-interpret-input to t.  This is normally not a good idea as
 ;; interpreting input is very much slower than copying text.
-;; 
+;;
 ;; Un-features
 ;; ===========
 ;;
 ;;  - The logic in vcursor-find-window is rather complicated and
 ;;    therefore bug-prone, though in practice it seems to work OK.
 ;;
-;; Possible enhnacements:
+;; Possible enhancements:
 ;; It would be easy to implement vcursor-push (save vcursor position
 ;; as mark and deactivate) and vcursor-pop (deactivate vcursor and
 ;; move to last pushed position) functions.
 
 ;;; Code:
 
+(eval-when-compile (require 'compare-w))
+
 (defgroup vcursor nil
   "Manipulate an alternative (\"virtual\") cursor."
   :prefix "vcursor-"
-  :group 'display)
+  :group 'editing)
 
-(or (memq 'vcursor (face-list))
-    (progn
-      (copy-face 'modeline 'vcursor)
-      (if (or (fboundp 'oemacs-version)
-             (and (eq window-system 'x) (x-display-color-p)))
-         (progn
-           (set-face-foreground 'vcursor "blue")
-           (set-face-background 'vcursor "cyan")))
-      (set-face-underline-p 'vcursor t)))
+(defface vcursor
+  '((((class color)) (:foreground "blue" :background "cyan" :underline t))
+    (t (:inverse-video t :underline t)))
+  "Face for the virtual cursor."
+  :group 'vcursor)
 
 (defcustom vcursor-auto-disable nil
   "*If non-nil, disable the virtual cursor after use.
-Any non-vcursor command will force `vcursor-disable' to be called."
-  :type 'boolean
+Any non-vcursor command will force `vcursor-disable' to be called.
+If non-nil but not t, just make sure copying is toggled off, but don't
+disable the vcursor."
+  :type '(choice (const t) (const nil) (const copy))
   :group 'vcursor)
 
-(defcustom vcursor-key-bindings t
-  "*How to bind keys when vcursor is loaded.
-If t (the default), guess; if xterm, use bindings suitable for an
-X terminal; if oemacs, use bindings which work on a PC with Oemacs.
-If nil, don't define any key bindings."
-  :type '(choice (const t) (const xterm) (const oemacs) (const nil))
+(defcustom vcursor-modifiers (list 'control 'shift)
+  "*A list of modifiers that are used to define vcursor key bindings."
+  :type '(repeat symbol)
   :group 'vcursor)
 
+;; Needed for defcustom, must be up here
+(defun vcursor-cs-binding (base &optional meta)
+  (vector (let ((key (append vcursor-modifiers (list (intern base)))))
+           (if meta
+               (cons 'meta key)
+             key))))
+
+(defun vcursor-bind-keys (var value)
+  "Alter the value of the variable VAR to VALUE, binding keys as required.
+VAR is usually `vcursor-key-bindings'.  Normally this function is called
+on loading vcursor and from the customize package."
+  (set var value)
+  (cond
+   ((not value));; don't set any key bindings
+   ((or (eq value 'oemacs)
+       (and (eq value t) (fboundp 'oemacs-version)))
+    (global-set-key [C-f1] 'vcursor-toggle-copy)
+    (global-set-key [C-f2] 'vcursor-copy)
+    (global-set-key [C-f3] 'vcursor-copy-word)
+    (global-set-key [C-f4] 'vcursor-copy-line)
+
+    (global-set-key [S-f1] 'vcursor-disable)
+    (global-set-key [S-f2] 'vcursor-other-window)
+    (global-set-key [S-f3] 'vcursor-goto)
+    (global-set-key [S-f4] 'vcursor-swap-point)
+
+    (global-set-key [C-f5] 'vcursor-backward-char)
+    (global-set-key [C-f6] 'vcursor-previous-line)
+    (global-set-key [C-f7] 'vcursor-next-line)
+    (global-set-key [C-f8] 'vcursor-forward-char)
+
+    (global-set-key [M-f5] 'vcursor-beginning-of-line)
+    (global-set-key [M-f6] 'vcursor-backward-word)
+    (global-set-key [M-f6] 'vcursor-forward-word)
+    (global-set-key [M-f8] 'vcursor-end-of-line)
+
+    (global-set-key [S-f5] 'vcursor-beginning-of-buffer)
+    (global-set-key [S-f6] 'vcursor-scroll-down)
+    (global-set-key [S-f7] 'vcursor-scroll-up)
+    (global-set-key [S-f8] 'vcursor-end-of-buffer)
+
+    (global-set-key [C-f9] 'vcursor-isearch-forward)
+
+    (global-set-key [S-f9] 'vcursor-execute-key)
+    (global-set-key [S-f10] 'vcursor-execute-command)
+
+;;; Partial dictionary of Oemacs key sequences for you to roll your own,
+;;; e.g C-S-up: (global-set-key "\M-[\C-f\M-\C-m" 'vcursor-previous-line)
+;;;    Sequence:         Sends:
+;;; "\M-[\C-f\M-\C-m"   C-S-up
+;;; "\M-[\C-f\M-\C-q"   C-S-down
+;;; "\M-[\C-fs"         C-S-left
+;;; "\M-[\C-ft"         C-S-right
+;;;
+;;; "\M-[\C-fw"         C-S-home
+;;; "\M-[\C-b\C-o"      S-tab
+;;; "\M-[\C-f\M-\C-r"   C-S-insert
+;;; "\M-[\C-fu"         C-S-end
+;;; "\M-[\C-f\M-\C-s"   C-S-delete
+;;; "\M-[\C-f\M-\C-d"   C-S-prior
+;;; "\M-[\C-fv"         C-S-next
+;;;
+;;; "\M-[\C-f^"         C-S-f1
+;;; "\M-[\C-f_"         C-S-f2
+;;; "\M-[\C-f`"         C-S-f3
+;;; "\M-[\C-fa"         C-S-f4
+;;; "\M-[\C-fb"         C-S-f5
+;;; "\M-[\C-fc"         C-S-f6
+;;; "\M-[\C-fd"         C-S-f7
+;;; "\M-[\C-fe"         C-S-f8
+;;; "\M-[\C-ff"         C-S-f9
+;;; "\M-[\C-fg"         C-S-f10
+    )
+   (t
+    (global-set-key (vcursor-cs-binding "up") 'vcursor-previous-line)
+    (global-set-key (vcursor-cs-binding "down") 'vcursor-next-line)
+    (global-set-key (vcursor-cs-binding "left") 'vcursor-backward-char)
+    (global-set-key (vcursor-cs-binding "right") 'vcursor-forward-char)
+
+    (global-set-key (vcursor-cs-binding "return") 'vcursor-disable)
+    (global-set-key (vcursor-cs-binding "insert")  'vcursor-copy)
+    (global-set-key (vcursor-cs-binding "delete") 'vcursor-copy-word)
+    (global-set-key (vcursor-cs-binding "remove") 'vcursor-copy-word)
+    (global-set-key (vcursor-cs-binding "tab") 'vcursor-toggle-copy)
+    (global-set-key (vcursor-cs-binding "backtab") 'vcursor-toggle-copy)
+    (global-set-key (vcursor-cs-binding "home") 'vcursor-beginning-of-buffer)
+    (global-set-key (vcursor-cs-binding "up" t) 'vcursor-beginning-of-buffer)
+    (global-set-key (vcursor-cs-binding "end") 'vcursor-end-of-buffer)
+    (global-set-key (vcursor-cs-binding "down" t) 'vcursor-end-of-buffer)
+    (global-set-key (vcursor-cs-binding "prior") 'vcursor-scroll-down)
+    (global-set-key (vcursor-cs-binding "next") 'vcursor-scroll-up)
+
+    (global-set-key (vcursor-cs-binding "f6") 'vcursor-other-window)
+    (global-set-key (vcursor-cs-binding "f7") 'vcursor-goto)
+
+    (global-set-key (vcursor-cs-binding "select")
+                   'vcursor-swap-point) ; DEC keyboards
+    (global-set-key (vcursor-cs-binding "tab" t) 'vcursor-swap-point)
+
+    (global-set-key (vcursor-cs-binding "find")
+                   'vcursor-isearch-forward) ; DEC keyboards
+    (global-set-key (vcursor-cs-binding "f8") 'vcursor-isearch-forward)
+
+    (global-set-key (vcursor-cs-binding "left" t) 'vcursor-beginning-of-line)
+    (global-set-key (vcursor-cs-binding "right" t) 'vcursor-end-of-line)
+
+    (global-set-key (vcursor-cs-binding "prior" t) 'vcursor-backward-word)
+    (global-set-key (vcursor-cs-binding "next" t) 'vcursor-forward-word)
+
+    (global-set-key (vcursor-cs-binding "return" t) 'vcursor-copy-line)
+
+    (global-set-key (vcursor-cs-binding "f9") 'vcursor-execute-key)
+    (global-set-key (vcursor-cs-binding "f10") 'vcursor-execute-command)
+    )))
+
+(defcustom vcursor-key-bindings nil
+  "*How to bind keys when vcursor is loaded.
+If t, guess; if `xterm', use bindings suitable for an X terminal; if
+`oemacs', use bindings which work on a PC with Oemacs.  If nil, don't
+define any key bindings.
+
+Default is nil."
+  :type '(choice (const t) (const nil) (const xterm) (const oemacs))
+  :group 'vcursor
+  :set 'vcursor-bind-keys
+  :version "20.3")
+
 (defcustom vcursor-interpret-input nil
   "*If non-nil, input from the vcursor is treated as interactive input.
 This will cause text insertion to be much slower.  Note that no special
@@ -346,7 +490,7 @@ characters.  The default is simply to copy strings."
   :group 'vcursor
   :version "20.3")
 
-(defvar vcursor-overlay nil 
+(defvar vcursor-overlay nil
   "Overlay for the virtual cursor.
 It is nil if that is not enabled.")
 
@@ -361,7 +505,7 @@ scrolling set this.  It is used by the `vcursor-auto-disable' code.")
 ;; could do some memq-ing with last-command instead, but this will
 ;; automatically handle any new commands using the primitives.
 
-(defcustom vcursor-copy-flag nil 
+(defcustom vcursor-copy-flag nil
   "*Non-nil means moving vcursor should copy characters moved over to point."
   :type 'boolean
   :group 'vcursor)
@@ -371,7 +515,7 @@ scrolling set this.  It is used by the `vcursor-auto-disable' code.")
 
 (defvar vcursor-use-vcursor-map nil
   "Non-nil if the vcursor map is mapped directly onto the main keymap.
-See vcursor-toggle-vcursor-map.")
+See `vcursor-toggle-vcursor-map'.")
 (make-variable-buffer-local 'vcursor-use-vcursor-map)
 
 (defvar vcursor-map nil "Keymap for vcursor command.")
@@ -406,105 +550,11 @@ See vcursor-toggle-vcursor-map.")
 (define-key vcursor-map "k" 'vcursor-execute-key)
 (define-key vcursor-map "\M-x" 'vcursor-execute-command)
 
-(cond
- ((not vcursor-key-bindings))  ;; don't set any key bindings
- ((or (eq vcursor-key-bindings 'oemacs)
-      (and (eq vcursor-key-bindings t) (fboundp 'oemacs-version)))
-  (global-set-key [C-f1] 'vcursor-toggle-copy)
-  (global-set-key [C-f2] 'vcursor-copy)
-  (global-set-key [C-f3] 'vcursor-copy-word)
-  (global-set-key [C-f4] 'vcursor-copy-line)
-
-  (global-set-key [S-f1] 'vcursor-disable)
-  (global-set-key [S-f2] 'vcursor-other-window)
-  (global-set-key [S-f3] 'vcursor-goto)
-  (global-set-key [S-f4] 'vcursor-swap-point)
-
-  (global-set-key [C-f5] 'vcursor-backward-char)
-  (global-set-key [C-f6] 'vcursor-previous-line)
-  (global-set-key [C-f7] 'vcursor-next-line)
-  (global-set-key [C-f8] 'vcursor-forward-char)
-
-  (global-set-key [M-f5] 'vcursor-beginning-of-line)
-  (global-set-key [M-f6] 'vcursor-backward-word)
-  (global-set-key [M-f6] 'vcursor-forward-word)
-  (global-set-key [M-f8] 'vcursor-end-of-line)
-
-  (global-set-key [S-f5] 'vcursor-beginning-of-buffer)
-  (global-set-key [S-f6] 'vcursor-scroll-down)
-  (global-set-key [S-f7] 'vcursor-scroll-up)
-  (global-set-key [S-f8] 'vcursor-end-of-buffer)
-
-  (global-set-key [C-f9] 'vcursor-isearch-forward)
-
-  (global-set-key [S-f9] 'vcursor-execute-key)
-  (global-set-key [S-f10] 'vcursor-execute-command)
-
-;;; Partial dictionary of Oemacs key sequences for you to roll your own,
-;;; e.g C-S-up: (global-set-key "\M-[\C-f\M-\C-m" 'vcursor-previous-line)
-;;;    Sequence:         Sends:
-;;; "\M-[\C-f\M-\C-m"   C-S-up
-;;; "\M-[\C-f\M-\C-q"   C-S-down
-;;; "\M-[\C-fs"         C-S-left
-;;; "\M-[\C-ft"         C-S-right
-;;;
-;;; "\M-[\C-fw"         C-S-home
-;;; "\M-[\C-b\C-o"      S-tab
-;;; "\M-[\C-f\M-\C-r"   C-S-insert
-;;; "\M-[\C-fu"         C-S-end
-;;; "\M-[\C-f\M-\C-s"   C-S-delete
-;;; "\M-[\C-f\M-\C-d"   C-S-prior
-;;; "\M-[\C-fv"         C-S-next
-;;;                      
-;;; "\M-[\C-f^"         C-S-f1
-;;; "\M-[\C-f_"         C-S-f2
-;;; "\M-[\C-f`"         C-S-f3
-;;; "\M-[\C-fa"         C-S-f4
-;;; "\M-[\C-fb"         C-S-f5
-;;; "\M-[\C-fc"         C-S-f6
-;;; "\M-[\C-fd"         C-S-f7
-;;; "\M-[\C-fe"         C-S-f8
-;;; "\M-[\C-ff"         C-S-f9
-;;; "\M-[\C-fg"         C-S-f10
-  )
- (t
-  (global-set-key [C-S-up] 'vcursor-previous-line)
-  (global-set-key [C-S-down] 'vcursor-next-line)
-  (global-set-key [C-S-left] 'vcursor-backward-char)
-  (global-set-key [C-S-right] 'vcursor-forward-char)
-   
-  (global-set-key [C-S-return] 'vcursor-disable)
-  (global-set-key [C-S-insert]  'vcursor-copy)
-  (global-set-key [C-S-delete] 'vcursor-copy-word)
-  (global-set-key [C-S-remove] 'vcursor-copy-word)
-  (global-set-key [C-S-tab] 'vcursor-toggle-copy)
-  (global-set-key [C-S-home] 'vcursor-beginning-of-buffer)
-  (global-set-key [M-C-S-up] 'vcursor-beginning-of-buffer)
-  (global-set-key [C-S-end] 'vcursor-end-of-buffer)
-  (global-set-key [M-C-S-down] 'vcursor-end-of-buffer)
-  (global-set-key [C-S-prior] 'vcursor-scroll-down)
-  (global-set-key [C-S-next] 'vcursor-scroll-up)
-   
-  (global-set-key [C-S-f6] 'vcursor-other-window)
-  (global-set-key [C-S-f7] 'vcursor-goto)
-
-  (global-set-key [C-S-select] 'vcursor-swap-point) ; DEC keyboards
-  (global-set-key [M-C-S-tab] 'vcursor-swap-point)
-
-  (global-set-key [C-S-find] 'vcursor-isearch-forward) ; DEC keyboards
-  (global-set-key [C-S-f8] 'vcursor-isearch-forward)
-
-  (global-set-key [M-C-S-left] 'vcursor-beginning-of-line)
-  (global-set-key [M-C-S-right] 'vcursor-end-of-line)
-
-  (global-set-key [M-C-S-prior] 'vcursor-backward-word)
-  (global-set-key [M-C-S-next] 'vcursor-forward-word)
-
-  (global-set-key [M-C-S-return] 'vcursor-copy-line)
-
-  (global-set-key [C-S-f9] 'vcursor-execute-key)
-  (global-set-key [C-S-f10] 'vcursor-execute-command)
-  ))
+;; If vcursor-key-bindings is already set on loading, bind the keys now.
+;; This hybrid way of doing it retains compatibility while allowing
+;; customize to work smoothly.
+(if vcursor-key-bindings
+    (vcursor-bind-keys 'vcursor-key-bindings vcursor-key-bindings))
 
 (defun vcursor-locate ()
   "Go to the starting point of the virtual cursor.
@@ -526,7 +576,7 @@ With optional NOT-THIS non-nil never return the current window.
 
 With NEW-WIN non-nil, display the virtual cursor buffer in another
 window if the virtual cursor is not currently visible \(note, however,
-that this function never changes window-point\).
+that this function never changes `window-point'\).
 
 With THIS-FRAME non-nil, don't search other frames for a new window
 \(though if the vcursor is already off-frame then its current window is
@@ -555,7 +605,7 @@ Set `vcursor-window' to the returned value as a side effect."
               (pos-visible-in-window-p (point) vcursor-window))
          (progn
            (walk-windows
-            (function 
+            (function
              (lambda (win)
                (and (not winok)
                     (eq (current-buffer) (window-buffer win))
@@ -608,6 +658,7 @@ another window.  With LEAVE-W, use the current `vcursor-window'."
        (move-overlay vcursor-overlay pt (+ pt 1) (current-buffer))
       (setq vcursor-overlay (make-overlay pt (+ pt 1)))
       (or window-system
+         (display-color-p)
          (overlay-put vcursor-overlay 'before-string vcursor-string))
       (overlay-put vcursor-overlay 'face 'vcursor))
     (or leave-w (vcursor-find-window nil t))
@@ -624,15 +675,15 @@ another window.  With LEAVE-W, use the current `vcursor-window'."
     (insert text))
   )
 
-(defun vcursor-relative-move (fn &rest args)
-  "Use FUNCTION with arbitrary ARG1 ... to move the virtual cursor.
+(defun vcursor-relative-move (func &rest args)
+  "Call FUNC with arbitrary ARGS ... to move the virtual cursor.
 
 This is called by most of the virtual-cursor motion commands."
   (let (text opoint)
     (save-excursion
       (vcursor-locate)
       (setq opoint (point))
-      (apply fn args)
+      (apply func args)
       (and (eq opoint (point-max)) (eq opoint (point))
           (signal 'end-of-buffer nil))
       (vcursor-move (point))
@@ -680,7 +731,7 @@ The vcursor will always appear in an unselected window."
 )
 
 (defun vcursor-scroll-down (&optional n)
-  "Scroll down the vcursor window ARG lines or near-full screen if none.
+  "Scroll down the vcursor window ARG lines or near full screen if none.
 The vcursor will always appear in an unselected window."
 
   (interactive "P")
@@ -741,10 +792,10 @@ is visible in the current one."
   (setq vcursor-last-command t)
   )
 
-(defun vcursor-get-char-count (fn &rest args)
-  "Apply FN to ARG1 ... and return the number of characters moved.
-Point is temporarily set to the virtual cursor position before FN is
-called.
+(defun vcursor-get-char-count (func &rest args)
+  "Apply FUNC to ARGS ... and return the number of characters moved.
+Point is temporarily set to the virtual cursor position before FUNC
+is called.
 
 This is called by most of the virtual-cursor copying commands to find
 out how much to copy."
@@ -753,7 +804,7 @@ out how much to copy."
   (save-excursion
     (set-buffer (overlay-buffer vcursor-overlay))
     (let ((start (goto-char (overlay-start vcursor-overlay))))
-      (- (progn (apply fn args) (point)) start)))
+      (- (progn (apply func args) (point)) start)))
   )
 
 ;; Make sure the virtual cursor is active.  Unless arg is non-nil,
@@ -763,7 +814,7 @@ out how much to copy."
    ((and (overlayp vcursor-overlay) (overlay-start vcursor-overlay))
     t)
    (arg nil)
-   (t (error "The virtual cursor is not active now.")))
+   (t (error "The virtual cursor is not active now")))
   )
 
 (defun vcursor-disable (&optional arg)
@@ -772,13 +823,12 @@ Next time you use it, it will start from point.
 
 With a positive prefix ARG, the first window in cyclic order
 displaying the virtual cursor (or which was recently displaying the
-virutal cursor) will be deleted unless it's the selected
-window.
+virtual cursor) will be deleted unless it's the selected window.
 
 With a negative prefix argument, enable the virtual cursor: make it
 active at the same point as the real cursor.
 
-Copying mode is always turned off:  the next use of the vcursor will
+Copying mode is always turned off: the next use of the vcursor will
 not copy text until you turn it on again."
 
   (interactive "P")
@@ -800,11 +850,11 @@ not copy text until you turn it on again."
 
 (defun vcursor-other-window (n &optional all-frames)
   "Activate the virtual cursor in another window.
-This is the next window cylically after one currently showing the
+This is the next window cyclically after one currently showing the
 virtual cursor, or else after the current selected window.  If there
 is no other window, the current window is split.
 
-Arguments N and optional ALL-FRAMES are the same as with other-window.
+Arguments N and optional ALL-FRAMES are the same as with `other-window'.
 ALL-FRAMES is also used to decide whether to split the window."
 
   (interactive "p")
@@ -992,7 +1042,7 @@ ARG is as for `end-of-line'."
 
 (defun vcursor-beginning-of-buffer (&optional arg)
   "Move the virtual cursor to the beginning of its buffer.
-ARG is as for beginning-of-buffer."
+ARG is as for `beginning-of-buffer'."
   (interactive "P")
   (vcursor-relative-move
    (lambda (arg)
@@ -1003,7 +1053,7 @@ ARG is as for beginning-of-buffer."
 
 (defun vcursor-end-of-buffer (&optional arg)
   "Move the virtual cursor to the end of its buffer.
-ARG is as for end-of-buffer.
+ARG is as for `end-of-buffer'.
 
 Actually, the vcursor is moved to the second from last character or it
 would be invisible."
@@ -1066,7 +1116,7 @@ is called interactively, so prefix argument etc. are usable."
   "Copy up to ARGth line after virtual cursor position.
 With no argument, copy to the end of the current line.
 
-Behaviour with regard to newlines is similar (but not identical) to
+Behavior with regard to newlines is similar (but not identical) to
 `kill-line'; the main difference is that whitespace at the end of the
 line is treated like ordinary characters."
 
@@ -1079,7 +1129,7 @@ line is treated like ordinary characters."
 (defun vcursor-toggle-vcursor-map (&optional force noredisp)
   "Toggle the state of the vcursor key map.
 When on, the keys defined in it are mapped directly on top of the main
-keymap,  allowing you to move the vcursor with ordinary motion keys.
+keymap, allowing you to move the vcursor with ordinary motion keys.
 An indication \"!VC\" appears in the mode list.  The effect is
 local to the current buffer.
 With prefix FORCE, turn on, or off if it is 0.
@@ -1105,7 +1155,10 @@ Disabling the vcursor automatically turns this off."
 
 (defun vcursor-post-command ()
   (and vcursor-auto-disable (not vcursor-last-command)
-       vcursor-overlay (vcursor-disable))
+       vcursor-overlay
+       (if (eq vcursor-auto-disable t)
+          (vcursor-disable)
+        (vcursor-toggle-copy -1 t)))
   (setq vcursor-last-command nil)
   )
 
@@ -1113,4 +1166,5 @@ Disabling the vcursor automatically turns this off."
 
 (provide 'vcursor)
 
-;; vcursor.el ends here
+;;; arch-tag: cdfe1cdc-2c46-4046-88e4-ed57d20f7aca
+;;; vcursor.el ends here