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