Mercurial > emacs
annotate lisp/emulation/vi.el @ 745:98bdd205ec6f
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Mon, 06 Jul 1992 22:33:26 +0000 |
parents | e4253da532fb |
children | 9c89fd7ddd41 |
rev | line source |
---|---|
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; vi.el --- major mode for emulating "vi" editor under GNU Emacs. |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
6 | 3 ; Originally written by : seismo!wucs!nz@rsch.wisc.edu (Neal Ziring) |
4 ; Extensively redesigned and rewritten by wu@crys.wisc.edu (Felix S.T. Wu) | |
5 ; Last revision: 01/07/87 Wed (for GNU Emacs 18.33) | |
6 ; | |
7 ; INSTALLATION PROCEDURE: | |
8 ; 1) Add a global key binding for command "vi-mode" (I use ESC ESC instead of | |
9 ; the single ESC used in real "vi", so I can access other ESC prefixed emacs | |
10 ; commands while I'm in "vi"), say, by putting the following line in your | |
11 ; ".emacs" file: | |
12 ; (define-key global-map "\e\e" 'vi-mode) ;quick switch into vi-mode | |
13 ; 2) If you wish you can define "find-file-hooks" to enter "vi" automatically | |
14 ; after a file is loaded into the buffer. For example, I defined it as: | |
15 ; (setq find-file-hooks (list | |
16 ; (function (lambda () | |
17 ; (if (not (or (eq major-mode 'Info-mode) | |
18 ; (eq major-mode 'vi-mode))) | |
19 ; (vi-mode)))))) | |
20 ; 3) In your .emacs file you can define the command "vi-mode" to be "autoload" | |
21 ; or you can execute the "load" command to load "vi" directly. | |
22 ; 4) Read the comments for command "vi-mode" before you start using it. | |
23 ; | |
24 ; COULD DO | |
25 ; 1). A general 'define-operator' function to replace current hack | |
26 ; 2). In operator handling, should allow other point moving Emacs commands | |
27 ; (such as ESC <, ESC >) to be used as arguments. | |
28 ; | |
29 | |
30 (defun vi-switch-mode (arg mode-char) | |
31 "Switch the major mode of current buffer as specified by the following char \\{vi-tilde-map}" | |
32 (interactive "P\nc") | |
33 (let ((mode-cmd (lookup-key vi-tilde-map (char-to-string mode-char)))) | |
34 (if (null mode-cmd) | |
35 (with-output-to-temp-buffer "*Help*" | |
36 (princ (substitute-command-keys "Possible major modes to switch to: \\{vi-tilde-map}"))) | |
37 (setq prefix-arg arg) ; prefix arg will be passed down | |
38 (command-execute mode-cmd nil) ; may need to save mode-line-format etc | |
39 (set-buffer-modified-p (buffer-modified-p))))) ; just in case | |
40 | |
41 | |
42 (if (null (where-is-internal 'vi-switch-mode (current-local-map))) | |
43 (define-key ctl-x-map "~" 'vi-switch-mode)) | |
44 | |
45 (defvar vi-tilde-map nil | |
46 "Keymap used for \\[vi-switch-mode] prefix key. Link to various major modes.") | |
47 | |
48 (if vi-tilde-map | |
49 nil | |
50 (setq vi-tilde-map (make-keymap)) | |
51 (define-key vi-tilde-map "a" 'abbrev-mode) | |
52 (define-key vi-tilde-map "c" 'c-mode) | |
53 (define-key vi-tilde-map "d" 'vi-debugging) | |
54 (define-key vi-tilde-map "e" 'emacs-lisp-mode) | |
55 (define-key vi-tilde-map "f" 'auto-fill-mode) | |
56 (define-key vi-tilde-map "g" 'prolog-mode) | |
57 (define-key vi-tilde-map "h" 'hanoi) | |
58 (define-key vi-tilde-map "i" 'info-mode) | |
59 (define-key vi-tilde-map "l" 'lisp-mode) | |
60 (define-key vi-tilde-map "n" 'nroff-mode) | |
61 (define-key vi-tilde-map "o" 'overwrite-mode) | |
62 (define-key vi-tilde-map "O" 'outline-mode) | |
63 (define-key vi-tilde-map "P" 'picture-mode) | |
64 (define-key vi-tilde-map "r" 'vi-readonly-mode) | |
65 (define-key vi-tilde-map "t" 'text-mode) | |
66 (define-key vi-tilde-map "v" 'vi-mode) | |
67 (define-key vi-tilde-map "x" 'tex-mode) | |
68 (define-key vi-tilde-map "~" 'vi-back-to-old-mode)) | |
69 | |
70 (defun vi-debugging (arg) | |
71 "Toggle debug-on-error flag. If prefix arg is given, set t." | |
72 (interactive "P") | |
73 (if arg | |
74 (setq debug-on-error t) | |
75 (setq debug-on-error (not debug-on-error))) | |
76 (if debug-on-error | |
77 (message "Debug-on-error ...") | |
78 (message "NO more debug-on-error"))) | |
79 | |
80 (defun vi-back-to-old-mode () | |
81 "Go back to the previous mode without setting up for insertion." | |
82 (interactive) | |
83 (if vi-mode-old-major-mode | |
84 (progn | |
85 (setq mode-name vi-mode-old-mode-name) | |
86 (use-local-map vi-mode-old-local-map) | |
87 (setq major-mode vi-mode-old-major-mode) | |
88 (setq case-fold-search vi-mode-old-case-fold) | |
89 (set-buffer-modified-p (buffer-modified-p))))) | |
90 | |
91 (defun vi-readonly-mode () | |
92 "Toggle current buffer's readonly flag." | |
93 (interactive) | |
94 (setq buffer-read-only (not buffer-read-only))) | |
95 | |
96 (defvar vi-com-map nil | |
97 "Keymap used in Evi's command state | |
98 Command state includes most of the vi editing commands, with some Emacs | |
99 command extensions.") | |
100 | |
101 (put 'vi-undefined 'suppress-keymap t) | |
102 (if vi-com-map nil | |
103 (setq vi-com-map (make-keymap)) | |
104 ;;(fillarray vi-com-map 'vi-undefined) | |
105 (define-key vi-com-map "\C-@" 'vi-mark-region) ; extension | |
106 (define-key vi-com-map "\C-a" 'vi-ask-for-info) ; extension | |
107 (define-key vi-com-map "\C-b" 'vi-backward-windowfull) | |
108 (define-key vi-com-map "\C-c" 'vi-do-old-mode-C-c-command) ; extension | |
109 (define-key vi-com-map "\C-d" 'vi-scroll-down-window) | |
110 (define-key vi-com-map "\C-e" 'vi-expose-line-below) | |
111 (define-key vi-com-map "\C-f" 'vi-forward-windowfull) | |
112 (define-key vi-com-map "\C-g" 'keyboard-quit) | |
113 (define-key vi-com-map "\C-i" 'indent-relative-maybe) ; TAB | |
114 (define-key vi-com-map "\C-j" 'vi-next-line) ; LFD | |
115 (define-key vi-com-map "\C-k" 'vi-kill-line) ; extension | |
116 (define-key vi-com-map "\C-l" 'recenter) | |
117 (define-key vi-com-map "\C-m" 'vi-next-line-first-nonwhite) ; RET | |
118 (define-key vi-com-map "\C-n" 'vi-next-line) | |
119 (define-key vi-com-map "\C-o" 'vi-split-open-line) | |
120 (define-key vi-com-map "\C-p" 'previous-line) | |
121 (define-key vi-com-map "\C-q" 'vi-query-replace) ; extension | |
122 (define-key vi-com-map "\C-r" 'vi-isearch-backward) ; modification | |
123 (define-key vi-com-map "\C-s" 'vi-isearch-forward) ; extension | |
124 (define-key vi-com-map "\C-t" 'vi-transpose-objects) ; extension | |
125 (define-key vi-com-map "\C-u" 'vi-scroll-up-window) | |
126 (define-key vi-com-map "\C-v" 'scroll-up) ; extension | |
127 (define-key vi-com-map "\C-w" 'vi-kill-region) ; extension | |
128 (define-key vi-com-map "\C-x" 'Control-X-prefix) ; extension | |
129 (define-key vi-com-map "\C-y" 'vi-expose-line-above) | |
130 (define-key vi-com-map "\C-z" 'suspend-emacs) | |
131 | |
132 (define-key vi-com-map "\e" 'ESC-prefix); C-[ (ESC) | |
133 (define-key vi-com-map "\C-\\" 'vi-unimplemented) | |
134 (define-key vi-com-map "\C-]" 'find-tag) | |
135 (define-key vi-com-map "\C-^" 'vi-locate-def) ; extension | |
136 (define-key vi-com-map "\C-_" 'vi-undefined) | |
137 | |
138 (define-key vi-com-map " " 'forward-char) | |
139 (define-key vi-com-map "!" 'vi-operator) | |
140 (define-key vi-com-map "\"" 'vi-char-argument) | |
141 (define-key vi-com-map "#" 'universal-argument) ; extension | |
142 (define-key vi-com-map "$" 'end-of-line) | |
143 (define-key vi-com-map "%" 'vi-find-matching-paren) | |
144 (define-key vi-com-map "&" 'vi-unimplemented) | |
145 (define-key vi-com-map "'" 'vi-goto-line-mark) | |
146 (define-key vi-com-map "(" 'backward-sexp) | |
147 (define-key vi-com-map ")" 'forward-sexp) | |
148 (define-key vi-com-map "*" 'vi-name-last-change-or-macro) ; extension | |
149 (define-key vi-com-map "+" 'vi-next-line-first-nonwhite) | |
150 (define-key vi-com-map "," 'vi-reverse-last-find-char) | |
151 (define-key vi-com-map "-" 'vi-previous-line-first-nonwhite) | |
152 (define-key vi-com-map "." 'vi-redo-last-change-command) | |
153 (define-key vi-com-map "/" 'vi-search-forward) | |
154 (define-key vi-com-map "0" 'beginning-of-line) | |
155 | |
156 (define-key vi-com-map "1" 'vi-digit-argument) | |
157 (define-key vi-com-map "2" 'vi-digit-argument) | |
158 (define-key vi-com-map "3" 'vi-digit-argument) | |
159 (define-key vi-com-map "4" 'vi-digit-argument) | |
160 (define-key vi-com-map "5" 'vi-digit-argument) | |
161 (define-key vi-com-map "6" 'vi-digit-argument) | |
162 (define-key vi-com-map "7" 'vi-digit-argument) | |
163 (define-key vi-com-map "8" 'vi-digit-argument) | |
164 (define-key vi-com-map "9" 'vi-digit-argument) | |
165 | |
166 (define-key vi-com-map ":" 'vi-ex-cmd) | |
167 (define-key vi-com-map ";" 'vi-repeat-last-find-char) | |
168 (define-key vi-com-map "<" 'vi-operator) | |
169 (define-key vi-com-map "=" 'vi-operator) | |
170 (define-key vi-com-map ">" 'vi-operator) | |
171 (define-key vi-com-map "?" 'vi-search-backward) | |
172 (define-key vi-com-map "@" 'vi-call-named-change-or-macro) ; extension | |
173 | |
174 (define-key vi-com-map "A" 'vi-append-at-end-of-line) | |
175 (define-key vi-com-map "B" 'vi-backward-blank-delimited-word) | |
176 (define-key vi-com-map "C" 'vi-change-rest-of-line) | |
177 (define-key vi-com-map "D" 'vi-kill-line) | |
178 (define-key vi-com-map "E" 'vi-end-of-blank-delimited-word) | |
179 (define-key vi-com-map "F" 'vi-backward-find-char) | |
180 (define-key vi-com-map "G" 'vi-goto-line) | |
181 (define-key vi-com-map "H" 'vi-home-window-line) | |
182 (define-key vi-com-map "I" 'vi-insert-before-first-nonwhite) | |
183 (define-key vi-com-map "J" 'vi-join-lines) | |
184 (define-key vi-com-map "K" 'vi-undefined) | |
185 (define-key vi-com-map "L" 'vi-last-window-line) | |
186 (define-key vi-com-map "M" 'vi-middle-window-line) | |
187 (define-key vi-com-map "N" 'vi-reverse-last-search) | |
188 (define-key vi-com-map "O" 'vi-open-above) | |
189 (define-key vi-com-map "P" 'vi-put-before) | |
190 (define-key vi-com-map "Q" 'vi-quote-words) ; extension | |
191 (define-key vi-com-map "R" 'vi-replace-chars) | |
192 (define-key vi-com-map "S" 'vi-substitute-lines) | |
193 (define-key vi-com-map "T" 'vi-backward-upto-char) | |
194 (define-key vi-com-map "U" 'vi-unimplemented) | |
195 (define-key vi-com-map "V" 'vi-undefined) | |
196 (define-key vi-com-map "W" 'vi-forward-blank-delimited-word) | |
197 (define-key vi-com-map "X" 'call-last-kbd-macro) ; modification/extension | |
198 (define-key vi-com-map "Y" 'vi-yank-line) | |
199 (define-key vi-com-map "Z" (make-sparse-keymap)) ;allow below prefix command | |
200 (define-key vi-com-map "ZZ" 'vi-save-all-and-exit) | |
201 | |
202 (define-key vi-com-map "[" 'vi-unimplemented) | |
203 (define-key vi-com-map "\\" 'vi-operator) ; extension for vi-narrow-op | |
204 (define-key vi-com-map "]" 'vi-unimplemented) | |
205 (define-key vi-com-map "^" 'back-to-indentation) | |
206 (define-key vi-com-map "_" 'vi-undefined) | |
207 (define-key vi-com-map "`" 'vi-goto-char-mark) | |
208 | |
209 (define-key vi-com-map "a" 'vi-insert-after) | |
210 (define-key vi-com-map "b" 'backward-word) | |
211 (define-key vi-com-map "c" 'vi-operator) | |
212 (define-key vi-com-map "d" 'vi-operator) | |
213 (define-key vi-com-map "e" 'vi-end-of-word) | |
214 (define-key vi-com-map "f" 'vi-forward-find-char) | |
215 (define-key vi-com-map "g" 'vi-beginning-of-buffer) ; extension | |
216 (define-key vi-com-map "h" 'backward-char) | |
217 (define-key vi-com-map "i" 'vi-insert-before) | |
218 (define-key vi-com-map "j" 'vi-next-line) | |
219 (define-key vi-com-map "k" 'previous-line) | |
220 (define-key vi-com-map "l" 'forward-char) | |
221 (define-key vi-com-map "m" 'vi-set-mark) | |
222 (define-key vi-com-map "n" 'vi-repeat-last-search) | |
223 (define-key vi-com-map "o" 'vi-open-below) | |
224 (define-key vi-com-map "p" 'vi-put-after) | |
225 (define-key vi-com-map "q" 'vi-replace) | |
226 (define-key vi-com-map "r" 'vi-replace-1-char) | |
227 (define-key vi-com-map "s" 'vi-substitute-chars) | |
228 (define-key vi-com-map "t" 'vi-forward-upto-char) | |
229 (define-key vi-com-map "u" 'undo) | |
230 (define-key vi-com-map "v" 'vi-verify-spelling) | |
231 (define-key vi-com-map "w" 'vi-forward-word) | |
232 (define-key vi-com-map "x" 'vi-kill-char) | |
233 (define-key vi-com-map "y" 'vi-operator) | |
234 (define-key vi-com-map "z" 'vi-adjust-window) | |
235 | |
236 (define-key vi-com-map "{" 'backward-paragraph) | |
237 (define-key vi-com-map "|" 'vi-goto-column) | |
238 (define-key vi-com-map "}" 'forward-paragraph) | |
239 (define-key vi-com-map "~" 'vi-change-case) | |
240 (define-key vi-com-map "\177" 'delete-backward-char)) | |
241 | |
242 (put 'backward-char 'point-moving-unit 'char) | |
243 (put 'vi-next-line 'point-moving-unit 'line) | |
244 (put 'next-line 'point-moving-unit 'line) | |
245 (put 'forward-line 'point-moving-unit 'line) | |
246 (put 'previous-line 'point-moving-unit 'line) | |
247 (put 'vi-isearch-backward 'point-moving-unit 'search) | |
248 (put 'vi-search-backward 'point-moving-unit 'search) | |
249 (put 'vi-isearch-forward 'point-moving-unit 'search) | |
250 (put 'vi-search-forward 'point-moving-unit 'search) | |
251 (put 'forward-char 'point-moving-unit 'char) | |
252 (put 'end-of-line 'point-moving-unit 'char) | |
253 (put 'vi-find-matching-paren 'point-moving-unit 'match) | |
254 (put 'vi-goto-line-mark 'point-moving-unit 'line) | |
255 (put 'backward-sexp 'point-moving-unit 'sexp) | |
256 (put 'forward-sexp 'point-moving-unit 'sexp) | |
257 (put 'vi-next-line-first-nonwhite 'point-moving-unit 'line) | |
258 (put 'vi-previous-line-first-nonwhite 'point-moving-unit 'line) | |
259 (put 'vi-reverse-last-find-char 'point-moving-unit 'rev-find) | |
260 (put 'vi-re-search-forward 'point-moving-unit 'search) | |
261 (put 'beginning-of-line 'point-moving-unit 'char) | |
262 (put 'vi-beginning-of-buffer 'point-moving-unit 'char) | |
263 (put 'vi-repeat-last-find-char 'point-moving-unit 'find) | |
264 (put 'vi-re-search-backward 'point-moving-unit 'search) | |
265 (put 'vi-backward-blank-delimited-word 'point-moving-unit 'WORD) | |
266 (put 'vi-end-of-blank-delimited-word 'point-moving-unit 'match) | |
267 (put 'vi-backward-find-char 'point-moving-unit 'find) | |
268 (put 'vi-goto-line 'point-moving-unit 'line) | |
269 (put 'vi-home-window-line 'point-moving-unit 'line) | |
270 (put 'vi-last-window-line 'point-moving-unit 'line) | |
271 (put 'vi-middle-window-line 'point-moving-unit 'line) | |
272 (put 'vi-reverse-last-search 'point-moving-unit 'rev-search) | |
273 (put 'vi-backward-upto-char 'point-moving-unit 'find) | |
274 (put 'vi-forward-blank-delimited-word 'point-moving-unit 'WORD) | |
275 (put 'back-to-indentation 'point-moving-unit 'char) | |
276 (put 'vi-goto-char-mark 'point-moving-unit 'char) | |
277 (put 'backward-word 'point-moving-unit 'word) | |
278 (put 'vi-end-of-word 'point-moving-unit 'match) | |
279 (put 'vi-forward-find-char 'point-moving-unit 'find) | |
280 (put 'backward-char 'point-moving-unit 'char) | |
281 (put 'vi-forward-char 'point-moving-unit 'char) | |
282 (put 'vi-repeat-last-search 'point-moving-unit 'search) | |
283 (put 'vi-forward-upto-char 'point-moving-unit 'find) | |
284 (put 'vi-forward-word 'point-moving-unit 'word) | |
285 (put 'vi-goto-column 'point-moving-unit 'match) | |
286 (put 'forward-paragraph 'point-moving-unit 'paragraph) | |
287 (put 'backward-paragraph 'point-moving-unit 'paragraph) | |
288 | |
289 ;;; region mark commands | |
290 (put 'mark-page 'point-moving-unit 'region) | |
291 (put 'mark-paragraph 'point-moving-unit 'region) | |
292 (put 'mark-word 'point-moving-unit 'region) | |
293 (put 'mark-sexp 'point-moving-unit 'region) | |
294 (put 'mark-defun 'point-moving-unit 'region) | |
295 (put 'mark-whole-buffer 'point-moving-unit 'region) | |
296 (put 'mark-end-of-sentence 'point-moving-unit 'region) | |
297 (put 'mark-c-function 'point-moving-unit 'region) | |
298 ;;; | |
299 | |
300 (defvar vi-mark-alist nil | |
301 "Alist of (NAME . MARK), marks are local to each buffer.") | |
302 | |
303 (defvar vi-scroll-amount (/ (window-height) 2) | |
304 "Default amount of lines for scrolling (used by "^D"/"^U").") | |
305 | |
306 (defvar vi-shift-width 4 | |
307 "Shift amount for "<"/">" operators.") | |
308 | |
309 (defvar vi-ins-point nil ; integer | |
310 "Last insertion point. Should use 'mark' instead.") | |
311 | |
312 (defvar vi-ins-length nil ; integer | |
313 "Length of last insertion.") | |
314 | |
315 (defvar vi-ins-repetition nil ; integer | |
316 "The repetition required for last insertion.") | |
317 | |
318 (defvar vi-ins-overwrt-p nil ; boolean | |
319 "T if last insertion was a replace actually.") | |
320 | |
321 (defvar vi-ins-prefix-code nil ; ready-to-eval sexp | |
322 "Code to be eval'ed before (redo-)insertion begins.") | |
323 | |
324 (defvar vi-last-find-char nil ; cons cell | |
325 "Save last direction, char and upto-flag used for char finding.") | |
326 | |
327 (defvar vi-last-change-command nil ; cons cell | |
328 "Save commmands for redoing last changes. Each command is in (FUNC . ARGS) | |
329 form that is ready to be 'apply'ed.") | |
330 | |
331 (defvar vi-last-shell-command nil ; last shell op command line | |
332 "Save last shell command given for \"!\" operator.") | |
333 | |
334 (defvar vi-insert-state nil ; boolean | |
335 "T if it is in insert state.") | |
336 | |
337 ; in "loaddefs.el" | |
338 ;(defvar search-last-string "" | |
339 ; "Last string search for by a search command.") | |
340 | |
341 (defvar vi-search-last-command nil ; (re-)search-forward(backward) | |
342 "Save last search command for possible redo.") | |
343 | |
344 (defvar vi-mode-old-local-map nil | |
345 "Save the local-map used before entering vi-mode.") | |
346 | |
347 (defvar vi-mode-old-mode-name nil | |
348 "Save the mode-name before entering vi-mode.") | |
349 | |
350 (defvar vi-mode-old-major-mode nil | |
351 "Save the major-mode before entering vi-mode.") | |
352 | |
353 (defvar vi-mode-old-case-fold nil) | |
354 | |
355 ;(defconst vi-add-to-mode-line-1 | |
356 ; '(overwrite-mode nil " Insert")) | |
357 | |
358 ;; Value is same as vi-add-to-mode-line-1 when in vi mode, | |
359 ;; but nil in other buffers. | |
360 ;(defvar vi-add-to-mode-line nil) | |
361 | |
362 (defun vi-mode-setup () | |
363 "Setup a buffer for vi-mode by creating necessary buffer-local variables." | |
364 ; (make-local-variable 'vi-add-to-mode-line) | |
365 ; (setq vi-add-to-mode-line vi-add-to-mode-line-1) | |
366 ; (or (memq vi-add-to-mode-line minor-mode-alist) | |
367 ; (setq minor-mode-alist (cons vi-add-to-mode-line minor-mode-alist))) | |
368 (make-local-variable 'vi-scroll-amount) | |
369 (setq vi-scroll-amount (/ (window-height) 2)) | |
370 (make-local-variable 'vi-shift-width) | |
371 (setq vi-shift-width 4) | |
372 (make-local-variable 'vi-ins-point) | |
373 (make-local-variable 'vi-ins-length) | |
374 (make-local-variable 'vi-ins-repetition) | |
375 (make-local-variable 'vi-ins-overwrt-p) | |
376 (make-local-variable 'vi-ins-prefix-code) | |
377 (make-local-variable 'vi-last-change-command) | |
378 (make-local-variable 'vi-last-shell-command) | |
379 (make-local-variable 'vi-last-find-char) | |
380 (make-local-variable 'vi-mark-alist) | |
381 (make-local-variable 'vi-insert-state) | |
382 (make-local-variable 'vi-mode-old-local-map) | |
383 (make-local-variable 'vi-mode-old-mode-name) | |
384 (make-local-variable 'vi-mode-old-major-mode) | |
385 (make-local-variable 'vi-mode-old-case-fold) | |
386 (run-hooks 'vi-mode-hook)) | |
387 | |
258 | 388 ;;;###autoload |
6 | 389 (defun vi-mode () |
390 "Major mode that acts like the `vi' editor. | |
391 The purpose of this mode is to provide you the combined power of vi (namely, | |
392 the \"cross product\" effect of commands and repeat last changes) and Emacs. | |
393 | |
394 This command redefines nearly all keys to look like vi commands. | |
395 It records the previous major mode, and any vi command for input | |
396 \(`i', `a', `s', etc.) switches back to that mode. | |
397 Thus, ordinary Emacs (in whatever major mode you had been using) | |
398 is \"input\" mode as far as vi is concerned. | |
399 | |
400 To get back into vi from \"input\" mode, you must issue this command again. | |
401 Therefore, it is recommended that you assign it to a key. | |
402 | |
403 Major differences between this mode and real vi : | |
404 | |
405 * Limitations and unsupported features | |
406 - Search patterns with line offset (e.g. /pat/+3 or /pat/z.) are | |
407 not supported. | |
408 - Ex commands are not implemented; try ':' to get some hints. | |
409 - No line undo (i.e. the 'U' command), but multi-undo is a standard feature. | |
410 | |
411 * Modifications | |
412 - The stopping positions for some point motion commands (word boundary, | |
413 pattern search) are slightly different from standard 'vi'. | |
414 Also, no automatic wrap around at end of buffer for pattern searching. | |
415 - Since changes are done in two steps (deletion then insertion), you need | |
416 to undo twice to completely undo a change command. But this is not needed | |
417 for undoing a repeated change command. | |
418 - No need to set/unset 'magic', to search for a string with regular expr | |
419 in it just put a prefix arg for the search commands. Replace cmds too. | |
420 - ^R is bound to incremental backward search, so use ^L to redraw screen. | |
421 | |
422 * Extensions | |
423 - Some standard (or modified) Emacs commands were integrated, such as | |
424 incremental search, query replace, transpose objects, and keyboard macros. | |
425 - In command state, ^X links to the 'ctl-x-map', and ESC can be linked to | |
426 esc-map or set undefined. These can give you the full power of Emacs. | |
427 - See vi-com-map for those keys that are extensions to standard vi, e.g. | |
428 `vi-name-last-change-or-macro', `vi-verify-spelling', `vi-locate-def', | |
429 `vi-mark-region', and 'vi-quote-words'. Some of them are quite handy. | |
430 - Use \\[vi-switch-mode] to switch among different modes quickly. | |
431 | |
432 Syntax table and abbrevs while in vi mode remain as they were in Emacs." | |
433 (interactive) | |
434 (if (null vi-mode-old-major-mode) ; very first call for current buffer | |
435 (vi-mode-setup)) | |
436 | |
437 (if (eq major-mode 'vi-mode) | |
438 (message "Already in vi-mode." (ding)) | |
439 (setq vi-mode-old-local-map (current-local-map)) | |
440 (setq vi-mode-old-mode-name mode-name) | |
441 (setq vi-mode-old-major-mode major-mode) | |
442 (setq vi-mode-old-case-fold case-fold-search) ; this is needed !! | |
443 (setq case-fold-search nil) ; exact case match in searching | |
444 (use-local-map vi-com-map) | |
445 (setq major-mode 'vi-mode) | |
446 (setq mode-name "VI") | |
447 (set-buffer-modified-p (buffer-modified-p)) ; force mode line update | |
448 (if vi-insert-state ; this is a return from insertion | |
449 (vi-end-of-insert-state)))) | |
450 | |
451 (defun vi-ding() | |
452 "Ding !" | |
453 (interactive) | |
454 (ding)) | |
455 | |
456 (defun vi-save-all-and-exit () | |
457 "Save all modified buffers without asking, then exits emacs." | |
458 (interactive) | |
459 (save-some-buffers t) | |
460 (kill-emacs)) | |
461 | |
462 ;; to be used by "ex" commands | |
463 (defvar vi-replaced-string nil) | |
464 (defvar vi-replacing-string nil) | |
465 | |
466 (defun vi-ex-cmd () | |
467 "Ex commands are not implemented in Evi mode. For some commonly used ex | |
468 commands, you can use the following alternatives for similar effect : | |
469 w C-x C-s (save-buffer) | |
470 wq C-x C-c (save-buffers-kill-emacs) | |
471 w fname C-x C-w (write-file) | |
472 e fname C-x C-f (find-file) | |
473 r fname C-x i (insert-file) | |
474 s/old/new use q (vi-replace) to do unconditional replace | |
475 use C-q (vi-query-replace) to do query replace | |
476 set sw=n M-x set-variable vi-shift-width n " | |
477 (interactive) | |
478 ;; (let ((cmd (read-string ":")) (lines 1)) | |
479 ;; (cond ((string-match "s")))) | |
480 (with-output-to-temp-buffer "*Help*" | |
481 (princ (documentation 'vi-ex-cmd)))) | |
482 | |
483 (defun vi-undefined () | |
484 (interactive) | |
485 (message "Command key \"%s\" is undefined in Evi." | |
486 (single-key-description last-command-char)) | |
487 (ding)) | |
488 | |
489 (defun vi-unimplemented () | |
490 (interactive) | |
491 (message "Command key \"%s\" is not implemented in Evi." | |
492 (single-key-description last-command-char)) | |
493 (ding)) | |
494 | |
495 ;;;;; | |
496 (defun vi-goto-insert-state (repetition &optional prefix-code do-it-now-p) | |
497 "Go into insert state, the text entered will be repeated if REPETITION > 1. | |
498 If PREFIX-CODE is given, do it before insertion begins if DO-IT-NOW-P is T. | |
499 In any case, the prefix-code will be done before each 'redo-insert'. | |
500 This function expects 'overwrite-mode' being set properly beforehand." | |
501 (if do-it-now-p (apply (car prefix-code) (cdr prefix-code))) | |
502 (setq vi-ins-point (point)) | |
503 (setq vi-ins-repetition repetition) | |
504 (setq vi-ins-prefix-code prefix-code) | |
505 (setq mode-name vi-mode-old-mode-name) | |
506 (setq case-fold-search vi-mode-old-case-fold) | |
507 (use-local-map vi-mode-old-local-map) | |
508 (setq major-mode vi-mode-old-major-mode) | |
509 (set-buffer-modified-p (buffer-modified-p)) ; force mode line update | |
510 (setq vi-insert-state t)) | |
511 | |
512 (defun vi-end-of-insert-state () | |
513 "Terminate insertion and set up last change command." | |
514 (if (or (< (point) vi-ins-point) ;Check if there is any effective change | |
515 (and (= (point) vi-ins-point) (null vi-ins-prefix-code)) | |
516 (<= vi-ins-repetition 0)) | |
517 (vi-goto-command-state t) | |
518 (if (> vi-ins-repetition 1) | |
519 (progn | |
520 (let ((str (buffer-substring vi-ins-point (point)))) | |
521 (while (> vi-ins-repetition 1) | |
522 (insert str) | |
523 (setq vi-ins-repetition (1- vi-ins-repetition)))))) | |
524 (vi-set-last-change-command 'vi-first-redo-insertion vi-ins-point (point) | |
525 overwrite-mode vi-ins-prefix-code) | |
526 (vi-goto-command-state t))) | |
527 | |
528 (defun vi-first-redo-insertion (begin end &optional overwrite-p prefix-code) | |
529 "Redo last insertion the first time. Extract the string and save it for | |
530 future redoes. Do prefix-code if it's given, use overwrite mode if asked." | |
531 (let ((str (buffer-substring begin end))) | |
532 (if prefix-code (apply (car prefix-code) (cdr prefix-code))) | |
533 (if overwrite-p (delete-region (point) (+ (point) (length str)))) | |
534 (insert str) | |
535 (vi-set-last-change-command 'vi-more-redo-insertion str overwrite-p prefix-code))) | |
536 | |
537 (defun vi-more-redo-insertion (str &optional overwrite-p prefix-code) | |
538 "Redo more insertion : copy string from STR to point, use overwrite mode | |
539 if overwrite-p is T; apply prefix-code first if it's non-nil." | |
540 (if prefix-code (apply (car prefix-code) (cdr prefix-code))) | |
541 (if overwrite-p (delete-region (point) (+ (point) (length str)))) | |
542 (insert str)) | |
543 | |
544 (defun vi-goto-command-state (&optional from-insert-state-p) | |
545 "Go to vi-mode command state. If optional arg exists, means return from | |
546 insert state." | |
547 (use-local-map vi-com-map) | |
548 (setq vi-insert-state nil) | |
549 (if from-insert-state-p | |
550 (if overwrite-mode | |
551 (overwrite-mode 0) | |
552 ; (set-minor-mode 'ins "Insert" nil) | |
553 ))) | |
554 | |
555 (defun vi-kill-line (arg) | |
556 "kill specified number of lines (=d$), text saved in the kill ring." | |
557 (interactive "*P") | |
558 (kill-line arg) | |
559 (vi-set-last-change-command 'kill-line arg)) | |
560 | |
561 (defun vi-kill-region () | |
562 (interactive) | |
563 (kill-region) | |
564 (vi-set-last-change-command 'kill-region)) | |
565 | |
566 (defun vi-append-at-end-of-line (arg) | |
567 "go to end of line and then go into vi insert state." | |
568 (interactive "*p") | |
569 (vi-goto-insert-state arg '(end-of-line) t)) | |
570 | |
571 (defun vi-change-rest-of-line (arg) | |
572 "Change the rest of (ARG) lines (= c$ in vi)." | |
573 (interactive "*P") | |
574 (vi-goto-insert-state 1 (list 'kill-line arg) t)) | |
575 | |
576 (defun vi-insert-before-first-nonwhite (arg) | |
577 "(= ^i in vi)" | |
578 (interactive "*p") | |
579 (vi-goto-insert-state arg '(back-to-indentation) t)) | |
580 | |
581 (defun vi-open-above (arg) | |
582 "open new line(s) above current line and enter insert state." | |
583 (interactive "*p") | |
584 (vi-goto-insert-state 1 | |
585 (list (function (lambda (x) | |
586 (or (beginning-of-line) | |
587 (open-line x)))) arg) | |
588 t)) | |
589 | |
590 (defun vi-open-below (arg) | |
591 "open new line(s) and go into insert mode on the last line." | |
592 (interactive "*p") | |
593 (vi-goto-insert-state 1 | |
594 (list (function (lambda (x) | |
595 (or (end-of-line) | |
596 (open-line x) | |
597 (forward-line x)))) arg) | |
598 t)) | |
599 | |
600 (defun vi-insert-after (arg) | |
601 "start vi insert state after cursor." | |
602 (interactive "*p") | |
603 (vi-goto-insert-state arg | |
604 (list (function (lambda () | |
605 (if (not (eolp)) (forward-char))))) | |
606 t)) | |
607 | |
608 (defun vi-insert-before (arg) | |
609 "enter insert state before the cursor." | |
610 (interactive "*p") | |
611 (vi-goto-insert-state arg)) | |
612 | |
613 (defun vi-goto-line (arg) | |
614 "Go to ARGth line." | |
615 (interactive "P") | |
616 (if (null (vi-raw-numeric-prefix arg)) | |
617 (end-of-buffer) | |
618 (goto-line (vi-prefix-numeric-value arg)))) | |
619 | |
620 (defun vi-beginning-of-buffer () | |
621 "Move point to the beginning of current buffer." | |
622 (interactive) | |
623 (goto-char (point-min))) | |
624 | |
625 ;;;;; not used now | |
626 ;;(defvar regexp-search t ; string | |
627 ;; "*T if search string can contain regular expressions. (= set magic in vi)") | |
628 ;;;;; | |
629 | |
630 (defun vi-isearch-forward (arg) | |
631 "Incremental search forward. Use regexp version if ARG is non-nil." | |
632 (interactive "P") | |
633 (let ((scmd (if arg 'isearch-forward-regexp 'isearch-forward)) | |
634 (opoint (point))) | |
635 (call-interactively scmd) | |
636 (if (= opoint (point)) | |
637 nil | |
638 (setq vi-search-last-command (if arg 're-search-forward 'search-forward))))) | |
639 | |
640 (defun vi-isearch-backward (arg) | |
641 "Incremental search backward. Use regexp version if ARG is non-nil." | |
642 (interactive "P") | |
643 (let ((scmd (if arg 'isearch-backward-regexp 'isearch-backward)) | |
644 (opoint (point))) | |
645 (call-interactively scmd) | |
646 (if (= opoint (point)) | |
647 nil | |
648 (setq vi-search-last-command (if arg 're-search-backward 'search-backward))))) | |
649 | |
650 (defun vi-search-forward (arg string) | |
651 "Nonincremental search forward. Use regexp version if ARG is non-nil." | |
652 (interactive (if current-prefix-arg | |
653 (list t (read-string "regexp/" nil)) | |
654 (list nil (read-string "/" nil)))) | |
655 (setq vi-search-last-command (if arg 're-search-forward 'search-forward)) | |
656 (if (> (length string) 0) (setq search-last-string string)) | |
657 (funcall vi-search-last-command search-last-string nil nil 1)) | |
658 | |
659 (defun vi-search-backward (arg string) | |
660 "Nonincremental search backward. Use regexp version if ARG is non-nil." | |
661 (interactive (if current-prefix-arg | |
662 (list t (read-string "regexp?" nil)) | |
663 (list nil (read-string "?" nil)))) | |
664 (setq vi-search-last-command (if arg 're-search-backward 'search-backward)) | |
665 (if (> (length string) 0) (setq search-last-string string)) | |
666 (funcall vi-search-last-command search-last-string nil nil 1)) | |
667 | |
668 (defun vi-repeat-last-search (arg &optional search-command search-string) | |
669 "Repeat last search command. If optional search-command/string are given, | |
670 use those instead of the ones saved." | |
671 (interactive "p") | |
672 (if (null search-command) (setq search-command vi-search-last-command)) | |
673 (if (null search-string) (setq search-string search-last-string)) | |
674 (if (null search-command) | |
675 (message "No last search command to repeat." (ding)) | |
676 (funcall search-command search-string nil nil arg))) | |
677 | |
678 (defun vi-reverse-last-search (arg &optional search-command search-string) | |
679 "Redo last search command in reverse direction. If the optional search args | |
680 are given, use those instead of the ones saved." | |
681 (interactive "p") | |
682 (if (null search-command) (setq search-command vi-search-last-command)) | |
683 (if (null search-string) (setq search-string search-last-string)) | |
684 (if (null search-command) | |
685 (message "No last search command to repeat." (ding)) | |
686 (funcall (cond ((eq search-command 're-search-forward) 're-search-backward) | |
687 ((eq search-command 're-search-backward) 're-search-forward) | |
688 ((eq search-command 'search-forward) 'search-backward) | |
689 ((eq search-command 'search-backward) 'search-forward)) | |
690 search-string nil nil arg))) | |
691 | |
692 (defun vi-join-lines (arg) | |
693 "join ARG lines from current line (default 2), cleaning up white space." | |
694 (interactive "P") | |
695 (if (null (vi-raw-numeric-prefix arg)) | |
696 (delete-indentation t) | |
697 (setq count (vi-prefix-numeric-value arg)) | |
698 (while (>= count 2) | |
699 (delete-indentation t) | |
700 (setq count (1- count)))) | |
701 (vi-set-last-change-command 'vi-join-lines arg)) | |
702 | |
703 (defun vi-backward-kill-line () | |
704 "kill the current line. Only works in insert state." | |
705 (interactive) | |
706 (if (not vi-insert-state) | |
707 nil | |
708 (beginning-of-line 1) | |
709 (kill-line nil))) | |
710 | |
711 (defun vi-abort-ins () | |
712 "abort insert state, kill inserted text and go back to command state." | |
713 (interactive) | |
714 (if (not vi-insert-state) | |
715 nil | |
716 (if (> (point) vi-ins-point) | |
717 (kill-region vi-ins-point (point))) | |
718 (vi-goto-command-state t))) | |
719 | |
720 (defun vi-backward-windowfull (count) | |
721 "Backward COUNT windowfulls. Default is one." | |
722 (interactive "p") | |
723 ; (set-mark-command nil) | |
724 (while (> count 0) | |
725 (scroll-down nil) | |
726 (setq count (1- count)))) | |
727 | |
728 (defun vi-scroll-down-window (count) | |
729 "Scrolls down window COUNT lines. If COUNT is nil (actually, non-integer), | |
730 scrolls default amount. The given COUNT is remembered for future scrollings." | |
731 (interactive "P") | |
732 (if (integerp count) | |
733 (setq vi-scroll-amount count)) | |
734 (scroll-up vi-scroll-amount)) | |
735 | |
736 (defun vi-expose-line-below (count) | |
737 "Expose COUNT more lines below the current window. Default COUNT is 1." | |
738 (interactive "p") | |
739 (scroll-up count)) | |
740 | |
741 (defun vi-forward-windowfull (count) | |
742 "Forward COUNT windowfulls. Default is one." | |
743 (interactive "p") | |
744 ; (set-mark-command nil) | |
745 (while (> count 0) | |
746 (scroll-up nil) | |
747 (setq count (1- count)))) | |
748 | |
749 (defun vi-next-line (count) | |
750 "Go down count lines, try to keep at the same column." | |
751 (interactive "p") | |
752 (setq this-command 'next-line) ; this is a needed trick | |
753 (if (= (point) (or (line-move count) (point))) | |
754 (ding) ; no moving, already at end of buffer | |
755 (setq last-command 'next-line))) | |
756 | |
757 (defun vi-next-line-first-nonwhite (count) | |
758 "Go down COUNT lines. Stop at first non-white." | |
759 (interactive "p") | |
760 (if (= (point) (progn (forward-line count) (back-to-indentation) (point))) | |
761 (ding))) ; no moving, already at end of buffer | |
762 | |
763 (defun vi-previous-line-first-nonwhite (count) | |
764 "Go up COUNT lines. Stop at first non-white." | |
765 (interactive "p") | |
766 (previous-line count) | |
767 (back-to-indentation)) | |
768 | |
769 (defun vi-scroll-up-window (count) | |
770 "Scrolls up window COUNT lines. If COUNT is nil (actually, non-integer), | |
771 scrolls default amount. The given COUNT is remembered for future scrollings." | |
772 (interactive "P") | |
773 (if (integerp count) | |
774 (setq vi-scroll-amount count)) | |
775 (scroll-down vi-scroll-amount)) | |
776 | |
777 (defun vi-expose-line-above (count) | |
778 "Expose COUNT more lines above the current window. Default COUNT is 1." | |
779 (interactive "p") | |
780 (scroll-down count)) | |
781 | |
782 (defun vi-char-argument (arg) | |
783 "Get following character (could be any CHAR) as part of the prefix argument. | |
784 Possible perfix-arg cases are NIL, INTEGER, (NIL . CHAR) or (INTEGER . CHAR)." | |
785 (interactive "P") | |
786 (let ((char (read-char))) | |
787 (cond ((null arg) (setq prefix-arg (cons nil char))) | |
788 ((integerp arg) (setq prefix-arg (cons arg char))) | |
789 ; This can happen only if the user changed his/her mind for CHAR, | |
790 ; Or there are some leading "universal-argument"s | |
791 (t (setq prefix-arg (cons (car arg) char)))))) | |
792 | |
793 (defun vi-goto-mark (mark-char &optional line-flag) | |
794 "Go to marked position or line (if line-flag is given). Goto mark '@' means | |
795 jump into and pop the top mark on the mark ring." | |
796 (cond ((char-equal mark-char last-command-char) ; `` or '' | |
797 (exchange-point-and-mark) (if line-flag (back-to-indentation))) | |
798 ((char-equal mark-char ?@) ; jump and pop mark | |
799 (set-mark-command t) (if line-flag (back-to-indentation))) | |
800 (t | |
801 (let ((mark (vi-get-mark mark-char))) | |
802 (if (null mark) | |
803 (message "Mark register undefined." (vi-ding)) | |
804 (set-mark-command nil) | |
805 (goto-char mark) | |
806 (if line-flag (back-to-indentation))))))) | |
807 | |
808 (defun vi-goto-line-mark (char) | |
809 "Go to the line (at first non-white) marked by next char." | |
810 (interactive "c") | |
811 (vi-goto-mark char t)) | |
812 | |
813 (defun vi-goto-char-mark (char) | |
814 "Go to the char position marked by next mark-char." | |
815 (interactive "c") | |
816 (vi-goto-mark char)) | |
817 | |
818 (defun vi-digit-argument (arg) | |
819 "Set numeric prefix argument." | |
820 (interactive "P") | |
821 (cond ((null arg) (digit-argument arg)) | |
822 ((integerp arg) (digit-argument nil) | |
823 (setq prefix-arg (* prefix-arg arg))) | |
824 (t (digit-argument nil) ; in (NIL . CHAR) or (NUM . CHAR) form | |
825 (setq prefix-arg (cons (* prefix-arg | |
826 (if (null (car arg)) 1 (car arg))) | |
827 (cdr arg)))))) | |
828 | |
829 (defun vi-raw-numeric-prefix (arg) | |
830 "Return the raw value of numeric part prefix argument." | |
831 (if (consp arg) (car arg) arg)) | |
832 | |
833 (defun vi-prefix-numeric-value (arg) | |
834 "Return numeric meaning of the raw prefix argument. This is a modification | |
835 to the standard one provided in `callint.c' to handle (_ . CHAR) cases." | |
836 (cond ((null arg) 1) | |
837 ((integerp arg) arg) | |
838 ((consp arg) (if (car arg) (car arg) 1)))) | |
839 | |
840 (defun vi-reverse-last-find-char (count &optional find-arg) | |
841 "Reverse last f F t T operation COUNT times. If the optional FIND-ARG | |
842 is given, it is used instead of the saved one." | |
843 (interactive "p") | |
844 (if (null find-arg) (setq find-arg vi-last-find-char)) | |
845 (if (null find-arg) | |
846 (message "No last find char to repeat." (ding)) | |
847 (vi-find-char (cons (* (car find-arg) -1) (cdr find-arg)) count))) ;6/13/86 | |
848 | |
849 (defun vi-find-char (arg count) | |
850 "Find in DIRECTION (1/-1) for CHAR of COUNT'th times on current line. | |
851 If UPTO-FLAG is T, stop before the char. ARG = (DIRECTION.CHAR.UPTO-FLAG." | |
852 (let* ((direction (car arg)) (char (car (cdr arg))) | |
853 (upto-flag (cdr (cdr arg))) (pos (+ (point) direction))) | |
854 (if (catch 'exit-find-char | |
855 (while t | |
856 (cond ((null (char-after pos)) (throw 'exit-find-char nil)) | |
857 ((char-equal (char-after pos) ?\n) (throw 'exit-find-char nil)) | |
858 ((char-equal char (char-after pos)) (setq count (1- count)) | |
859 (if (= count 0) | |
860 (throw 'exit-find-char | |
861 (if upto-flag | |
862 (setq pos (- pos direction)) | |
863 pos))))) | |
864 (setq pos (+ pos direction)))) | |
865 (goto-char pos) | |
866 (ding)))) | |
867 | |
868 (defun vi-repeat-last-find-char (count &optional find-arg) | |
869 "Repeat last f F t T operation COUNT times. If optional FIND-ARG is given, | |
870 it is used instead of the saved one." | |
871 (interactive "p") | |
872 (if (null find-arg) (setq find-arg vi-last-find-char)) | |
873 (if (null find-arg) | |
874 (message "No last find char to repeat." (ding)) | |
875 (vi-find-char find-arg count))) | |
876 | |
877 (defun vi-backward-find-char (count char) | |
878 "Find the COUNT'th CHAR backward on current line." | |
879 (interactive "p\nc") | |
880 (setq vi-last-find-char (cons -1 (cons char nil))) | |
881 (vi-repeat-last-find-char count)) | |
882 | |
883 (defun vi-forward-find-char (count char) | |
884 "Find the COUNT'th CHAR forward on current line." | |
885 (interactive "p\nc") | |
886 (setq vi-last-find-char (cons 1 (cons char nil))) | |
887 (vi-repeat-last-find-char count)) | |
888 | |
889 (defun vi-backward-upto-char (count char) | |
890 "Find upto the COUNT'th CHAR backward on current line." | |
891 (interactive "p\nc") | |
892 (setq vi-last-find-char (cons -1 (cons char t))) | |
893 (vi-repeat-last-find-char count)) | |
894 | |
895 (defun vi-forward-upto-char (count char) | |
896 "Find upto the COUNT'th CHAR forward on current line." | |
897 (interactive "p\nc") | |
898 (setq vi-last-find-char (cons 1 (cons char t))) | |
899 (vi-repeat-last-find-char count)) | |
900 | |
901 (defun vi-end-of-word (count) | |
902 "Move forward until encountering the end of a word. | |
903 With argument, do this that many times." | |
904 (interactive "p") | |
905 (if (not (eobp)) (forward-char)) | |
906 (if (re-search-forward "\\W*\\w+\\>" nil t count) | |
907 (backward-char))) | |
908 | |
909 (defun vi-replace-1-char (count char) | |
910 "Replace char after point by CHAR. Repeat COUNT times." | |
911 (interactive "p\nc") | |
912 (delete-char count nil) ; don't save in kill ring | |
913 (setq last-command-char char) | |
914 (self-insert-command count) | |
915 (vi-set-last-change-command 'vi-replace-1-char count char)) | |
916 | |
917 (defun vi-replace-chars (arg) | |
918 "Replace chars over old ones." | |
919 (interactive "*p") | |
920 (overwrite-mode 1) | |
921 (vi-goto-insert-state arg)) | |
922 | |
923 (defun vi-substitute-chars (count) | |
924 "Substitute COUNT chars by the input chars, enter insert state." | |
925 (interactive "*p") | |
926 (vi-goto-insert-state 1 (list (function (lambda (c) ; this is a bit tricky | |
927 (delete-region (point) | |
928 (+ (point) c)))) | |
929 count) t)) | |
930 | |
931 (defun vi-substitute-lines (count) | |
932 "Substitute COUNT lines by the input chars. (=cc in vi)" | |
933 (interactive "*p") | |
934 (vi-goto-insert-state 1 (list 'vi-delete-op 'next-line (1- count)) t)) | |
935 | |
936 (defun vi-prefix-char-value (arg) | |
937 "Get the char part of the current prefix argument." | |
938 (cond ((null arg) nil) | |
939 ((integerp arg) nil) | |
940 ((consp arg) (cdr arg)) | |
941 (t nil))) | |
942 | |
943 (defun vi-operator (arg) | |
944 "Handling vi operators (d/c/</>/!/=/y). Current implementation requires | |
945 the key bindings of the operators being fixed." | |
946 (interactive "P") | |
947 (catch 'vi-exit-op | |
948 (let ((this-op-char last-command-char)) | |
949 (setq last-command-char (read-char)) | |
950 (setq this-command (lookup-key vi-com-map (char-to-string last-command-char))) | |
951 (if (not (eq this-command 'vi-digit-argument)) | |
952 (setq prefix-arg arg) | |
953 (vi-digit-argument arg) | |
954 (setq last-command-char (read-char)) | |
955 (setq this-command (lookup-key vi-com-map (char-to-string last-command-char)))) | |
956 (cond ((char-equal this-op-char last-command-char) ; line op | |
957 (vi-execute-op this-op-char 'next-line | |
958 (cons (1- (vi-prefix-numeric-value prefix-arg)) | |
959 (vi-prefix-char-value prefix-arg)))) | |
960 ;; We assume any command that has no property 'point-moving-unit' | |
961 ;; as having that property with the value 'CHAR'. 3/12/86 | |
962 (t ;; (get this-command 'point-moving-unit) | |
963 (vi-execute-op this-op-char this-command prefix-arg)))))) | |
964 ;; (t (throw 'vi-exit-op (ding))))))) | |
965 | |
966 (defun vi-execute-op (op-char motion-command arg) | |
967 "Execute vi edit operator as specified by OP-CHAR, the operand is the region | |
968 determined by the MOTION-COMMAND with ARG." | |
969 (cond ((= op-char ?d) | |
970 (if (vi-delete-op motion-command arg) | |
971 (vi-set-last-change-command 'vi-delete-op (vi-repeat-command-of motion-command) arg))) | |
972 ((= op-char ?c) | |
973 (if (vi-delete-op motion-command arg) | |
974 (vi-goto-insert-state 1 (list 'vi-delete-op | |
975 (vi-repeat-command-of motion-command) arg) nil))) | |
976 ((= op-char ?y) | |
977 (if (vi-yank-op motion-command arg) | |
978 (vi-set-last-change-command 'vi-yank-op (vi-repeat-command-of motion-command) arg))) | |
979 ((= op-char ?!) | |
980 (if (vi-shell-op motion-command arg) | |
981 (vi-set-last-change-command 'vi-shell-op (vi-repeat-command-of motion-command) arg vi-last-shell-command))) | |
982 ((= op-char ?<) | |
983 (if (vi-shift-op motion-command arg (- vi-shift-width)) | |
984 (vi-set-last-change-command 'vi-shift-op (vi-repeat-command-of motion-command) arg (- vi-shift-width)))) | |
985 ((= op-char ?>) | |
986 (if (vi-shift-op motion-command arg vi-shift-width) | |
987 (vi-set-last-change-command 'vi-shift-op (vi-repeat-command-of motion-command) arg vi-shift-width))) | |
988 ((= op-char ?=) | |
989 (if (vi-indent-op motion-command arg) | |
990 (vi-set-last-change-command 'vi-indent-op (vi-repeat-command-of motion-command) arg))) | |
991 ((= op-char ?\\) | |
992 (vi-narrow-op motion-command arg)))) | |
993 | |
994 (defun vi-repeat-command-of (command) | |
995 "Return the command for redo the given command." | |
996 (let ((cmd-type (get command 'point-moving-unit))) | |
997 (cond ((eq cmd-type 'search) 'vi-repeat-last-search) | |
998 ((eq cmd-type 'find) 'vi-repeat-last-find-char) | |
999 (t command)))) | |
1000 | |
1001 (defun vi-effective-range (motion-command arg) | |
1002 "Return (begin . end) of the range spanned by executing the given | |
1003 MOTION-COMMAND with ARG. | |
1004 MOTION-COMMAND in ready-to-eval list form is not yet supported." | |
1005 (save-excursion | |
1006 (let ((begin (point)) end opoint | |
1007 (moving-unit (get motion-command 'point-moving-unit))) | |
1008 (setq prefix-arg arg) | |
1009 (setq opoint (point)) | |
1010 (command-execute motion-command nil) | |
1011 ;; Check if there is any effective motion. Note that for single line operation | |
1012 ;; the motion-command causes no effective point movement (since it moves up or | |
1013 ;; down zero lines), but it should be counted as effectively moved. | |
1014 (if (and (= (point) opoint) (not (eq moving-unit 'line))) | |
1015 (cons opoint opoint) ; no effective motion | |
1016 (if (eq moving-unit 'region) | |
1017 (setq begin (or (mark) (point)))) | |
1018 (if (<= begin (point)) | |
1019 (setq end (point)) | |
1020 (setq end begin) | |
1021 (setq begin (point))) | |
1022 (cond ((or (eq moving-unit 'match) (eq moving-unit 'find)) | |
1023 (setq end (1+ end))) | |
1024 ((eq moving-unit 'line) | |
1025 (goto-char begin) (beginning-of-line) (setq begin (point)) | |
1026 (goto-char end) (next-line 1) (beginning-of-line) (setq end (point)))) | |
1027 (if (> end (point-max)) (setq end (point-max))) ; force in buffer region | |
1028 (cons begin end))))) | |
1029 | |
1030 (defun vi-delete-op (motion-command arg) | |
1031 "Delete range specified by MOTION-COMMAND with ARG." | |
1032 (let* ((range (vi-effective-range motion-command arg)) | |
1033 (begin (car range)) (end (cdr range)) reg) | |
1034 (if (= begin end) | |
1035 nil ; point not moved, abort op | |
1036 (setq reg (vi-prefix-char-value arg)) | |
1037 (if (null reg) | |
1038 (kill-region begin end) ; kill ring as unnamed registers | |
1039 (if (and (>= reg ?A) (<= reg ?Z)) | |
1040 (append-to-register (downcase reg) begin end t) | |
1041 (copy-to-register reg begin end t))) | |
1042 t))) | |
1043 | |
1044 (defun vi-yank-op (motion-command arg) | |
1045 "Yank (in vi sense) range specified by MOTION-COMMAND with ARG." | |
1046 (let* ((range (vi-effective-range motion-command arg)) | |
1047 (begin (car range)) (end (cdr range)) reg) | |
1048 (if (= begin end) | |
1049 nil ; point not moved, abort op | |
1050 (setq reg (vi-prefix-char-value arg)) | |
1051 (if (null reg) | |
1052 (copy-region-as-kill begin end); kill ring as unnamed registers | |
1053 (if (and (>= reg ?A) (<= reg ?Z)) | |
1054 (append-to-register (downcase reg) begin end nil) | |
1055 (copy-to-register reg begin end nil))) | |
1056 t))) | |
1057 | |
1058 (defun vi-yank-line (arg) | |
1059 "Yank (in vi sense) lines (= `yy' command)." | |
1060 (interactive "*P") | |
1061 (setq arg (cons (1- (vi-prefix-numeric-value arg)) (vi-prefix-char-value arg))) | |
1062 (if (vi-yank-op 'next-line arg) | |
1063 (vi-set-last-change-command 'vi-yank-op 'next-line arg))) | |
1064 | |
1065 (defun vi-string-end-with-nl-p (string) | |
1066 "See if STRING ends with a newline char. Used in checking whether the yanked | |
1067 text should be put back as lines or not." | |
1068 (= (aref string (1- (length string))) ?\n)) | |
1069 | |
1070 (defun vi-put-before (arg &optional after-p) | |
1071 "Put yanked (in vi sense) text back before/above cursor. If a numeric prefix | |
1072 value (currently it should be >1) is given, put back text as lines. | |
1073 If the optional after-p is given, put after/below the cursor." | |
1074 (interactive "P") | |
1075 (let ((reg (vi-prefix-char-value arg)) put-text) | |
1076 (if (and reg (or (< reg ?1) (> reg ?9)) (null (get-register reg))) | |
1077 (error "Nothing in register %c" reg) | |
1078 (if (null reg) (setq reg ?1)) ; the default is the last text killed | |
1079 (setq put-text | |
707 | 1080 (cond |
1081 ((and (>= reg ?1) (<= reg ?9)) | |
1082 (setq this-command 'yank) ; So we may yank-pop !! | |
1083 (current-kill (- reg ?0 1) 'do-not-rotate)) | |
1084 ((stringp (get-register reg)) (get-register reg)) | |
1085 (t (error "Register %c is not containing text string" reg)))) | |
6 | 1086 (if (vi-string-end-with-nl-p put-text) ; put back text as lines |
1087 (if after-p | |
1088 (progn (next-line 1) (beginning-of-line)) | |
1089 (beginning-of-line)) | |
1090 (if after-p (forward-char 1))) | |
1091 (push-mark (point)) | |
1092 (insert put-text) | |
1093 (exchange-point-and-mark) | |
1094 ;; (back-to-indentation) ; this is not allowed if we allow yank-pop | |
1095 (vi-set-last-change-command 'vi-put-before arg after-p)))) | |
1096 | |
1097 (defun vi-put-after (arg) | |
1098 "Put yanked (in vi sense) text back after/below cursor." | |
1099 (interactive "P") | |
1100 (vi-put-before arg t)) | |
1101 | |
1102 (defun vi-shell-op (motion-command arg &optional shell-command) | |
1103 "Perform shell command (as filter) on range specified by MOTION-COMMAND | |
1104 with ARG. If SHELL-COMMAND is not given, ask for one from minibuffer. | |
1105 If char argument is given, it directs the output to a *temp* buffer." | |
1106 (let* ((range (vi-effective-range motion-command arg)) | |
1107 (begin (car range)) (end (cdr range))) | |
1108 (if (= begin end) | |
1109 nil ; point not moved, abort op | |
1110 (cond ((null shell-command) | |
1111 (setq shell-command (read-string "!" nil)) | |
1112 (setq vi-last-shell-command shell-command))) | |
1113 (shell-command-on-region begin end shell-command (not (vi-prefix-char-value arg))) | |
1114 t))) | |
1115 | |
1116 (defun vi-shift-op (motion-command arg amount) | |
1117 "Perform shift command on range specified by MOTION-COMMAND with ARG for | |
1118 AMOUNT on each line. Negative amount means shift left. | |
1119 SPECIAL FEATURE: char argument can be used to specify shift amount(1-9)." | |
1120 (let* ((range (vi-effective-range motion-command arg)) | |
1121 (begin (car range)) (end (cdr range))) | |
1122 (if (= begin end) | |
1123 nil ; point not moved, abort op | |
1124 (if (vi-prefix-char-value arg) | |
1125 (setq amount (if (> amount 0) | |
1126 (- (vi-prefix-char-value arg) ?0) | |
1127 (- ?0 (vi-prefix-char-value arg))))) | |
1128 (indent-rigidly begin end amount) | |
1129 t))) | |
1130 | |
1131 (defun vi-indent-op (motion-command arg) | |
1132 "Perform indent command on range specified by MOTION-COMMAND with ARG." | |
1133 (let* ((range (vi-effective-range motion-command arg)) | |
1134 (begin (car range)) (end (cdr range))) | |
1135 (if (= begin end) | |
1136 nil ; point not moved, abort op | |
1137 (indent-region begin end nil) ; insert TAB as indent command | |
1138 t))) | |
1139 | |
1140 (defun vi-narrow-op (motion-command arg) | |
1141 "Narrow to region specified by MOTION-COMMAND with ARG." | |
1142 (let* ((range (vi-effective-range motion-command arg)) | |
1143 (begin (car range)) (end (cdr range)) reg) | |
1144 (if (= begin end) | |
1145 nil ; point not moved, abort op | |
1146 (narrow-to-region begin end)))) | |
1147 | |
1148 (defun vi-get-mark (char) | |
1149 "Return contents of vi mark register named CHAR, or nil if undefined." | |
1150 (cdr (assq char vi-mark-alist))) | |
1151 | |
1152 (defun vi-set-mark (char) | |
1153 "Set contents of vi mark register named CHAR to current point. '@' is the | |
1154 special anonymous mark register." | |
1155 (interactive "c") | |
1156 (if (char-equal char ?@) | |
1157 (set-mark-command nil) | |
1158 (let ((aelt (assq char vi-mark-alist))) | |
1159 (if aelt | |
1160 (move-marker (cdr aelt) (point)) ; fixed 6/12/86 | |
1161 (setq aelt (cons char (copy-marker (point)))) | |
1162 (setq vi-mark-alist (cons aelt vi-mark-alist)))))) | |
1163 | |
1164 (defun vi-find-matching-paren () | |
1165 "Locate the matching paren. It's a hack right now." | |
1166 (interactive) | |
1167 (cond ((looking-at "[[({]") (forward-sexp 1) (backward-char 1)) | |
1168 ((looking-at "[])}]") (forward-char 1) (backward-sexp 1)) | |
1169 (t (ding)))) | |
1170 | |
1171 (defun vi-backward-blank-delimited-word (count) | |
1172 "Backward COUNT blank-delimited words." | |
1173 (interactive "p") | |
1174 (if (re-search-backward "[ \t\n\`][^ \t\n\`]+" nil t count) | |
1175 (if (not (bobp)) (forward-char 1)))) | |
1176 | |
1177 (defun vi-forward-blank-delimited-word (count) | |
1178 "Forward COUNT blank-delimited words." | |
1179 (interactive "p") | |
1180 (if (re-search-forward "[^ \t\n]*[ \t\n]+[^ \t\n]" nil t count) | |
1181 (if (not (eobp)) (backward-char 1)))) | |
1182 | |
1183 (defun vi-end-of-blank-delimited-word (count) | |
1184 "Forward to the end of the COUNT'th blank-delimited word." | |
1185 (interactive "p") | |
1186 (if (re-search-forward "[^ \t\n\']+[ \t\n\']" nil t count) | |
1187 (if (not (eobp)) (backward-char 2)))) | |
1188 | |
1189 (defun vi-home-window-line (arg) | |
1190 "To window home or arg'th line from the top of the window." | |
1191 (interactive "p") | |
1192 (move-to-window-line (1- arg)) | |
1193 (back-to-indentation)) | |
1194 | |
1195 (defun vi-last-window-line (arg) | |
1196 "To window last line or arg'th line from the bottom of the window." | |
1197 (interactive "p") | |
1198 (move-to-window-line (- arg)) | |
1199 (back-to-indentation)) | |
1200 | |
1201 (defun vi-middle-window-line () | |
1202 "To the middle line of the window." | |
1203 (interactive) | |
1204 (move-to-window-line nil) | |
1205 (back-to-indentation)) | |
1206 | |
1207 (defun vi-forward-word (count) | |
1208 "Stop at the beginning of the COUNT'th words from point." | |
1209 (interactive "p") | |
1210 (if (re-search-forward "\\w*\\W+\\<" nil t count) | |
1211 t | |
1212 (vi-ding))) | |
1213 | |
1214 (defun vi-set-last-change-command (fun &rest args) | |
1215 "Set (FUN . ARGS) as the last-change-command." | |
1216 (setq vi-last-change-command (cons fun args))) | |
1217 | |
1218 (defun vi-redo-last-change-command (count &optional command) | |
1219 "Redo last change command COUNT times. If the optional COMMAND is given, | |
1220 it is used instead of the current last-change-command." | |
1221 (interactive "p") | |
1222 (if (null command) | |
1223 (setq command vi-last-change-command)) | |
1224 (if (null command) | |
1225 (message "No last change command available.") | |
1226 (while (> count 0) | |
1227 (apply (car command) (cdr command)) | |
1228 (setq count (1- count))))) | |
1229 | |
1230 (defun vi-kill-char (count) | |
1231 "Kill COUNT chars from current point." | |
1232 (interactive "*p") | |
1233 (delete-char count t) ; save in kill ring | |
1234 (vi-set-last-change-command 'delete-char count t)) | |
1235 | |
1236 (defun vi-transpose-objects (arg unit) | |
1237 "Transpose objects, the following char specifies unit of objects to be | |
1238 transposed -- \"c\" for chars, \"l\" for lines, \"w\" for words, \"s\" for | |
1239 sexp, \"p\" for paragraph. | |
1240 For the use of the prefix-arg, refer to individual functions called." | |
1241 (interactive "*P\nc") | |
1242 (if (char-equal unit ??) | |
1243 (progn | |
1244 (message "Transpose: c(har), l(ine), p(aragraph), s(-exp), w(ord),") | |
1245 (setq unit (read-char)))) | |
1246 (vi-set-last-change-command 'vi-transpose-objects arg unit) | |
1247 (cond ((char-equal unit ?c) (transpose-chars arg)) | |
1248 ((char-equal unit ?l) (transpose-lines (vi-prefix-numeric-value arg))) | |
1249 ((char-equal unit ?p) (transpose-paragraphs (vi-prefix-numeric-value arg))) | |
1250 ((char-equal unit ?s) (transpose-sexps (vi-prefix-numeric-value arg))) | |
1251 ((char-equal unit ?w) (transpose-words (vi-prefix-numeric-value arg))) | |
1252 (t (vi-transpose-objects arg ??)))) | |
1253 | |
1254 (defun vi-query-replace (arg) | |
1255 "Query replace, use regexp version if ARG is non-nil." | |
1256 (interactive "*P") | |
1257 (let ((rcmd (if arg 'query-replace-regexp 'query-replace))) | |
1258 (call-interactively rcmd nil))) | |
1259 | |
1260 (defun vi-replace (arg) | |
1261 "Replace strings, use regexp version if ARG is non-nil." | |
1262 (interactive "*P") | |
1263 (let ((rcmd (if arg 'replace-regexp 'replace-string))) | |
1264 (call-interactively rcmd nil))) | |
1265 | |
1266 (defun vi-adjust-window (arg position) | |
1267 "Move current line to the top/center/bottom of the window." | |
1268 (interactive "p\nc") | |
1269 (cond ((char-equal position ?\r) (recenter 0)) | |
1270 ((char-equal position ?-) (recenter -1)) | |
1271 ((char-equal position ?.) (recenter (/ (window-height) 2))) | |
1272 (t (message "Move current line to: \\r(top) -(bottom) .(middle)") | |
1273 (setq position (read-char)) | |
1274 (vi-adjust-window arg position)))) | |
1275 | |
1276 (defun vi-goto-column (col) | |
1277 "Go to given column of the current line." | |
1278 (interactive "p") | |
1279 (let ((opoint (point))) | |
1280 (beginning-of-line) | |
1281 (while (> col 1) | |
1282 (if (eolp) | |
1283 (setq col 0) | |
1284 (forward-char 1) | |
1285 (setq col (1- col)))) | |
1286 (if (= col 1) | |
1287 t | |
1288 (goto-char opoint) | |
1289 (ding)))) | |
1290 | |
1291 (defun vi-name-last-change-or-macro (arg char) | |
1292 "Give name to the last change command or just defined kbd macro. If prefix | |
1293 ARG is given, name last macro, otherwise name last change command. The | |
1294 following CHAR will be the name for the command or macro." | |
1295 (interactive "P\nc") | |
1296 (if arg | |
1297 (name-last-kbd-macro (intern (char-to-string char))) | |
1298 (if (eq (car vi-last-change-command) 'vi-first-redo-insertion) | |
1299 (let* ((args (cdr vi-last-change-command)) ; save the insertion text | |
1300 (str (buffer-substring (nth 0 args) (nth 1 args))) | |
1301 (overwrite-p (nth 2 args)) | |
1302 (prefix-code (nth 3 args))) | |
1303 (vi-set-last-change-command 'vi-more-redo-insertion str | |
1304 overwrite-p prefix-code))) | |
1305 (fset (intern (char-to-string char)) vi-last-change-command))) | |
1306 | |
1307 (defun vi-call-named-change-or-macro (count char) | |
1308 "Execute COUNT times the keyboard macro definition named by the following CHAR." | |
1309 (interactive "p\nc") | |
1310 (if (stringp (symbol-function (intern (char-to-string char)))) | |
1311 (execute-kbd-macro (intern (char-to-string char)) count) | |
1312 (vi-redo-last-change-command count (symbol-function (intern (char-to-string char)))))) | |
1313 | |
1314 (defun vi-change-case (arg) ; could be made as an operator ? | |
1315 "Change the case of the char after point." | |
1316 (interactive "*p") | |
1317 (catch 'exit | |
1318 (if (looking-at "[a-z]") | |
1319 (upcase-region (point) (+ (point) arg)) | |
1320 (if (looking-at "[A-Z]") | |
1321 (downcase-region (point) (+ (point) arg)) | |
1322 (ding) | |
1323 (throw 'exit nil))) | |
1324 (vi-set-last-change-command 'vi-change-case arg) ;should avoid redundant save | |
1325 (forward-char arg))) | |
1326 | |
1327 (defun vi-ask-for-info (char) | |
1328 "Inquire status info. The next CHAR will specify the particular info requested." | |
1329 (interactive "c") | |
1330 (cond ((char-equal char ?l) (what-line)) | |
1331 ((char-equal char ?c) (what-cursor-position)) | |
1332 ((char-equal char ?p) (what-page)) | |
1333 (t (message "Ask for: l(ine number), c(ursor position), p(age number)") | |
1334 (setq char (read-char)) | |
1335 (vi-ask-for-info char)))) | |
1336 | |
1337 (defun vi-mark-region (arg region) | |
1338 "Mark region approriately. The next char REGION is d(efun),s(-exp),b(uffer), | |
1339 p(aragraph), P(age), f(unction in C/Pascal etc.), w(ord), e(nd of sentence), | |
1340 l(ines)." | |
1341 (interactive "p\nc") | |
1342 (cond ((char-equal region ?d) (mark-defun arg)) | |
1343 ((char-equal region ?s) (mark-sexp arg)) | |
1344 ((char-equal region ?b) (mark-whole-buffer)) | |
1345 ((char-equal region ?p) (mark-paragraph arg)) | |
1346 ((char-equal region ?P) (mark-page arg)) | |
1347 ((char-equal region ?f) (mark-c-function arg)) | |
1348 ((char-equal region ?w) (mark-word arg)) | |
1349 ((char-equal region ?e) (mark-end-of-sentence arg)) | |
1350 ((char-equal region ?l) (vi-mark-lines arg)) | |
1351 (t (message "Mark: d(efun),s(-exp),b(uf),p(arag),P(age),f(unct),w(ord),e(os),l(ines)") | |
1352 (setq region (read-char)) | |
1353 (vi-mark-region arg region)))) | |
1354 | |
1355 (defun vi-mark-lines (num) | |
1356 "Mark NUM of lines from current line as current region." | |
1357 (beginning-of-line 1) | |
1358 (push-mark) | |
1359 (end-of-line num)) | |
1360 | |
1361 (defun vi-verify-spelling (arg unit) | |
1362 "Verify spelling for the objects specified by char UNIT : [b(uffer), | |
1363 r(egion), s(tring), w(ord) ]." | |
1364 (interactive "P\nc") | |
1365 (setq prefix-arg arg) ; seems not needed | |
1366 (cond ((char-equal unit ?b) (call-interactively 'spell-buffer)) | |
1367 ((char-equal unit ?r) (call-interactively 'spell-region)) | |
1368 ((char-equal unit ?s) (call-interactively 'spell-string)) | |
1369 ((char-equal unit ?w) (call-interactively 'spell-word)) | |
1370 (t (message "Spell check: b(uffer), r(egion), s(tring), w(ord)") | |
1371 (setq unit (read-char)) | |
1372 (vi-verify-spelling arg unit)))) | |
1373 | |
1374 (defun vi-do-old-mode-C-c-command (arg) | |
1375 "This is a hack for accessing mode specific C-c commands in vi-mode." | |
1376 (interactive "P") | |
1377 (let ((cmd (lookup-key vi-mode-old-local-map | |
1378 (concat "\C-c" (char-to-string (read-char)))))) | |
1379 (if (catch 'exit-vi-mode ; kludge hack due to dynamic binding | |
1380 ; of case-fold-search | |
1381 (if (null cmd) | |
1382 (progn (ding) nil) | |
1383 (let ((case-fold-search vi-mode-old-case-fold)) ; a hack | |
1384 (setq prefix-arg arg) | |
1385 (command-execute cmd nil) | |
1386 nil))) | |
1387 (progn | |
1388 (vi-back-to-old-mode) | |
1389 (setq prefix-arg arg) | |
1390 (command-execute cmd nil))))) | |
1391 | |
1392 (defun vi-quote-words (arg char) | |
1393 "Quote ARG words from the word point is on with the pattern specified by the | |
1394 CHAR. Currently, CHAR could be [,{,(,\",',`,<,*, etc." | |
1395 (interactive "*p\nc") | |
1396 (while (not (string-match "[[({<\"'`*]" (char-to-string char))) | |
1397 (message "Enter any of [,{,(,<,\",',`,* as quoting character.") | |
1398 (setq char (read-char))) | |
1399 (vi-set-last-change-command 'vi-quote-words arg char) | |
1400 (if (not (looking-at "\\<")) (forward-word -1)) | |
1401 (insert char) | |
1402 (cond ((char-equal char ?[) (setq char ?])) | |
1403 ((char-equal char ?{) (setq char ?})) | |
1404 ((char-equal char ?<) (setq char ?>)) | |
1405 ((char-equal char ?() (setq char ?))) | |
1406 ((char-equal char ?`) (setq char ?'))) | |
1407 (vi-end-of-word arg) | |
1408 (forward-char 1) | |
1409 (insert char)) | |
1410 | |
1411 (defun vi-locate-def () | |
1412 "Locate definition in current file for the name before the point. It assumes | |
1413 a `(def..' always starts at the beginning of a line." | |
1414 (interactive) | |
1415 (let (name) | |
1416 (save-excursion | |
1417 (setq name (buffer-substring (progn (vi-backward-blank-delimited-word 1) | |
1418 (skip-chars-forward "^a-zA-Z") | |
1419 (point)) | |
1420 (progn (vi-end-of-blank-delimited-word 1) | |
1421 (forward-char) | |
1422 (skip-chars-backward "^a-zA-Z") | |
1423 (point))))) | |
1424 (set-mark-command nil) | |
1425 (goto-char (point-min)) | |
1426 (if (re-search-forward (concat "^(def[unvarconst ]*" name) nil t) | |
1427 nil | |
1428 (message "No definition for \"%s\" in current file." name (ding)) | |
1429 (set-mark-command t)))) | |
1430 | |
1431 (defun vi-split-open-line (arg) | |
1432 "Insert a newline and leave point before it. | |
1433 With arg, inserts that many newlines." | |
1434 (interactive "*p") | |
1435 (vi-goto-insert-state 1 | |
1436 (list (function (lambda (arg) | |
1437 (let ((flag (and (bolp) (not (bobp))))) | |
1438 (if flag (forward-char -1)) | |
1439 (while (> arg 0) | |
1440 (save-excursion | |
1441 (insert ?\n) | |
1442 (if fill-prefix (insert fill-prefix))) | |
1443 (setq arg (1- arg))) | |
1444 (if flag (forward-char 1))))) arg) | |
1445 t)) | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1446 |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1447 ;;; vi.el ends here |