annotate lisp/emulation/vip.el @ 10559:dcb43c6d4c42

Integer width changes.
author Richard M. Stallman <rms@gnu.org>
date Fri, 27 Jan 1995 01:43:02 +0000
parents 67b7d1ea7b2e
children 506881d20003
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1 ;;; vip.el --- a VI Package for GNU Emacs
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
3 ;; Author: Masahiko Sato <ms@sail.stanford.edu>
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
4 ;; Version: 3.5
812
485e82a8acb5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 773
diff changeset
5 ;; Keywords: emulations
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
6
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
7 ;;; Commentary:
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
8
2319
d98c49df2acd Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1821
diff changeset
9 ;; A full-featured vi(1) emulator.
d98c49df2acd Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1821
diff changeset
10 ;;
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
11 ;; In Japan, the author's address is: masahiko@sato.riec.tohoku.junet
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
12 ;;
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; Send suggestions and bug reports to one of the above addresses.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; When you report a bug, be sure to include the version number of VIP and
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; Emacs you are using.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; Execute info command by typing "M-x info" to get information on VIP.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
19 ;;; Code:
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
20
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; external variables
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 (defvar vip-emacs-local-map nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 "Local map used in emacs mode. \(buffer specific\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 (defvar vip-insert-local-map nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 "Local map used in insert command mode. \(buffer specific\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 (make-variable-buffer-local 'vip-emacs-local-map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 (make-variable-buffer-local 'vip-insert-local-map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (defvar vip-insert-point nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 "Remember insert point as a marker. \(buffer specific\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (set-default 'vip-insert-point (make-marker))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (make-variable-buffer-local 'vip-insert-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (defvar vip-com-point nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 "Remember com point as a marker. \(buffer specific\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (set-default 'vip-com-point (make-marker))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (make-variable-buffer-local 'vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (defvar vip-current-mode nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 "Current mode. One of emacs-mode, vi-mode, insert-mode.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (make-variable-buffer-local 'vip-current-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (setq-default vip-current-mode 'emacs-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defvar vip-emacs-mode-line-buffer-identification nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 "value of mode-line-buffer-identification in emacs-mode.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (make-variable-buffer-local 'vip-emacs-mode-line-buffer-identification)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (setq-default vip-emacs-mode-line-buffer-identification
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 '("Emacs: %17b"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (defvar vip-current-major-mode nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 "vip-current-major-mode is the major-mode vi considers it is now.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 \(buffer specific\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (make-variable-buffer-local 'vip-current-major-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (defvar vip-last-shell-com nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 "last shell command executed by ! command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (defvar vip-use-register nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 "name of register to store deleted or yanked strings.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (defvar vip-d-com nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 "If non-nil, it's value is a list (M-COM VAL COM), and is used to
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
70 re-execute last destructive command")
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (defconst vip-shift-width 8
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 "*The number of colums shifted by > and < command.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (defconst vip-re-replace nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 "*If t then do regexp replace, if nil then do string replace.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (defvar vip-d-char nil
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
79 "The character remembered by the vi \"r\" command")
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (defvar vip-f-char nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 "for use by \";\" command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (defvar vip-F-char nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 "for use by \".\" command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (defvar vip-f-forward nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 "for use by \";\" command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defvar vip-f-offset nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 "for use by \";\" command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (defconst vip-search-wrap-around t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 "*if t, search wraps around")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (defconst vip-re-search nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 "*if t, search is reg-exp search, otherwise vanilla search.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (defvar vip-s-string nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "last search string")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (defvar vip-s-forward nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 "if t, search is forward.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defconst vip-case-fold-search nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "*if t, search ignores cases.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defconst vip-re-query-replace nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "*If t then do regexp replace, if nil then do string replace.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defconst vip-open-with-indent nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 "*if t, indent when open a new line.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (defconst vip-help-in-insert-mode nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 "*if t then C-h is bound to help-command in insert mode, if nil then it is
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 bound to delete-backward-char.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (defvar vip-quote-string "> "
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 "string inserted at the beginning of region")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (defvar vip-tags-file-name "TAGS")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defvar vip-inhibit-startup-message nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; basic set up
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (global-set-key "\C-z" 'vip-change-mode-to-vi)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defmacro vip-loop (count body)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 "(COUNT BODY) Execute BODY COUNT times."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (list 'let (list (list 'count count))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (list 'while (list '> 'count 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 body
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (list 'setq 'count (list '1- 'count)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (defun vip-push-mark-silent (&optional location)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 No message."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (if (null (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (if (> (length mark-ring) mark-ring-max)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (set-mark (or location (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (defun vip-goto-col (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 "Go to ARG's column."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (if (> val (1+ (current-column))) (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (forward-char (1- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (if com (vip-execute-com 'vip-goto-col val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (defun vip-refresh-mode-line ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 "Redraw mode line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (set-buffer-modified-p (buffer-modified-p)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (defun vip-copy-keymap (map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (if (null map) (make-sparse-keymap) (copy-keymap map)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; changing mode
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (defun vip-change-mode (new-mode)
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
172 "Change mode to NEW-MODE---either emacs-mode, vi-mode, or insert-mode."
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (or (eq new-mode vip-current-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (cond ((eq new-mode 'vi-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (if (eq vip-current-mode 'insert-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (vip-copy-region-as-kill (point) vip-insert-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (vip-repeat-insert-command))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (setq vip-emacs-local-map (current-local-map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 vip-emacs-mode-line-buffer-identification
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 mode-line-buffer-identification
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 vip-insert-local-map (vip-copy-keymap
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (current-local-map))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (vip-change-mode-line "Vi: ")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (use-local-map vip-mode-map))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ((eq new-mode 'insert-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (move-marker vip-insert-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (if (eq vip-current-mode 'emacs-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (setq vip-emacs-local-map (current-local-map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 vip-emacs-mode-line-buffer-identification
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 mode-line-buffer-identification
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 vip-insert-local-map (vip-copy-keymap
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (current-local-map)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (setq vip-insert-local-map (vip-copy-keymap
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 vip-emacs-local-map)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (vip-change-mode-line "Insert")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (use-local-map vip-insert-local-map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (define-key vip-insert-local-map "\e" 'vip-change-mode-to-vi)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (define-key vip-insert-local-map "\C-z" 'vip-ESC)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (define-key vip-insert-local-map "\C-h"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (if vip-help-in-insert-mode 'help-command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 'delete-backward-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (define-key vip-insert-local-map "\C-w"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 'vip-delete-backward-word))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ((eq new-mode 'emacs-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (vip-change-mode-line "Emacs:")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (use-local-map vip-emacs-local-map)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (setq vip-current-mode new-mode)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (vip-refresh-mode-line))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (defun vip-copy-region-as-kill (beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 "If BEG and END do not belong to the same buffer, it copies empty region."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (condition-case nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (copy-region-as-kill beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (error (copy-region-as-kill beg beg))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (defun vip-change-mode-line (string)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 "Assuming that the mode line format contains the string \"Emacs:\", this
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 function replaces the string by \"Vi: \" etc."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (setq mode-line-buffer-identification
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (if (string= string "Emacs:")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 vip-emacs-mode-line-buffer-identification
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (list (concat string " %17b")))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 11
diff changeset
226 ;;;###autoload
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (defun vip-mode ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 "Turn on VIP emulation of VI."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (if (not vip-inhibit-startup-message)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (switch-to-buffer "VIP Startup Message")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (erase-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (insert
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 "VIP is a Vi emulation package for GNU Emacs. VIP provides most Vi commands
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 including Ex commands. VIP is however different from Vi in several points.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 You can get more information on VIP by:
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 1. Typing `M-x info' and selecting menu item \"vip\".
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 2. Typing `C-h k' followed by a key whose description you want.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 3. Printing VIP manual which can be found as GNU/man/vip.texinfo
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 4. Printing VIP Reference Card which can be found as GNU/etc/vipcard.tex
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 This startup message appears whenever you load VIP unless you type `y' now.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 Type `n' to quit this window for now.\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (goto-char (point-min))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (if (y-or-n-p "Inhibit VIP startup message? ")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (set-buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (find-file-noselect (substitute-in-file-name "~/.vip")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (goto-char (point-max))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (insert "\n(setq vip-inhibit-startup-message t)\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (save-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (kill-buffer (current-buffer)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (message "VIP startup message inhibited.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (sit-for 2)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (kill-buffer (current-buffer))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (message "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (setq vip-inhibit-startup-message t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (vip-change-mode-to-vi))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (defun vip-change-mode-to-vi ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 "Change mode to vi mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (vip-change-mode 'vi-mode))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (defun vip-change-mode-to-insert ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 "Change mode to insert mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (vip-change-mode 'insert-mode))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (defun vip-change-mode-to-emacs ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 "Change mode to emacs mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (vip-change-mode 'emacs-mode))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
2319
d98c49df2acd Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1821
diff changeset
278 ;; escape to emacs mode temporarily
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
280 (defun vip-escape-to-emacs (arg &optional events)
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
281 "Escape to Emacs mode for one Emacs command.
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
282 ARG is used as the prefix value for the executed command. If
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
283 EVENTS is a list of events, which become the beginning of the command."
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (interactive "P")
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
285 (let (com key (old-map (current-local-map)))
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
286 (if events (setq unread-command-events events))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (setq prefix-arg arg)
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
288 (use-local-map vip-emacs-local-map)
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
289 (unwind-protect
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
290 (setq com (key-binding (setq key (read-key-sequence nil))))
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
291 (use-local-map old-map))
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
292 (command-execute com prefix-arg)
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (setq prefix-arg nil) ;; reset prefix arg
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (defun vip-message-conditions (conditions)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 "Print CONDITIONS as a message."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (let ((case (car conditions)) (msg (cdr conditions)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (if (null msg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (message "%s" case)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (message "%s %s" case (prin1-to-string msg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (ding)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (defun vip-ESC (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 "Emulate ESC key in Emacs mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (interactive "P")
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
307 (vip-escape-to-emacs arg '(?\e)))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (defun vip-ctl-c (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 "Emulate C-c key in Emacs mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (interactive "P")
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
312 (vip-escape-to-emacs arg '(?\C-c)))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (defun vip-ctl-x (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 "Emulate C-x key in Emacs mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (interactive "P")
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
317 (vip-escape-to-emacs arg '(?\C-x)))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (defun vip-ctl-h (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 "Emulate C-h key in Emacs mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (interactive "P")
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
322 (vip-escape-to-emacs arg '(?\C-h)))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
325 ;; prefix argument for vi mode
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 ;; In vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 ;; represents the numeric value of the prefix argument and COM represents
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 ;; command prefix such as "c", "d", "m" and "y".
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (defun vip-prefix-arg-value (char value com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 "Compute numeric prefix arg value. Invoked by CHAR. VALUE is the value
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 obtained so far, and COM is the command part obtained so far."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (while (and (>= char ?0) (<= char ?9))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (setq char (read-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (setq prefix-arg value)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (if com (setq prefix-arg (cons prefix-arg com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (while (= char ?U)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (vip-describe-arg prefix-arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (setq char (read-char)))
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1625
diff changeset
342 (setq unread-command-events (list char)))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (defun vip-prefix-arg-com (char value com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 "Vi operator as prefix argument."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (let ((cont t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (while (and cont
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (or (= char ?c) (= char ?d) (= char ?y)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (= char ?!) (= char ?<) (= char ?>) (= char ?=)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (= char ?#) (= char ?r) (= char ?R) (= char ?\")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 ;; this means that we already have a command character, so we
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 ;; construct a com list and exit while. however, if char is "
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 ;; it is an error.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 ;; new com is (CHAR . OLDCOM)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (if (or (= char ?#) (= char ?\")) (error ""))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (setq com (cons char com))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 ;; if com is nil we set com as char, and read more. again, if char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 ;; is ", we read the name of register and store it in vip-use-register.
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
362 ;; if char is !, =, or #, a complete com is formed so we exit while.
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (cond ((or (= char ?!) (= char ?=))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (setq com char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (setq char (read-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 ((= char ?#)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 ;; read a char and encode it as com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (setq com (+ 128 (read-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (setq char (read-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 ((or (= char ?<) (= char ?>))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (setq com char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (setq char (read-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (if (= com char) (setq com (cons char com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 ((= char ?\")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (let ((reg (read-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (if (or (and (<= ?A reg) (<= reg ?z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (and (<= ?1 reg) (<= reg ?9)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (setq vip-use-register reg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (error ""))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (setq char (read-char))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (setq com char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (setq char (read-char)))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (if (atom com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 ;; com is a single char, so we construct prefix-arg
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 ;; and if char is ?, describe prefix arg, otherwise exit by
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 ;; pushing the char back
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (setq prefix-arg (cons value com))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (while (= char ?U)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (vip-describe-arg prefix-arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (setq char (read-char)))
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1625
diff changeset
396 (setq unread-command-events (list char)))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 ;; as com is non-nil, this means that we have a command to execute
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (if (or (= (car com) ?r) (= (car com) ?R))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 ;; execute apropriate region command.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (let ((char (car com)) (com (cdr com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (setq prefix-arg (cons value com))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (if (= char ?r) (vip-region prefix-arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (vip-Region prefix-arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 ;; reset prefix-arg
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (setq prefix-arg nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 ;; otherwise, reset prefix arg and call appropriate command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (setq value (if (null value) 1 value))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (setq prefix-arg nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 ((equal com '(?d . ?d)) (vip-line (cons value ?D)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 ((equal com '(?d . ?y)) (vip-yank-defun))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 ((equal com '(?y . ?y)) (vip-line (cons value ?Y)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 ((equal com '(?< . ?<)) (vip-line (cons value ?<)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 ((equal com '(?> . ?>)) (vip-line (cons value ?>)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 ((equal com '(?! . ?!)) (vip-line (cons value ?!)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 ((equal com '(?= . ?=)) (vip-line (cons value ?=)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (t (error ""))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (defun vip-describe-arg (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (let (val com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (setq val (vip-P-val arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 com (vip-getcom arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (if (null val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (if (null com)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
425 (message "Value is nil, and command is nil.")
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (message "Value is nil, and command is %c." com))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (if (null com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (message "Value is %d, and command is nil." val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (message "Value is %d, and command is %c." val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (defun vip-digit-argument (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 "Begin numeric argument for the next command."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (vip-prefix-arg-value last-command-char nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (if (consp arg) (cdr arg) nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (defun vip-command-argument (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 "Accept a motion command as an argument."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (condition-case conditions
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (vip-prefix-arg-com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 last-command-char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (cond ((null arg) nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 ((consp arg) (car arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 ((numberp arg) arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (t (error "strange arg")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (cond ((null arg) nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 ((consp arg) (cdr arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ((numberp arg) nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (t (error "strange arg"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (quit
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (signal 'quit nil))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (defun vip-p-val (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 "Get value part of prefix-argument ARG."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (cond ((null arg) 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 ((consp arg) (if (null (car arg)) 1 (car arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (t arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (defun vip-P-val (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 "Get value part of prefix-argument ARG."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (cond ((consp arg) (car arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (t arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (defun vip-getcom (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 "Get com part of prefix-argument ARG."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (cond ((null arg) nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 ((consp arg) (cdr arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (t nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (defun vip-getCom (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 "Get com part of prefix-argument ARG and modify it."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (let ((com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (cond ((equal com ?c) ?C)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 ((equal com ?d) ?D)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 ((equal com ?y) ?Y)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (t com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 ;; repeat last destructive command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (defun vip-append-to-register (reg start end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 "Append region to text in register REG.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 START and END are buffer positions indicating what to append."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (set-register reg (concat (or (get-register reg) "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (buffer-substring start end))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (defun vip-execute-com (m-com val com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 "(M-COM VAL COM) Execute command COM. The list (M-COM VAL COM) is set
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 to vip-d-com for later use by vip-repeat"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (let ((reg vip-use-register))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (cond ((= com ?c) (vip-change vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 ((= com (- ?c)) (vip-change-subr vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 ((or (= com ?C) (= com (- ?C)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (cond ((and (<= ?a vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (<= vip-use-register ?z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (copy-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 vip-use-register (mark) (point) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 ((and (<= ?A vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (<= vip-use-register ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (vip-append-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (+ vip-use-register 32) (mark) (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (t (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (delete-region (mark) (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (open-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (if (= com ?C) (vip-change-mode-to-insert) (yank)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 ((= com ?d)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (cond ((and (<= ?a vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (<= vip-use-register ?z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (copy-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 vip-use-register vip-com-point (point) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 ((and (<= ?A vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (<= vip-use-register ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (vip-append-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (+ vip-use-register 32) vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (t (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (setq last-command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (if (eq last-command 'd-command) 'kill-region nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (kill-region vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (setq this-command 'd-command))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 ((= com ?D)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (cond ((and (<= ?a vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (<= vip-use-register ?z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (copy-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 vip-use-register (mark) (point) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 ((and (<= ?A vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (<= vip-use-register ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (vip-append-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (+ vip-use-register 32) (mark) (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (t (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (setq last-command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (if (eq last-command 'D-command) 'kill-region nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (kill-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (if (eq m-com 'vip-line) (setq this-command 'D-command)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (back-to-indentation))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 ((= com ?y)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (cond ((and (<= ?a vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (<= vip-use-register ?z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (copy-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 vip-use-register vip-com-point (point) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 ((and (<= ?A vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (<= vip-use-register ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (vip-append-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (+ vip-use-register 32) vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (t (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (setq last-command nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (copy-region-as-kill vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (goto-char vip-com-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 ((= com ?Y)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (cond ((and (<= ?a vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (<= vip-use-register ?z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (copy-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 vip-use-register (mark) (point) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 ((and (<= ?A vip-use-register)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (<= vip-use-register ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 (vip-append-to-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (+ vip-use-register 32) (mark) (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (t (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (setq last-command nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (copy-region-as-kill (mark) (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (goto-char vip-com-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 ((or (= com ?!) (= com (- ?!)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 (shell-command-on-region
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (mark) (point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (if (= com ?!)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (setq vip-last-shell-com (vip-read-string "!"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 vip-last-shell-com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 ((= com ?=)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (if (> (mark) (point)) (exchange-point-and-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (indent-region (mark) (point) nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 ((= com ?<)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (indent-rigidly (mark) (point) (- vip-shift-width)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (goto-char vip-com-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 ((= com ?>)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (indent-rigidly (mark) (point) vip-shift-width))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (goto-char vip-com-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 ((>= com 128)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 ;; this is special command #
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (vip-special-prefix-com (- com 128)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (setq vip-d-com (list m-com val (if (or (= com ?c) (= com ?C) (= com ?!))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 (- com) com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 reg))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (defun vip-repeat (arg)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
629 "(ARG) Re-execute last destructive command. vip-d-com has the form
7639
67b7d1ea7b2e Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5308
diff changeset
630 \(COM ARG CH REG), where COM is the command to be re-executed, ARG is the
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 argument for COM, CH is a flag for repeat, and REG is optional and if exists
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 is the name of the register for COM."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (if (eq last-command 'vip-undo)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 ;; if the last command was vip-undo, then undo-more
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (vip-undo-more)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 ;; its prefix value is used as new prefix value for the command.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 (let ((m-com (car vip-d-com))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (val (vip-P-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 (com (car (cdr (cdr vip-d-com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 (reg (nth 3 vip-d-com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 (if (null val) (setq val (car (cdr vip-d-com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (if (null m-com) (error "No previous command to repeat."))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 (setq vip-use-register reg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 (funcall m-com (cons val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 (defun vip-special-prefix-com (char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 "This command is invoked interactively by the key sequence #<char>"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 (cond ((= char ?c)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (downcase-region (min vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 (max vip-com-point (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 ((= char ?C)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (upcase-region (min vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 (max vip-com-point (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 ((= char ?g)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (vip-global-execute))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 ((= char ?q)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (set-mark vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (vip-quote-region))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 ((= char ?s) (spell-region vip-com-point (point)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 ;; undoing
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 (defun vip-undo ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 "Undo previous change."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (message "undo!")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 (undo-start)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 (undo-more 2)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (setq this-command 'vip-undo))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (defun vip-undo-more ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 "Continue undoing previous changes."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (message "undo more!")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 (undo-more 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (setq this-command 'vip-undo))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 ;; utilities
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 (defun vip-string-tail (str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (if (or (null str) (string= str "")) nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (substring str 1)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (defun vip-yank-defun ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (mark-defun)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (copy-region-as-kill (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 (defun vip-enlarge-region (beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 "Enlarge region between BEG and END."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (if (< beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 (progn (goto-char beg) (set-mark end))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 (goto-char end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (set-mark beg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (if (or (not (eobp)) (not (bolp))) (next-line 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (if (> beg end) (exchange-point-and-mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 (defun vip-global-execute ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 "Call last keyboad macro for each line in the region."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (if (> (point) (mark)) (exchange-point-and-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (call-last-kbd-macro)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (while (< (point) (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (forward-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (call-last-kbd-macro)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (defun vip-quote-region ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 "Quote region by inserting the user supplied string at the beginning of
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 each line in the region."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (setq vip-quote-string
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (let ((str
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (vip-read-string (format "quote string \(default \"%s\"\): "
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 vip-quote-string))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (if (string= str "") vip-quote-string str)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 (vip-enlarge-region (point) (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (if (> (point) (mark)) (exchange-point-and-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (insert vip-quote-string)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 (forward-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (while (and (< (point) (mark)) (bolp))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (insert vip-quote-string)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (forward-line 1)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 (defun vip-end-with-a-newline-p (string)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 "Check if the string ends with a newline."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (or (string= text "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (= (aref string (1- (length string))) ?\n)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (defun vip-read-string (prompt &optional init)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (setq save-minibuffer-local-map (copy-keymap minibuffer-local-map))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (define-key minibuffer-local-map "\C-h" 'backward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 (define-key minibuffer-local-map "\C-w" 'backward-word)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 (define-key minibuffer-local-map "\e" 'exit-minibuffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 (let (str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 (condition-case conditions
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (setq str (read-string prompt init))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (quit
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 (setq minibuffer-local-map save-minibuffer-local-map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 (signal 'quit nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (setq minibuffer-local-map save-minibuffer-local-map)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 str))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 ;; insertion commands
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (defun vip-repeat-insert-command ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 "This function is called when mode changes from insertion mode to
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 vi command mode. It will repeat the insertion command if original insertion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 command was invoked with argument > 1."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 (let ((i-com (car vip-d-com)) (val (car (cdr vip-d-com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (if (and val (> val 1)) ;; first check that val is non-nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (setq vip-d-com (list i-com (1- val) ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (vip-repeat nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 (setq vip-d-com (list i-com val ?r))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (defun vip-insert (arg) ""
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 (setq vip-d-com (list 'vip-insert val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 (if com (vip-loop val (yank))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 (vip-change-mode-to-insert))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (defun vip-append (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 "Append after point."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 (setq vip-d-com (list 'vip-append val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (if (not (eolp)) (forward-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 (if (equal com ?r)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 (vip-loop val (yank))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (vip-change-mode-to-insert))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (defun vip-Append (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 "Append at end of line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (setq vip-d-com (list 'vip-Append val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 (if (equal com ?r)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 (vip-loop val (yank))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (vip-change-mode-to-insert))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (defun vip-Insert (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 "Insert before first non-white."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 (setq vip-d-com (list 'vip-Insert val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (back-to-indentation)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (if (equal com ?r)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 (vip-loop val (yank))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 (vip-change-mode-to-insert))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 (defun vip-open-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 "Open line below."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 (setq vip-d-com (list 'vip-open-line val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 (let ((col (current-indentation)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 (if (equal com ?r)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (vip-loop val
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 (newline 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 (if vip-open-with-indent (indent-to col))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 (yank)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (newline 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 (if vip-open-with-indent (indent-to col))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 (vip-change-mode-to-insert)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 (defun vip-Open-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 "Open line above."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 (setq vip-d-com (list 'vip-Open-line val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 (let ((col (current-indentation)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 (if (equal com ?r)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 (vip-loop val
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 (open-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 (if vip-open-with-indent (indent-to col))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 (yank)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 (open-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 (if vip-open-with-indent (indent-to col))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 (vip-change-mode-to-insert)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 (defun vip-open-line-at-point (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 "Open line at point."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 (setq vip-d-com (list 'vip-open-line-at-point val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843 (if (equal com ?r)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844 (vip-loop val
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 (open-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 (yank)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848 (open-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 (vip-change-mode-to-insert))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
851 (defun vip-substitute (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 "Substitute characters."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
854 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857 (forward-char val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
858 (if (equal com ?r)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 (vip-change-subr (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 (vip-change (mark) (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 (setq vip-d-com (list 'vip-substitute val ?r))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863 (defun vip-substitute-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
864 "Substitute lines."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866 (vip-line (cons arg ?C)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
867
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 ;; line command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871 (defun vip-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 (let ((val (car arg)) (com (cdr arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 (move-marker vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 (next-line (1- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 (vip-execute-com 'vip-line val com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 (defun vip-yank-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
878 "Yank ARG lines (in vi's sense)"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 (let ((val (vip-p-val arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 (vip-line (cons val ?Y))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 ;; region command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 (defun vip-region (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 (let ((val (vip-P-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 (move-marker vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 (vip-execute-com 'vip-region val com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 (defun vip-Region (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 (let ((val (vip-P-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 (move-marker vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 (vip-execute-com 'vip-Region val com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 (defun vip-replace-char (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 "Replace the following ARG chars by the character read."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 (setq vip-d-com (list 'vip-replace-char val ?r))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 (vip-replace-char-subr (if (equal com ?r) vip-d-char (read-char)) val)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 (defun vip-replace-char-subr (char arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 (delete-char arg t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 (setq vip-d-char char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 (vip-loop (if (> arg 0) arg (- arg)) (insert char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 (backward-char arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915 (defun vip-replace-string ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 "Replace string. If you supply null string as the string to be replaced,
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 the query replace mode will toggle between string replace and regexp replace."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 (let (str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 (setq str (vip-read-string
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 (if vip-re-replace "Replace regexp: " "Replace string: ")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 (if (string= str "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924 (setq vip-re-replace (not vip-re-replace))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 (message (format "Replace mode changed to %s."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 (if vip-re-replace "regexp replace"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 "string replace"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 (if vip-re-replace
5308
f14639c69ed3 (vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
929 ;; (replace-regexp
f14639c69ed3 (vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
930 ;; str
f14639c69ed3 (vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
931 ;; (vip-read-string (format "Replace regexp \"%s\" with: " str)))
f14639c69ed3 (vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
932 (while (re-search-forward str nil t)
f14639c69ed3 (vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
933 (replace-match (vip-read-string
f14639c69ed3 (vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
934 (format "Replace regexp \"%s\" with: " str))
f14639c69ed3 (vip-replace-string): Don't use replace-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
935 nil nil))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 (replace-string
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 str
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 (vip-read-string (format "Replace \"%s\" with: " str)))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 ;; basic cursor movement. j, k, l, m commands.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 (defun vip-forward-char (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
944 "Move point right ARG characters (left if ARG negative).On reaching end
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 of buffer, stop and signal error."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
947 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 (forward-char val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 (if com (vip-execute-com 'vip-forward-char val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
951
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 (defun vip-backward-char (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
953 "Move point left ARG characters (right if ARG negative). On reaching
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 beginning of buffer, stop and signal error."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 (backward-char val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959 (if com (vip-execute-com 'vip-backward-char val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
961
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
962 ;; word command
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
963
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
964 (defun vip-forward-word (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
965 "Forward word."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
968 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
969 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 (forward-word val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
971 (skip-chars-forward " \t\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
974 (if (or (= com ?c) (= com (- ?c)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
975 (progn (backward-word 1) (forward-word 1)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
976 (if (or (= com ?d) (= com ?y))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
977 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978 (backward-word 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979 (forward-word 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981 (vip-execute-com 'vip-forward-word val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 (defun vip-end-of-word (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 "Move point to end of current word."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
989 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990 (forward-word val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991 (backward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 (vip-execute-com 'vip-end-of-word val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 (defun vip-backward-word (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 "Backward word."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1003 (backward-word val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 (if com (vip-execute-com 'vip-backward-word val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 (defun vip-forward-Word (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 "Forward word delimited by white character."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 (re-search-forward "[^ \t\n]*[ \t\n]+" nil t val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 (if (or (= com ?c) (= com (- ?c)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 (progn (backward-word 1) (forward-word 1)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 (if (or (= com ?d) (= com ?y))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 (backward-word 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 (forward-word 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 (vip-execute-com 'vip-forward-Word val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 (defun vip-end-of-Word (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 "Move forward to end of word delimited by white character."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1031 (if (re-search-forward "[^ \t\n]+" nil t val) (backward-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035 (vip-execute-com 'vip-end-of-Word val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1037 (defun vip-backward-Word (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 "Backward word delimited by white character."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 (if (re-search-backward "[ \t\n]+[^ \t\n]+" nil t val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 (goto-char (point-min)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 (if com (vip-execute-com 'vip-backward-Word val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 (defun vip-beginning-of-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 "Go to beginning of line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 (beginning-of-line val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 (if com (vip-execute-com 'vip-beginning-of-line val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1055
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 (defun vip-bol-and-skip-white (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 "Beginning of line at first non-white character."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 (back-to-indentation)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062 (if com (vip-execute-com 'vip-bol-and-skip-white val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 (defun vip-goto-eol (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065 "Go to end of line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 (end-of-line val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 (if com (vip-execute-com 'vip-goto-eol val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072 (defun vip-next-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 "Go to next line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 (let ((val (vip-p-val arg)) (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 (line-move val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 (setq this-command 'next-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 (if com (vip-execute-com 'vip-next-line val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 (defun vip-next-line-at-bol (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082 "Next line at beginning of line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084 (let ((val (vip-p-val arg)) (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086 (next-line val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 (back-to-indentation)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088 (if com (vip-execute-com 'vip-next-line-at-bol val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090 (defun vip-previous-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091 "Go to previous line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 (let ((val (vip-p-val arg)) (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 (next-line (- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 (setq this-command 'previous-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 (if com (vip-execute-com 'vip-previous-line val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 (defun vip-previous-line-at-bol (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 "Previous line at beginning of line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 (let ((val (vip-p-val arg)) (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 (next-line (- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 (back-to-indentation)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1106 (if com (vip-execute-com 'vip-previous-line val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108 (defun vip-change-to-eol (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109 "Change to end of line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1110 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111 (vip-goto-eol (cons arg ?c)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1112
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1113 (defun vip-kill-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1114 "Delete line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 (vip-goto-eol (cons arg ?d)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119 ;; moving around
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121 (defun vip-goto-line (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122 "Go to ARG's line. Without ARG go to end of buffer."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1123 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1124 (let ((val (vip-P-val arg)) (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 (move-marker vip-com-point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 (if (null val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 (goto-char (point-max))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 (goto-char (point-min))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 (forward-line (1- val)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 (back-to-indentation)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 (if com (vip-execute-com 'vip-goto-line val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134 (defun vip-find-char (arg char forward offset)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
1135 "Find ARG's occurrence of CHAR on the current line. If FORWARD then
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 search is forward, otherwise backward. OFFSET is used to adjust point
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 after search."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 (let ((arg (if forward arg (- arg))) point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140 (save-restriction
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 (if (> arg 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142 (narrow-to-region
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 ;; forward search begins here
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 (if (eolp) (error "") (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 ;; forward search ends here
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 (progn (next-line 1) (beginning-of-line) (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 (narrow-to-region
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 ;; backward search begins from here
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 (if (bolp) (error "") (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 ;; backward search ends here
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151 (progn (beginning-of-line) (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152 ;; if arg > 0, point is forwarded before search.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153 (if (> arg 0) (goto-char (1+ (point-min)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1154 (goto-char (point-max)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1155 (let ((case-fold-search nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 (search-forward (char-to-string char) nil 0 arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157 (setq point (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 (if (or (and (> arg 0) (= point (point-max)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 (and (< arg 0) (= point (point-min))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 (error ""))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 (defun vip-find-char-forward (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 "Find char on the line. If called interactively read the char to find
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 from the terminal, and if called from vip-repeat, the char last used is
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 used. This behaviour is controlled by the sign of prefix numeric value."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169 (if (> val 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 ;; this means that the function was called interactively
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 (setq vip-f-char (read-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 vip-f-forward t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 vip-f-offset nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 (setq val (- val)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177 (setq val (- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 (setq vip-F-char vip-f-char);; set new vip-F-char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182 (vip-execute-com 'vip-find-char-forward val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 (defun vip-goto-char-forward (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 "Go up to char ARG forward on line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 (if (> val 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 ;; this means that the function was called interactively
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 (setq vip-f-char (read-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 vip-f-forward t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 vip-f-offset t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193 (setq val (- val)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 (setq val (- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199 (setq vip-F-char vip-f-char);; set new vip-F-char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 (vip-execute-com 'vip-goto-char-forward val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 (defun vip-find-char-backward (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 "Find char ARG on line backward."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 (if (> val 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 ;; this means that the function was called interactively
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 (setq vip-f-char (read-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 vip-f-forward nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 vip-f-offset nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 (setq val (- val)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 (vip-find-char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216 (setq val (- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 (setq vip-F-char vip-f-char);; set new vip-F-char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 (vip-execute-com 'vip-find-char-backward val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 (defun vip-goto-char-backward (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 "Go up to char ARG backward on line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 (if (> val 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 ;; this means that the function was called interactively
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228 (setq vip-f-char (read-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 vip-f-forward nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 vip-f-offset t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 (setq val (- val)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234 (setq val (- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237 (setq vip-F-char vip-f-char);; set new vip-F-char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238 (vip-execute-com 'vip-goto-char-backward val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240 (defun vip-repeat-find (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 "Repeat previous find command."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 (vip-find-char val vip-f-char vip-f-forward vip-f-offset)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 (if vip-f-forward (forward-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 (vip-execute-com 'vip-repeat-find val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 (defun vip-repeat-find-opposite (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 "Repeat previous find command in the opposite direction."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 (if vip-f-forward (forward-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 (vip-execute-com 'vip-repeat-find-opposite val com)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 ;; window scrolling etc.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1264
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 (defun vip-other-window (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1266 "Switch to other window."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1268 (other-window arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269 (or (not (eq vip-current-mode 'emacs-mode))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1270 (string= (buffer-name (current-buffer)) " *Minibuf-1*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1271 (vip-change-mode-to-vi)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1272
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273 (defun vip-window-top (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 "Go to home window line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1275 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1277 (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1278 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279 (move-to-window-line (1- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280 (if com (vip-execute-com 'vip-window-top val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1281
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1282 (defun vip-window-middle (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1283 "Go to middle window line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1288 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289 (if com (vip-execute-com 'vip-window-middle val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291 (defun vip-window-bottom (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 "Go to last window line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297 (move-to-window-line (- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1298 (if com (vip-execute-com 'vip-window-bottom val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300 (defun vip-line-to-top (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 "Put current line on the home line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303 (recenter (1- arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (defun vip-line-to-middle (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306 "Put current line on the middle line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 (recenter (+ (1- arg) (/ (1- (window-height)) 2))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 (defun vip-line-to-bottom (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 "Put current line on the last line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 (recenter (- (window-height) (1+ arg))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 ;; paren match
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 (defun vip-paren-match (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 "Go to the matching parenthesis."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 (let ((com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 (if (numberp arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 (if (or (> arg 99) (< arg 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 (error "Prefix must be between 1 and 99.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 (goto-char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 (if (> (point-max) 80000)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 (* (/ (point-max) 100) arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1328 (/ (* (point-max) arg) 100)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 (back-to-indentation))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330 (cond ((looking-at "[\(\[{]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332 (forward-sexp 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1333 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1334 (vip-execute-com 'vip-paren-match nil com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1335 (backward-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1336 ((looking-at "[])}]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337 (forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 (backward-sexp 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 (if com (vip-execute-com 'vip-paren-match nil com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1341 (t (error ""))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344 ;; sentence and paragraph
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 (defun vip-forward-sentence (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 "Forward sentence."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 (forward-sentence val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 (if com (vip-execute-com 'vip-forward-sentence nil com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 (defun vip-backward-sentence (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 "Backward sentence."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 (backward-sentence val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362 (if com (vip-execute-com 'vip-backward-sentence nil com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 (defun vip-forward-paragraph (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 "Forward paragraph."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 (forward-paragraph val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 (if com (vip-execute-com 'vip-forward-paragraph nil com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 (defun vip-backward-paragraph (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 "Backward paragraph."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1379 (backward-paragraph val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1380 (if com (vip-execute-com 'vip-backward-paragraph nil com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1381
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1382
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1383 ;; scrolling
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1384
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1385 (defun vip-scroll (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1386 "Scroll to next screen."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1387 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1388 (if (> arg 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389 (while (> arg 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1390 (scroll-up)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1391 (setq arg (1- arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1392 (while (> 0 arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1393 (scroll-down)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394 (setq arg (1+ arg)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1395
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1396 (defun vip-scroll-back (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1397 "Scroll to previous screen."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1398 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1399 (vip-scroll (- arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1400
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1401 (defun vip-scroll-down (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1402 "Scroll up half screen."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1403 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1404 (if (null arg) (scroll-down (/ (window-height) 2))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1405 (scroll-down arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1407 (defun vip-scroll-down-one (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408 "Scroll up one line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 (scroll-down arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1412 (defun vip-scroll-up (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1413 "Scroll down half screen."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1415 (if (null arg) (scroll-up (/ (window-height) 2))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416 (scroll-up arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1417
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1418 (defun vip-scroll-up-one (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419 "Scroll down one line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1420 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1421 (scroll-up arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1422
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1424 ;; splitting window
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1425
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426 (defun vip-buffer-in-two-windows ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1427 "Show current buffer in two windows."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429 (delete-other-windows)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1430 (split-window-vertically nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1432
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1433 ;; searching
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1434
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1435 (defun vip-search-forward (arg)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
1436 "Search a string forward. ARG is used to find the ARG's occurrence
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1437 of the string. Default is vanilla search. Search mode can be toggled by
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438 giving null search string."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440 (let ((val (vip-P-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441 (setq vip-s-forward t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442 vip-s-string (vip-read-string (if vip-re-search "RE-/" "/")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443 (if (string= vip-s-string "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1445 (setq vip-re-search (not vip-re-search))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1446 (message (format "Search mode changed to %s search."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1447 (if vip-re-search "regular expression"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1448 "vanilla"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449 (vip-search vip-s-string t val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1450 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1451 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1452 (move-marker vip-com-point (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1453 (vip-execute-com 'vip-search-next val com))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1454
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1455 (defun vip-search-backward (arg)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
1456 "Search a string backward. ARG is used to find the ARG's occurrence
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 of the string. Default is vanilla search. Search mode can be toggled by
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458 giving null search string."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 (let ((val (vip-P-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 (setq vip-s-forward nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 vip-s-string (vip-read-string (if vip-re-search "RE-?" "?")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1463 (if (string= vip-s-string "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1464 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465 (setq vip-re-search (not vip-re-search))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466 (message (format "Search mode changed to %s search."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467 (if vip-re-search "regular expression"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 "vanilla"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1469 (vip-search vip-s-string nil val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1470 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472 (move-marker vip-com-point (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 (vip-execute-com 'vip-search-next val com))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1475 (defun vip-search (string forward arg &optional no-offset init-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 "(STRING FORWARD COUNT &optional NO-OFFSET) Search COUNT's occurrence of
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 STRING. Search will be forward if FORWARD, otherwise backward."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (let ((val (vip-p-val arg)) (com (vip-getcom arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479 (null-arg (null (vip-P-val arg))) (offset (not no-offset))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480 (case-fold-search vip-case-fold-search)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481 (start-point (or init-point (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 (if forward
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1483 (condition-case conditions
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1485 (if (and offset (not (eobp))) (forward-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1486 (if vip-re-search
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1488 (re-search-forward string nil nil val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1489 (re-search-backward string))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1490 (search-forward string nil nil val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1491 (search-backward string))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1492 (push-mark start-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1493 (search-failed
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494 (if (and null-arg vip-search-wrap-around)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1495 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496 (goto-char (point-min))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1497 (vip-search string forward (cons 1 com) t start-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1498 (goto-char start-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499 (signal 'search-failed (cdr conditions)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500 (condition-case conditions
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1501 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502 (if vip-re-search
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1503 (re-search-backward string nil nil val)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1504 (search-backward string nil nil val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1505 (push-mark start-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1506 (search-failed
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507 (if (and null-arg vip-search-wrap-around)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1508 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509 (goto-char (point-max))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1510 (vip-search string forward (cons 1 com) t start-point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1511 (goto-char start-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1512 (signal 'search-failed (cdr conditions))))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1513
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1514 (defun vip-search-next (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1515 "Repeat previous search."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1516 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1517 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1518 (if (null vip-s-string) (error "No previous search string."))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519 (vip-search vip-s-string vip-s-forward arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1520 (if com (vip-execute-com 'vip-search-next val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1521
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1522 (defun vip-search-Next (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 "Repeat previous search in the reverse direction."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1524 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1525 (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1526 (if (null vip-s-string) (error "No previous search string."))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1527 (vip-search vip-s-string (not vip-s-forward) arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1528 (if com (vip-execute-com 'vip-search-Next val com))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1529
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1530
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1531 ;; visiting and killing files, buffers
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1532
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1533 (defun vip-switch-to-buffer ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1534 "Switch to buffer in the current window."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1535 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1536 (let (buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1537 (setq buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 (read-buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539 (format "switch to buffer \(%s\): "
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1540 (buffer-name (other-buffer (current-buffer))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1541 (switch-to-buffer buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1542 (vip-change-mode-to-vi)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1543
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544 (defun vip-switch-to-buffer-other-window ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 "Switch to buffer in another window."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1547 (let (buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548 (setq buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (read-buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 (format "Switch to buffer \(%s\): "
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1551 (buffer-name (other-buffer (current-buffer))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 (switch-to-buffer-other-window buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1553 (vip-change-mode-to-vi)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1554
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 (defun vip-kill-buffer ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1556 "Kill a buffer."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1557 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 (let (buffer buffer-name)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1559 (setq buffer-name
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1560 (read-buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1561 (format "Kill buffer \(%s\): "
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1562 (buffer-name (current-buffer)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1563 (setq buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1564 (if (null buffer-name)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1565 (current-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1566 (get-buffer buffer-name)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567 (if (null buffer) (error "Buffer %s nonexistent." buffer-name))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1568 (if (or (not (buffer-modified-p buffer))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1569 (y-or-n-p "Buffer is modified, are you sure? "))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1570 (kill-buffer buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1571 (error "Buffer not killed."))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1572
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1573 (defun vip-find-file ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1574 "Visit file in the current window."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1575 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1576 (let (file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1577 (setq file (read-file-name "visit file: "))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1578 (switch-to-buffer (find-file-noselect file))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1579 (vip-change-mode-to-vi)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1580
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1581 (defun vip-find-file-other-window ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1582 "Visit file in another window."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1583 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1584 (let (file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1585 (setq file (read-file-name "Visit file: "))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1586 (switch-to-buffer-other-window (find-file-noselect file))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1587 (vip-change-mode-to-vi)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1588
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1589 (defun vip-info-on-file ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1590 "Give information of the file associated to the current buffer."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1591 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1592 (message "\"%s\" line %d of %d"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1593 (if (buffer-file-name) (buffer-file-name) "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1594 (1+ (count-lines (point-min) (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1595 (1+ (count-lines (point-min) (point-max)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1596
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1597
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1598 ;; yank and pop
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1599
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1600 (defun vip-yank (text)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1601 "yank TEXT silently."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1602 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1603 (vip-push-mark-silent (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1604 (insert text)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1605 (exchange-point-and-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1606 (skip-chars-forward " \t"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1607
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1608 (defun vip-put-back (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1609 "Put back after point/below line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1610 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1611 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1612 (text (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613 (if (and (<= ?1 vip-use-register) (<= vip-use-register ?9))
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1614 (current-kill (- vip-use-register ?1) 'do-not-rotate)
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1615 (get-register vip-use-register))
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1616 (current-kill 0))))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1617 (if (null text)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1618 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619 (let ((reg vip-use-register))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620 (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621 (error "Nothing in register %c" reg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1622 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1623 (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1624 (if (vip-end-with-a-newline-p text)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1625 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1626 (next-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1627 (beginning-of-line))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1628 (if (and (not (eolp)) (not (eobp))) (forward-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1629 (setq vip-d-com (list 'vip-put-back val nil vip-use-register))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1630 (vip-loop val (vip-yank text))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1631
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1632 (defun vip-Put-back (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1633 "Put back at point/above line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1634 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1635 (let ((val (vip-p-val arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1636 (text (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1637 (if (and (<= ?1 vip-use-register) (<= vip-use-register ?9))
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1638 (current-kill (- vip-use-register ?1) 'do-not-rotate)
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1639 (get-register vip-use-register))
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1640 (current-kill 0))))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1641 (if (null text)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1642 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1643 (let ((reg vip-use-register))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1644 (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1645 (error "Nothing in register %c" reg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1646 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1647 (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1648 (if (vip-end-with-a-newline-p text) (beginning-of-line))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1649 (setq vip-d-com (list 'vip-Put-back val nil vip-use-register))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1650 (vip-loop val (vip-yank text))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1651
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1652 (defun vip-delete-char (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1653 "Delete character."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1654 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1655 (let ((val (vip-p-val arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1656 (setq vip-d-com (list 'vip-delete-char val nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1657 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1658 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1659 (if (and (<= ?A vip-use-register) (<= vip-use-register ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1660 (vip-append-to-register
1625
376427dea90a * bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
1661 (+ vip-use-register 32) (point) (- (point) val))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1662 (copy-to-register vip-use-register (point) (- (point) val) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1663 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1664 (delete-char val t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1665
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1666 (defun vip-delete-backward-char (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1667 "Delete previous character."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1668 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1669 (let ((val (vip-p-val arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1670 (setq vip-d-com (list 'vip-delete-backward-char val nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1671 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1672 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1673 (if (and (<= ?A vip-use-register) (<= vip-use-register ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1674 (vip-append-to-register
1625
376427dea90a * bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
1675 (+ vip-use-register 32) (point) (+ (point) val))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1676 (copy-to-register vip-use-register (point) (+ (point) val) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1677 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1678 (delete-backward-char val t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1679
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1680
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1681 ;; join lines.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1682
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1683 (defun vip-join-lines (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1684 "Join this line to next, if ARG is nil. Otherwise, join ARG lines"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1685 (interactive "*P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1686 (let ((val (vip-P-val arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1687 (setq vip-d-com (list 'vip-join-lines val nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1688 (vip-loop (if (null val) 1 (1- val))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1689 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1690 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1691 (if (not (eobp))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1692 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1693 (forward-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1694 (delete-region (point) (1- (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1695 (fixup-whitespace)))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1696
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1697
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1698 ;; making small changes
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1699
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1700 (defun vip-change (beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1701 (setq c-string
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1702 (vip-read-string (format "%s => " (buffer-substring beg end))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1703 (vip-change-subr beg end))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1704
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1705 (defun vip-change-subr (beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1706 (if vip-use-register
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1707 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1708 (copy-to-register vip-use-register beg end nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1709 (setq vip-use-register nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1710 (kill-region beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1711 (setq this-command 'vip-change)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1712 (insert c-string))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1713
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1714
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1715 ;; query replace
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1716
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1717 (defun vip-query-replace ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1718 "Query replace. If you supply null string as the string to be replaced,
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1719 the query replace mode will toggle between string replace and regexp replace."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1720 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1721 (let (str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1722 (setq str (vip-read-string
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1723 (if vip-re-query-replace "Query replace regexp: "
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1724 "Query replace: ")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1725 (if (string= str "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1726 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1727 (setq vip-re-query-replace (not vip-re-query-replace))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1728 (message "Query replace mode changed to %s."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1729 (if vip-re-query-replace "regexp replace"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1730 "string replace")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1731 (if vip-re-query-replace
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1732 (query-replace-regexp
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1733 str
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1734 (vip-read-string (format "Query replace regexp \"%s\" with: " str)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1735 (query-replace
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1736 str
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1737 (vip-read-string (format "Query replace \"%s\" with: " str)))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1738
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1739
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1740 ;; marking
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1741
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1742 (defun vip-mark-beginning-of-buffer ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1744 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1745 (goto-char (point-min))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1746 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1747 (message "mark set at the beginning of buffer"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1748
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1749 (defun vip-mark-end-of-buffer ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1750 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1751 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1752 (goto-char (point-max))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1753 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1754 (message "mark set at the end of buffer"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1755
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1756 (defun vip-mark-point (char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1757 (interactive "c")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1758 (cond ((and (<= ?a char) (<= char ?z))
1625
376427dea90a * bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
1759 (point-to-register (- char (- ?a ?\C-a)) nil))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1760 ((= char ?<) (vip-mark-beginning-of-buffer))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1761 ((= char ?>) (vip-mark-end-of-buffer))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1762 ((= char ?.) (push-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1763 ((= char ?,) (set-mark-command 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1764 ((= char ?D) (mark-defun))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1765 (t (error ""))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1766
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1767 (defun vip-goto-mark (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1768 "Go to mark."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1769 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1770 (let ((char (read-char)) (com (vip-getcom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1771 (vip-goto-mark-subr char com nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1772
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1773 (defun vip-goto-mark-and-skip-white (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1774 "Go to mark and skip to first non-white on line."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1775 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1776 (let ((char (read-char)) (com (vip-getCom arg)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1777 (vip-goto-mark-subr char com t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1778
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1779 (defun vip-goto-mark-subr (char com skip-white)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1780 (cond ((and (<= ?a char) (<= char ?z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1781 (let ((buff (current-buffer)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1782 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1783 (goto-char (register-to-point (- char (- ?a ?\C-a))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784 (if skip-white (back-to-indentation))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1785 (vip-change-mode-to-vi)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1786 (if com
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1787 (if (equal buff (current-buffer))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1788 (vip-execute-com (if skip-white
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1789 'vip-goto-mark-and-skip-white
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1790 'vip-goto-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1791 nil com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1792 (switch-to-buffer buff)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1793 (goto-char vip-com-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1794 (vip-change-mode-to-vi)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1795 (error "")))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1796 ((and (not skip-white) (= char ?`))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1797 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1798 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1799 (if com (vip-execute-com 'vip-goto-mark nil com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1800 ((and skip-white (= char ?'))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1801 (if com (move-marker vip-com-point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1802 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1803 (back-to-indentation)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1804 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1805 (t (error ""))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1806
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1807 (defun vip-exchange-point-and-mark ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1808 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1809 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1810 (back-to-indentation))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1811
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1812 (defun vip-keyboard-quit ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1813 "Abort partially formed or running command."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1814 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1815 (setq vip-use-register nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1816 (keyboard-quit))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1817
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1818 (defun vip-ctl-c-equivalent (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1819 "Emulate C-c in Emacs mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1820 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1821 (vip-ctl-key-equivalent "\C-c" arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1822
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1823 (defun vip-ctl-x-equivalent (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1824 "Emulate C-x in Emacs mode."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1825 (interactive "P")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1826 (vip-ctl-key-equivalent "\C-x" arg))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1827
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1828 (defun vip-ctl-key-equivalent (key arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1829 (let ((char (read-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1830 (if (and (<= ?A char) (<= char ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1831 (setq char (- char (- ?A ?\C-a))))
3519
093c4dc7e884 (vip-ctl-key-equivalent): Use vip-escape-to-emacs.
Richard M. Stallman <rms@gnu.org>
parents: 2319
diff changeset
1832 (vip-escape-to-emacs arg (list (aref key 0) char))))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1833
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1834 ;; commands in insertion mode
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1835
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1836 (defun vip-delete-backward-word (arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1837 "Delete previous word."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1838 (interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1839 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1840 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1841 (backward-word arg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1842 (delete-region (point) (mark))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1843
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1844
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1845 ;; key bindings
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1846
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1847 (set 'vip-mode-map (make-keymap))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1848
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1849 (define-key vip-mode-map "\C-a" 'beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1850 (define-key vip-mode-map "\C-b" 'vip-scroll-back)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1851 (define-key vip-mode-map "\C-c" 'vip-ctl-c)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1852 (define-key vip-mode-map "\C-d" 'vip-scroll-up)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1853 (define-key vip-mode-map "\C-e" 'vip-scroll-up-one)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1854 (define-key vip-mode-map "\C-f" 'vip-scroll)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1855 (define-key vip-mode-map "\C-g" 'vip-keyboard-quit)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1856 (define-key vip-mode-map "\C-h" 'help-command)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1857 (define-key vip-mode-map "\C-m" 'vip-scroll-back)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1858 (define-key vip-mode-map "\C-n" 'vip-other-window)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1859 (define-key vip-mode-map "\C-o" 'vip-open-line-at-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1860 (define-key vip-mode-map "\C-u" 'vip-scroll-down)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1861 (define-key vip-mode-map "\C-x" 'vip-ctl-x)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1862 (define-key vip-mode-map "\C-y" 'vip-scroll-down-one)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1863 (define-key vip-mode-map "\C-z" 'vip-change-mode-to-emacs)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1864 (define-key vip-mode-map "\e" 'vip-ESC)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1865
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1866 (define-key vip-mode-map " " 'vip-scroll)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1867 (define-key vip-mode-map "!" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1868 (define-key vip-mode-map "\"" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1869 (define-key vip-mode-map "#" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1870 (define-key vip-mode-map "$" 'vip-goto-eol)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1871 (define-key vip-mode-map "%" 'vip-paren-match)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1872 (define-key vip-mode-map "&" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1873 (define-key vip-mode-map "'" 'vip-goto-mark-and-skip-white)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1874 (define-key vip-mode-map "(" 'vip-backward-sentence)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1875 (define-key vip-mode-map ")" 'vip-forward-sentence)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1876 (define-key vip-mode-map "*" 'call-last-kbd-macro)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1877 (define-key vip-mode-map "+" 'vip-next-line-at-bol)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1878 (define-key vip-mode-map "," 'vip-repeat-find-opposite)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1879 (define-key vip-mode-map "-" 'vip-previous-line-at-bol)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1880 (define-key vip-mode-map "." 'vip-repeat)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1881 (define-key vip-mode-map "/" 'vip-search-forward)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1882
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1883 (define-key vip-mode-map "0" 'vip-beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1884 (define-key vip-mode-map "1" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1885 (define-key vip-mode-map "2" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1886 (define-key vip-mode-map "3" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1887 (define-key vip-mode-map "4" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1888 (define-key vip-mode-map "5" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1889 (define-key vip-mode-map "6" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1890 (define-key vip-mode-map "7" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1891 (define-key vip-mode-map "8" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1892 (define-key vip-mode-map "9" 'vip-digit-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1893
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1894 (define-key vip-mode-map ":" 'vip-ex)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1895 (define-key vip-mode-map ";" 'vip-repeat-find)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1896 (define-key vip-mode-map "<" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1897 (define-key vip-mode-map "=" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1898 (define-key vip-mode-map ">" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1899 (define-key vip-mode-map "?" 'vip-search-backward)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1900 (define-key vip-mode-map "@" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1901
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1902 (define-key vip-mode-map "A" 'vip-Append)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1903 (define-key vip-mode-map "B" 'vip-backward-Word)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1904 (define-key vip-mode-map "C" 'vip-ctl-c-equivalent)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1905 (define-key vip-mode-map "D" 'vip-kill-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1906 (define-key vip-mode-map "E" 'vip-end-of-Word)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1907 (define-key vip-mode-map "F" 'vip-find-char-backward)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1908 (define-key vip-mode-map "G" 'vip-goto-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1909 (define-key vip-mode-map "H" 'vip-window-top)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1910 (define-key vip-mode-map "I" 'vip-Insert)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1911 (define-key vip-mode-map "J" 'vip-join-lines)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1912 (define-key vip-mode-map "K" 'vip-kill-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1913 (define-key vip-mode-map "L" 'vip-window-bottom)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1914 (define-key vip-mode-map "M" 'vip-window-middle)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1915 (define-key vip-mode-map "N" 'vip-search-Next)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1916 (define-key vip-mode-map "O" 'vip-Open-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1917 (define-key vip-mode-map "P" 'vip-Put-back)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1918 (define-key vip-mode-map "Q" 'vip-query-replace)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1919 (define-key vip-mode-map "R" 'vip-replace-string)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1920 (define-key vip-mode-map "S" 'vip-switch-to-buffer-other-window)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1921 (define-key vip-mode-map "T" 'vip-goto-char-backward)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1922 (define-key vip-mode-map "U" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1923 (define-key vip-mode-map "V" 'vip-find-file-other-window)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1924 (define-key vip-mode-map "W" 'vip-forward-Word)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1925 (define-key vip-mode-map "X" 'vip-ctl-x-equivalent)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1926 (define-key vip-mode-map "Y" 'vip-yank-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1927 (define-key vip-mode-map "ZZ" 'save-buffers-kill-emacs)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1928
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1929 (define-key vip-mode-map "[" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1930 (define-key vip-mode-map "\\" 'vip-escape-to-emacs)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1931 (define-key vip-mode-map "]" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1932 (define-key vip-mode-map "^" 'vip-bol-and-skip-white)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1933 (define-key vip-mode-map "_" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1934 (define-key vip-mode-map "`" 'vip-goto-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1935
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1936 (define-key vip-mode-map "a" 'vip-append)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1937 (define-key vip-mode-map "b" 'vip-backward-word)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1938 (define-key vip-mode-map "c" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1939 (define-key vip-mode-map "d" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1940 (define-key vip-mode-map "e" 'vip-end-of-word)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1941 (define-key vip-mode-map "f" 'vip-find-char-forward)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1942 (define-key vip-mode-map "g" 'vip-info-on-file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1943 (define-key vip-mode-map "h" 'vip-backward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1944 (define-key vip-mode-map "i" 'vip-insert)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1945 (define-key vip-mode-map "j" 'vip-next-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1946 (define-key vip-mode-map "k" 'vip-previous-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1947 (define-key vip-mode-map "l" 'vip-forward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1948 (define-key vip-mode-map "m" 'vip-mark-point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1949 (define-key vip-mode-map "n" 'vip-search-next)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1950 (define-key vip-mode-map "o" 'vip-open-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1951 (define-key vip-mode-map "p" 'vip-put-back)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1952 (define-key vip-mode-map "q" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1953 (define-key vip-mode-map "r" 'vip-replace-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1954 (define-key vip-mode-map "s" 'vip-switch-to-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1955 (define-key vip-mode-map "t" 'vip-goto-char-forward)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1956 (define-key vip-mode-map "u" 'vip-undo)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1957 (define-key vip-mode-map "v" 'vip-find-file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1958 (define-key vip-mode-map "w" 'vip-forward-word)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1959 (define-key vip-mode-map "x" 'vip-delete-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1960 (define-key vip-mode-map "y" 'vip-command-argument)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1961 (define-key vip-mode-map "zH" 'vip-line-to-top)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1962 (define-key vip-mode-map "zM" 'vip-line-to-middle)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1963 (define-key vip-mode-map "zL" 'vip-line-to-bottom)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1964 (define-key vip-mode-map "z\C-m" 'vip-line-to-top)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1965 (define-key vip-mode-map "z." 'vip-line-to-middle)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1966 (define-key vip-mode-map "z-" 'vip-line-to-bottom)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1967
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1968 (define-key vip-mode-map "{" 'vip-backward-paragraph)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1969 (define-key vip-mode-map "|" 'vip-goto-col)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1970 (define-key vip-mode-map "}" 'vip-forward-paragraph)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1971 (define-key vip-mode-map "~" 'vip-nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1972 (define-key vip-mode-map "\177" 'vip-delete-backward-char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1973
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1974 (define-key ctl-x-map "3" 'vip-buffer-in-two-windows)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1975 (define-key ctl-x-map "\C-i" 'insert-file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1976
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1977 (defun vip-version ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1978 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1979 (message "VIP version 3.5 of September 15, 1987"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1980
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1981
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1982 ;; implement ex commands
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1983
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1984 (defvar ex-token-type nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1985 "type of token. if non-nil, gives type of address. if nil, it
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1986 is a command.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1987
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1988 (defvar ex-token nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1989 "value of token.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1990
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1991 (defvar ex-addresses nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1992 "list of ex addresses")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1993
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1994 (defvar ex-flag nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1995 "flag for ex flag")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1996
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1997 (defvar ex-buffer nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1998 "name of ex buffer")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1999
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2000 (defvar ex-count nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2001 "value of ex count")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2002
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2003 (defvar ex-g-flag nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2004 "flag for global command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2005
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2006 (defvar ex-g-variant nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2007 "if t global command is executed on lines not matching ex-g-pat")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2008
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2009 (defvar ex-reg-exp nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2010 "save reg-exp used in substitute")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2011
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2012 (defvar ex-repl nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2013 "replace pattern for substitute")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2014
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2015 (defvar ex-g-pat nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2016 "pattern for global command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2017
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2018 (defvar ex-map (make-sparse-keymap)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
2019 "save commands for mapped keys")
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2020
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2021 (defvar ex-tag nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2022 "save ex tag")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2023
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2024 (defvar ex-file nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2025
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2026 (defvar ex-variant nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2027
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2028 (defvar ex-offset nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2029
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2030 (defvar ex-append nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2031
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2032 (defun vip-nil ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2033 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2034 (error ""))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2035
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2036 (defun vip-looking-back (str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2037 "returns t if looking back reg-exp STR before point."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2038 (and (save-excursion (re-search-backward str nil t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2039 (= (point) (match-end 0))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2040
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2041 (defun vip-check-sub (str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2042 "check if ex-token is an initial segment of STR"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2043 (let ((length (length ex-token)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2044 (if (and (<= length (length str))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2045 (string= ex-token (substring str 0 length)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2046 (setq ex-token str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2047 (setq ex-token-type "non-command"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2048
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2049 (defun vip-get-ex-com-subr ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2050 "get a complete ex command"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2051 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2052 (re-search-forward "[a-z][a-z]*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2053 (setq ex-token-type "command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2054 (setq ex-token (buffer-substring (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2055 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2056 (cond ((looking-at "a")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2057 (cond ((looking-at "ab") (vip-check-sub "abbreviate"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2058 ((looking-at "ar") (vip-check-sub "args"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2059 (t (vip-check-sub "append"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2060 ((looking-at "[bh]") (setq ex-token-type "non-command"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2061 ((looking-at "c")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2062 (if (looking-at "co") (vip-check-sub "copy")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2063 (vip-check-sub "change")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2064 ((looking-at "d") (vip-check-sub "delete"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2065 ((looking-at "e")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2066 (if (looking-at "ex") (vip-check-sub "ex")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2067 (vip-check-sub "edit")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2068 ((looking-at "f") (vip-check-sub "file"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2069 ((looking-at "g") (vip-check-sub "global"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2070 ((looking-at "i") (vip-check-sub "insert"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2071 ((looking-at "j") (vip-check-sub "join"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2072 ((looking-at "l") (vip-check-sub "list"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2073 ((looking-at "m")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2074 (cond ((looking-at "map") (vip-check-sub "map"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2075 ((looking-at "mar") (vip-check-sub "mark"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2076 (t (vip-check-sub "move"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2077 ((looking-at "n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2078 (if (looking-at "nu") (vip-check-sub "number")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2079 (vip-check-sub "next")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2080 ((looking-at "o") (vip-check-sub "open"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2081 ((looking-at "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2082 (cond ((looking-at "pre") (vip-check-sub "preserve"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2083 ((looking-at "pu") (vip-check-sub "put"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2084 (t (vip-check-sub "print"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2085 ((looking-at "q") (vip-check-sub "quit"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2086 ((looking-at "r")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2087 (cond ((looking-at "rec") (vip-check-sub "recover"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2088 ((looking-at "rew") (vip-check-sub "rewind"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2089 (t (vip-check-sub "read"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2090 ((looking-at "s")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2091 (cond ((looking-at "se") (vip-check-sub "set"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2092 ((looking-at "sh") (vip-check-sub "shell"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2093 ((looking-at "so") (vip-check-sub "source"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2094 ((looking-at "st") (vip-check-sub "stop"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2095 (t (vip-check-sub "substitute"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2096 ((looking-at "t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2097 (if (looking-at "ta") (vip-check-sub "tag")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2098 (vip-check-sub "t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2099 ((looking-at "u")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2100 (cond ((looking-at "una") (vip-check-sub "unabbreviate"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2101 ((looking-at "unm") (vip-check-sub "unmap"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2102 (t (vip-check-sub "undo"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2103 ((looking-at "v")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2104 (cond ((looking-at "ve") (vip-check-sub "version"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2105 ((looking-at "vi") (vip-check-sub "visual"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2106 (t (vip-check-sub "v"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2107 ((looking-at "w")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2108 (if (looking-at "wq") (vip-check-sub "wq")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2109 (vip-check-sub "write")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2110 ((looking-at "x") (vip-check-sub "xit"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2111 ((looking-at "y") (vip-check-sub "yank"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2112 ((looking-at "z") (vip-check-sub "z")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2113 (exchange-point-and-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2114
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2115 (defun vip-get-ex-token ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2116 "get an ex-token which is either an address or a command.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2117 a token has type \(command, address, end-mark\) and value."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2118 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2119 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2120 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2121 (cond ((looking-at "[k#]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2122 (setq ex-token-type "command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2123 (setq ex-token (char-to-string (following-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2124 (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2125 ((looking-at "[a-z]") (vip-get-ex-com-subr))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2126 ((looking-at "\\.")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2127 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2128 (setq ex-token-type "dot"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2129 ((looking-at "[0-9]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2130 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2131 (re-search-forward "[0-9]*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2132 (setq ex-token-type
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2133 (cond ((string= ex-token-type "plus") "add-number")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2134 ((string= ex-token-type "minus") "sub-number")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2135 (t "abs-number")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2136 (setq ex-token (string-to-int (buffer-substring (point) (mark)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2137 ((looking-at "\\$")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2138 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2139 (setq ex-token-type "end"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2140 ((looking-at "%")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2141 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2142 (setq ex-token-type "whole"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2143 ((looking-at "+")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2144 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2145 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2146 (insert "1")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2147 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2148 (setq ex-token-type "plus"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2149 ((looking-at "+[0-9]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2150 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2151 (setq ex-token-type "plus"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2152 (t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2153 (error "Badly formed address"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2154 ((looking-at "-")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2155 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2156 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2157 (insert "1")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2158 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2159 (setq ex-token-type "minus"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2160 ((looking-at "-[0-9]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2161 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2162 (setq ex-token-type "minus"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2163 (t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2164 (error "Badly formed address"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2165 ((looking-at "/")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2166 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2167 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2168 (let ((cont t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2169 (while (and (not (eolp)) cont)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2170 ;;(re-search-forward "[^/]*/")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2171 (re-search-forward "[^/]*\\(/\\|\n\\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2172 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2173 (setq cont nil))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2174 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2175 (setq ex-token (buffer-substring (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2176 (if (looking-at "/") (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2177 (setq ex-token-type "search-forward"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2178 ((looking-at "\\?")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2179 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2180 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2181 (let ((cont t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2182 (while (and (not (eolp)) cont)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2183 ;;(re-search-forward "[^\\?]*\\?")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2184 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2185 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2186 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2187 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2188 (if (not (looking-at "\n")) (forward-char 1))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2189 (setq ex-token-type "search-backward")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2190 (setq ex-token (buffer-substring (1- (point)) (mark))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2191 ((looking-at ",")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2192 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2193 (setq ex-token-type "comma"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2194 ((looking-at ";")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2195 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2196 (setq ex-token-type "semi-colon"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2197 ((looking-at "[!=><&~]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2198 (setq ex-token-type "command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2199 (setq ex-token (char-to-string (following-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2200 (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2201 ((looking-at "'")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2202 (setq ex-token-type "goto-mark")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2203 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2204 (cond ((looking-at "'") (setq ex-token nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2205 ((looking-at "[a-z]") (setq ex-token (following-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2206 (t (error "Marks are ' and a-z")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2207 (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2208 ((looking-at "\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2209 (setq ex-token-type "end-mark")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2210 (setq ex-token "goto"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2211 (t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2212 (error "illegal token")))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2213
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2214 (defun vip-ex (&optional string)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2215 "ex commands within VIP."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2216 (interactive)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2217 (or string
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2218 (setq ex-g-flag nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2219 ex-g-variant nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2220 (let ((com-str (or string (vip-read-string ":")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2221 (address nil) (cont t) (dot (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2222 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2223 (set-buffer (get-buffer-create " *ex-working-space*"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2224 (delete-region (point-min) (point-max))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2225 (insert com-str "\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2226 (goto-char (point-min)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2227 (setq ex-token-type "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2228 (setq ex-addresses nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2229 (while cont
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2230 (vip-get-ex-token)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2231 (cond ((or (string= ex-token-type "command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2232 (string= ex-token-type "end-mark"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2233 (if address (setq ex-addresses (cons address ex-addresses)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2234 (cond ((string= ex-token "global")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2235 (ex-global nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2236 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2237 ((string= ex-token "v")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2238 (ex-global t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2239 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2240 (t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2241 (vip-execute-ex-command)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2242 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2243 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2244 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2245 (cond ((looking-at "|")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2246 (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2247 ((looking-at "\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2248 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2249 (t (error "Extra character at end of a command")))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2250 ((string= ex-token-type "non-command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2251 (error (format "%s: Not an editor command" ex-token)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2252 ((string= ex-token-type "whole")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2253 (setq ex-addresses
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2254 (cons (point-max) (cons (point-min) ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2255 ((string= ex-token-type "comma")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2256 (setq ex-addresses
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2257 (cons (if (null address) (point) address) ex-addresses)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2258 ((string= ex-token-type "semi-colon")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2259 (if address (setq dot address))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2260 (setq ex-addresses
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2261 (cons (if (null address) (point) address) ex-addresses)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2262 (t (let ((ans (vip-get-ex-address-subr address dot)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2263 (if ans (setq address ans))))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2264
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2265 (defun vip-get-ex-pat ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2266 "get a regular expression and set ex-variant if found"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2267 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2268 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2269 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2270 (if (looking-at "!")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2271 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2272 (setq ex-g-variant (not ex-g-variant)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2273 ex-g-flag (not ex-g-flag))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2274 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2275 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2276 (if (looking-at "/")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2277 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2278 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2279 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2280 (let ((cont t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2281 (while (and (not (eolp)) cont)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2282 (re-search-forward "[^/]*\\(/\\|\n\\)")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2283 ;;(re-search-forward "[^/]*/")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2284 (if (not (vip-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2285 (setq cont nil))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2286 (setq ex-token
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2287 (if (= (mark) (point)) ""
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2288 (buffer-substring (1- (point)) (mark))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2289 (backward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2290 (setq ex-token nil))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2291
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2292 (defun vip-get-ex-command ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2293 "get an ex command"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2294 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2295 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2296 (if (looking-at "/") (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2297 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2298 (cond ((looking-at "[a-z]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2299 (vip-get-ex-com-subr)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2300 (if (string= ex-token-type "non-command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2301 (error "%s: not an editor command" ex-token)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2302 ((looking-at "[!=><&~]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2303 (setq ex-token (char-to-string (following-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2304 (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2305 (t (error "Could not find an ex command")))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2306
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2307 (defun vip-get-ex-opt-gc ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2308 "get an ex option g or c"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2309 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2310 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2311 (if (looking-at "/") (forward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2312 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2313 (cond ((looking-at "g")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2314 (setq ex-token "g")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2315 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2316 t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2317 ((looking-at "c")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2318 (setq ex-token "c")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2319 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2320 t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2321 (t nil))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2322
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2323 (defun vip-default-ex-addresses (&optional whole-flag)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2324 "compute default addresses. whole-flag means whole buffer."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2325 (cond ((null ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2326 (setq ex-addresses
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2327 (if whole-flag
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2328 (cons (point-max) (cons (point-min) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2329 (cons (point) (cons (point) nil)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2330 ((null (cdr ex-addresses))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2331 (setq ex-addresses
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2332 (cons (car ex-addresses) ex-addresses)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2333
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2334 (defun vip-get-ex-address ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2335 "get an ex-address as a marker and set ex-flag if a flag is found"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2336 (let ((address (point-marker)) (cont t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2337 (setq ex-token "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2338 (setq ex-flag nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2339 (while cont
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2340 (vip-get-ex-token)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2341 (cond ((string= ex-token-type "command")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2342 (if (or (string= ex-token "print") (string= ex-token "list")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2343 (string= ex-token "#"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2344 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2345 (setq ex-flag t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2346 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2347 (error "address expected")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2348 ((string= ex-token-type "end-mark")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2349 (setq cont nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2350 ((string= ex-token-type "whole")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2351 (error "a trailing address is expected"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2352 ((string= ex-token-type "comma")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2353 (error "Extra characters after an address"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2354 (t (let ((ans (vip-get-ex-address-subr address (point-marker))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2355 (if ans (setq address ans))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2356 address))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2357
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2358 (defun vip-get-ex-address-subr (old-address dot)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2359 "returns an address as a point"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2360 (let ((address nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2361 (if (null old-address) (setq old-address dot))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2362 (cond ((string= ex-token-type "dot")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2363 (setq address dot))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2364 ((string= ex-token-type "add-number")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2365 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2366 (goto-char old-address)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2367 (forward-line (if (= old-address 0) (1- ex-token) ex-token))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2368 (setq address (point-marker))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2369 ((string= ex-token-type "sub-number")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2370 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2371 (goto-char old-address)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2372 (forward-line (- ex-token))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2373 (setq address (point-marker))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2374 ((string= ex-token-type "abs-number")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2375 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2376 (goto-char (point-min))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2377 (if (= ex-token 0) (setq address 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2378 (forward-line (1- ex-token))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2379 (setq address (point-marker)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2380 ((string= ex-token-type "end")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2381 (setq address (point-max-marker)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2382 ((string= ex-token-type "plus") t);; do nothing
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2383 ((string= ex-token-type "minus") t);; do nothing
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2384 ((string= ex-token-type "search-forward")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2385 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2386 (ex-search-address t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2387 (setq address (point-marker))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2388 ((string= ex-token-type "search-backward")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2389 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2390 (ex-search-address nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2391 (setq address (point-marker))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2392 ((string= ex-token-type "goto-mark")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2393 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2394 (if (null ex-token)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2395 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2396 (goto-char (register-to-point (- ex-token (- ?a ?\C-a)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2397 (setq address (point-marker)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2398 address))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2399
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2400 (defun ex-search-address (forward)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2401 "search pattern and set address"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2402 (if (string= ex-token "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2403 (if (null vip-s-string) (error "No previous search string")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2404 (setq ex-token vip-s-string))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2405 (setq vip-s-string ex-token))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2406 (if forward
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2407 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2408 (forward-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2409 (re-search-forward ex-token))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2410 (forward-line -1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2411 (re-search-backward ex-token)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2412
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2413 (defun vip-get-ex-buffer ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2414 "get a buffer name and set ex-count and ex-flag if found"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2415 (setq ex-buffer nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2416 (setq ex-count nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2417 (setq ex-flag nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2418 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2419 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2420 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2421 (if (looking-at "[a-zA-Z]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2422 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2423 (setq ex-buffer (following-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2424 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2425 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2426 (if (looking-at "[0-9]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2427 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2428 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2429 (re-search-forward "[0-9][0-9]*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2430 (setq ex-count (string-to-int (buffer-substring (point) (mark))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2431 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2432 (if (looking-at "[pl#]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2433 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2434 (setq ex-flag t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2435 (forward-char 1)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2436 (if (not (looking-at "[\n|]"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2437 (error "Illegal extra characters"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2438
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2439 (defun vip-get-ex-count ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2440 (setq ex-variant nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2441 ex-count nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2442 ex-flag nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2443 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2444 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2445 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2446 (if (looking-at "!")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2447 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2448 (setq ex-variant t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2449 (forward-char 1)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2450 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2451 (if (looking-at "[0-9]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2452 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2453 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2454 (re-search-forward "[0-9][0-9]*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2455 (setq ex-count (string-to-int (buffer-substring (point) (mark))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2456 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2457 (if (looking-at "[pl#]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2458 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2459 (setq ex-flag t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2460 (forward-char 1)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2461 (if (not (looking-at "[\n|]"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2462 (error "Illegal extra characters"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2463
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2464 (defun vip-get-ex-file ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2465 "get a file name and set ex-variant, ex-append and ex-offset if found"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2466 (setq ex-file nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2467 ex-variant nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2468 ex-append nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2469 ex-offset nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2470 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2471 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2472 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2473 (if (looking-at "!")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2474 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2475 (setq ex-variant t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2476 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2477 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2478 (if (looking-at ">>")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2479 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2480 (setq ex-append t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2481 ex-variant t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2482 (forward-char 2)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2483 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2484 (if (looking-at "+")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2485 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2486 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2487 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2488 (re-search-forward "[ \t\n]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2489 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2490 (setq ex-offset (buffer-substring (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2491 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2492 (skip-chars-forward " \t")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2493 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2494 (re-search-forward "[ \t\n]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2495 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2496 (setq ex-file (buffer-substring (point) (mark)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2497
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2498 (defun vip-execute-ex-command ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2499 "execute ex command using the value of addresses."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2500 (cond ((string= ex-token "goto") (ex-goto))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2501 ((string= ex-token "copy") (ex-copy nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2502 ((string= ex-token "delete") (ex-delete))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2503 ((string= ex-token "edit") (ex-edit))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2504 ((string= ex-token "file") (vip-info-on-file))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2505 ;((string= ex-token "global") (ex-global nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2506 ((string= ex-token "join") (ex-line "join"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2507 ((string= ex-token "k") (ex-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2508 ((string= ex-token "mark") (ex-mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2509 ((string= ex-token "map") (ex-map))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2510 ((string= ex-token "move") (ex-copy t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2511 ((string= ex-token "put") (ex-put))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2512 ((string= ex-token "quit") (ex-quit))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2513 ((string= ex-token "read") (ex-read))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2514 ((string= ex-token "set") (ex-set))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2515 ((string= ex-token "shell") (ex-shell))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2516 ((string= ex-token "substitute") (ex-substitute))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2517 ((string= ex-token "stop") (suspend-emacs))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2518 ((string= ex-token "t") (ex-copy nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2519 ((string= ex-token "tag") (ex-tag))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2520 ((string= ex-token "undo") (vip-undo))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2521 ((string= ex-token "unmap") (ex-unmap))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2522 ;((string= ex-token "v") (ex-global t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2523 ((string= ex-token "version") (vip-version))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2524 ((string= ex-token "visual") (ex-edit))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2525 ((string= ex-token "write") (ex-write nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2526 ((string= ex-token "wq") (ex-write t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2527 ((string= ex-token "yank") (ex-yank))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2528 ((string= ex-token "!") (ex-command))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2529 ((string= ex-token "=") (ex-line-no))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2530 ((string= ex-token ">") (ex-line "right"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2531 ((string= ex-token "<") (ex-line "left"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2532 ((string= ex-token "&") (ex-substitute t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2533 ((string= ex-token "~") (ex-substitute t t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2534 ((or (string= ex-token "append")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2535 (string= ex-token "args")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2536 (string= ex-token "change")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2537 (string= ex-token "insert")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2538 (string= ex-token "open")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2539 )
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2540 (error (format "%s: no such command from VIP" ex-token)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2541 ((or (string= ex-token "abbreviate")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2542 (string= ex-token "list")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2543 (string= ex-token "next")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2544 (string= ex-token "print")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2545 (string= ex-token "preserve")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2546 (string= ex-token "recover")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2547 (string= ex-token "rewind")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2548 (string= ex-token "source")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2549 (string= ex-token "unabbreviate")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2550 (string= ex-token "xit")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2551 (string= ex-token "z")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2552 )
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2553 (error (format "%s: not implemented in VIP" ex-token)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2554 (t (error (format "%s: Not an editor command" ex-token)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2555
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2556 (defun ex-goto ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2557 "ex goto command"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2558 (if (null ex-addresses)
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
2559 (setq ex-addresses (cons (point) nil)))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2560 (push-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2561 (goto-char (car ex-addresses))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2562 (beginning-of-line))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2563
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2564 (defun ex-copy (del-flag)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2565 "ex copy and move command. DEL-FLAG means delete."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2566 (vip-default-ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2567 (let ((address (vip-get-ex-address))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2568 (end (car ex-addresses)) (beg (car (cdr ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2569 (goto-char end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2570 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2571 (set-mark beg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2572 (vip-enlarge-region (mark) (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2573 (if del-flag (kill-region (point) (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2574 (copy-region-as-kill (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2575 (if ex-flag
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2576 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2577 (with-output-to-temp-buffer "*copy text*"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2578 (princ
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2579 (if (or del-flag ex-g-flag ex-g-variant)
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
2580 (current-kill 0)
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2581 (buffer-substring (point) (mark)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2582 (condition-case nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2583 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2584 (vip-read-string "[Hit return to continue] ")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2585 (save-excursion (kill-buffer "*copy text*")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2586 (quit
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2587 (save-excursion (kill-buffer "*copy text*"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2588 (signal 'quit nil))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2589 (if (= address 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2590 (goto-char (point-min))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2591 (goto-char address)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2592 (forward-line 1))
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
2593 (insert (current-kill 0))))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2594
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2595 (defun ex-delete ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2596 "ex delete"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2597 (vip-default-ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2598 (vip-get-ex-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2599 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2600 (if (> beg end) (error "First address exceeds second"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2601 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2602 (vip-enlarge-region beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2603 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2604 (if ex-count
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2605 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2606 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2607 (forward-line (1- ex-count)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2608 (set-mark end))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2609 (vip-enlarge-region (point) (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2610 (if ex-flag
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2611 ;; show text to be deleted and ask for confirmation
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2612 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2613 (with-output-to-temp-buffer " *delete text*"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2614 (princ (buffer-substring (point) (mark))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2615 (condition-case conditions
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2616 (vip-read-string "[Hit return to continue] ")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2617 (quit
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2618 (save-excursion (kill-buffer " *delete text*"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2619 (error "")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2620 (save-excursion (kill-buffer " *delete text*")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2621 (if ex-buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2622 (if (and (<= ?A ex-buffer) (<= ex-buffer ?Z))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2623 (vip-append-to-register
1625
376427dea90a * bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
2624 (+ ex-buffer 32) (point) (mark))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2625 (copy-to-register ex-buffer (point) (mark) nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2626 (delete-region (point) (mark))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2627
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2628 (defun ex-edit ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2629 "ex-edit"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2630 (vip-get-ex-file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2631 (if (and (not ex-variant) (buffer-modified-p) buffer-file-name)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2632 (error "No write since last change \(:e! overrides\)"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2633 (vip-change-mode-to-emacs)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2634 (set-buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2635 (find-file-noselect (concat default-directory ex-file)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2636 (vip-change-mode-to-vi)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2637 (goto-char (point-min))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2638 (if ex-offset
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2639 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2640 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2641 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2642 (delete-region (point-min) (point-max))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2643 (insert ex-offset "\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2644 (goto-char (point-min)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2645 (goto-char (vip-get-ex-address))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2646 (beginning-of-line))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2647
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2648 (defun ex-global (variant)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2649 "ex global command"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2650 (if (or ex-g-flag ex-g-variant)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2651 (error "Global within global not allowed")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2652 (if variant
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2653 (setq ex-g-flag nil
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2654 ex-g-variant t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2655 (setq ex-g-flag t
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2656 ex-g-variant nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2657 (vip-get-ex-pat)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2658 (if (null ex-token)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2659 (error "Missing regular expression for global command"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2660 (if (string= ex-token "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2661 (if (null vip-s-string) (error "No previous search string")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2662 (setq ex-g-pat vip-s-string))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2663 (setq ex-g-pat ex-token
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2664 vip-s-string ex-token))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2665 (if (null ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2666 (setq ex-addresses (list (point-max) (point-min))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2667 (let ((marks nil) (mark-count 0)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2668 com-str (end (car ex-addresses)) (beg (car (cdr ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2669 (if (> beg end) (error "First address exceeds second"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2670 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2671 (vip-enlarge-region beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2672 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2673 (let ((cont t) (limit (point-marker)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2674 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2675 ;; skip the last line if empty
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2676 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2677 (if (and (eobp) (not (bobp))) (backward-char 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2678 (while (and cont (not (bobp)) (>= (point) limit))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2679 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2680 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2681 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2682 (let ((found (re-search-backward ex-g-pat (mark) t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2683 (if (or (and ex-g-flag found)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2684 (and ex-g-variant (not found)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2685 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2686 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2687 (setq mark-count (1+ mark-count))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2688 (setq marks (cons (point-marker) marks)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2689 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2690 (if (bobp) (setq cont nil)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2691 (forward-line -1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2692 (end-of-line)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2693 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2694 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2695 (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2696 (while marks
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2697 (goto-char (car marks))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2698 ; report progress of execution on a slow machine.
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2699 ;(message "Executing global command...")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2700 ;(if (zerop (% mark-count 10))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2701 ;(message "Executing global command...%d" mark-count))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2702 (vip-ex com-str)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2703 (setq mark-count (1- mark-count))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2704 (setq marks (cdr marks)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2705 ;(message "Executing global command...done")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2706
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2707 (defun ex-line (com)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2708 "ex line commands. COM is join, shift-right or shift-left."
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2709 (vip-default-ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2710 (vip-get-ex-count)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2711 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))) point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2712 (if (> beg end) (error "First address exceeds second"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2713 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2714 (vip-enlarge-region beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2715 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2716 (if ex-count
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2717 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2718 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2719 (forward-line ex-count)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2720 (if ex-flag
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2721 ;; show text to be joined and ask for confirmation
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2722 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2723 (with-output-to-temp-buffer " *text*"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2724 (princ (buffer-substring (point) (mark))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2725 (condition-case conditions
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2726 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2727 (vip-read-string "[Hit return to continue] ")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2728 (ex-line-subr com (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2729 (quit
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2730 (ding)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2731 (save-excursion (kill-buffer " *text*")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2732 (ex-line-subr com (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2733 (setq point (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2734 (goto-char (1- point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2735 (beginning-of-line)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2736
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2737 (defun ex-line-subr (com beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2738 (cond ((string= com "join")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2739 (goto-char (min beg end))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2740 (while (and (not (eobp)) (< (point) (max beg end)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2741 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2742 (if (and (<= (point) (max beg end)) (not (eobp)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2743 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2744 (forward-line 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2745 (delete-region (point) (1- (point)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2746 (if (not ex-variant) (fixup-whitespace))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2747 ((or (string= com "right") (string= com "left"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2748 (indent-rigidly
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2749 (min beg end) (max beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2750 (if (string= com "right") vip-shift-width (- vip-shift-width)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2751 (goto-char (max beg end))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2752 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2753 (forward-char 1))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2754
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2755 (defun ex-mark ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2756 "ex mark"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2757 (let (char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2758 (if (null ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2759 (setq ex-addresses
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2760 (cons (point) nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2761 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2762 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2763 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2764 (if (looking-at "[a-z]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2765 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2766 (setq char (following-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2767 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2768 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2769 (if (not (looking-at "[\n|]"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2770 (error "Extra characters at end of \"k\" command")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2771 (if (looking-at "[\n|]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2772 (error "\"k\" requires a following letter")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2773 (error "Mark must specify a letter"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2774 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2775 (goto-char (car ex-addresses))
1625
376427dea90a * bytecomp.el: Declare unread-command-char an obsolete variable.
Jim Blandy <jimb@redhat.com>
parents: 1577
diff changeset
2776 (point-to-register (- char (- ?a ?\C-a)) nil))))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2777
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2778 (defun ex-map ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2779 "ex map"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2780 (let (char string)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2781 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2782 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2783 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2784 (setq char (char-to-string (following-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2785 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2786 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2787 (if (looking-at "[\n|]") (error "Missing rhs"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2788 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2789 (end-of-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2790 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2791 (setq string (buffer-substring (mark) (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2792 (if (not (lookup-key ex-map char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2793 (define-key ex-map char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2794 (or (lookup-key vip-mode-map char) 'vip-nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2795 (define-key vip-mode-map char
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2796 (eval
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2797 (list 'quote
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2798 (cons 'lambda
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2799 (list '(count)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2800 '(interactive "p")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2801 (list 'execute-kbd-macro string 'count))))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2802
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2803 (defun ex-unmap ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2804 "ex unmap"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2805 (let (char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2806 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2807 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2808 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2809 (setq char (char-to-string (following-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2810 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2811 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2812 (if (not (looking-at "[\n|]")) (error "Macro must be a character")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2813 (if (not (lookup-key ex-map char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2814 (error "That macro wasn't mapped"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2815 (define-key vip-mode-map char (lookup-key ex-map char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2816 (define-key ex-map char nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2817
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2818 (defun ex-put ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2819 "ex put"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2820 (let ((point (if (null ex-addresses) (point) (car ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2821 (vip-get-ex-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2822 (setq vip-use-register ex-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2823 (goto-char point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2824 (if (= point 0) (vip-Put-back 1) (vip-put-back 1))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2825
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2826 (defun ex-quit ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2827 "ex quit"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2828 (let (char)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2829 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2830 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2831 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2832 (setq char (following-char)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2833 (if (= char ?!) (kill-emacs t) (save-buffers-kill-emacs))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2834
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2835 (defun ex-read ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2836 "ex read"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2837 (let ((point (if (null ex-addresses) (point) (car ex-addresses)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2838 (variant nil) command file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2839 (goto-char point)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2840 (if (not (= point 0)) (next-line 1))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2841 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2842 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2843 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2844 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2845 (if (looking-at "!")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2846 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2847 (setq variant t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2848 (forward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2849 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2850 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2851 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2852 (setq command (buffer-substring (mark) (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2853 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2854 (re-search-forward "[ \t\n]")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2855 (backward-char 1)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2856 (setq file (buffer-substring (point) (mark)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2857 (if variant
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2858 (shell-command command t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2859 (insert-file file))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2860
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2861 (defun ex-set ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2862 (eval (list 'setq
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2863 (read-variable "Variable: ")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2864 (eval (read-minibuffer "Value: ")))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2865
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2866 (defun ex-shell ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2867 "ex shell"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2868 (vip-change-mode-to-emacs)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2869 (shell))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2870
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2871 (defun ex-substitute (&optional repeat r-flag)
1577
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
2872 "ex substitute.
a52da8d63ff3 Doc fix.
Christopher Zaborsky <rogue@erratum.com>
parents: 841
diff changeset
2873 If REPEAT use previous reg-exp which is ex-reg-exp or
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2874 vip-s-string"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2875 (let (pat repl (opt-g nil) (opt-c nil) (matched-pos nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2876 (if repeat (setq ex-token nil) (vip-get-ex-pat))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2877 (if (null ex-token)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2878 (setq pat (if r-flag vip-s-string ex-reg-exp)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2879 repl ex-repl)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2880 (setq pat (if (string= ex-token "") vip-s-string ex-token))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2881 (setq vip-s-string pat
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2882 ex-reg-exp pat)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2883 (vip-get-ex-pat)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2884 (if (null ex-token)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2885 (setq ex-token ""
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2886 ex-repl "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2887 (setq repl ex-token
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2888 ex-repl ex-token)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2889 (while (vip-get-ex-opt-gc)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2890 (if (string= ex-token "g") (setq opt-g t) (setq opt-c t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2891 (vip-get-ex-count)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2892 (if ex-count
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2893 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2894 (if ex-addresses (goto-char (car ex-addresses)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2895 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2896 (forward-line (1- ex-count))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2897 (setq ex-addresses (cons (point) (cons (mark) nil))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2898 (if (null ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2899 (setq ex-addresses (cons (point) (cons (point) nil)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2900 (if (null (cdr ex-addresses))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2901 (setq ex-addresses (cons (car ex-addresses) ex-addresses)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2902 ;(setq G opt-g)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2903 (let ((beg (car ex-addresses)) (end (car (cdr ex-addresses)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2904 (cont t) eol-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2905 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2906 (vip-enlarge-region beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2907 (let ((limit (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2908 (goto-char (max (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2909 (point-marker))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2910 (goto-char (min (point) (mark)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2911 (while (< (point) limit)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2912 (end-of-line)
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
2913 (setq eol-mark (point-marker))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2914 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2915 (if opt-g
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2916 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2917 (while (and (not (eolp))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2918 (re-search-forward pat eol-mark t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2919 (if (or (not opt-c) (y-or-n-p "Replace? "))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2920 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2921 (setq matched-pos (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2922 (replace-match repl))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2923 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2924 (forward-char))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2925 (if (and (re-search-forward pat eol-mark t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2926 (or (not opt-c) (y-or-n-p "Replace? ")))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2927 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2928 (setq matched-pos (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2929 (replace-match repl)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2930 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2931 (forward-char))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2932 (if matched-pos (goto-char matched-pos))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2933 (beginning-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2934 (if opt-c (message "done"))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2935
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2936 (defun ex-tag ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2937 "ex tag"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2938 (let (tag)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2939 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2940 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2941 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2942 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2943 (skip-chars-forward "^ |\t\n")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2944 (setq tag (buffer-substring (mark) (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2945 (if (not (string= tag "")) (setq ex-tag tag))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2946 (vip-change-mode-to-emacs)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2947 (condition-case conditions
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2948 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2949 (if (string= tag "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2950 (find-tag ex-tag t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2951 (find-tag-other-window ex-tag))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2952 (vip-change-mode-to-vi))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2953 (error
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2954 (vip-change-mode-to-vi)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2955 (vip-message-conditions conditions)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2956
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2957 (defun ex-write (q-flag)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2958 "ex write"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2959 (vip-default-ex-addresses t)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2960 (vip-get-ex-file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2961 (if (string= ex-file "")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2962 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2963 (if (null buffer-file-name)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2964 (error "No file associated with this buffer"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2965 (setq ex-file buffer-file-name))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2966 (setq ex-file (expand-file-name ex-file)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2967 (if (and (not (string= ex-file (buffer-file-name)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2968 (file-exists-p ex-file)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2969 (not ex-variant))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2970 (error (format "\"%s\" File exists - use w! to override" ex-file)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2971 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2972 (if (> beg end) (error "First address exceeds second"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2973 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2974 (vip-enlarge-region beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2975 (write-region (point) (mark) ex-file ex-append t)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2976 (if (null buffer-file-name) (setq buffer-file-name ex-file))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2977 (if q-flag (save-buffers-kill-emacs)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2978
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2979 (defun ex-yank ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2980 "ex yank"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2981 (vip-default-ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2982 (vip-get-ex-buffer)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2983 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2984 (if (> beg end) (error "First address exceeds second"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2985 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2986 (vip-enlarge-region beg end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2987 (exchange-point-and-mark)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2988 (if (or ex-g-flag ex-g-variant) (error "Can't yank within global"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2989 (if ex-count
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2990 (progn
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2991 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2992 (forward-line (1- ex-count)))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2993 (set-mark end))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2994 (vip-enlarge-region (point) (mark))
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3519
diff changeset
2995 (if ex-flag (error "Extra characters at end of command"))
11
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2996 (if ex-buffer
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2997 (copy-to-register ex-buffer (point) (mark) nil))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2998 (copy-region-as-kill (point) (mark)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2999
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3000 (defun ex-command ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3001 "execute shell command"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3002 (let (command)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3003 (save-window-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3004 (set-buffer " *ex-working-space*")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3005 (skip-chars-forward " \t")
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3006 (set-mark (point))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3007 (end-of-line)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3008 (setq command (buffer-substring (mark) (point))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3009 (if (null ex-addresses)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3010 (shell-command command)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3011 (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3012 (if (null beg) (setq beg end))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3013 (save-excursion
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3014 (goto-char beg)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3015 (set-mark end)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3016 (vip-enlarge-region (point) (mark))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3017 (shell-command-on-region (point) (mark) command t))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3018 (goto-char beg)))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3019
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3020 (defun ex-line-no ()
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3021 "print line number"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3022 (message "%d"
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3023 (1+ (count-lines
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3024 (point-min)
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3025 (if (null ex-addresses) (point-max) (car ex-addresses))))))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3026
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3027 (if (file-exists-p "~/.vip") (load "~/.vip"))
5d42bce31792 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3028
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
3029 ;;; vip.el ends here