Implement mouse highlight for bidi-reordered lines.
[bpt/emacs.git] / lisp / emulation / vip.el
index b4f80a9..0474ba7 100644 (file)
@@ -1,17 +1,17 @@
 ;;; vip.el --- a VI Package for GNU Emacs
 
 ;; Copyright (C) 1986, 1987, 1988, 1992, 1993, 1998, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Masahiko Sato <ms@sail.stanford.edu>
 ;; Keywords: emulations
 
 ;; 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 3, 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 +19,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:
 
   "How to reexecute last destructive command.  Value is list (M-COM VAL COM).")
 
 (defcustom vip-shift-width 8
-  "*The number of columns shifted by > and < command."
+  "The number of columns shifted by > and < command."
   :type 'integer
   :group 'vip)
 
 (defcustom vip-re-replace nil
-  "*If t then do regexp replace, if nil then do string replace."
+  "If t then do regexp replace, if nil then do string replace."
   :type 'boolean
   :group 'vip)
 
   "For use by \";\" command.")
 
 (defcustom vip-search-wrap-around t
-  "*If t, search wraps around."
+  "If t, search wraps around."
   :type 'boolean
   :group 'vip)
 
 (defcustom vip-re-search nil
-  "*If t, search is reg-exp search, otherwise vanilla search."
+  "If t, search is reg-exp search, otherwise vanilla search."
   :type 'boolean
   :group 'vip)
 
   "If t, search is forward.")
 
 (defcustom vip-case-fold-search nil
-  "*If t, search ignores cases."
+  "If t, search ignores cases."
   :type 'boolean
   :group 'vip)
 
 (defcustom vip-re-query-replace nil
-  "*If t then do regexp replace, if nil then do string replace."
+  "If t then do regexp replace, if nil then do string replace."
   :type 'boolean
   :group 'vip)
 
 (defcustom vip-open-with-indent nil
-  "*If t, indent when open a new line."
+  "If t, indent when open a new line."
   :type 'boolean
   :group 'vip)
 
 (defcustom vip-help-in-insert-mode nil
-  "*If t then C-h is bound to help-command in insert mode.
+  "If t then C-h is bound to help-command in insert mode.
 If nil then it is bound to `delete-backward-char'."
   :type 'boolean
   :group 'vip)
@@ -421,10 +419,9 @@ Type `n' to quit this window for now.\n")
        (goto-char (point-min))
        (if (y-or-n-p "Inhibit VIP startup message? ")
            (progn
-             (save-excursion
-               (set-buffer
-                (find-file-noselect
-                 (substitute-in-file-name vip-startup-file)))
+             (with-current-buffer 
+                  (find-file-noselect
+                   (substitute-in-file-name vip-startup-file))
                (goto-char (point-max))
                (insert "\n(setq vip-inhibit-startup-message t)\n")
                (save-buffer)
@@ -608,7 +605,7 @@ obtained so far, and COM is the command part obtained so far."
 (defun vip-digit-argument (arg)
   "Begin numeric argument for the next command."
   (interactive "P")
-  (vip-prefix-arg-value last-command-char nil
+  (vip-prefix-arg-value last-command-event nil
                        (if (consp arg) (cdr arg) nil)))
 
 (defun vip-command-argument (arg)
@@ -616,7 +613,7 @@ obtained so far, and COM is the command part obtained so far."
   (interactive "P")
   (condition-case conditions
       (vip-prefix-arg-com
-       last-command-char
+       last-command-event
        (cond ((null arg) nil)
             ((consp arg) (car arg))
             ((numberp arg) arg)
@@ -836,7 +833,7 @@ is the name of the register for COM."
        ((= char ?q)
         (set-mark vip-com-point)
         (vip-quote-region))
-       ((= char ?s) (spell-region vip-com-point (point)))))
+       ((= char ?s) (ispell-region vip-com-point (point)))))
 
 \f
 ;; undoing
@@ -2160,8 +2157,7 @@ is a command.")
 (defun vip-get-ex-token ()
   "get an ex-token which is either an address or a command.
 a token has type \(command, address, end-mark\) and value."
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
+  (with-current-buffer " *ex-working-space*"
     (skip-chars-forward " \t")
     (cond ((looking-at "[k#]")
           (setq ex-token-type "command")
@@ -2264,8 +2260,7 @@ a token has type \(command, address, end-mark\) and value."
            ex-g-variant nil))
   (let ((com-str (or string (vip-read-string ":")))
        (address nil) (cont t) (dot (point)))
-    (save-window-excursion
-      (set-buffer (get-buffer-create " *ex-working-space*"))
+    (with-current-buffer (get-buffer-create " *ex-working-space*")
       (delete-region (point-min) (point-max))
       (insert com-str "\n")
       (goto-char (point-min)))
@@ -2284,8 +2279,7 @@ a token has type \(command, address, end-mark\) and value."
                    (setq cont nil))
                   (t
                    (vip-execute-ex-command)
-                   (save-window-excursion
-                     (set-buffer " *ex-working-space*")
+                   (with-current-buffer " *ex-working-space*"
                      (skip-chars-forward " \t")
                      (cond ((looking-at "|")
                             (forward-char 1))
@@ -2309,8 +2303,7 @@ a token has type \(command, address, end-mark\) and value."
 
 (defun vip-get-ex-pat ()
   "get a regular expression and set ex-variant if found"
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
+  (with-current-buffer " *ex-working-space*"
     (skip-chars-forward " \t")
     (if (looking-at "!")
        (progn
@@ -2336,8 +2329,7 @@ a token has type \(command, address, end-mark\) and value."
 
 (defun vip-get-ex-command ()
   "get an ex command"
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
+  (with-current-buffer " *ex-working-space*"
     (if (looking-at "/") (forward-char 1))
     (skip-chars-forward " \t")
     (cond ((looking-at "[a-z]")
@@ -2351,8 +2343,7 @@ a token has type \(command, address, end-mark\) and value."
 
 (defun vip-get-ex-opt-gc ()
   "get an ex option g or c"
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
+  (with-current-buffer " *ex-working-space*"
     (if (looking-at "/") (forward-char 1))
     (skip-chars-forward " \t")
     (cond ((looking-at "g")
@@ -2460,8 +2451,7 @@ a token has type \(command, address, end-mark\) and value."
   (setq ex-buffer nil)
   (setq ex-count nil)
   (setq ex-flag nil)
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
+  (with-current-buffer " *ex-working-space*"
     (skip-chars-forward " \t")
     (if (looking-at "[a-zA-Z]")
        (progn
@@ -2485,8 +2475,7 @@ a token has type \(command, address, end-mark\) and value."
   (setq ex-variant nil
        ex-count nil
        ex-flag nil)
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
+  (with-current-buffer " *ex-working-space*"
     (skip-chars-forward " \t")
     (if (looking-at "!")
        (progn
@@ -2512,8 +2501,7 @@ a token has type \(command, address, end-mark\) and value."
        ex-variant nil
        ex-append nil
        ex-offset nil)
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
+  (with-current-buffer " *ex-working-space*"
     (skip-chars-forward " \t")
     (if (looking-at "!")
        (progn
@@ -2682,8 +2670,7 @@ a token has type \(command, address, end-mark\) and value."
   (goto-char (point-min))
   (if ex-offset
       (progn
-       (save-window-excursion
-         (set-buffer " *ex-working-space*")
+       (with-current-buffer " *ex-working-space*"
          (delete-region (point-min) (point-max))
          (insert ex-offset "\n")
          (goto-char (point-min)))
@@ -2735,19 +2722,18 @@ a token has type \(command, address, end-mark\) and value."
          (if (bobp) (setq cont nil)
            (forward-line -1)
            (end-of-line)))))
-  (save-window-excursion
-    (set-buffer " *ex-working-space*")
-    (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
-  (while marks
-    (goto-char (car marks))
-    ; report progress of execution on a slow machine.
-    ;(message "Executing global command...")
-    ;(if (zerop (% mark-count 10))
-       ;(message "Executing global command...%d" mark-count))
-    (vip-ex com-str)
-    (setq mark-count (1- mark-count))
-    (setq marks (cdr marks)))))
-  ;(message "Executing global command...done")))
+    (with-current-buffer " *ex-working-space*"
+      (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
+    (while marks
+      (goto-char (car marks))
+      ;; report progress of execution on a slow machine.
+      ;;(message "Executing global command...")
+      ;;(if (zerop (% mark-count 10))
+      ;;    (message "Executing global command...%d" mark-count))
+      (vip-ex com-str)
+      (setq mark-count (1- mark-count))
+      (setq marks (cdr marks)))))
+;;(message "Executing global command...done")))
 
 (defun ex-line (com)
   "ex line commands.  COM is join, shift-right or shift-left."
@@ -2803,8 +2789,7 @@ a token has type \(command, address, end-mark\) and value."
     (if (null ex-addresses)
        (setq ex-addresses
              (cons (point) nil)))
-    (save-window-excursion
-      (set-buffer " *ex-working-space*")
+    (with-current-buffer " *ex-working-space*"
       (skip-chars-forward " \t")
       (if (looking-at "[a-z]")
          (progn
@@ -2823,8 +2808,7 @@ a token has type \(command, address, end-mark\) and value."
 (defun ex-map ()
   "ex map"
   (let (char string)
-    (save-window-excursion
-      (set-buffer " *ex-working-space*")
+    (with-current-buffer " *ex-working-space*"
       (skip-chars-forward " \t")
       (setq char (char-to-string (following-char)))
       (forward-char 1)
@@ -2849,8 +2833,7 @@ a token has type \(command, address, end-mark\) and value."
 (defun ex-unmap ()
   "ex unmap"
   (let (char)
-    (save-window-excursion
-      (set-buffer " *ex-working-space*")
+    (with-current-buffer " *ex-working-space*"
       (skip-chars-forward " \t")
       (setq char (char-to-string (following-char)))
       (forward-char 1)
@@ -2872,8 +2855,7 @@ a token has type \(command, address, end-mark\) and value."
 (defun ex-quit ()
   "ex quit"
   (let (char)
-    (save-window-excursion
-      (set-buffer " *ex-working-space*")
+    (with-current-buffer " *ex-working-space*"
       (skip-chars-forward " \t")
       (setq char (following-char)))
     (if (= char ?!) (kill-emacs t) (save-buffers-kill-emacs))))
@@ -2885,8 +2867,7 @@ a token has type \(command, address, end-mark\) and value."
     (goto-char point)
     (if (not (= point 0)) (with-no-warnings (next-line 1)))
     (beginning-of-line)
-    (save-window-excursion
-      (set-buffer " *ex-working-space*")
+    (with-current-buffer " *ex-working-space*"
       (skip-chars-forward " \t")
       (if (looking-at "!")
          (progn
@@ -2983,8 +2964,7 @@ vip-s-string"
 (defun ex-tag ()
   "ex tag"
   (let (tag)
-    (save-window-excursion
-      (set-buffer " *ex-working-space*")
+    (with-current-buffer " *ex-working-space*"
       (skip-chars-forward " \t")
       (set-mark (point))
       (skip-chars-forward "^ |\t\n")
@@ -3047,8 +3027,7 @@ vip-s-string"
 (defun ex-command ()
   "execute shell command"
   (let (command)
-    (save-window-excursion
-      (set-buffer " *ex-working-space*")
+    (with-current-buffer " *ex-working-space*"
       (skip-chars-forward " \t")
       (set-mark (point))
       (end-of-line)
@@ -3075,5 +3054,5 @@ vip-s-string"
 
 (provide 'vip)
 
-;;; arch-tag: bff623ef-48f7-41d4-9aa3-2e840c9ab415
+;; arch-tag: bff623ef-48f7-41d4-9aa3-2e840c9ab415
 ;;; vip.el ends here