;;; vip.el --- a VI Package for GNU Emacs
-;; Copyright (C) 1986, 1987, 1988, 1992, 1993, 1998
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1986, 1987, 1988, 1992, 1993, 1998, 2002, 2003, 2004,
+;; 2005, 2006 Free Software Foundation, Inc.
;; Author: Masahiko Sato <ms@sail.stanford.edu>
;; Keywords: emulations
;; 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., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(defvar vip-insert-local-map nil
"Local map used in insert command mode. (Buffer-specific.)")
-
+
(make-variable-buffer-local 'vip-emacs-local-map)
(make-variable-buffer-local 'vip-insert-local-map)
(defvar vip-f-forward nil
"For use by \";\" command.")
-
+
(defvar vip-f-offset nil
"For use by \";\" command.")
(define-key vip-mode-map "~" 'vip-nil)
(define-key vip-mode-map "\177" 'vip-delete-backward-char)
-(define-key ctl-x-map "3" 'vip-buffer-in-two-windows)
-(define-key ctl-x-map "\C-i" 'insert-file)
-
(defun vip-version ()
(interactive)
(message "VIP version 3.5 of September 15, 1987"))
\f
;; basic set up
-(global-set-key "\C-z" 'vip-change-mode-to-vi)
+;;;###autoload
+(defun vip-setup ()
+ "Set up bindings for C-x 7 and C-z that are useful for VIP users."
+ (define-key ctl-x-map "7" 'vip-buffer-in-two-windows)
+ (global-set-key "\C-z" 'vip-change-mode-to-vi))
(defmacro vip-loop (count body)
"(COUNT BODY) Execute BODY COUNT times."
'delete-backward-char))
(define-key vip-insert-local-map "\C-w"
'vip-delete-backward-word))
- ((eq new-mode 'emacs-mode)
+ ((eq new-mode 'emacs-mode)
(vip-change-mode-line "Emacs:")
(use-local-map vip-emacs-local-map)))
(setq vip-current-mode new-mode)
"Compute numeric prefix arg value. Invoked by CHAR. VALUE is the value
obtained so far, and COM is the command part obtained so far."
(while (and (>= char ?0) (<= char ?9))
- (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)))
+ (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)))
(setq char (read-char)))
(setq prefix-arg value)
(if com (setq prefix-arg (cons prefix-arg com)))
(setq com char)
(setq char (read-char)))))))
(if (atom com)
- ;; com is a single char, so we construct prefix-arg
+ ;; com is a single char, so we construct prefix-arg
;; and if char is ?, describe prefix arg, otherwise exit by
;; pushing the char back
(progn
(interactive "P")
(condition-case conditions
(vip-prefix-arg-com
- last-command-char
+ last-command-char
(cond ((null arg) nil)
((consp arg) (car arg))
((numberp arg) arg)
(com (car (cdr (cdr vip-d-com))))
(reg (nth 3 vip-d-com)))
(if (null val) (setq val (car (cdr vip-d-com))))
- (if (null m-com) (error "No previous command to repeat."))
+ (if (null m-com) (error "No previous command to repeat"))
(setq vip-use-register reg)
(funcall m-com (cons val com)))))
each line in the region."
(setq vip-quote-string
(let ((str
- (vip-read-string (format "quote string \(default \"%s\"\): "
+ (vip-read-string (format "quote string (default %s): "
vip-quote-string))))
(if (string= str "") vip-quote-string str)))
(vip-enlarge-region (point) (mark))
command was invoked with argument > 1."
(let ((i-com (car vip-d-com)) (val (car (cdr vip-d-com))))
(if (and val (> val 1)) ;; first check that val is non-nil
- (progn
+ (progn
(setq vip-d-com (list i-com (1- val) ?r))
(vip-repeat nil)
(setq vip-d-com (list i-com val ?r))))))
(vip-change-subr (mark) (point))
(vip-change (mark) (point))))
(setq vip-d-com (list 'vip-substitute val ?r))))
-
+
(defun vip-substitute-line (arg)
"Substitute lines."
(interactive "p")
(interactive "P")
(let ((val (vip-p-val arg)))
(vip-line (cons val ?Y))))
-
+
\f
;; region command
(move-marker vip-com-point (point))
(exchange-point-and-mark)
(vip-execute-com 'vip-Region val com)))
-
+
(defun vip-replace-char (arg)
"Replace the following ARG chars by the character read."
(interactive "P")
(replace-match (vip-read-string
(format "Replace regexp \"%s\" with: " str))
nil nil))
- (replace-string
- str
- (vip-read-string (format "Replace \"%s\" with: " str)))))))
+ (with-no-warnings
+ (replace-string
+ str
+ (vip-read-string (format "Replace \"%s\" with: " str))))))))
\f
;; basic cursor movement. j, k, l, m commands.
(progn
(forward-char)
(vip-execute-com 'vip-end-of-word val com)))))
-
+
(defun vip-backward-word (arg)
"Backward word."
(interactive "P")
(defun vip-find-char-forward (arg)
"Find char on the line. If called interactively read the char to find
from the terminal, and if called from vip-repeat, the char last used is
-used. This behaviour is controlled by the sign of prefix numeric value."
+used. This behavior is controlled by the sign of prefix numeric value."
(interactive "P")
(let ((val (vip-p-val arg)) (com (vip-getcom arg)))
(if (> val 0)
(let ((com (vip-getcom arg)))
(if (numberp arg)
(if (or (> arg 99) (< arg 1))
- (error "Prefix must be between 1 and 99.")
+ (error "Prefix must be between 1 and 99")
(goto-char
(if (> (point-max) 80000)
(* (/ (point-max) 100) arg)
"Repeat previous search."
(interactive "P")
(let ((val (vip-p-val arg)) (com (vip-getcom arg)))
- (if (null vip-s-string) (error "No previous search string."))
+ (if (null vip-s-string) (error "No previous search string"))
(vip-search vip-s-string vip-s-forward arg)
(if com (vip-execute-com 'vip-search-next val com))))
"Repeat previous search in the reverse direction."
(interactive "P")
(let ((val (vip-p-val arg)) (com (vip-getcom arg)))
- (if (null vip-s-string) (error "No previous search string."))
+ (if (null vip-s-string) (error "No previous search string"))
(vip-search vip-s-string (not vip-s-forward) arg)
(if com (vip-execute-com 'vip-search-Next val com))))
(if (null buffer-name)
(current-buffer)
(get-buffer buffer-name)))
- (if (null buffer) (error "Buffer %s nonexistent." buffer-name))
+ (if (null buffer) (error "Buffer %s nonexistent" buffer-name))
(if (or (not (buffer-modified-p buffer))
(y-or-n-p "Buffer is modified, are you sure? "))
(kill-buffer buffer)
- (error "Buffer not killed."))))
+ (error "Buffer not killed"))))
(defun vip-find-file ()
"Visit file in the current window."
(cond ((string= ex-token-type "plus") "add-number")
((string= ex-token-type "minus") "sub-number")
(t "abs-number")))
- (setq ex-token (string-to-int (buffer-substring (point) (mark)))))
+ (setq ex-token (string-to-number (buffer-substring (point) (mark)))))
((looking-at "\\$")
(forward-char 1)
(setq ex-token-type "end"))
(setq ex-token-type "end-mark")
(setq ex-token "goto"))
(t
- (error "illegal token")))))
+ (error "invalid token")))))
(defun vip-ex (&optional string)
"ex commands within VIP."
(setq cont nil))
(t (error "Extra character at end of a command")))))))
((string= ex-token-type "non-command")
- (error (format "%s: Not an editor command" ex-token)))
+ (error "%s: Not an editor command" ex-token))
((string= ex-token-type "whole")
(setq ex-addresses
(cons (point-max) (cons (point-min) ex-addresses))))
(progn
(set-mark (point))
(re-search-forward "[0-9][0-9]*")
- (setq ex-count (string-to-int (buffer-substring (point) (mark))))
+ (setq ex-count (string-to-number (buffer-substring (point) (mark))))
(skip-chars-forward " \t")))
(if (looking-at "[pl#]")
(progn
(setq ex-flag t)
(forward-char 1)))
(if (not (looking-at "[\n|]"))
- (error "Illegal extra characters"))))
+ (error "Invalid extra characters"))))
(defun vip-get-ex-count ()
(setq ex-variant nil
(progn
(set-mark (point))
(re-search-forward "[0-9][0-9]*")
- (setq ex-count (string-to-int (buffer-substring (point) (mark))))
+ (setq ex-count (string-to-number (buffer-substring (point) (mark))))
(skip-chars-forward " \t")))
(if (looking-at "[pl#]")
(progn
(setq ex-flag t)
(forward-char 1)))
(if (not (looking-at "[\n|]"))
- (error "Illegal extra characters"))))
+ (error "Invalid extra characters"))))
(defun vip-get-ex-file ()
"get a file name and set ex-variant, ex-append and ex-offset if found"
(skip-chars-forward " \t")
(if (looking-at "[\n|]") (error "Missing rhs"))
(set-mark (point))
- (end-of-buffer)
+ (with-no-warnings
+ (end-of-buffer))
(backward-char 1)
(setq string (buffer-substring (mark) (point))))
(if (not (lookup-key ex-map char))
(setq file (buffer-substring (point) (mark)))))
(if variant
(shell-command command t)
- (insert-file file))))
+ (with-no-warnings
+ (insert-file file)))))
(defun ex-set ()
(eval (list 'setq
(vip-change-mode-to-emacs)
(shell))
-(defun ex-substitute (&optional repeat r-flag)
+(defun ex-substitute (&optional repeat r-flag)
"ex substitute.
If REPEAT use previous reg-exp which is ex-reg-exp or
vip-s-string"
(provide 'vip)
+;;; arch-tag: bff623ef-48f7-41d4-9aa3-2e840c9ab415
;;; vip.el ends here