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