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