*** empty log message ***
[bpt/emacs.git] / lisp / vcursor.el
index fd7d141..4f5ebf8 100644 (file)
@@ -1,6 +1,7 @@
 ;;; vcursor.el --- manipulate an alternative ("virtual") cursor
 
-;; Copyright (C) 1994, 1996, 1998 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1996, 1998, 2001, 2002, 2003,
+;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author:   Peter Stephenson <pws@ibmth.df.unipi.it>
 ;; Maintainer: FSF
@@ -8,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; 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., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -31,7 +30,7 @@
 ;; - *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
+;;   the old behavior.  (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.
@@ -53,7 +52,7 @@
 ;; Virtual cursor commands.  I got this idea from the old BBC micro.
 ;; You need Emacs 19 or 20 and a window system for the best effects.
 ;; For character terminals, at least Emacs 19.29 is required
-;; (special behaviour for the overlay property
+;; (special behavior for the overlay property
 ;; "before-string" must be implemented).  Search for "dumb terminals"
 ;; for more information.
 ;;
 ;; In the "on" state, moving the virtual cursor will copy the
 ;; moved-over text to the normal cursor position (including when going
 ;; backwards, though each piece of text moved over is copied forwards:
-;; compare the behaviour of C-S-up and C-S-left).
+;; compare the behavior of C-S-up and C-S-left).
 ;;
 ;; However, that's just a small part of the magic.  If the virtual
 ;; cursor goes off the display, it will be redisplayed in some other
 ;; and also as usual \C-h in this map will list the key definitions, which
 ;; are designed to be easy to remember.
 ;;
-;; A special feature is provided by (vcursor-toggle-vcursor-map), bound
+;; A special feature is provided by (vcursor-use-vcursor-map), bound
 ;; to t in that keymap.  With this in effect, the main keymap
 ;; is overridden by the vcursor map, so keys like \C-p and so on
 ;; move the vcursor instead.  Remember how to turn it off (type t),
   :group 'vcursor)
 
 (defcustom vcursor-auto-disable nil
-  "*If non-nil, disable the virtual cursor after use.
+  "If non-nil, disable the virtual cursor after use.
 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."
@@ -343,7 +342,7 @@ disable the vcursor."
   :group 'vcursor)
 
 (defcustom vcursor-modifiers (list 'control 'shift)
-  "*A list of modifiers that are used to define vcursor key bindings."
+  "A list of modifiers that are used to define vcursor key bindings."
   :type '(repeat symbol)
   :group 'vcursor)
 
@@ -356,7 +355,7 @@ disable the vcursor."
 
 (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
+VAR is usually `vcursor-key-bindings'.  Normally this function is called
 on loading vcursor and from the customize package."
   (set var value)
   (cond
@@ -463,9 +462,9 @@ on loading vcursor and from the customize package."
     )))
 
 (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
+  "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."
@@ -475,7 +474,7 @@ Default is nil."
   :version "20.3")
 
 (defcustom vcursor-interpret-input nil
-  "*If non-nil, input from the vcursor is treated as interactive input.
+  "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
 interpretation of strings is done: \"\C-x\" is a string of four
 characters.  The default is simply to copy strings."
@@ -505,49 +504,48 @@ scrolling set this.  It is used by the `vcursor-auto-disable' code.")
 ;; automatically handle any new commands using the primitives.
 
 (defcustom vcursor-copy-flag nil
-  "*Non-nil means moving vcursor should copy characters moved over to point."
+  "Non-nil means moving vcursor should copy characters moved over to point."
   :type 'boolean
   :group 'vcursor)
 
 (defvar vcursor-temp-goal-column nil
   "Keeps track of temporary goal columns for the virtual cursor.")
 
-(defvar vcursor-use-vcursor-map nil
-  "Non-nil if the vcursor map is mapped directly onto the main keymap.
-See vcursor-toggle-vcursor-map.")
-(make-variable-buffer-local 'vcursor-use-vcursor-map)
-
-(defvar vcursor-map nil "Keymap for vcursor command.")
-(define-prefix-command 'vcursor-map)
-
-(define-key vcursor-map "t" 'vcursor-toggle-vcursor-map)
-
-(define-key vcursor-map "\C-p" 'vcursor-previous-line)
-(define-key vcursor-map "\C-n" 'vcursor-next-line)
-(define-key vcursor-map "\C-b" 'vcursor-backward-char)
-(define-key vcursor-map "\C-f" 'vcursor-forward-char)
-
-(define-key vcursor-map "\r" 'vcursor-disable)
-(define-key vcursor-map " " 'vcursor-copy)
-(define-key vcursor-map "\C-y" 'vcursor-copy-word)
-(define-key vcursor-map "\C-i" 'vcursor-toggle-copy)
-(define-key vcursor-map "<" 'vcursor-beginning-of-buffer)
-(define-key vcursor-map ">" 'vcursor-end-of-buffer)
-(define-key vcursor-map "\M-v" 'vcursor-scroll-down)
-(define-key vcursor-map "\C-v" 'vcursor-scroll-up)
-(define-key vcursor-map "o" 'vcursor-other-window)
-(define-key vcursor-map "g" 'vcursor-goto)
-(define-key vcursor-map "x" 'vcursor-swap-point)
-(define-key vcursor-map "\C-s" 'vcursor-isearch-forward)
-(define-key vcursor-map "\C-r" 'vcursor-isearch-backward)
-(define-key vcursor-map "\C-a" 'vcursor-beginning-of-line)
-(define-key vcursor-map "\C-e" 'vcursor-end-of-line)
-(define-key vcursor-map "\M-w" 'vcursor-forward-word)
-(define-key vcursor-map "\M-b" 'vcursor-backward-word)
-(define-key vcursor-map "\M-l" 'vcursor-copy-line)
-(define-key vcursor-map "c" 'vcursor-compare-windows)
-(define-key vcursor-map "k" 'vcursor-execute-key)
-(define-key vcursor-map "\M-x" 'vcursor-execute-command)
+(defvar vcursor-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "t" 'vcursor-use-vcursor-map)
+
+    (define-key map "\C-p" 'vcursor-previous-line)
+    (define-key map "\C-n" 'vcursor-next-line)
+    (define-key map "\C-b" 'vcursor-backward-char)
+    (define-key map "\C-f" 'vcursor-forward-char)
+
+    (define-key map "\r" 'vcursor-disable)
+    (define-key map " " 'vcursor-copy)
+    (define-key map "\C-y" 'vcursor-copy-word)
+    (define-key map "\C-i" 'vcursor-toggle-copy)
+    (define-key map "<" 'vcursor-beginning-of-buffer)
+    (define-key map ">" 'vcursor-end-of-buffer)
+    (define-key map "\M-v" 'vcursor-scroll-down)
+    (define-key map "\C-v" 'vcursor-scroll-up)
+    (define-key map "o" 'vcursor-other-window)
+    (define-key map "g" 'vcursor-goto)
+    (define-key map "x" 'vcursor-swap-point)
+    (define-key map "\C-s" 'vcursor-isearch-forward)
+    (define-key map "\C-r" 'vcursor-isearch-backward)
+    (define-key map "\C-a" 'vcursor-beginning-of-line)
+    (define-key map "\C-e" 'vcursor-end-of-line)
+    (define-key map "\M-w" 'vcursor-forward-word)
+    (define-key map "\M-b" 'vcursor-backward-word)
+    (define-key map "\M-l" 'vcursor-copy-line)
+    (define-key map "c" 'vcursor-compare-windows)
+    (define-key map "k" 'vcursor-execute-key)
+    (define-key map "\M-x" 'vcursor-execute-command)
+    map)
+  "Keymap for vcursor command.")
+;; This seems unused, but it was done as part of define-prefix-command,
+;; so let's keep it for now.
+(fset 'vcursor-map vcursor-map)
 
 ;; If vcursor-key-bindings is already set on loading, bind the keys now.
 ;; This hybrid way of doing it retains compatibility while allowing
@@ -575,7 +573,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
@@ -674,15 +672,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))
@@ -715,8 +713,7 @@ not be visible otherwise, display it in another window."
   (interactive)
   (let ((buf (current-buffer)) (here (point)) (win (selected-window)))
     (vcursor-goto) ; will disable the vcursor
-    (save-excursion
-      (set-buffer buf)
+    (with-current-buffer buf
       (setq vcursor-window win)
       (vcursor-move here)))
 )
@@ -730,7 +727,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")
@@ -791,19 +788,18 @@ 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."
 
   (vcursor-check)
-  (save-excursion
-    (set-buffer (overlay-buffer vcursor-overlay))
+  (with-current-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,
@@ -816,19 +812,28 @@ out how much to copy."
    (t (error "The virtual cursor is not active now")))
   )
 
+(define-minor-mode vcursor-use-vcursor-map
+  "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.
+An indication \"!VC\" appears in the mode list.  The effect is
+local to the current buffer.
+Disabling the vcursor automatically turns this off."
+  :keymap vcursor-map
+  :lighter " !VC")
+
 (defun vcursor-disable (&optional arg)
   "Disable the virtual cursor.
 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
-virtual 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")
@@ -844,7 +849,7 @@ not copy text until you turn it on again."
    ((and arg (< (prefix-numeric-value arg) 0))
     (vcursor-move (point))
     (setq vcursor-window (selected-window)))
-   (vcursor-use-vcursor-map (vcursor-toggle-vcursor-map 0)))
+   (vcursor-use-vcursor-map (vcursor-use-vcursor-map 0)))
   (setq vcursor-copy-flag nil)
   )
 
@@ -854,7 +859,7 @@ 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")
@@ -867,8 +872,7 @@ ALL-FRAMES is also used to decide whether to split the window."
       ;; We don't use fancy vcursor-find-window trickery, since we're
       ;; quite happy to have the vcursor cycle back into the current
       ;; window.
-      (let ((sw (selected-window))
-           (win (vcursor-find-window nil nil (not all-frames))))
+      (let ((win (vcursor-find-window nil nil (not all-frames))))
        (if win (select-window win))
        ;; else start from here
        (other-window n all-frames)
@@ -891,7 +895,7 @@ If `compare-ignore-case' is non-nil, changes in case are also ignored."
   ;; (vcursor-window-funcall 'compare-windows arg)
   (require 'compare-w)
   (let* (p1 p2 maxp1 maxp2 b1 b2 w2
-           success size
+           success
            (opoint1 (point))
            opoint2
            (skip-whitespace (if ignore-whitespace
@@ -905,8 +909,7 @@ If `compare-ignore-case' is non-nil, changes in case are also ignored."
       (setq p2 (point) b2 (current-buffer)))
     (setq opoint2 p2)
     (setq maxp1 (point-max))
-    (save-excursion
-      (set-buffer b2)
+    (with-current-buffer b2
       (setq maxp2 (point-max)))
 
     (setq success t)
@@ -921,7 +924,7 @@ If `compare-ignore-case' is non-nil, changes in case are also ignored."
 
       (and skip-whitespace
           (save-excursion
-            (let (p1a p2a w1 w2 result1 result2)
+            (let (p1a p2a result1 result2)
               (setq result1
                     (if (stringp skip-whitespace)
                         (compare-windows-skip-whitespace opoint1)
@@ -1042,7 +1045,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)
@@ -1053,7 +1056,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."
@@ -1096,8 +1099,7 @@ is called interactively, so prefix argument etc. are usable."
   (interactive "p")
   (vcursor-check)
   (vcursor-insert
-   (save-excursion
-     (set-buffer (overlay-buffer vcursor-overlay))
+   (with-current-buffer (overlay-buffer vcursor-overlay)
      (let* ((ostart (overlay-start vcursor-overlay))
            (end (+ ostart arg)))
        (prog1
@@ -1126,32 +1128,8 @@ line is treated like ordinary characters."
     (vcursor-copy (if (or (= count 0) arg) (1+ count) count)))
   )
 
-(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.
-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.
-With NOREDISP, don't force redisplay.
-Disabling the vcursor automatically turns this off."
-  (interactive "P")
-  (let ((new (cond ((not force) (not vcursor-use-vcursor-map))
-                  ((eq force 0) nil)
-                  (t))))
-    (or (eq new vcursor-use-vcursor-map)
-       (progn
-         (setq vcursor-use-vcursor-map new)
-         (or (assq 'vcursor-use-vcursor-map minor-mode-map-alist)
-             (setq minor-mode-map-alist
-                   (cons (cons 'vcursor-use-vcursor-map vcursor-map)
-                         minor-mode-map-alist)))
-         (or (assq 'vcursor-use-vcursor-map minor-mode-alist)
-             (setq minor-mode-alist
-                   (cons (list 'vcursor-use-vcursor-map " !VC")
-                         minor-mode-alist)))
-         (or noredisp (redraw-display)))))
-  )
+(define-obsolete-function-alias
+  'vcursor-toggle-vcursor-map 'vcursor-use-vcursor-map "23.1")
 
 (defun vcursor-post-command ()
   (and vcursor-auto-disable (not vcursor-last-command)
@@ -1166,5 +1144,5 @@ Disabling the vcursor automatically turns this off."
 
 (provide 'vcursor)
 
-;;; arch-tag: cdfe1cdc-2c46-4046-88e4-ed57d20f7aca
+;; arch-tag: cdfe1cdc-2c46-4046-88e4-ed57d20f7aca
 ;;; vcursor.el ends here