]> code.delx.au - gnu-emacs/blobdiff - lisp/emulation/viper-ex.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / emulation / viper-ex.el
index acaedde3004b297183eccadebf340bdfc553475e..9c9cd681bfae08578f08a28d89392465ca73f4f3 100644 (file)
@@ -1,6 +1,6 @@
 ;;; viper-ex.el --- functions implementing the Ex commands for Viper
 
-;; Copyright (C) 1994-1998, 2000-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1994-1998, 2000-2016 Free Software Foundation, Inc.
 
 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
 ;; Package: viper
 (defvar viper-case-fold-search)
 (defvar explicit-shell-file-name)
 (defvar compile-command)
-
-;; loading happens only in non-interactive compilation
-;; in order to spare non-viperized emacs from being viperized
-(if noninteractive
-    (eval-when-compile
-      (if (not (featurep 'viper-cmd))
-         (require 'viper-cmd))
-      ))
+(require 'viper-keym)
 ;; end pacifier
 
 (require 'viper-util)
@@ -403,7 +396,7 @@ reversed."
     ))
 
 ;; Get an ex-token which is either an address or a command.
-;; A token has a type, \(command, address, end-mark\), and a value
+;; A token has a type, (command, address, end-mark), and a value
 (defun viper-get-ex-token ()
   (save-window-excursion
     (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
@@ -462,7 +455,8 @@ reversed."
               (while (and (not (eolp)) cont)
                 ;;(re-search-forward "[^/]*/")
                 (re-search-forward "[^/]*\\(/\\|\n\\)")
-                (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
+                (if (not (looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"
+                                        (line-beginning-position 0)))
                     (setq cont nil))))
             (backward-char 1)
             (setq ex-token (buffer-substring (point) (mark t)))
@@ -475,7 +469,8 @@ reversed."
               (while (and (not (eolp)) cont)
                 ;;(re-search-forward "[^\\?]*\\?")
                 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
-                (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
+                (if (not (looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"
+                                        (line-beginning-position 0)))
                     (setq cont nil))
                 (backward-char 1)
                 (if (not (looking-at "\n")) (forward-char 1))))
@@ -496,7 +491,7 @@ reversed."
             (forward-char 1)
             (cond ((looking-at "'") (setq ex-token nil))
                   ((looking-at "[a-z]") (setq ex-token (following-char)))
-                  (t (error "Marks are ' and a-z")))
+                  (t (error "%s" "Marks are ' and a-z")))
             (forward-char 1))
            ((looking-at "\n")
             (setq ex-token-type 'end-mark)
@@ -553,11 +548,13 @@ reversed."
       (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
       (set-buffer viper-ex-work-buf)
       (goto-char (point-max)))
-    (cond ((viper-looking-back quit-regex1) (exit-minibuffer))
-         ((viper-looking-back stay-regex)  (insert " "))
-         ((viper-looking-back quit-regex2) (exit-minibuffer))
+    (cond ((looking-back quit-regex1) (exit-minibuffer))
+         ((looking-back stay-regex)  (insert " "))
+         ((looking-back quit-regex2) (exit-minibuffer))
          (t (insert " ")))))
 
+(declare-function viper-tmp-insert-at-eob "viper-cmd" (msg))
+
 ;; complete Ex command
 (defun ex-cmd-complete ()
   (interactive)
@@ -568,14 +565,18 @@ reversed."
            save-pos (point)))
 
     (if (or (= dist 0)
-           (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
-           (viper-looking-back
-            "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*[ \t]+[a-zA-Z!=>&~]+"))
+           (looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)"
+                          (line-beginning-position))
+           (looking-back
+            "^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*[ \t]+[a-zA-Z!=>&~]+"
+             (line-beginning-position)))
        ;; Preceding characters are not the ones allowed in an Ex command
        ;; or we have typed past command name.
        ;; Note: we didn't do parsing, so there can be surprises.
-       (if (or (viper-looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*")
-               (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
+       (if (or (looking-back "[a-zA-Z!=>&~][ \t]*[/?]*[ \t]*"
+                              (line-beginning-position))
+               (looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)"
+                              (line-beginning-position))
                (looking-at "[^ \t\n\C-m]"))
            nil
          (with-output-to-temp-buffer "*Completions*"
@@ -605,6 +606,11 @@ reversed."
       )))
 
 
+(declare-function viper-enlarge-region "viper-cmd" (beg end))
+(declare-function viper-read-string-with-history "viper-cmd"
+                 (prompt &optional viper-initial history-var
+                         default keymap init-message))
+
 ;; Read Ex commands
 ;; ARG is a prefix argument. If given, the ex command runs on the region
 ;;(without the user having to specify the address :a,b
@@ -746,8 +752,9 @@ reversed."
                    (if (member ex-token '("global" "vglobal"))
                        (error "Missing closing delimiter for global regexp")
                      (goto-char (point-max))))
-               (if (not (viper-looking-back
-                         (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)))
+               (if (not (looking-back
+                         (format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)
+                          (line-beginning-position 0)))
                    (setq cont nil)
                  ;; we are at an escaped delimiter: unescape it and continue
                  (delete-char -2)
@@ -826,6 +833,9 @@ reversed."
                 (if ans (setq address ans))))))
     address))
 
+(declare-function viper-register-to-point "viper-cmd"
+                 (char &optional enforce-buffer))
+
 ;; Returns an address as a point
 (defun viper-get-ex-address-subr (old-address dot)
   (let ((address nil))
@@ -960,7 +970,7 @@ reversed."
       (while (re-search-forward "%\\|#" nil t)
        (let ((data (match-data))
              (char (buffer-substring (match-beginning 0) (match-end 0))))
-         (if (viper-looking-back (concat "\\\\" char))
+         (if (looking-back "\\\\." (- (point) 2))
              (replace-match char)
            (store-match-data data)
            (if (string= char "%")
@@ -986,7 +996,7 @@ reversed."
                                  (get-buffer-create viper-ex-work-buf-name))
        (skip-chars-forward " \t")
        (if (looking-at "!")
-           (if (and (not (viper-looking-back "[ \t]"))
+           (if (and (not (looking-back "[ \t]" (1- (point))))
                     ;; read doesn't have a corresponding :r! form, so ! is
                     ;; immediately interpreted as a shell command.
                     (not (string= ex-token "read")))
@@ -1063,7 +1073,7 @@ reversed."
   (cond ((ex-cmd-accepts-multiple-files-p ex-token) (exit-minibuffer))
        ;; apparently the argument to an Ex command is
        ;; supposed to be a shell command
-       ((viper-looking-back "^[ \t]*!.*")
+       ((looking-back "^[ \t]*!.*" (line-beginning-position))
         (setq ex-cmdfile t)
         (insert " "))
        (t
@@ -1202,6 +1212,8 @@ reversed."
       (forward-line 1))
       (insert (current-kill 0))))
 
+(declare-function viper-append-to-register "viper-cmd" (reg start end))
+
 ;; Ex delete command
 (defun ex-delete ()
   (viper-default-ex-addresses)
@@ -1238,6 +1250,7 @@ reversed."
        (kill-region (point) (mark t))))))
 
 
+(declare-function viper-change-state-to-vi "viper-cmd" (&rest _))
 
 ;; Ex edit command
 ;; In Viper, `e' and `e!' behave identically.  In both cases, the user is
@@ -1308,6 +1321,8 @@ reversed."
     ))
 
 
+(declare-function viper-backward-char-carefully "viper-cmd" (&optional arg))
+
 ;; Ex global command
 ;; This is executed in response to:
 ;;             :global "pattern" ex-command
@@ -1416,6 +1431,8 @@ reversed."
     (goto-char (1- point))
     (beginning-of-line)))
 
+(declare-function viper-forward-char-carefully "viper-cmd" (&optional arg))
+
 (defun ex-line-subr (com beg end)
   (cond ((string= com "join")
         (goto-char (min beg end))
@@ -1566,6 +1583,9 @@ reversed."
   (message "Autosaving all buffers that need to be saved...")
   (do-auto-save t))
 
+(declare-function viper-Put-back "viper-cmd" (arg))
+(declare-function viper-put-back "viper-cmd" (arg))
+
 ;; Ex put
 (defun ex-put ()
   (let ((point (if (null ex-addresses) (point) (car ex-addresses))))
@@ -1589,6 +1609,8 @@ reversed."
     (kill-buffer (current-buffer))))
 
 
+(declare-function viper-add-newline-at-eob-if-necessary "viper-cmd" ())
+
 ;; Ex read command
 ;; ex-read doesn't support wildcards, because file completion is a better
 ;; mechanism. We also don't support # and % (except in :r <shell-command>
@@ -1636,7 +1658,7 @@ reversed."
   (if (and (not (string= ex-file (buffer-file-name)))
           (buffer-modified-p)
           (not ex-variant))
-      (error "No write since last change \(:rec! overrides\)"))
+      (error "No write since last change (:rec! overrides)"))
   (recover-file ex-file))
 
 ;; Tell that `rewind' is obsolete and to use `:next count' instead
@@ -1872,7 +1894,8 @@ Please contact your system administrator. "
                            (if (featurep 'xemacs) "X" "")
                            ))))))
 
-;; Ex source command.  Loads the file specified as argument or `~/.viper'
+;; Ex source command.
+;; Loads the file specified as argument or viper-custom-file-name.
 (defun ex-source ()
   (viper-get-ex-file)
   (if (string= ex-file "")
@@ -1975,6 +1998,8 @@ Please contact your system administrator. "
     (beginning-of-line)
     (if opt-c (message "done"))))
 
+(declare-function viper-change-state-to-emacs "viper-cmd" (&rest _))
+
 ;; Ex tag command
 (defun ex-tag ()
   (let (tag)
@@ -2159,13 +2184,13 @@ Please contact your system administrator. "
          (goto-char beg)
          (set-mark end)
          (viper-enlarge-region (point) (mark t))
-         (shell-command-on-region (point) (mark t) command t))
+         (shell-command-on-region (point) (mark t) command t t))
        (goto-char beg)))))
 
 (defun ex-compile ()
   "Reads args from the command line, then runs make with the args.
 If no args are given, then it runs the last compile command.
-Type 'mak ' (including the space) to run make with no args."
+Type `mak ' (including the space) to run make with no args."
   (let (args)
     (with-current-buffer (setq viper-ex-work-buf
                                (get-buffer-create viper-ex-work-buf-name))