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