;;; vip.el --- a VI Package for GNU Emacs
;; Copyright (C) 1986, 1987, 1988, 1992, 1993, 1998, 2001, 2002, 2003,
-;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 2, 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 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)
(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)
(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)
(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)
((= 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
(set-mark beg))
(beginning-of-line)
(exchange-point-and-mark)
- (if (or (not (eobp)) (not (bolp))) (next-line 1))
+ (if (or (not (eobp)) (not (bolp))) (with-no-warnings (next-line 1)))
(beginning-of-line)
(if (> beg end) (exchange-point-and-mark)))
(defun vip-line (arg)
(let ((val (car arg)) (com (cdr arg)))
(move-marker vip-com-point (point))
- (next-line (1- val))
+ (with-no-warnings (next-line (1- val)))
(vip-execute-com 'vip-line val com)))
(defun vip-yank-line (arg)
(interactive "P")
(let ((val (vip-p-val arg)) (com (vip-getCom arg)))
(if com (move-marker vip-com-point (point)))
- (next-line val)
+ (with-no-warnings (next-line val))
(back-to-indentation)
(if com (vip-execute-com 'vip-next-line-at-bol val com))))
(interactive "P")
(let ((val (vip-p-val arg)) (com (vip-getCom arg)))
(if com (move-marker vip-com-point (point)))
- (next-line (- val))
+ (with-no-warnings (next-line (- val)))
(setq this-command 'previous-line)
(if com (vip-execute-com 'vip-previous-line val com))))
(interactive "P")
(let ((val (vip-p-val arg)) (com (vip-getCom arg)))
(if com (move-marker vip-com-point (point)))
- (next-line (- val))
+ (with-no-warnings (next-line (- val)))
(back-to-indentation)
(if com (vip-execute-com 'vip-previous-line val com))))
;; forward search begins here
(if (eolp) (error "") (point))
;; forward search ends here
- (progn (next-line 1) (beginning-of-line) (point)))
+ (progn (with-no-warnings (next-line 1)) (beginning-of-line) (point)))
(narrow-to-region
;; backward search begins from here
(if (bolp) (error "") (point))
(setq vip-use-register nil)
(if (vip-end-with-a-newline-p text)
(progn
- (next-line 1)
+ (with-no-warnings (next-line 1))
(beginning-of-line))
(if (and (not (eolp)) (not (eobp))) (forward-char)))
(setq vip-d-com (list 'vip-put-back val nil vip-use-register))
(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")
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)))
(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))
(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
(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]")
(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")
(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
(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
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
(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)))
(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."
(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
(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)
(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)
(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))))
(let ((point (if (null ex-addresses) (point) (car ex-addresses)))
(variant nil) command file)
(goto-char point)
- (if (not (= point 0)) (next-line 1))
+ (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
(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")
(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)
(provide 'vip)
-;;; arch-tag: bff623ef-48f7-41d4-9aa3-2e840c9ab415
+;; arch-tag: bff623ef-48f7-41d4-9aa3-2e840c9ab415
;;; vip.el ends here