]> code.delx.au - gnu-emacs/blobdiff - lisp/emulation/viper-ex.el
Implement mouse highlight for bidi-reordered lines.
[gnu-emacs] / lisp / emulation / viper-ex.el
index a5eab5baf641531241bca9c10a79d2e0c1dee049..be387d7724b2afef60ab7e220397df64759ffac0 100644 (file)
@@ -1,16 +1,17 @@
 ;;; viper-ex.el --- functions implementing the Ex commands for Viper
 
 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
 ;;; viper-ex.el --- functions implementing the Ex commands for Viper
 
 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
 
 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
+;; Package: viper
 
 ;; This file is part of GNU Emacs.
 
 
 ;; 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
 ;; 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
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; 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:
 
 
 ;;; Commentary:
 
@@ -331,14 +330,12 @@ Don't put `-c' here, as it is added automatically."
 
 (defcustom viper-glob-function
   (cond (ex-unix-type-shell 'viper-glob-unix-files)
 
 (defcustom viper-glob-function
   (cond (ex-unix-type-shell 'viper-glob-unix-files)
-       ((eq system-type 'emx) 'viper-glob-mswindows-files) ; OS/2
        (viper-ms-style-os-p 'viper-glob-mswindows-files) ; Microsoft OS
        (viper-ms-style-os-p 'viper-glob-mswindows-files) ; Microsoft OS
-       (viper-vms-os-p 'viper-glob-unix-files) ; VMS
        (t  'viper-glob-unix-files) ; presumably UNIX
        )
   "Expand the file spec containing wildcard symbols.
 The default tries to set this variable to work with Unix, Windows,
        (t  'viper-glob-unix-files) ; presumably UNIX
        )
   "Expand the file spec containing wildcard symbols.
 The default tries to set this variable to work with Unix, Windows,
-OS/2, and VMS.
+and OS/2.
 
 However, if it doesn't work right for some types of Unix shells or some OS,
 the user should supply the appropriate function and set this variable to the
 
 However, if it doesn't work right for some types of Unix shells or some OS,
 the user should supply the appropriate function and set this variable to the
@@ -754,7 +751,7 @@ reversed."
                          (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)))
                    (setq cont nil)
                  ;; we are at an escaped delimiter: unescape it and continue
                          (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)))
                    (setq cont nil)
                  ;; we are at an escaped delimiter: unescape it and continue
-                 (delete-backward-char 2)
+                 (delete-char -2)
                  (insert c)
                  (if (eolp)
                      ;; if at eol, exit loop and go to next line
                  (insert c)
                  (if (eolp)
                      ;; if at eol, exit loop and go to next line
@@ -950,16 +947,14 @@ reversed."
 ;; Expand \% and \# in ex command
 (defun ex-expand-filsyms (cmd buf)
   (let (cf pf ret)
 ;; Expand \% and \# in ex command
 (defun ex-expand-filsyms (cmd buf)
   (let (cf pf ret)
-    (save-excursion
-      (set-buffer buf)
+    (with-current-buffer buf
       (setq cf buffer-file-name)
       (setq pf (ex-next nil t))) ; this finds alternative file name
     (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd))
        (error "No current file to substitute for `%%'"))
     (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd))
        (error "No alternate file to substitute for `#'"))
       (setq cf buffer-file-name)
       (setq pf (ex-next nil t))) ; this finds alternative file name
     (if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd))
        (error "No current file to substitute for `%%'"))
     (if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd))
        (error "No alternate file to substitute for `#'"))
-    (save-excursion
-      (set-buffer (get-buffer-create viper-ex-tmp-buf-name))
+    (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
       (erase-buffer)
       (insert cmd)
       (goto-char (point-min))
       (erase-buffer)
       (insert cmd)
       (goto-char (point-min))
@@ -988,9 +983,8 @@ reversed."
          ex-cmdfile nil
          ex-cmdfile-args "")
     (save-excursion
          ex-cmdfile nil
          ex-cmdfile-args "")
     (save-excursion
-      (save-window-excursion
-       (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-       (set-buffer viper-ex-work-buf)
+      (with-current-buffer (setq viper-ex-work-buf
+                                 (get-buffer-create viper-ex-work-buf-name))
        (skip-chars-forward " \t")
        (if (looking-at "!")
            (if (and (not (viper-looking-back "[ \t]"))
        (skip-chars-forward " \t")
        (if (looking-at "!")
            (if (and (not (viper-looking-back "[ \t]"))
@@ -1293,9 +1287,8 @@ reversed."
     (switch-to-buffer file))
   (if ex-offset
       (progn
     (switch-to-buffer file))
   (if ex-offset
       (progn
-       (save-window-excursion
-         (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-         (set-buffer viper-ex-work-buf)
+       (with-current-buffer (setq viper-ex-work-buf
+                                   (get-buffer-create viper-ex-work-buf-name))
          (delete-region (point-min) (point-max))
          (insert ex-offset "\n")
          (goto-char (point-min)))
          (delete-region (point-min) (point-max))
          (insert ex-offset "\n")
          (goto-char (point-min)))
@@ -1376,9 +1369,8 @@ reversed."
          (if (bobp) (setq cont nil)
            (forward-line -1)
            (end-of-line)))))
          (if (bobp) (setq cont nil)
            (forward-line -1)
            (end-of-line)))))
-    (save-window-excursion
-      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-      (set-buffer viper-ex-work-buf)
+    (with-current-buffer (setq viper-ex-work-buf
+                               (get-buffer-create viper-ex-work-buf-name))
       ;; com-str is the command string, i.e., g/pattern/ or v/pattern'
       (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
     (while ex-g-marks
       ;; com-str is the command string, i.e., g/pattern/ or v/pattern'
       (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
     (while ex-g-marks
@@ -1457,18 +1449,17 @@ reversed."
            (setq char (string-to-char name))
          (error "`%s': Spurious text \"%s\" after mark name"
                 name (substring name 1)))
            (setq char (string-to-char name))
          (error "`%s': Spurious text \"%s\" after mark name"
                 name (substring name 1)))
-    (save-window-excursion
-      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-      (set-buffer viper-ex-work-buf)
-      (skip-chars-forward " \t")
-      (if (looking-at "[a-z]")
-         (progn
-           (setq char (following-char))
-           (forward-char 1)
-           (skip-chars-forward " \t")
-           (if (not (looking-at "[\n|]"))
-               (error "`%s': %s" ex-token viper-SpuriousText)))
-       (error "`%s' requires a following letter" ex-token))))
+      (with-current-buffer (setq viper-ex-work-buf
+                                 (get-buffer-create viper-ex-work-buf-name))
+        (skip-chars-forward " \t")
+        (if (looking-at "[a-z]")
+            (progn
+              (setq char (following-char))
+              (forward-char 1)
+              (skip-chars-forward " \t")
+              (if (not (looking-at "[\n|]"))
+                  (error "`%s': %s" ex-token viper-SpuriousText)))
+          (error "`%s' requires a following letter" ex-token))))
     (save-excursion
       (goto-char (car ex-addresses))
       (point-to-register (viper-int-to-char (1+ (- char ?a)))))))
     (save-excursion
       (goto-char (car ex-addresses))
       (point-to-register (viper-int-to-char (1+ (- char ?a)))))))
@@ -1564,8 +1555,7 @@ reversed."
              (select-window wind)))
        (save-window-excursion (select-window wind) (sit-for 1)))
 
              (select-window wind)))
        (save-window-excursion (select-window wind) (sit-for 1)))
 
-      (save-excursion
-       (set-buffer buf)
+      (with-current-buffer buf
        (setq viper-related-files-and-buffers-ring old-ring))
 
       (setq viper-local-search-start-marker (point-marker))
        (setq viper-related-files-and-buffers-ring old-ring))
 
       (setq viper-local-search-start-marker (point-marker))
@@ -1592,9 +1582,8 @@ reversed."
 ;; Ex quit command
 (defun ex-quit ()
   ;; skip "!", if it is q!.  In Viper q!, w!, etc., behave as q, w, etc.
 ;; Ex quit command
 (defun ex-quit ()
   ;; skip "!", if it is q!.  In Viper q!, w!, etc., behave as q, w, etc.
-  (save-excursion
-    (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-    (set-buffer viper-ex-work-buf)
+  (with-current-buffer (setq viper-ex-work-buf
+                             (get-buffer-create viper-ex-work-buf-name))
     (if (looking-at "!") (forward-char 1)))
   (if (< viper-expert-level 3)
       (save-buffers-kill-emacs)
     (if (looking-at "!") (forward-char 1)))
   (if (< viper-expert-level 3)
       (save-buffers-kill-emacs)
@@ -1841,9 +1830,8 @@ reversed."
 ;; Optional 3d arg is a string that should replace ' ' to prevent its
 ;; special meaning
 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)
 ;; Optional 3d arg is a string that should replace ' ' to prevent its
 ;; special meaning
 (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)
-  (save-excursion
-    (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-    (set-buffer viper-ex-work-buf)
+  (with-current-buffer (setq viper-ex-work-buf
+                             (get-buffer-create viper-ex-work-buf-name))
     (goto-char (point-min))
     (re-search-forward regex-forw nil t)
     (let ((beg (point))
     (goto-char (point-min))
     (re-search-forward regex-forw nil t)
     (let ((beg (point))
@@ -1991,9 +1979,8 @@ Please contact your system administrator. "
 ;; Ex tag command
 (defun ex-tag ()
   (let (tag)
 ;; Ex tag command
 (defun ex-tag ()
   (let (tag)
-    (save-window-excursion
-      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-      (set-buffer viper-ex-work-buf)
+    (with-current-buffer (setq viper-ex-work-buf
+                               (get-buffer-create viper-ex-work-buf-name))
       (skip-chars-forward " \t")
       (set-mark (point))
       (skip-chars-forward "^ |\t\n")
       (skip-chars-forward " \t")
       (set-mark (point))
       (skip-chars-forward "^ |\t\n")
@@ -2152,9 +2139,8 @@ Please contact your system administrator. "
 ;; Execute shell command
 (defun ex-command ()
   (let (command)
 ;; Execute shell command
 (defun ex-command ()
   (let (command)
-    (save-window-excursion
-      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-      (set-buffer viper-ex-work-buf)
+    (with-current-buffer (setq viper-ex-work-buf
+                               (get-buffer-create viper-ex-work-buf-name))
       (skip-chars-forward " \t")
       (setq command (buffer-substring (point) (point-max)))
       (end-of-line))
       (skip-chars-forward " \t")
       (setq command (buffer-substring (point) (point-max)))
       (end-of-line))
@@ -2182,9 +2168,8 @@ Please contact your system administrator. "
 If no args are given, then it runs the last compile command.
 Type 'mak ' (including the space) to run make with no args."
   (let (args)
 If no args are given, then it runs the last compile command.
 Type 'mak ' (including the space) to run make with no args."
   (let (args)
-    (save-window-excursion
-      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
-      (set-buffer viper-ex-work-buf)
+    (with-current-buffer (setq viper-ex-work-buf
+                               (get-buffer-create viper-ex-work-buf-name))
       (setq args (buffer-substring (point) (point-max)))
       (end-of-line))
     ;; Remove the newline that may (will?) be at the end of the args
       (setq args (buffer-substring (point) (point-max)))
       (end-of-line))
     ;; Remove the newline that may (will?) be at the end of the args