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