;;; viper-ex.el --- functions implementing the Ex commands for Viper
-;; Copyright (C) 1994-1998, 2000-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1994-1998, 2000-2013 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)
(defvar ex-addresses nil)
;; This flag is supposed to be set only by `#', `print', and `list',
-;; none of which is implemented. So, it and the pices of the code it
+;; none of which is implemented. So, it and the pieces of the code it
;; controls are dead weight. We keep it just in case this might be
;; needed in the future.
(defvar ex-flag nil)
(defvar viper-keep-reading-filename nil)
(defcustom ex-cycle-other-window t
- "*If t, :n and :b cycles through files and buffers in other window.
+ "If t, :n and :b cycles through files and buffers in other window.
Then :N and :B cycles in the current window. If nil, this behavior is
reversed."
:type 'boolean
:group 'viper-ex)
(defcustom ex-cycle-through-non-files nil
- "*Cycle through *scratch* and other buffers that don't visit any file."
+ "Cycle through *scratch* and other buffers that don't visit any file."
:type 'boolean
:group 'viper-ex)
(while (and (not (eolp)) cont)
;;(re-search-forward "[^/]*/")
(re-search-forward "[^/]*\\(/\\|\n\\)")
- (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
+ (if (not (looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
(setq cont nil))))
(backward-char 1)
(setq ex-token (buffer-substring (point) (mark t)))
(while (and (not (eolp)) cont)
;;(re-search-forward "[^\\?]*\\?")
(re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
- (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
+ (if (not (looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
(setq cont nil))
(backward-char 1)
(if (not (looking-at "\n")) (forward-char 1))))
(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)
save-pos (point)))
(if (or (= dist 0)
- (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
- (viper-looking-back
+ (looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
+ (looking-back
"^[ \t]*[a-zA-Z!=>&~][ \t]*[/?]*[ \t]+[a-zA-Z!=>&~]+"))
;; 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]*")
+ (looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
(looking-at "[^ \t\n\C-m]"))
nil
(with-output-to-temp-buffer "*Completions*"
)))
+(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
(if (member ex-token '("global" "vglobal"))
(error "Missing closing delimiter for global regexp")
(goto-char (point-max))))
- (if (not (viper-looking-back
+ (if (not (looking-back
(format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)))
(setq cont nil)
;; we are at an escaped delimiter: unescape it and continue
(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))
(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 (concat "\\\\" char))
(replace-match char)
(store-match-data data)
(if (string= char "%")
(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]"))
;; read doesn't have a corresponding :r! form, so ! is
;; immediately interpreted as a shell command.
(not (string= ex-token "read")))
(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]*!.*")
(setq ex-cmdfile t)
(insert " "))
(t
(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)
(kill-region (point) (mark t))))))
+(declare-function viper-change-state-to-vi "viper-cmd" ())
;; Ex edit command
;; In Viper, `e' and `e!' behave identically. In both cases, the user is
))
+(declare-function viper-backward-char-carefully "viper-cmd" (&optional arg))
+
;; Ex global command
;; This is executed in response to:
;; :global "pattern" ex-command
(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))
(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))))
(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>
(beginning-of-line)
(if opt-c (message "done"))))
+(declare-function viper-change-state-to-emacs "viper-cmd" ())
+
;; Ex tag command
(defun ex-tag ()
(let (tag)
(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 ()