Mercurial > emacs
annotate lisp/emulation/viper.el @ 16191:7397d7d0ed17
Fix previous change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 15 Sep 1996 01:49:08 +0000 |
parents | de1340e6ddb4 |
children | b2fae8abc5b0 |
rev | line source |
---|---|
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1 ;;; viper.el --- A full-featured Vi emulator for GNU Emacs 19 and XEmacs 19, |
10789 | 2 ;; a VI Plan for Emacs Rescue, |
3 ;; and a venomous VI PERil. | |
4 ;; Viper Is also a Package for Emacs Rebels. | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5 ;; |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
6 ;; Keywords: emulations |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
8 |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
9 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
10 |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
11 (defconst viper-version "2.91 of August 5, 1996" |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
12 "The current version of Viper") |
14169 | 13 |
10789 | 14 ;; This file is part of GNU Emacs. |
15 | |
16 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
17 ;; it under the terms of the GNU General Public License as published by | |
18 ;; the Free Software Foundation; either version 2, or (at your option) | |
19 ;; any later version. | |
20 | |
21 ;; GNU Emacs is distributed in the hope that it will be useful, | |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 ;; GNU General Public License for more details. | |
25 | |
26 ;; You should have received a copy of the GNU General Public License | |
15742 | 27 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
29 ;; Boston, MA 02111-1307, USA. | |
10789 | 30 |
31 ;;; Commentary: | |
32 | |
33 ;; Viper is a full-featured Vi emulator for Emacs 19. It emulates and | |
34 ;; improves upon the standard features of Vi and, at the same time, allows | |
35 ;; full access to all Emacs facilities. Viper supports multiple undo, | |
36 ;; file name completion, command, file, and search history and it extends | |
37 ;; Vi in many other ways. Viper is highly customizable through the various | |
38 ;; hooks, user variables, and keymaps. It is implemented as a collection | |
39 ;; of minor modes and it is designed to provide full access to all Emacs | |
40 ;; major and minor modes. | |
41 ;; | |
42 ;;; History | |
43 ;; | |
44 ;; Viper is a new name for a package formerly known as VIP-19, | |
45 ;; which was a successor of VIP version 3.5 by Masahiko Sato | |
46 ;; <ms@sail.stanford.edu> and VIP version 4.2 by Aamod Sane | |
47 ;; <sane@cs.uiuc.edu>. Some ideas from vip 4.4.2 by Aamod Sane | |
48 ;; were also shamelessly plagiarized. | |
49 ;; | |
50 ;; Viper maintains some degree of compatibility with these older | |
51 ;; packages. See the documentation for customization. | |
52 ;; | |
53 ;; The main difference between Viper and these older packages are: | |
54 ;; | |
55 ;; 1. Viper emulates Vi at several levels, from almost complete conformity | |
56 ;; to a rather loose Vi-compliance. | |
57 ;; | |
58 ;; 2. Viper provides full access to all major and minor modes of Emacs | |
59 ;; without the need to type extra keys. | |
60 ;; The older versions of VIP (and other Vi emulators) do not work with | |
61 ;; some major and minor modes. | |
62 ;; | |
63 ;; 3. Viper supports vi-style undo. | |
64 ;; | |
65 ;; 4. Viper fully emulates (and improves upon) vi's replacement mode. | |
66 ;; | |
67 ;; 5. Viper has a better interface to ex, including command, variable, and | |
68 ;; file name completion. | |
69 ;; | |
70 ;; 6. Viper uses native Emacs history and completion features; it doesn't | |
71 ;; rely on other packages (such as gmhist.el and completer.el) to provide | |
72 ;; these features. | |
73 ;; | |
74 ;; 7. Viper supports Vi-style editing in the minibuffer, by allowing the | |
75 ;; user to switch from Insert state to Vi state to Replace state, etc. | |
76 ;; | |
77 ;; 8. Viper keeps history of recently inserted pieces of text and recently | |
78 ;; executed Vi-style destructive commands, such as `i', `d', etc. | |
79 ;; These pieces of text can be inserted in later insertion commands; | |
80 ;; the previous destructive commands can be re-executed. | |
81 ;; | |
82 ;; 9. Viper has Vi-style keyboard macros, which enhances the similar | |
83 ;; facility in the original Vi. | |
84 ;; First, one can execute any Emacs command while defining a | |
85 ;; macro, not just the Vi commands. Second, macros are defined in a | |
86 ;; WYSYWYG mode, using an interface to Emacs' WYSIWYG style of defining | |
87 ;; macros. Third, in Viper, one can define macros that are specific to | |
88 ;; a given buffer, a given major mode, or macros defined for all buffers. | |
89 ;; The same macro name can have several different definitions: | |
90 ;; one global, several definitions for various major modes, and | |
91 ;; definitions for specific buffers. | |
15739 | 92 ;; Buffer-specific definitions override mode-specific |
10789 | 93 ;; definitions, which, in turn, override global definitions. |
94 ;; | |
95 ;; | |
96 ;;; Installation: | |
97 ;; ------------- | |
98 ;; | |
99 ;; (require 'viper) | |
100 ;; | |
101 | |
102 ;;; Acknowledgements: | |
103 ;; ----------------- | |
15739 | 104 ;; Bug reports and ideas contributed by many users have helped |
105 ;; improve Viper and the various versions of VIP. | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
106 ;; See the on-line manual for a complete list of contributors. |
10789 | 107 ;; |
108 ;; | |
109 ;;; Notes: | |
110 ;; | |
111 ;; 1. Major modes. | |
112 ;; In most cases, Viper handles major modes correctly, i.e., they come up | |
113 ;; in the right state (either vi-state or emacs-state). For instance, text | |
114 ;; files come up in vi-state, while, say, Dired appears in emacs-state by | |
115 ;; default. | |
116 ;; However, some modes do not appear in the right mode in the beginning, | |
117 ;; usually because they neglect to follow Emacs conventions (e.g., they don't | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
118 ;; use kill-all-local-variables when they start). Some major modes |
10789 | 119 ;; may fail to come up in emacs-state if they call hooks, such as |
120 ;; text-hook, for no good reason. | |
121 ;; | |
122 ;; As an immediate solution, you can hit C-z to bring about the right mode. | |
123 ;; An interim solution is to add an appropriate hook to the mode like this: | |
124 ;; | |
125 ;; (add-hook 'your-favorite-mode 'viper-mode) | |
126 ;; or | |
127 ;; (add-hook 'your-favorite-mode 'vip-change-state-to-emacs) | |
128 ;; | |
129 ;; whichever applies. The right thing to do, however, is to complain to the | |
130 ;; author of the respective package. (Sometimes they also neglect to equip | |
131 ;; their modes with hooks, which is one more reason for complaining.) | |
132 ;; | |
133 ;; 2. Keymap handling | |
134 ;; Because Emacs 19 has an elegant mechanism for turning minor mode keymaps | |
135 ;; on and off, implementation of Viper has been greatly simplified. Viper | |
136 ;; has several minor modes. | |
137 ;; | |
138 ;; Viper's Vi state consists of seven minor modes: | |
139 ;; | |
140 ;; vip-vi-intercept-minor-mode | |
141 ;; vip-vi-local-user-minor-mode | |
142 ;; vip-vi-global-user-minor-mode | |
143 ;; vip-vi-kbd-minor-mode | |
144 ;; vip-vi-state-modifier-minor-mode | |
145 ;; vip-vi-diehard-minor-mode | |
146 ;; vip-vi-basic-minor-mode | |
147 ;; | |
148 ;; Bindings done to the keymap of the first mode overshadow those done to | |
149 ;; the second, which, in turn, overshadows those done to the third, etc. | |
150 ;; | |
151 ;; The last vip-vi-basic-minor-mode contains most of the usual Vi bindings | |
152 ;; in its edit mode. This mode provides access to all Emacs facilities. | |
153 ;; Novice users, however, may want to set their vip-expert-level to 1 | |
154 ;; in their .vip file. This will enable vip-vi-diehard-minor-mode. This | |
155 ;; minor mode's bindings make Viper simulate the usual Vi very closely. | |
156 ;; For instance, C-c will not have its standard Emacs binding | |
157 ;; and so many of the goodies of Emacs are not available. | |
158 ;; | |
15739 | 159 ;; A skilled user should set vip-expert-level to at least 3. This will |
160 ;; enable `C-c' and many Emacs facilities will become available. | |
10789 | 161 ;; In this case, vip-vi-diehard-minor-mode is inactive. |
162 ;; | |
163 ;; Viper gurus should have at least | |
164 ;; (setq vip-expert-level 4) | |
165 ;; in their ~/.vip files. This will unsuppress all Emacs keys that are not | |
166 ;; essential for VI-style editing. | |
167 ;; Pick-and-choose users may want to put | |
168 ;; (setq vip-expert-level 5) | |
169 ;; in ~/.vip. Viper will then leave it up to the user to set the variables | |
170 ;; vip-want-* See vip-set-expert-level for details. | |
171 ;; | |
172 ;; The very first minor mode, vip-vi-intercept-minor-mode, is of no | |
173 ;; concern for the user. It is needed to bind Viper's vital keys, such as | |
174 ;; ESC and C-z. | |
175 ;; | |
176 ;; The second mode, vip-vi-local-user-minor-mode, usually has an | |
177 ;; empty keymap. However, the user can set bindings in this keymap, which | |
178 ;; will overshadow the corresponding bindings in the other two minor | |
179 ;; modes. This is useful, for example, for setting up ZZ in gnus, | |
180 ;; rmail, mh-e, etc., to send message instead of saving it in a file. | |
181 ;; Likewise, in Dired mode, you may want to bind ZN and ZP to commands | |
182 ;; that would visit the next or the previous file in the Dired buffer. | |
183 ;; Setting local keys is tricky, so don't do it directly. Instead, use | |
184 ;; vip-add-local-keys function (see its doc). | |
185 ;; | |
186 ;; The third minor mode, vip-vi-global-user-minor-mode, is also intended | |
187 ;; for the users but, unlike vip-vi-local-user-minor-mode, its key | |
188 ;; bindings are seen in all Viper buffers. This mode keys can be done | |
189 ;; with define-key command. | |
190 ;; | |
191 ;; The fourth minor mode, vip-vi-kbd-minor-mode, is used by keyboard | |
192 ;; macros. Users are NOT supposed to modify this keymap directly. | |
193 ;; | |
194 ;; The fifth mode, vip-vi-state-modifier-minor-mode, can be used to set | |
195 ;; key bindings that are visible in some major modes but not in others. | |
196 ;; | |
197 ;; Users are allowed to modify keymaps that belong to | |
198 ;; vip-vi-local-user-minor-mode, vip-vi-global-user-minor-mode, | |
199 ;; and vip-vi-state-modifier-minor-mode only. | |
200 ;; | |
201 ;; Viper's Insert state also has seven minor modes: | |
202 ;; | |
203 ;; vip-insert-intercept-minor-mode | |
204 ;; vip-insert-local-user-minor-mode | |
205 ;; vip-insert-global-user-minor-mode | |
206 ;; vip-insert-kbd-minor-mode | |
207 ;; vip-insert-state-modifier-minor-mode | |
208 ;; vip-insert-diehard-minor-mode | |
209 ;; vip-insert-basic-minor-mode | |
210 ;; | |
211 ;; As with VI's editing modes, the first mode, vip-insert-intercept-minor-mode | |
212 ;; is used to bind vital keys that are not to be changed by the user. | |
213 ;; | |
214 ;; The next mode, vip-insert-local-user-minor-mode, is used to customize | |
215 ;; bindings in the insert state of Viper. The third mode, | |
216 ;; vip-insert-global-user-minor-mode is like | |
217 ;; vip-insert-local-user-minor-mode, except that its bindings are seen in | |
218 ;; all Viper buffers. As with vip-vi-local-user-minor-mode, its bindings | |
219 ;; should be done via the function vip-add-local-keys. Bindings for | |
220 ;; vip-insert-global-user-minor-mode can be set with the define-key command. | |
221 ;; | |
222 ;; The next minor mode, vip-insert-kbd-minor-mode, | |
223 ;; is used for keyboard VI-style macros defined with :map!. | |
224 ;; | |
225 ;; The fifth minor mode, vip-insert-state-modifier-minor-mode, is like | |
226 ;; vip-vi-state-modifier-minor-mode, except that it is used in the Insert | |
227 ;; state; it can be used to modify keys in a mode-specific fashion. | |
228 ;; | |
229 ;; The minor mode vip-insert-diehard-minor-mode is in effect when | |
230 ;; the user wants a high degree of Vi compatibility (a bad idea, really!). | |
231 ;; The last minor mode, vip-insert-basic-minor-mode, is always in effect | |
232 ;; when Viper is in insert state. It binds a small number of keys needed for | |
233 ;; Viper's operation. | |
234 ;; | |
235 ;; Finally, Viper provides minor modes for overriding bindings set by Emacs | |
236 ;; modes when Viper is in Emacs state: | |
237 ;; | |
238 ;; vip-emacs-local-user-minor-mode | |
239 ;; vip-emacs-global-user-minor-mode | |
240 ;; vip-emacs-kbd-minor-mode | |
241 ;; vip-emacs-state-modifier-minor-mode | |
242 ;; | |
243 ;; These minor modes are in effect when Viper is in Emacs state. The keymap | |
244 ;; associated with vip-emacs-global-user-minor-mode, | |
245 ;; vip-emacs-global-user-map, overrides the global and local keymaps as | |
246 ;; well as the minor mode keymaps set by other modes. The keymap of | |
247 ;; vip-emacs-local-user-minor-mode, vip-emacs-local-user-map, overrides | |
248 ;; everything, but it is used on a per buffer basis. | |
249 ;; The keymap associated with vip-emacs-state-modifier-minor-mode | |
250 ;; overrides keys on a per-major-mode basis. The mode | |
251 ;; vip-emacs-kbd-minor-mode is used to define Vi-style macros in Emacs | |
252 ;; state. | |
253 ;; | |
254 ;; 3. There is also one minor mode that is used when Viper is in its | |
255 ;; replace-state (used for commands like cw, C, etc.). This mode is | |
256 ;; called | |
257 ;; | |
258 ;; vip-replace-minor-mode | |
259 ;; | |
260 ;; and its keymap is vip-replace-map. Replace minor mode is always | |
261 ;; used in conjunction with the minor modes for insert-state, and its | |
262 ;; keymap overshadows the keymaps for insert minor modes. | |
263 ;; | |
264 ;; 4. Defining buffer-local bindings in Vi and Insert modes. | |
265 ;; As mentioned before, sometimes, it is convenient to have | |
266 ;; buffer-specific of mode-specific key bindings in Vi and insert modes. | |
267 ;; Viper provides a special function, vip-add-local-keys, to do precisely | |
268 ;; this. For instance, is you need to add couple of mode-specific bindings | |
269 ;; to Insert mode, you can put | |
270 ;; | |
271 ;; (vip-add-local-keys 'insert-state '((key1 . func1) (key2 .func2))) | |
272 ;; | |
273 ;; somewhere in a hook of this major mode. If you put something like this | |
274 ;; in your own elisp function, this will define bindings specific to the | |
275 ;; buffer that was current at the time of the call to vip-add-local-keys. | |
276 ;; The only thing to make sure here is that the major mode of this buffer | |
277 ;; is written according to Emacs conventions, which includes a call to | |
278 ;; (kill-all-local-variables). See vip-add-local-keys for more details. | |
279 ;; | |
280 ;; | |
281 ;; TO DO (volunteers?): | |
282 ;; | |
283 ;; 1. Some of the code that is inherited from VIP-3.5 is rather | |
284 ;; convoluted. Instead of vip-command-argument, keymaps should bind the | |
285 ;; actual commands. E.g., "dw" should be bound to a generic command | |
286 ;; vip-delete that will delete things based on the value of | |
287 ;; last-command-char. This would greatly simplify the logic and the code. | |
288 ;; | |
289 ;; 2. Somebody should venture to write a customization package a la | |
290 ;; options.el that would allow the user to change values of variables | |
291 ;; that meet certain specs (e.g., match a regexp) and whose doc string | |
292 ;; starts with a '*'. Then, the user should be offered to save | |
293 ;; variables that were changed. This will make user's customization job | |
294 ;; much easier. | |
295 ;; | |
296 | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
297 ;; Code |
10789 | 298 |
299 (require 'advice) | |
300 (require 'cl) | |
301 (require 'ring) | |
302 | |
303 (require 'viper-util) | |
304 | |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
305 ;; Compiler pacifier |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
306 (defvar vip-minibuffer-current-face) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
307 (defvar vip-minibuffer-insert-face) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
308 (defvar vip-minibuffer-vi-face) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
309 (defvar vip-minibuffer-emacs-face) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
310 (defvar iso-accents-mode) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
311 (defvar zmacs-region-stays) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
312 ;; end pacifier |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
313 |
10789 | 314 |
315 ;;; Variables | |
316 | |
317 ;; Is t until viper-mode executes for the very first time. | |
318 ;; Prevents recursive descend into startup messages. | |
319 (defvar vip-first-time t) | |
320 | |
321 (defvar vip-expert-level 0 | |
322 "User's expert level. | |
323 The minor mode vip-vi-diehard-minor-mode is in effect when | |
324 vip-expert-level is 1 or 2 or when vip-want-emacs-keys-in-vi is t. | |
325 The minor mode vip-insert-diehard-minor-mode is in effect when | |
326 vip-expert-level is 1 or 2 or if vip-want-emacs-keys-in-insert is t. | |
327 Use `M-x vip-set-expert-level' to change this.") | |
328 | |
329 ;; Max expert level supported by Viper. This is NOT a user option. | |
330 ;; It is here to make it hard for the user from resetting it. | |
331 (defconst vip-max-expert-level 5) | |
332 | |
333 ;; Contains user settings for vars affected by vip-set-expert-level function. | |
334 ;; Not a user option. | |
335 (defvar vip-saved-user-settings nil) | |
336 | |
337 | |
338 ;;; Viper minor modes | |
339 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
340 ;; This is not local in Emacs, so we make it local. |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
341 ;; This must be local because although the stack of minor modes can be the same |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
342 ;; for all buffers, the associated *keymaps* can be different. In Viper, |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
343 ;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
344 ;; different keymaps for different buffers. |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
345 ;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
346 ;; can be different. |
10789 | 347 (make-variable-buffer-local 'minor-mode-map-alist) |
348 | |
349 ;; Mode for vital things like \e, C-z. | |
350 (vip-deflocalvar vip-vi-intercept-minor-mode nil) | |
351 | |
352 (vip-deflocalvar vip-vi-basic-minor-mode nil | |
353 "Viper's minor mode for Vi bindings.") | |
354 | |
355 (vip-deflocalvar vip-vi-local-user-minor-mode nil | |
356 "Auxiliary minor mode for user-defined local bindings in Vi state.") | |
357 | |
358 (vip-deflocalvar vip-vi-global-user-minor-mode nil | |
359 "Auxiliary minor mode for user-defined global bindings in Vi state.") | |
360 | |
361 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil | |
362 "Minor mode used to make major-mode-specific modification to Vi state.") | |
363 | |
364 (vip-deflocalvar vip-vi-diehard-minor-mode nil | |
365 "This minor mode is in effect when the user wants Viper to be Vi.") | |
366 | |
367 (vip-deflocalvar vip-vi-kbd-minor-mode nil | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
368 "Minor mode for Ex command macros in Vi state. |
10789 | 369 The corresponding keymap stores key bindings of Vi macros defined with |
370 the Ex command :map.") | |
371 | |
372 ;; Mode for vital things like \e, C-z. | |
373 (vip-deflocalvar vip-insert-intercept-minor-mode nil) | |
374 | |
375 (vip-deflocalvar vip-insert-basic-minor-mode nil | |
376 "Viper's minor mode for bindings in Insert mode.") | |
377 | |
378 (vip-deflocalvar vip-insert-local-user-minor-mode nil | |
379 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state. | |
380 This is a way to overshadow normal Insert mode bindings locally to certain | |
381 designated buffers.") | |
382 | |
383 (vip-deflocalvar vip-insert-global-user-minor-mode nil | |
384 "Auxiliary minor mode for global user-defined bindings in Insert state.") | |
385 | |
386 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil | |
387 "Minor mode used to make major-mode-specific modification to Insert state.") | |
388 | |
389 (vip-deflocalvar vip-insert-diehard-minor-mode nil | |
390 "Minor mode that simulates Vi very closely. | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
391 Not recommened, except for the novice user.") |
10789 | 392 |
393 (vip-deflocalvar vip-insert-kbd-minor-mode nil | |
394 "Minor mode for Ex command macros Insert state. | |
395 The corresponding keymap stores key bindings of Vi macros defined with | |
396 the Ex command :map!.") | |
397 | |
398 (vip-deflocalvar vip-replace-minor-mode nil | |
399 "Minor mode in effect in replace state (cw, C, and the like commands).") | |
400 | |
401 ;; Mode for vital things like \C-z and \C-x) | |
402 ;; This is t, by default. So, any new buffer will have C-z defined as | |
403 ;; switch to Vi, unless we switched states in this buffer | |
404 (vip-deflocalvar vip-emacs-intercept-minor-mode t) | |
405 | |
406 (vip-deflocalvar vip-emacs-local-user-minor-mode t | |
407 "Minor mode for local user bindings effective in Emacs state. | |
408 Users can use it to override Emacs bindings when Viper is in its Emacs | |
409 state.") | |
410 | |
411 (vip-deflocalvar vip-emacs-global-user-minor-mode t | |
412 "Minor mode for global user bindings in effect in Emacs state. | |
413 Users can use it to override Emacs bindings when Viper is in its Emacs | |
414 state.") | |
415 | |
416 (vip-deflocalvar vip-emacs-kbd-minor-mode t | |
417 "Minor mode for Vi style macros in Emacs state. | |
418 The corresponding keymap stores key bindings of Vi macros defined with | |
419 `vip-record-kbd-macro' command. There is no Ex-level command to do this | |
420 interactively.") | |
421 | |
422 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t | |
423 "Minor mode used to make major-mode-specific modification to Emacs state. | |
424 For instance, a Vi purist may want to bind `dd' in Dired mode to a function | |
425 that deletes a file.") | |
426 | |
427 | |
428 | |
429 ;;; ISO characters | |
430 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
431 (vip-deflocalvar vip-automatic-iso-accents nil |
10789 | 432 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state. |
433 For some users, this behavior may be too primitive. In this case, use | |
434 insert/emacs/vi state hooks.") | |
435 | |
436 | |
437 ;;; Emacs keys in other states. | |
438 | |
439 (defvar vip-want-emacs-keys-in-insert t | |
440 "*Set to nil if you want complete Vi compatibility in insert mode. | |
441 Complete compatibility with Vi is not recommended for power use of Viper.") | |
442 | |
443 (defvar vip-want-emacs-keys-in-vi t | |
444 "*Set to nil if you want complete Vi compatibility in Vi mode. | |
445 Full Vi compatibility is not recommended for power use of Viper.") | |
446 | |
447 | |
448 | |
449 ;; VI-style Undo | |
450 | |
451 ;; Used to 'undo' complex commands, such as replace and insert commands. | |
452 (vip-deflocalvar vip-undo-needs-adjustment nil) | |
453 (put 'vip-undo-needs-adjustment 'permanent-local t) | |
454 | |
455 ;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a | |
456 ;; complex command that must be undone atomically. If inserted, it is | |
457 ;; erased by vip-change-state-to-vi and vip-repeat. | |
458 (defconst vip-buffer-undo-list-mark 'viper) | |
459 | |
460 (defvar vip-keep-point-on-undo nil | |
461 "*Non-nil means not to move point while undoing commands. | |
462 This style is different from Emacs and Vi. Try it to see if | |
463 it better fits your working style.") | |
464 | |
465 ;; Replace mode and changing text | |
466 | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
467 ;; Viper's own after/before change functions, which get vip-add-hook'ed to |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
468 ;; Emacs's |
10789 | 469 (vip-deflocalvar vip-after-change-functions nil "") |
470 (vip-deflocalvar vip-before-change-functions nil "") | |
471 (vip-deflocalvar vip-post-command-hooks nil "") | |
472 (vip-deflocalvar vip-pre-command-hooks nil "") | |
473 | |
474 ;; Can be used to pass global states around for short period of time | |
475 (vip-deflocalvar vip-intermediate-command nil "") | |
476 | |
477 ;; Indicates that the current destructive command has started in replace mode. | |
478 (vip-deflocalvar vip-began-as-replace nil "") | |
479 | |
480 (defvar vip-replace-overlay-cursor-color "Red" | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
481 "*Cursor color to use in Replace state") |
10789 | 482 |
483 | |
484 (vip-deflocalvar vip-replace-overlay nil "") | |
485 (put 'vip-replace-overlay 'permanent-local t) | |
486 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
487 (defvar vip-replace-overlay-pixmap "gray3" |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
488 "Pixmap to use for search face on non-color displays.") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
489 (defvar vip-search-face-pixmap "gray3" |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
490 "Pixmap to use for search face on non-color displays.") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
491 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
492 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
493 (defun vip-set-replace-overlay-face () |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
494 (if (vip-has-face-support-p) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
495 (defvar vip-replace-overlay-face |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
496 (progn |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
497 (make-face 'vip-replace-overlay-face) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
498 (vip-hide-face 'vip-replace-overlay-face) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
499 (or (face-differs-from-default-p 'vip-replace-overlay-face) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
500 (progn |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
501 (if (vip-can-use-colors "darkseagreen2" "Black") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
502 (progn |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
503 (set-face-background |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
504 'vip-replace-overlay-face "darkseagreen2") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
505 (set-face-foreground 'vip-replace-overlay-face "Black"))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
506 (set-face-underline-p 'vip-replace-overlay-face t) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
507 (vip-set-face-pixmap |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
508 'vip-replace-overlay-face vip-replace-overlay-pixmap))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
509 'vip-replace-overlay-face) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
510 "*Face for highlighting replace regions on a window display.") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
511 )) |
10789 | 512 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
513 (defvar vip-replace-region-end-delimiter "$" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
514 "A string marking the end of replacement regions. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
515 It is used only with TTYs or if `vip-use-replace-region-delimiters' |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
516 is non-nil.") |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
517 (defvar vip-replace-region-start-delimiter "" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
518 "A string marking the beginning of replacement regions. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
519 It is used only with TTYs or if `vip-use-replace-region-delimiters' |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
520 is non-nil.") |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
521 (defvar vip-use-replace-region-delimiters (not (vip-has-face-support-p)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
522 "*If non-nil, Viper will always use `vip-replace-region-end-delimiter' and |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
523 `vip-replace-region-start-delimiter' to delimit replacement regions, even on |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
524 color displays. By default, the delimiters are used only on TTYs.") |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
525 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
526 ;; XEmacs requires glyphs |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
527 (if vip-xemacs-p |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
528 (progn |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
529 (or (glyphp vip-replace-region-end-delimiter) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
530 (setq vip-replace-region-end-delimiter |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
531 (make-glyph vip-replace-region-end-delimiter))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
532 (or (glyphp vip-replace-region-start-delimiter) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
533 (setq vip-replace-region-start-delimiter |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
534 (make-glyph vip-replace-region-start-delimiter))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
535 )) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
536 |
10789 | 537 |
538 ;; These are local marker that must be initialized to nil and moved with | |
539 ;; `vip-move-marker-locally' | |
540 ;; | |
541 ;; Remember the last position inside the replace region. | |
542 (vip-deflocalvar vip-last-posn-in-replace-region nil) | |
543 ;; Remember the last position while inserting | |
544 (vip-deflocalvar vip-last-posn-while-in-insert-state nil) | |
545 (put 'vip-last-posn-in-replace-region 'permanent-local t) | |
546 (put 'vip-last-posn-while-in-insert-state 'permanent-local t) | |
547 | |
548 (vip-deflocalvar vip-sitting-in-replace nil "") | |
549 (put 'vip-sitting-in-replace 'permanent-local t) | |
550 | |
551 ;; Remember the number of characters that have to be deleted in replace | |
552 ;; mode to compensate for the inserted characters. | |
553 (vip-deflocalvar vip-replace-chars-to-delete 0 "") | |
554 (vip-deflocalvar vip-replace-chars-deleted 0 "") | |
555 | |
556 ;; Insertion ring and command ring | |
557 (defvar vip-insertion-ring-size 14 | |
558 "The size of the insertion ring.") | |
559 ;; The insertion ring. | |
560 (defvar vip-insertion-ring nil) | |
561 ;; This is temp insertion ring. Used to do rotation for display purposes. | |
562 ;; When rotation just started, it is initialized to vip-insertion-ring. | |
563 (defvar vip-temp-insertion-ring nil) | |
564 (defvar vip-last-inserted-string-from-insertion-ring "") | |
565 | |
566 (defvar vip-command-ring-size 14 | |
567 "The size of the command ring.") | |
568 ;; The command ring. | |
569 (defvar vip-command-ring nil) | |
570 ;; This is temp command ring. Used to do rotation for display purposes. | |
571 ;; When rotation just started, it is initialized to vip-command-ring. | |
572 (defvar vip-temp-command-ring nil) | |
573 | |
574 ;; Modes and related variables | |
575 | |
576 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state' | |
577 (vip-deflocalvar vip-current-state 'emacs-state) | |
578 | |
579 (defvar vip-no-multiple-ESC t | |
580 "*If true, multiple ESC in Vi mode will cause bell to ring. | |
581 This is set to t on a windowing terminal and to 'twice on a dumb | |
582 terminal (unless the user level is 1, 2, or 5). On a dumb terminal, this | |
583 enables cursor keys and is generally more convenient, as terminals usually | |
584 don't have a convenient Meta key. | |
585 Setting vip-no-multiple-ESC to nil will allow as many multiple ESC, | |
586 as is allowed by the major mode in effect.") | |
587 | |
588 | |
589 (defvar vip-want-ctl-h-help nil | |
590 "*If t then C-h is bound to help-command in insert mode, if nil then it is | |
591 bound to delete-backward-char.") | |
592 | |
593 ;; Autoindent in insert | |
594 | |
595 ;; Variable that keeps track of whether C-t has been pressed. | |
596 (vip-deflocalvar vip-cted nil "") | |
597 | |
598 ;; Preserve the indent value, used by C-d in insert mode. | |
599 (vip-deflocalvar vip-current-indent 0) | |
600 | |
601 ;; Whether to preserve the indent, used by C-d in insert mode. | |
602 (vip-deflocalvar vip-preserve-indent nil) | |
603 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
604 (vip-deflocalvar vip-auto-indent nil |
10789 | 605 "*Autoindent if t.") |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
606 (vip-deflocalvar vip-electric-mode t |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
607 "*If t, enable electric behavior. |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
608 Currently only enables auto-indentation `according to mode'.") |
10789 | 609 |
610 (defconst vip-shift-width 8 | |
611 "*The shiftwidth variable.") | |
612 | |
613 ;; Variables for repeating destructive commands | |
614 | |
615 (defconst vip-keep-point-on-repeat t | |
616 "*If t, don't move point when repeating previous command. | |
617 This is useful for doing repeated changes with the '.' key. | |
618 The user can change this to nil, if she likes when the cursor moves | |
619 to a new place after repeating previous Vi command.") | |
620 | |
621 ;; Remember insert point as a marker. This is a local marker that must be | |
622 ;; initialized to nil and moved with `vip-move-marker-locally'. | |
623 (vip-deflocalvar vip-insert-point nil) | |
624 (put 'vip-insert-point 'permanent-local t) | |
625 | |
626 ;; This remembers the point before dabbrev-expand was called. | |
627 ;; If vip-insert-point turns out to be bigger than that, it is reset | |
628 ;; back to vip-pre-command-point. | |
629 ;; The reason this is needed is because dabbrev-expand (and possibly | |
630 ;; others) may jump to before the insertion point, delete something and | |
631 ;; then reinsert a bigger piece. For instance: bla^blo | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
632 ;; If dabbrev-expand is called after `blo' and ^ undicates vip-insert-point, |
10789 | 633 ;; then point jumps to the beginning of `blo'. If expansion is found, `blablo' |
634 ;; is deleted, and we have |^, where | denotes point. Next, dabbrev-expand | |
635 ;; will insert the expansion, and we get: blablo^ | |
636 ;; Whatever we insert next goes before the ^, i.e., before the | |
637 ;; vip-insert-point marker. So, Viper will think that nothing was | |
638 ;; inserted. Remembering the orig position of the marker circumvents the | |
639 ;; problem. | |
640 ;; We don't know of any command, except dabbrev-expand, that has the same | |
641 ;; problem. However, the same trick can be used if such a command is | |
642 ;; discovered later. | |
643 ;; | |
644 (vip-deflocalvar vip-pre-command-point nil) | |
645 (put 'vip-pre-command-point 'permanent-local t) ; this is probably an overkill | |
646 | |
647 ;; This is used for saving inserted text. | |
648 (defvar vip-last-insertion nil) | |
649 | |
650 ;; Remembers the last replaced region. | |
651 (defvar vip-last-replace-region "") | |
652 | |
653 ;; Remember com point as a marker. | |
654 ;; This is a local marker. Should be moved with `vip-move-marker-locally' | |
655 (vip-deflocalvar vip-com-point nil) | |
656 | |
657 ;; If non-nil, the value is a list (M-COM VAL COM REG inserted-text cmd-keys) | |
658 ;; It is used to re-execute last destructive command. | |
659 ;; M-COM is a Lisp symbol representing the function to be executed. | |
660 ;; VAL is the prefix argument that was used with that command. | |
661 ;; COM is an internal descriptor, such as ?r, ?c, ?C, which contains | |
662 ;; additional information on how the function in M-COM is to be handled. | |
663 ;; REG is the register used by command | |
664 ;; INSERTED-TEXT is text inserted by that command (in case of o, c, C, i, r | |
665 ;; commands). | |
666 ;; COMMAND-KEYS are the keys that were typed to invoke the command. | |
667 (defvar vip-d-com nil) | |
668 | |
669 ;; The character remembered by the Vi `r' command. | |
670 (defvar vip-d-char nil) | |
671 | |
672 ;; Name of register to store deleted or yanked strings | |
673 (defvar vip-use-register nil) | |
674 | |
675 | |
676 | |
677 ;; Variables for Moves and Searches | |
678 | |
679 ;; For use by `;' command. | |
680 (defvar vip-f-char nil) | |
681 | |
682 ;; For use by `.' command. | |
683 (defvar vip-F-char nil) | |
684 | |
685 ;; For use by `;' command. | |
686 (defvar vip-f-forward nil) | |
687 | |
688 ;; For use by `;' command. | |
689 (defvar vip-f-offset nil) | |
690 | |
691 ;; Last search string | |
692 (defvar vip-s-string "") | |
693 | |
694 (defvar vip-quote-string "> " | |
695 "String inserted at the beginning of quoted region.") | |
696 | |
697 ;; If t, search is forward. | |
698 (defvar vip-s-forward nil) | |
699 | |
700 (defconst vip-case-fold-search nil | |
701 "*If t, search ignores cases.") | |
702 | |
703 (defconst vip-re-search t | |
704 "*If t, search is reg-exp search, otherwise vanilla search.") | |
705 | |
706 (defconst vip-re-query-replace t | |
707 "*If t then do regexp replace, if nil then do string replace.") | |
708 | |
709 (defconst vip-re-replace t | |
710 "*If t, do regexp replace. nil means do string replace.") | |
711 | |
712 (vip-deflocalvar vip-ex-style-motion t | |
713 "*Ex-style: the commands l,h do not cross lines, etc.") | |
714 | |
715 (vip-deflocalvar vip-ex-style-editing-in-insert t | |
716 "*The keys ^H, ^? don't jump lines in insert, ESC moves cursor back, etc. | |
717 Note: this doesn't preclude ^H and ^? from deleting characters by moving | |
718 past the insertion point. This is a feature, not a bug. ") | |
719 | |
720 (vip-deflocalvar vip-delete-backwards-in-replace nil | |
721 "*If t, DEL key will delete characters while moving the cursor backwards. | |
722 If nil, the cursor will move backwards without deleting anything.") | |
723 | |
724 (defconst vip-buffer-search-char nil | |
725 "*Key bound for buffer-searching.") | |
726 | |
727 (defconst vip-search-wrap-around-t t | |
728 "*If t, search wraps around.") | |
729 | |
730 (vip-deflocalvar vip-related-files-and-buffers-ring nil | |
731 "*Ring of file and buffer names that are considered to be related to the | |
732 current buffer. | |
733 These buffers can be cycled through via :R and :P commands.") | |
734 (put 'vip-related-files-and-buffers-ring 'permanent-local t) | |
735 | |
736 ;; Used to find out if we are done with searching the current buffer. | |
737 (vip-deflocalvar vip-local-search-start-marker nil) | |
738 ;; As above, but global | |
739 (defvar vip-search-start-marker (make-marker)) | |
740 | |
741 ;; the search overlay | |
742 (vip-deflocalvar vip-search-overlay nil) | |
743 | |
744 | |
745 (defvar vip-heading-start | |
10792
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
746 (concat "^\\s-*(\\s-*defun\\s-\\|" ; lisp |
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
747 "^{\\s-*$\\|^[_a-zA-Z][^()]*[()].*{\\s-*$\\|" ; C/C++ |
10789 | 748 "^\\s-*class.*{\\|^\\s-*struct.*{\\|^\\s-*enum.*{\\|" |
10792
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
749 "^\\\\[sb][a-z]*{.*}\\s-*$\\|" ; latex |
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
750 "^@node\\|@table\\|^@m?enu\\|^@itemize\\|^@if\\|" ; texinfo |
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
751 "^.+:-") ; prolog |
10789 | 752 "*Regexps for Headings. Used by \[\[ and \]\].") |
753 | |
754 (defvar vip-heading-end | |
10792
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
755 (concat "^}\\|" ; C/C++ |
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
756 "^\\\\end{\\|" ; latex |
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
757 "^@end \\|" ; texinfo |
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
758 ")\n\n[ \t\n]*\\|" ; lisp |
70977216c215
Use single semicolon in comments.
Karl Heuer <kwzh@gnu.org>
parents:
10789
diff
changeset
|
759 "\\.\\s-*$") ; prolog |
10789 | 760 "*Regexps to end Headings/Sections. Used by \[\].") |
761 | |
762 | |
763 ;; These two vars control the interaction of jumps performed by ' and `. | |
764 ;; In this new version, '' doesn't erase the marks set by ``, so one can | |
765 ;; use both kinds of jumps interchangeably and without loosing positions | |
766 ;; inside the lines. | |
767 | |
768 ;; Remembers position of the last jump done using ``'. | |
769 (vip-deflocalvar vip-last-jump nil) | |
770 ;; Remembers position of the last jump done using `''. | |
771 (vip-deflocalvar vip-last-jump-ignore 0) | |
772 | |
773 ;; Some common error messages | |
774 | |
775 (defconst vip-SpuriousText "Spurious text after command" "") | |
776 (defconst vip-BadExCommand "Not an editor command" "") | |
777 (defconst vip-InvalidCommandArgument "Invalid command argument" "") | |
778 (defconst vip-NoPrevSearch "No previous search string" "") | |
779 (defconst vip-EmptyRegister "`%c': Nothing in this register" "") | |
780 (defconst vip-InvalidRegister "`%c': Invalid register" "") | |
781 (defconst vip-EmptyTextmarker "`%c': Text marker doesn't point anywhere" "") | |
782 (defconst vip-InvalidTextmarker "`%c': Invalid text marker" "") | |
783 (defconst vip-InvalidViCommand "Invalid command" "") | |
784 (defconst vip-BadAddress "Ill-formed address" "") | |
785 (defconst vip-FirstAddrExceedsSecond "First address exceeds second" "") | |
786 (defconst vip-NoFileSpecified "No file specified" "") | |
787 | |
788 | |
789 ;; History variables | |
790 | |
791 ;; History of search strings. | |
792 (defvar vip-search-history (list "")) | |
793 ;; History of query-replace strings used as a source. | |
794 (defvar vip-replace1-history nil) | |
795 ;; History of query-replace strings used as replacement. | |
796 (defvar vip-replace2-history nil) | |
797 ;; History of region quoting strings. | |
798 (defvar vip-quote-region-history (list vip-quote-string)) | |
799 ;; History of Ex-style commands. | |
800 (defvar vip-ex-history nil) | |
801 ;; History of shell commands. | |
802 (defvar vip-shell-history nil) | |
803 | |
804 | |
805 ;; Last shell command. There are two of these, one for Ex (in viper-ex) | |
806 ;; and one for Vi. | |
807 | |
808 ;; Last shell command executed with ! command. | |
809 (defvar vip-last-shell-com nil) | |
810 | |
811 | |
812 | |
813 ;;; Miscellaneous | |
814 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
815 ;; don't bark when mark is inactive |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
816 (setq mark-even-if-inactive t) |
10789 | 817 |
818 (defvar vip-inhibit-startup-message nil | |
819 "Whether Viper startup message should be inhibited.") | |
820 | |
821 (defvar vip-always t | |
822 "t means, arrange that vi-state will be a default.") | |
823 | |
16136
de1340e6ddb4
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16135
diff
changeset
|
824 (defvar vip-custom-file-name (convert-standard-filename "~/.vip") |
10789 | 825 "Viper customisation file. |
826 This variable must be set _before_ loading Viper.") | |
827 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
828 |
10789 | 829 (defvar vip-spell-function 'ispell-region |
830 "Spell function used by #s<move> command to spell.") | |
831 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
832 (defvar vip-tags-file-name "TAGS" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
833 "The tags file used by Viper.") |
10789 | 834 |
835 ;; Minibuffer | |
836 | |
837 (defvar vip-vi-style-in-minibuffer t | |
838 "If t, use vi-style editing in minibuffer. | |
839 Should be set in `~/.vip' file.") | |
840 | |
841 ;; overlay used in the minibuffer to indicate which state it is in | |
842 (vip-deflocalvar vip-minibuffer-overlay nil) | |
843 | |
844 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer. | |
845 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run | |
846 ;; *after* exiting the minibuffer | |
847 (defvar vip-minibuffer-exit-hook nil) | |
848 | |
849 (vip-deflocalvar vip-vi-minibuffer-minor-mode nil | |
850 "Minor mode that forces Vi-style when the Minibuffer is in Vi state.") | |
851 (vip-deflocalvar vip-insert-minibuffer-minor-mode nil | |
852 "Minor mode that forces Vi-style when the Minibuffer is in Insert state.") | |
853 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
854 ;; setup emacs-supported vi-style feel |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
855 (setq next-line-add-newlines nil |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
856 require-final-newline t) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
857 |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
858 (make-variable-buffer-local 'require-final-newline) |
10789 | 859 |
860 | |
861 ;; Mode line | |
862 (defconst vip-vi-state-id "<V> " | |
863 "Mode line tag identifying the Vi mode of Viper.") | |
864 (defconst vip-emacs-state-id "<E> " | |
865 "Mode line tag identifying the Emacs mode of Viper.") | |
866 (defconst vip-insert-state-id "<I> " | |
867 "Mode line tag identifying the Insert mode of Viper.") | |
868 (defconst vip-replace-state-id "<R> " | |
869 "Mode line tag identifying the Replace mode of Viper.") | |
870 | |
871 ;; Viper changes the default mode-line-buffer-identification | |
872 (setq-default mode-line-buffer-identification '(" %b")) | |
873 | |
874 ;; Variable displaying the current Viper state in the mode line. | |
875 (vip-deflocalvar vip-mode-string vip-emacs-state-id) | |
876 (or (memq 'vip-mode-string global-mode-string) | |
877 (setq global-mode-string | |
878 (append '("" vip-mode-string) (cdr global-mode-string)))) | |
879 | |
880 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
881 (defvar vip-vi-state-hook nil |
10789 | 882 "*Hooks run just before the switch to Vi mode is completed.") |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
883 (defvar vip-insert-state-hook nil |
10789 | 884 "*Hooks run just before the switch to Insert mode is completed.") |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
885 (defvar vip-replace-state-hook nil |
10789 | 886 "*Hooks run just before the switch to Replace mode is completed.") |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
887 (defvar vip-emacs-state-hook nil |
10789 | 888 "*Hooks run just before the switch to Emacs mode is completed.") |
889 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
890 (defvar vip-load-hook nil |
10789 | 891 "Hooks run just after loading Viper.") |
892 | |
893 | |
894 ;; Generic predicates | |
895 | |
896 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane | |
897 | |
898 ;; generate test functions | |
899 ;; given symbol foo, foo-p is the test function, foos is the set of | |
900 ;; Viper command keys | |
901 ;; (macroexpand '(vip-test-com-defun foo)) | |
902 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos))) | |
903 | |
904 (defmacro vip-test-com-defun (name) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
905 (let* ((snm (symbol-name name)) |
10789 | 906 (nm-p (intern (concat snm "-p"))) |
907 (nms (intern (concat snm "s")))) | |
908 (` (defun (, nm-p) (com) | |
909 (consp (memq (if (< com 0) (- com) com) (, nms))))))) | |
910 | |
911 ;; Variables for defining VI commands | |
912 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
913 ;; Modifying commands that can be prefixes to movement commands |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
914 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) |
10789 | 915 (vip-test-com-defun vip-prefix-command) |
916 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
917 ;; Commands that are pairs eg. dd. r and R here are a hack |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
918 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) |
10789 | 919 (vip-test-com-defun vip-charpair-command) |
920 | |
921 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l | |
922 ?H ?M ?n ?t ?T ?w ?W ?$ ?% | |
923 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` | |
924 ?; ?, ?0 ?? ?/ | |
925 ) | |
926 "Movement commands") | |
927 (vip-test-com-defun vip-movement-command) | |
928 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
929 ;; Commands that can be repeated by . (dotted) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
930 (defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<)) |
10789 | 931 (vip-test-com-defun vip-dotable-command) |
932 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
933 ;; Commands that can follow a # |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
934 (defconst vip-hash-cmds '(?c ?C ?g ?q ?S)) |
10789 | 935 (vip-test-com-defun vip-hash-cmd) |
936 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
937 ;; Commands that may have registers as prefix |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
938 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) |
10789 | 939 (vip-test-com-defun vip-regsuffix-command) |
940 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
941 (defconst vip-vi-commands (append vip-movement-commands |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
942 vip-dotable-commands |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
943 vip-charpair-commands |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
944 vip-hash-cmds |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
945 vip-prefix-commands |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
946 vip-regsuffix-commands) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
947 "The list of all commands in Vi-state.") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
948 (vip-test-com-defun vip-vi-command) |
10789 | 949 |
950 | |
951 ;;; Arrange the keymaps | |
952 (require 'viper-keym) | |
953 | |
954 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
955 ;;; CODE |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
956 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
957 ;; sentinels |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
958 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
959 ;; Runs vip-after-change-functions inside after-change-functions |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
960 (defun vip-after-change-sentinel (beg end len) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
961 (let ((list vip-after-change-functions)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
962 (while list |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
963 (funcall (car list) beg end len) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
964 (setq list (cdr list))))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
965 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
966 ;; Runs vip-before-change-functions inside before-change-functions |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
967 (defun vip-before-change-sentinel (beg end) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
968 (let ((list vip-before-change-functions)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
969 (while list |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
970 (funcall (car list) beg end) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
971 (setq list (cdr list))))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
972 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
973 (defsubst vip-post-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
974 (run-hooks 'vip-post-command-hooks)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
975 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
976 (defsubst vip-pre-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
977 (run-hooks 'vip-pre-command-hooks)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
978 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
979 ;; Needed so that Viper will be able to figure the last inserted |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
980 ;; chunk of text with reasonable accuracy. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
981 (defsubst vip-insert-state-post-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
982 (if (and (memq vip-current-state '(insert-state replace-state)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
983 vip-insert-point |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
984 (>= (point) vip-insert-point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
985 (setq vip-last-posn-while-in-insert-state (point-marker))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
986 (if (and (eq this-command 'dabbrev-expand) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
987 (integerp vip-pre-command-point) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
988 (> vip-insert-point vip-pre-command-point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
989 (move-marker vip-insert-point vip-pre-command-point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
990 ) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
991 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
992 (defsubst vip-insert-state-pre-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
993 (if (and (eq this-command 'dabbrev-expand) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
994 (markerp vip-insert-point) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
995 (marker-position vip-insert-point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
996 (setq vip-pre-command-point (marker-position vip-insert-point)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
997 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
998 (defsubst vip-R-state-post-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
999 ;; Restoring cursor color is needed despite |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1000 ;; vip-replace-state-pre-command-sentinel: When you jump to another buffer in |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1001 ;; another frame, the pre-command hook won't change cursor color to default |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1002 ;; in that other frame. So, if the second frame cursor was red and we set |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1003 ;; the point outside the replacement region, then the cursor color will |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1004 ;; remain red. Restoring the default, below, prevents this. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1005 (if (and (<= (vip-replace-start) (point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1006 (<= (point) (vip-replace-end))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1007 (vip-change-cursor-color vip-replace-overlay-cursor-color) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1008 (vip-restore-cursor-color) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1009 )) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1010 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1011 ;; to speed up, don't change cursor color before self-insert |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1012 ;; and common move commands |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1013 (defsubst vip-replace-state-pre-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1014 (or (memq this-command '(self-insert-command)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1015 (memq (vip-event-key last-command-event) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1016 '(up down left right (meta f) (meta b) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1017 (control n) (control p) (control f) (control b))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1018 (vip-restore-cursor-color))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1019 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1020 (defun vip-replace-state-post-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1021 ;; Restoring cursor color is needed despite |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1022 ;; vip-replace-state-pre-command-sentinel: When one jumps to another buffer |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1023 ;; in another frame, the pre-command hook won't change cursor color to |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1024 ;; default in that other frame. So, if the second frame cursor was red and |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1025 ;; we set the point outside the replacement region, then the cursor color |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1026 ;; will remain red. Restoring the default, below, fixes this problem. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1027 ;; |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1028 ;; We optimize for self-insert-command's here, since they either don't change |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1029 ;; cursor color or, if they terminate replace mode, the color will be changed |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1030 ;; in vip-finish-change |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1031 (or (memq this-command '(self-insert-command)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1032 (vip-restore-cursor-color)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1033 (cond |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1034 ((eq vip-current-state 'replace-state) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1035 ;; delete characters to compensate for inserted chars. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1036 (let ((replace-boundary (vip-replace-end))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1037 (save-excursion |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1038 (goto-char vip-last-posn-in-replace-region) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1039 (delete-char vip-replace-chars-to-delete) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1040 (setq vip-replace-chars-to-delete 0 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1041 vip-replace-chars-deleted 0) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1042 ;; terminate replace mode if reached replace limit |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1043 (if (= vip-last-posn-in-replace-region |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1044 (vip-replace-end)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1045 (vip-finish-change vip-last-posn-in-replace-region))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1046 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1047 (if (and (<= (vip-replace-start) (point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1048 (<= (point) replace-boundary)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1049 (progn |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1050 ;; the state may have changed in vip-finish-change above |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1051 (if (eq vip-current-state 'replace-state) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1052 (vip-change-cursor-color vip-replace-overlay-cursor-color)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1053 (setq vip-last-posn-in-replace-region (point-marker)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1054 )) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1055 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1056 (t ;; terminate replace mode if changed Viper states. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1057 (vip-finish-change vip-last-posn-in-replace-region)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1058 |
10789 | 1059 |
1060 ;; changing mode | |
1061 | |
1062 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. | |
1063 (defun vip-change-state (new-state) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1064 ;; Keep vip-post/pre-command-hooks fresh. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1065 ;; We remove then add vip-post/pre-command-sentinel since it is very |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1066 ;; desirable that vip-pre-command-sentinel is the last hook and |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1067 ;; vip-post-command-sentinel is the first hook. |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1068 (remove-hook 'post-command-hook 'vip-post-command-sentinel) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1069 (add-hook 'post-command-hook 'vip-post-command-sentinel) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1070 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) |
10789 | 1071 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) |
1072 ;; These hooks will be added back if switching to insert/replace mode | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1073 (vip-remove-hook 'vip-post-command-hooks |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1074 'vip-insert-state-post-command-sentinel) |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1075 (vip-remove-hook 'vip-pre-command-hooks |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1076 'vip-insert-state-pre-command-sentinel) |
10789 | 1077 (cond ((eq new-state 'vi-state) |
1078 (cond ((member vip-current-state '(insert-state replace-state)) | |
1079 | |
1080 ;; move vip-last-posn-while-in-insert-state | |
1081 ;; This is a normal hook that is executed in insert/replace | |
1082 ;; states after each command. In Vi/Emacs state, it does | |
1083 ;; nothing. We need to execute it here to make sure that | |
1084 ;; the last posn was recorded when we hit ESC. | |
1085 ;; It may be left unrecorded if the last thing done in | |
1086 ;; insert/repl state was dabbrev-expansion or abbrev | |
1087 ;; expansion caused by hitting ESC | |
1088 (vip-insert-state-post-command-sentinel) | |
1089 | |
1090 (condition-case conds | |
1091 (progn | |
1092 (vip-save-last-insertion | |
1093 vip-insert-point | |
1094 vip-last-posn-while-in-insert-state) | |
1095 (if vip-began-as-replace | |
1096 (setq vip-began-as-replace nil) | |
1097 ;; repeat insert commands if numerical arg > 1 | |
1098 (save-excursion | |
1099 (vip-repeat-insert-command)))) | |
1100 (error | |
1101 (vip-message-conditions conds))) | |
1102 | |
1103 (if (> (length vip-last-insertion) 0) | |
1104 (vip-push-onto-ring vip-last-insertion | |
1105 'vip-insertion-ring)) | |
1106 | |
1107 (if vip-ex-style-editing-in-insert | |
1108 (or (bolp) (backward-char 1)))) | |
1109 )) | |
1110 | |
1111 ;; insert or replace | |
1112 ((memq new-state '(insert-state replace-state)) | |
1113 (if (memq vip-current-state '(emacs-state vi-state)) | |
1114 (vip-move-marker-locally 'vip-insert-point (point))) | |
1115 (vip-move-marker-locally 'vip-last-posn-while-in-insert-state (point)) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1116 (vip-add-hook 'vip-post-command-hooks |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1117 'vip-insert-state-post-command-sentinel t) |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1118 (vip-add-hook 'vip-pre-command-hooks |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1119 'vip-insert-state-pre-command-sentinel t)) |
10789 | 1120 ) ; outermost cond |
1121 | |
1122 ;; Nothing needs to be done to switch to emacs mode! Just set some | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1123 ;; variables, which is already done in vip-change-state-to-emacs! |
10789 | 1124 |
1125 (setq vip-current-state new-state) | |
1126 (vip-normalize-minor-mode-map-alist) | |
1127 (vip-adjust-keys-for new-state) | |
1128 (vip-set-mode-vars-for new-state) | |
1129 (vip-refresh-mode-line) | |
1130 ) | |
1131 | |
1132 | |
1133 | |
1134 (defun vip-adjust-keys-for (state) | |
1135 "Make necessary adjustments to keymaps before entering STATE." | |
1136 (cond ((memq state '(insert-state replace-state)) | |
1137 (if vip-auto-indent | |
1138 (progn | |
1139 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent) | |
1140 (if vip-want-emacs-keys-in-insert | |
1141 ;; expert | |
1142 (define-key vip-insert-basic-map "\C-j" nil) | |
1143 ;; novice | |
1144 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent)))) | |
1145 | |
1146 (setq vip-insert-diehard-minor-mode | |
1147 (not vip-want-emacs-keys-in-insert)) | |
1148 | |
1149 (if vip-want-ctl-h-help | |
1150 (progn | |
1151 (define-key vip-insert-basic-map "\C-h" 'help-command) | |
1152 (define-key vip-replace-map "\C-h" 'help-command)) | |
1153 (define-key vip-insert-basic-map | |
1154 "\C-h" 'vip-del-backward-char-in-insert) | |
1155 (define-key vip-replace-map | |
1156 "\C-h" 'vip-del-backward-char-in-replace))) | |
1157 | |
1158 (t | |
1159 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi)) | |
1160 (if vip-want-ctl-h-help | |
1161 (define-key vip-vi-basic-map "\C-h" 'help-command) | |
1162 (define-key vip-vi-basic-map "\C-h" 'vip-backward-char))) | |
1163 )) | |
1164 | |
1165 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1166 ;; Normalizes minor-mode-map-alist by putting Viper keymaps first. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1167 ;; This ensures that Viper bindings are in effect, regardless of which minor |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1168 ;; modes were turned on by the user or by other packages. |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1169 (defun vip-normalize-minor-mode-map-alist () |
10789 | 1170 (setq minor-mode-map-alist |
1171 (vip-append-filter-alist | |
1172 (list | |
1173 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map) | |
1174 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map) | |
1175 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map) | |
1176 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map) | |
1177 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map) | |
1178 (cons 'vip-vi-state-modifier-minor-mode | |
1179 (if (keymapp | |
1180 (cdr (assoc major-mode vip-vi-state-modifier-alist))) | |
1181 (cdr (assoc major-mode vip-vi-state-modifier-alist)) | |
1182 vip-empty-keymap)) | |
1183 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map) | |
1184 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map) | |
1185 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map) | |
1186 (cons 'vip-replace-minor-mode vip-replace-map) | |
1187 ;; vip-insert-minibuffer-minor-mode must come after | |
1188 ;; vip-replace-minor-mode | |
1189 (cons 'vip-insert-minibuffer-minor-mode | |
1190 vip-minibuffer-map) | |
1191 (cons 'vip-insert-local-user-minor-mode | |
1192 vip-insert-local-user-map) | |
1193 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map) | |
1194 (cons 'vip-insert-global-user-minor-mode | |
1195 vip-insert-global-user-map) | |
1196 (cons 'vip-insert-state-modifier-minor-mode | |
1197 (if (keymapp | |
1198 (cdr | |
1199 (assoc major-mode vip-insert-state-modifier-alist))) | |
1200 (cdr | |
1201 (assoc major-mode vip-insert-state-modifier-alist)) | |
1202 vip-empty-keymap)) | |
1203 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map) | |
1204 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map) | |
1205 (cons 'vip-emacs-intercept-minor-mode | |
1206 vip-emacs-intercept-map) | |
1207 (cons 'vip-emacs-local-user-minor-mode | |
1208 vip-emacs-local-user-map) | |
1209 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map) | |
1210 (cons 'vip-emacs-global-user-minor-mode | |
1211 vip-emacs-global-user-map) | |
1212 (cons 'vip-emacs-state-modifier-minor-mode | |
1213 (if (keymapp | |
1214 (cdr | |
1215 (assoc major-mode vip-emacs-state-modifier-alist))) | |
1216 (cdr | |
1217 (assoc major-mode vip-emacs-state-modifier-alist)) | |
1218 vip-empty-keymap)) | |
1219 ) | |
1220 minor-mode-map-alist))) | |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | |
1226 ;; Viper mode-changing commands and utilities | |
1227 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1228 ;; Modifies mode-line-buffer-identification. |
10789 | 1229 (defun vip-refresh-mode-line () |
1230 (setq vip-mode-string | |
1231 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id) | |
1232 ((eq vip-current-state 'vi-state) vip-vi-state-id) | |
1233 ((eq vip-current-state 'replace-state) vip-replace-state-id) | |
1234 ((eq vip-current-state 'insert-state) vip-insert-state-id))) | |
1235 | |
1236 ;; Sets Viper mode string in global-mode-string | |
1237 (force-mode-line-update)) | |
1238 | |
1239 ;;;###autoload | |
1240 (defun viper-mode () | |
1241 "Turn on Viper emulation of Vi." | |
1242 (interactive) | |
1243 (if (not noninteractive) | |
1244 (progn | |
1245 (if vip-first-time ; This check is important. Without it, startup and | |
1246 (progn ; expert-level msgs mix up when viper-mode recurses | |
1247 (setq vip-first-time nil) | |
1248 (if (not vip-inhibit-startup-message) | |
1249 (save-window-excursion | |
1250 (setq vip-inhibit-startup-message t) | |
1251 (delete-other-windows) | |
1252 (switch-to-buffer "Viper Startup Message") | |
1253 (erase-buffer) | |
1254 (insert | |
1255 (substitute-command-keys | |
1256 "Viper Is a Package for Emacs Rebels. | |
1257 It is also a VI Plan for Emacs Rescue and a venomous VI PERil. | |
1258 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1259 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and |
10789 | 1260 XEmacs 19. It supports virtually all of Vi and Ex functionality, extending |
1261 and improving upon much of it. | |
1262 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1263 1. Viper supports Vi at several levels. Level 1 is the closest to Vi, |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1264 level 5 provides the most flexibility to depart from many Vi conventions. |
10789 | 1265 |
1266 You will be asked to specify your user level in a following screen. | |
1267 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1268 If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1269 as in VI, to smooth transition to Viper for the beginners. However, to |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1270 use Emacs productively, you are advised to reach user level 3 or higher. |
10789 | 1271 |
1272 If your user level is 2 or higher, ^X and ^C will invoke Emacs | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1273 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and |
10789 | 1274 ^G will be the usual Emacs's keyboard-quit (something like ^C in VI). |
1275 | |
1276 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they | |
1277 do not cause Emacs to quit, except at user level 1 (a novice). | |
1278 3. ^X^C EXITS EMACS. | |
1279 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat | |
1280 undo. Another `u' changes direction. | |
1281 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1282 6. Emacs Meta functions are invoked by typing `C-\\' or `\\ ESC'. |
10789 | 1283 On a window system, the best way is to use the Meta-key. |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1284 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1285 something funny happens. This would abort the current editing command. |
10789 | 1286 |
1287 You can get more information on Viper by: | |
1288 | |
1289 a. Typing `:help' in Vi state | |
1290 b. Printing Viper manual, found in ./etc/viper.dvi | |
1291 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi | |
1292 | |
1293 This startup message appears whenever you load Viper, unless you type `y' now." | |
1294 )) | |
1295 (goto-char (point-min)) | |
1296 (if (y-or-n-p "Inhibit Viper startup message? ") | |
1297 (vip-save-setting | |
1298 'vip-inhibit-startup-message | |
1299 "Viper startup message inhibited" | |
1300 vip-custom-file-name t)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1301 ;;(kill-buffer (current-buffer)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1302 (message |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1303 "The last message is in buffer `Viper Startup Message'") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1304 (sit-for 4) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1305 )) |
10789 | 1306 (vip-set-expert-level 'dont-change-unless))) |
1307 (vip-change-state-to-vi)))) | |
1308 | |
1309 ;;;###autoload | |
1310 (defalias 'vip-mode 'viper-mode) | |
1311 | |
1312 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1313 ;; Switch from Insert state to Vi state. |
10789 | 1314 (defun vip-exit-insert-state () |
1315 (interactive) | |
1316 (vip-change-state-to-vi)) | |
1317 | |
1318 (defun vip-set-mode-vars-for (state) | |
1319 "Sets Viper minor mode variables to put Viper's state STATE in effect." | |
1320 | |
1321 ;; Emacs state | |
1322 (setq vip-vi-minibuffer-minor-mode nil | |
1323 vip-insert-minibuffer-minor-mode nil | |
1324 vip-vi-intercept-minor-mode nil | |
1325 vip-insert-intercept-minor-mode nil | |
1326 | |
1327 vip-vi-local-user-minor-mode nil | |
1328 vip-vi-kbd-minor-mode nil | |
1329 vip-vi-global-user-minor-mode nil | |
1330 vip-vi-state-modifier-minor-mode nil | |
1331 vip-vi-diehard-minor-mode nil | |
1332 vip-vi-basic-minor-mode nil | |
1333 | |
1334 vip-replace-minor-mode nil | |
1335 | |
1336 vip-insert-local-user-minor-mode nil | |
1337 vip-insert-kbd-minor-mode nil | |
1338 vip-insert-global-user-minor-mode nil | |
1339 vip-insert-state-modifier-minor-mode nil | |
1340 vip-insert-diehard-minor-mode nil | |
1341 vip-insert-basic-minor-mode nil | |
1342 vip-emacs-intercept-minor-mode t | |
1343 vip-emacs-local-user-minor-mode t | |
1344 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer)) | |
1345 vip-emacs-global-user-minor-mode t | |
1346 vip-emacs-state-modifier-minor-mode t | |
1347 ) | |
1348 | |
1349 ;; Vi state | |
1350 (if (eq state 'vi-state) ; adjust for vi-state | |
1351 (setq | |
1352 vip-vi-intercept-minor-mode t | |
1353 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer) | |
1354 vip-vi-local-user-minor-mode t | |
1355 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer)) | |
1356 vip-vi-global-user-minor-mode t | |
1357 vip-vi-state-modifier-minor-mode t | |
1358 ;; don't let the diehard keymap block command completion | |
1359 ;; and other things in the minibuffer | |
1360 vip-vi-diehard-minor-mode (not | |
1361 (or vip-want-emacs-keys-in-vi | |
1362 (vip-is-in-minibuffer))) | |
1363 vip-vi-basic-minor-mode t | |
1364 vip-emacs-intercept-minor-mode nil | |
1365 vip-emacs-local-user-minor-mode nil | |
1366 vip-emacs-kbd-minor-mode nil | |
1367 vip-emacs-global-user-minor-mode nil | |
1368 vip-emacs-state-modifier-minor-mode nil | |
1369 )) | |
1370 | |
1371 ;; Insert and Replace states | |
1372 (if (member state '(insert-state replace-state)) | |
1373 (setq | |
1374 vip-insert-intercept-minor-mode t | |
1375 vip-replace-minor-mode (eq state 'replace-state) | |
1376 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer) | |
1377 vip-insert-local-user-minor-mode t | |
1378 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer)) | |
1379 vip-insert-global-user-minor-mode t | |
1380 vip-insert-state-modifier-minor-mode t | |
1381 ;; don't let the diehard keymap block command completion | |
1382 ;; and other things in the minibuffer | |
1383 vip-insert-diehard-minor-mode (not | |
1384 (or vip-want-emacs-keys-in-insert | |
1385 (vip-is-in-minibuffer))) | |
1386 vip-insert-basic-minor-mode t | |
1387 vip-emacs-intercept-minor-mode nil | |
1388 vip-emacs-local-user-minor-mode nil | |
1389 vip-emacs-kbd-minor-mode nil | |
1390 vip-emacs-global-user-minor-mode nil | |
1391 vip-emacs-state-modifier-minor-mode nil | |
1392 )) | |
1393 | |
1394 ;; minibuffer faces | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
1395 (if (vip-has-face-support-p) |
10789 | 1396 (setq vip-minibuffer-current-face |
1397 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face) | |
1398 ((eq state 'vi-state) vip-minibuffer-vi-face) | |
1399 ((memq state '(insert-state replace-state)) | |
1400 vip-minibuffer-insert-face)))) | |
1401 | |
1402 (if (vip-is-in-minibuffer) | |
1403 (vip-set-minibuffer-overlay)) | |
1404 ) | |
1405 | |
1406 ;; This also takes care of the annoying incomplete lines in files. | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1407 ;; Also, this fixes `undo' to work vi-style for complex commands. |
10789 | 1408 (defun vip-change-state-to-vi () |
1409 "Change Viper state to Vi." | |
1410 (interactive) | |
1411 (if (and vip-first-time (not (vip-is-in-minibuffer))) | |
1412 (viper-mode) | |
1413 (if overwrite-mode (overwrite-mode nil)) | |
1414 (if abbrev-mode (expand-abbrev)) | |
1415 (if (and auto-fill-function (> (current-column) fill-column)) | |
1416 (funcall auto-fill-function)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1417 ;; don't leave whitespace lines around |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1418 (if (and (memq last-command |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1419 '(vip-autoindent |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1420 vip-open-line vip-Open-line |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1421 vip-replace-state-exit-cmd)) |
12203
0078571e5330
(vip-change-state-to-vi): bug fix.
Karl Heuer <kwzh@gnu.org>
parents:
12137
diff
changeset
|
1422 (vip-over-whitespace-line)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1423 (indent-to-left-margin)) |
10789 | 1424 (vip-add-newline-at-eob-if-necessary) |
1425 (if vip-undo-needs-adjustment (vip-adjust-undo)) | |
1426 (vip-change-state 'vi-state) | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1427 |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1428 ;; always turn off iso-accents-mode, or else we won't be able to use the |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1429 ;; keys `,',^ in Vi state, as they will do accents instead of Vi actions. |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1430 (if (and (boundp 'iso-accents-mode) iso-accents-mode) |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1431 (iso-accents-mode -1)) |
10789 | 1432 |
1433 ;; Protection against user errors in hooks | |
1434 (condition-case conds | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
1435 (run-hooks 'vip-vi-state-hook) |
10789 | 1436 (error |
1437 (vip-message-conditions conds))))) | |
1438 | |
1439 (defun vip-change-state-to-insert () | |
1440 "Change Viper state to Insert." | |
1441 (interactive) | |
1442 (vip-change-state 'insert-state) | |
1443 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | |
1444 (iso-accents-mode 1)) ; turn iso accents on | |
1445 | |
1446 ;; Protection against user errors in hooks | |
1447 (condition-case conds | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
1448 (run-hooks 'vip-insert-state-hook) |
10789 | 1449 (error |
1450 (vip-message-conditions conds)))) | |
1451 | |
1452 (defsubst vip-downgrade-to-insert () | |
1453 (setq vip-current-state 'insert-state | |
1454 vip-replace-minor-mode nil) | |
1455 ) | |
1456 | |
1457 | |
1458 | |
1459 ;; Change to replace state. When the end of replacement region is reached, | |
1460 ;; replace state changes to insert state. | |
1461 (defun vip-change-state-to-replace (&optional non-R-cmd) | |
1462 (vip-change-state 'replace-state) | |
1463 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | |
1464 (iso-accents-mode 1)) ; turn iso accents on | |
1465 ;; Run insert-state-hook | |
1466 (condition-case conds | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
1467 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook) |
10789 | 1468 (error |
1469 (vip-message-conditions conds))) | |
1470 | |
1471 (if non-R-cmd | |
1472 (vip-start-replace) | |
1473 ;; 'R' is implemented using Emacs's overwrite-mode | |
1474 (vip-start-R-mode)) | |
1475 ) | |
1476 | |
1477 | |
1478 (defun vip-change-state-to-emacs () | |
1479 "Change Viper state to Emacs." | |
1480 (interactive) | |
1481 (vip-change-state 'emacs-state) | |
1482 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | |
1483 (iso-accents-mode 1)) ; turn iso accents on | |
1484 | |
1485 ;; Protection agains user errors in hooks | |
1486 (condition-case conds | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
1487 (run-hooks 'vip-emacs-state-hook) |
10789 | 1488 (error |
1489 (vip-message-conditions conds)))) | |
1490 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1491 ;; escape to emacs mode termporarily |
10789 | 1492 (defun vip-escape-to-emacs (arg &optional events) |
1493 "Escape to Emacs state from Vi state for one Emacs command. | |
1494 ARG is used as the prefix value for the executed command. If | |
1495 EVENTS is a list of events, which become the beginning of the command." | |
1496 (interactive "P") | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1497 (if (= last-command-char ?\\) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1498 (message "Switched to EMACS state for the next command...")) |
10789 | 1499 (vip-escape-to-state arg events 'emacs-state)) |
1500 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1501 ;; escape to Vi mode termporarily |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1502 (defun vip-escape-to-vi (arg) |
10789 | 1503 "Escape from Emacs state to Vi state for one Vi 1-character command. |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1504 If the Vi command that the user types has a prefix argument, e.g., `d2w', then |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1505 Vi's prefix argument will be used. Otherwise, the prefix argument passed to |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1506 `vip-escape-to-vi' is used." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1507 (interactive "P") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1508 (message "Switched to VI state for the next command...") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1509 (vip-escape-to-state arg nil 'vi-state)) |
10789 | 1510 |
1511 ;; Escape to STATE mode for one Emacs command. | |
1512 (defun vip-escape-to-state (arg events state) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1513 ;;(let (com key prefix-arg) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1514 (let (com key) |
10789 | 1515 ;; this temporarily turns off Viper's minor mode keymaps |
1516 (vip-set-mode-vars-for state) | |
1517 (vip-normalize-minor-mode-map-alist) | |
1518 (if events (vip-set-unread-command-events events)) | |
1519 | |
1520 ;; protect against keyboard quit and other errors | |
1521 (condition-case nil | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1522 (let (vip-vi-kbd-minor-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1523 vip-insert-kbd-minor-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1524 vip-emacs-kbd-minor-mode) |
10789 | 1525 (unwind-protect |
1526 (progn | |
1527 (setq com (key-binding (setq key | |
1528 (if vip-xemacs-p | |
1529 (read-key-sequence nil) | |
1530 (read-key-sequence nil t))))) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1531 ;; In case of binding indirection--chase definitions. |
10789 | 1532 ;; Have to do it here because we execute this command under |
1533 ;; different keymaps, so command-execute may not do the | |
1534 ;; right thing there | |
1535 (while (vectorp com) (setq com (key-binding com)))) | |
1536 nil) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1537 ;; Execute command com in the original Viper state, not in state |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1538 ;; `state'. Otherwise, if we switch buffers while executing the |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1539 ;; escaped to command, Viper's mode vars will remain those of |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1540 ;; `state'. When we return to the orig buffer, the bindings will be |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1541 ;; screwed up. |
10789 | 1542 (vip-set-mode-vars-for vip-current-state) |
1543 | |
1544 ;; this-command, last-command-char, last-command-event | |
1545 (setq this-command com) | |
1546 (if vip-xemacs-p ; XEmacs represents key sequences as vectors | |
1547 (setq last-command-event (vip-seq-last-elt key) | |
1548 last-command-char (event-to-character last-command-event)) | |
1549 ;; Emacs represents them as sequences (str or vec) | |
1550 (setq last-command-event (vip-seq-last-elt key) | |
1551 last-command-char last-command-event)) | |
1552 | |
1553 (if (commandp com) | |
1554 (progn | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1555 (setq prefix-arg (or prefix-arg arg)) |
10789 | 1556 (command-execute com))) |
1557 ) | |
1558 (quit (ding)) | |
1559 (error (beep 1)))) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1560 ;; set state in the new buffer |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1561 (vip-set-mode-vars-for vip-current-state)) |
10789 | 1562 |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1563 (defun vip-exec-form-in-vi (form) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1564 "Execute FORM in Vi state, regardless of the Ccurrent Vi state." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1565 (let ((buff (current-buffer)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1566 result) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1567 (vip-set-mode-vars-for 'vi-state) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1568 (setq result (eval form)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1569 (if (not (equal buff (current-buffer))) ; cmd switched buffer |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1570 (save-excursion |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1571 (set-buffer buff) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1572 (vip-set-mode-vars-for vip-current-state))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1573 (vip-set-mode-vars-for vip-current-state) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1574 result)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1575 |
10789 | 1576 (defun vip-exec-form-in-emacs (form) |
1577 "Execute FORM in Emacs, temporarily disabling Viper's minor modes. | |
1578 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes." | |
1579 (let ((buff (current-buffer)) | |
1580 result) | |
1581 (vip-set-mode-vars-for 'emacs-state) | |
1582 (setq result (eval form)) | |
1583 (if (not (equal buff (current-buffer))) ; cmd switched buffer | |
1584 (save-excursion | |
1585 (set-buffer buff) | |
1586 (vip-set-mode-vars-for vip-current-state))) | |
1587 (vip-set-mode-vars-for vip-current-state) | |
1588 result)) | |
1589 | |
1590 | |
1591 ;; This is needed because minor modes sometimes override essential Viper | |
1592 ;; bindings. By letting Viper know which files these modes are in, it will | |
1593 ;; arrange to reorganize minor-mode-map-alist so that things will work right. | |
1594 (defun vip-harness-minor-mode (load-file) | |
1595 "Familiarize Viper with a minor mode defined in LOAD_FILE. | |
1596 Minor modes that have their own keymaps may overshadow Viper keymaps. | |
1597 This function is designed to make Viper aware of the packages that define | |
1598 such minor modes. | |
1599 Usage: | |
1600 (vip-harness-minor-mode load-file) | |
1601 | |
1602 LOAD-FILE is a name of the file where the specific minor mode is defined. | |
1603 Suffixes such as .el or .elc should be stripped." | |
1604 | |
1605 (interactive "sEnter name of the load file: ") | |
1606 | |
1607 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist)) | |
1608 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1609 ;; Change the default for minor-mode-map-alist each time a harnessed minor |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1610 ;; mode adds its own keymap to the a-list. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1611 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1612 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) |
10789 | 1613 ) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1614 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1615 |
10789 | 1616 (defun vip-ESC (arg) |
1617 "Emulate ESC key in Emacs. | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1618 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1619 If vip-no-multiple-ESC is 'twice double ESC would ding in vi-state. |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1620 Other ESC sequences are emulated via the current Emacs's major mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1621 keymap. This is more convenient on TTYs, since this won't block |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1622 function keys such as up,down, etc. ESC will also will also work as |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1623 a Meta key in this case. When vip-no-multiple-ESC is nil, ESC functions |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1624 as a Meta key and any number of multiple escapes is allowed." |
10789 | 1625 (interactive "P") |
1626 (let (char) | |
1627 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state)) | |
1628 (setq char (vip-read-char-exclusive)) | |
1629 (vip-escape-to-emacs arg (list ?\e char) )) | |
1630 ((and (eq vip-no-multiple-ESC 'twice) | |
1631 (eq vip-current-state 'vi-state)) | |
1632 (setq char (vip-read-char-exclusive)) | |
1633 (if (= char (string-to-char vip-ESC-key)) | |
1634 (ding) | |
1635 (vip-escape-to-emacs arg (list ?\e char) ))) | |
1636 (t (ding))) | |
1637 )) | |
1638 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1639 (defun vip-alternate-Meta-key (arg) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1640 "Simulate Emacs Meta key." |
10789 | 1641 (interactive "P") |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1642 (sit-for 1) (message "ESC-") |
10789 | 1643 (vip-escape-to-emacs arg '(?\e))) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1644 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1645 (defun vip-toggle-key-action () |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1646 "Action bound to `vip-toggle-key'." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1647 (interactive) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1648 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z")) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1649 (if (vip-window-display-p) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1650 (vip-iconify) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1651 (suspend-emacs)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1652 (vip-change-state-to-emacs))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1653 |
10789 | 1654 |
1655 ;; Intercept ESC sequences on dumb terminals. | |
1656 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es> | |
1657 | |
1658 ;; Check if last key was ESC and if so try to reread it as a function key. | |
1659 ;; But only if there are characters to read during a very short time. | |
1660 ;; Returns the last event, if any. | |
1661 (defun vip-envelop-ESC-key () | |
1662 (let ((event last-input-event) | |
1663 (keyseq [nil]) | |
1664 inhibit-quit) | |
1665 (if (vip-ESC-event-p event) | |
1666 (progn | |
1667 (if (vip-fast-keysequence-p) | |
1668 (progn | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1669 (let (minor-mode-map-alist) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1670 (vip-set-unread-command-events event) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1671 (setq keyseq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1672 (funcall |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1673 (ad-get-orig-definition 'read-key-sequence) nil)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1674 ) ; let |
10789 | 1675 ;; If keyseq translates into something that still has ESC |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1676 ;; at the beginning, separate ESC from the rest of the seq. |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1677 ;; In XEmacs we check for events that are keypress meta-key |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1678 ;; and convert them into [escape key] |
10789 | 1679 ;; |
1680 ;; This is needed for the following reason: | |
1681 ;; If ESC is the first symbol, we interpret it as if the | |
1682 ;; user typed ESC and then quickly some other symbols. | |
1683 ;; If ESC is not the first one, then the key sequence | |
1684 ;; entered was apparently translated into a function key or | |
1685 ;; something (e.g., one may have | |
1686 ;; (define-key function-key-map "\e[192z" [f11]) | |
1687 ;; which would translate the escape-sequence generated by | |
1688 ;; f11 in an xterm window into the symbolic key f11. | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1689 ;; |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1690 ;; If `first-key' is not an ESC event, we make it into the |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1691 ;; last-command-event in order to pretend that this key was |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1692 ;; pressed. This is needed to allow arrow keys to be bound to |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1693 ;; macros. Otherwise, vip-exec-mapped-kbd-macro will think that |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1694 ;; the last event was ESC and so it'll execute whatever is |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1695 ;; bound to ESC. (Viper macros can't be bound to |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1696 ;; ESC-sequences). |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1697 (let* ((first-key (elt keyseq 0)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1698 (key-mod (event-modifiers first-key))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1699 (cond ((vip-ESC-event-p first-key) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1700 ;; put keys following ESC on the unread list |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1701 ;; and return ESC as the key-sequence |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1702 (vip-set-unread-command-events (subseq keyseq 1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1703 (setq last-input-event event |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1704 keyseq (if vip-emacs-p |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1705 "\e" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1706 (vector (character-to-event ?\e))))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1707 ((and vip-xemacs-p |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1708 (key-press-event-p first-key) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1709 (equal '(meta) key-mod)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1710 (vip-set-unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1711 (vconcat (vector |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1712 (character-to-event (event-key first-key))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1713 (subseq keyseq 1))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1714 (setq last-input-event event |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1715 keyseq (vector (character-to-event ?\e)))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1716 ((eventp first-key) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1717 (setq last-command-event first-key)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1718 )) |
10789 | 1719 ) ; end progn |
1720 | |
1721 ;; this is escape event with nothing after it | |
1722 ;; put in unread-command-event and then re-read | |
1723 (vip-set-unread-command-events event) | |
1724 (setq keyseq | |
1725 (funcall (ad-get-orig-definition 'read-key-sequence) nil)) | |
1726 )) | |
1727 ;; not an escape event | |
1728 (setq keyseq (vector event))) | |
1729 keyseq)) | |
1730 | |
1731 | |
1732 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1733 (defadvice read-key-sequence (around vip-read-keyseq-ad activate) |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1734 "Harness to work for Viper. This advice is harmless---don't worry!" |
10789 | 1735 (let (inhibit-quit event keyseq) |
1736 (setq keyseq ad-do-it) | |
1737 (setq event (if vip-xemacs-p | |
1738 (elt keyseq 0) ; XEmacs returns vector of events | |
1739 (elt (listify-key-sequence keyseq) 0))) | |
1740 (if (vip-ESC-event-p event) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1741 (let (unread-command-events) |
10789 | 1742 (vip-set-unread-command-events keyseq) |
1743 (if (vip-fast-keysequence-p) | |
1744 (let ((vip-vi-global-user-minor-mode nil) | |
1745 (vip-vi-local-user-minor-mode nil) | |
1746 (vip-replace-minor-mode nil) ; actually unnecessary | |
1747 (vip-insert-global-user-minor-mode nil) | |
1748 (vip-insert-local-user-minor-mode nil)) | |
1749 (setq keyseq ad-do-it)) | |
1750 (setq keyseq ad-do-it)))) | |
1751 keyseq)) | |
1752 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1753 (defadvice describe-key (before vip-read-keyseq-ad protect activate) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1754 "Force to read key via `read-key-sequence'." |
10789 | 1755 (interactive (list (vip-events-to-keys |
1756 (read-key-sequence "Describe key: "))))) | |
1757 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1758 (defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1759 "Force to read key via `read-key-sequence'." |
10789 | 1760 (interactive (list (vip-events-to-keys |
1761 (read-key-sequence "Describe key briefly: "))))) | |
1762 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1763 ;; Listen to ESC key. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1764 ;; If a sequence of keys starting with ESC is issued with very short delays, |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1765 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key. |
10789 | 1766 (defun vip-intercept-ESC-key () |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1767 "Function that implements ESC key in Viper emulation of Vi." |
10789 | 1768 (interactive) |
1769 (let ((cmd (or (key-binding (vip-envelop-ESC-key)) | |
1770 '(lambda () (interactive) (error ""))))) | |
1771 | |
1772 ;; call the actual function to execute ESC (if no other symbols followed) | |
1773 ;; or the key bound to the ESC sequence (if the sequence was issued | |
1774 ;; with very short delay between characters. | |
1775 (if (eq cmd 'vip-intercept-ESC-key) | |
1776 (setq cmd | |
1777 (cond ((eq vip-current-state 'vi-state) | |
1778 'vip-ESC) | |
1779 ((eq vip-current-state 'insert-state) | |
1780 'vip-exit-insert-state) | |
1781 ((eq vip-current-state 'replace-state) | |
1782 'vip-replace-state-exit-cmd) | |
1783 (t 'vip-change-state-to-vi) | |
1784 ))) | |
1785 (call-interactively cmd))) | |
1786 | |
1787 | |
1788 | |
1789 ;; prefix argument for Vi mode | |
1790 | |
1791 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM | |
1792 ;; represents the numeric value of the prefix argument and COM represents | |
1793 ;; command prefix such as "c", "d", "m" and "y". | |
1794 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1795 ;; Get value part of prefix-argument ARG. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1796 (defsubst vip-p-val (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1797 (cond ((null arg) 1) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1798 ((consp arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1799 (if (or (null (car arg)) (equal (car arg) '(nil))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1800 1 (car arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1801 (t arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1802 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1803 ;; Get raw value part of prefix-argument ARG. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1804 (defsubst vip-P-val (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1805 (cond ((consp arg) (car arg)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1806 (t arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1807 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1808 ;; Get com part of prefix-argument ARG. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1809 (defsubst vip-getcom (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1810 (cond ((null arg) nil) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1811 ((consp arg) (cdr arg)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1812 (t nil))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1813 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1814 ;; Get com part of prefix-argument ARG and modify it. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1815 (defun vip-getCom (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1816 (let ((com (vip-getcom arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1817 (cond ((equal com ?c) ?C) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1818 ((equal com ?d) ?D) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1819 ((equal com ?y) ?Y) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1820 (t com)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1821 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1822 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1823 ;; Compute numeric prefix arg value. |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1824 ;; Invoked by EVENT. COM is the command part obtained so far. |
10789 | 1825 (defun vip-prefix-arg-value (event com) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1826 (let (value func) |
10789 | 1827 ;; read while number |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1828 (while (and (vip-characterp event) (>= event ?0) (<= event ?9)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1829 (setq value (+ (* (if (vip-characterp value) value 0) 10) (- event ?0))) |
10789 | 1830 (setq event (vip-read-event-convert-to-char))) |
1831 | |
1832 (setq prefix-arg value) | |
1833 (if com (setq prefix-arg (cons prefix-arg com))) | |
1834 (while (eq event ?U) | |
1835 (vip-describe-arg prefix-arg) | |
1836 (setq event (vip-read-event-convert-to-char))) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1837 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1838 (if (or com (and (not (eq vip-current-state 'vi-state)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1839 ;; make sure it is a Vi command |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1840 (vip-characterp event) (vip-vi-command-p event) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1841 )) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1842 ;; If appears to be one of the vi commands, |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1843 ;; then execute it with funcall and clear prefix-arg in order to not |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1844 ;; confuse subsequent commands |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1845 (progn |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1846 ;; last-command-char is the char we want emacs to think was typed |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1847 ;; last. If com is not nil, the vip-digit-argument command was called |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1848 ;; from within vip-prefix-arg command, such as `d', `w', etc., i.e., |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1849 ;; the user typed, say, d2. In this case, `com' would be `d', `w', |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1850 ;; etc. |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1851 ;; If vip-digit-argument was invoked by vip-escape-to-vi (which is |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1852 ;; indicated by the fact that the current state is not vi-state, |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1853 ;; then `event' represents the vi command to be executed (e.g., `d', |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1854 ;; `w', etc. Again, last-command-char must make emacs believe that |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1855 ;; this is the command we typed. |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1856 (setq last-command-char (or com event)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1857 (setq func (vip-exec-form-in-vi |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1858 (` (key-binding (char-to-string (, event)))))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1859 (funcall func prefix-arg) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1860 (setq prefix-arg nil)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1861 ;; some other command -- let emacs do it in its own way |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1862 (vip-set-unread-command-events event)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1863 )) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1864 |
10789 | 1865 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1866 ;; Vi operator as prefix argument." |
10789 | 1867 (defun vip-prefix-arg-com (char value com) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1868 (let ((cont t) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1869 cmd-info mv-or-digit-cmd) |
10789 | 1870 (while (and cont |
1871 (memq char | |
1872 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" | |
1873 vip-buffer-search-char))) | |
1874 (if com | |
1875 ;; this means that we already have a command character, so we | |
1876 ;; construct a com list and exit while. however, if char is " | |
1877 ;; it is an error. | |
1878 (progn | |
1879 ;; new com is (CHAR . OLDCOM) | |
1880 (if (memq char '(?# ?\")) (error "")) | |
1881 (setq com (cons char com)) | |
1882 (setq cont nil)) | |
1883 ;; If com is nil we set com as char, and read more. Again, if char | |
1884 ;; is ", we read the name of register and store it in vip-use-register. | |
1885 ;; if char is !, =, or #, a complete com is formed so we exit the | |
1886 ;; while loop. | |
1887 (cond ((memq char '(?! ?=)) | |
1888 (setq com char) | |
1889 (setq char (read-char)) | |
1890 (setq cont nil)) | |
1891 ((= char ?#) | |
1892 ;; read a char and encode it as com | |
1893 (setq com (+ 128 (read-char))) | |
1894 (setq char (read-char))) | |
1895 ((= char ?\") | |
1896 (let ((reg (read-char))) | |
1897 (if (vip-valid-register reg) | |
1898 (setq vip-use-register reg) | |
1899 (error "")) | |
1900 (setq char (read-char)))) | |
1901 (t | |
1902 (setq com char) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1903 (setq char (vip-read-char-exclusive)))))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1904 |
10789 | 1905 (if (atom com) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1906 ;; `com' is a single char, so we construct the command argument |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1907 ;; and if `char' is `?', we describe the arg; otherwise |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1908 ;; we prepare the command that will be executed at the end. |
10789 | 1909 (progn |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1910 (setq cmd-info (cons value com)) |
10789 | 1911 (while (= char ?U) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1912 (vip-describe-arg cmd-info) |
10789 | 1913 (setq char (read-char))) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1914 ;; `char' is a movement command or a digit arg command---so we execute |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1915 ;; it at the very end |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1916 (setq mv-or-digit-cmd |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1917 (vip-exec-form-in-vi |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1918 (` (key-binding (char-to-string (, char))))))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1919 |
10789 | 1920 ;; as com is non-nil, this means that we have a command to execute |
1921 (if (memq (car com) '(?r ?R)) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1922 ;; execute apropriate region command. |
10789 | 1923 (let ((char (car com)) (com (cdr com))) |
1924 (setq prefix-arg (cons value com)) | |
1925 (if (= char ?r) (vip-region prefix-arg) | |
1926 (vip-Region prefix-arg)) | |
1927 ;; reset prefix-arg | |
1928 (setq prefix-arg nil)) | |
1929 ;; otherwise, reset prefix arg and call appropriate command | |
1930 (setq value (if (null value) 1 value)) | |
1931 (setq prefix-arg nil) | |
1932 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C))) | |
1933 ((equal com '(?d . ?d)) (vip-line (cons value ?D))) | |
1934 ((equal com '(?d . ?y)) (vip-yank-defun)) | |
1935 ((equal com '(?y . ?y)) (vip-line (cons value ?Y))) | |
1936 ((equal com '(?< . ?<)) (vip-line (cons value ?<))) | |
1937 ((equal com '(?> . ?>)) (vip-line (cons value ?>))) | |
1938 ((equal com '(?! . ?!)) (vip-line (cons value ?!))) | |
1939 ((equal com '(?= . ?=)) (vip-line (cons value ?=))) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1940 (t (error ""))))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1941 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1942 (if mv-or-digit-cmd |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1943 (progn |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1944 (setq last-command-char char) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1945 (funcall mv-or-digit-cmd cmd-info))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1946 )) |
10789 | 1947 |
1948 (defun vip-describe-arg (arg) | |
1949 (let (val com) | |
1950 (setq val (vip-P-val arg) | |
1951 com (vip-getcom arg)) | |
1952 (if (null val) | |
1953 (if (null com) | |
1954 (message "Value is nil, and command is nil") | |
1955 (message "Value is nil, and command is `%c'" com)) | |
1956 (if (null com) | |
1957 (message "Value is `%d', and command is nil" val) | |
1958 (message "Value is `%d', and command is `%c'" val com))))) | |
1959 | |
1960 (defun vip-digit-argument (arg) | |
1961 "Begin numeric argument for the next command." | |
1962 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
1963 (vip-leave-region-active) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1964 (vip-prefix-arg-value |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1965 last-command-char (if (consp arg) (cdr arg) nil))) |
10789 | 1966 |
1967 (defun vip-command-argument (arg) | |
1968 "Accept a motion command as an argument." | |
1969 (interactive "P") | |
1970 (condition-case nil | |
1971 (vip-prefix-arg-com | |
1972 last-command-char | |
1973 (cond ((null arg) nil) | |
1974 ((consp arg) (car arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1975 ((integerp arg) arg) |
10789 | 1976 (t (error vip-InvalidCommandArgument))) |
1977 (cond ((null arg) nil) | |
1978 ((consp arg) (cdr arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1979 ((integerp arg) nil) |
10789 | 1980 (t (error vip-InvalidCommandArgument)))) |
1981 (quit (setq vip-use-register nil) | |
1982 (signal 'quit nil))) | |
1983 (vip-deactivate-mark)) | |
1984 | |
1985 | |
1986 ;; repeat last destructive command | |
1987 | |
1988 ;; Append region to text in register REG. | |
1989 ;; START and END are buffer positions indicating what to append. | |
1990 (defsubst vip-append-to-register (reg start end) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1991 (set-register reg (concat (if (stringp (get-register reg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1992 (get-register reg) "") |
10789 | 1993 (buffer-substring start end)))) |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1994 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1995 ;; Saves last inserted text for possible use by vip-repeat command. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1996 (defun vip-save-last-insertion (beg end) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1997 (setq vip-last-insertion (buffer-substring beg end)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1998 (or (< (length vip-d-com) 5) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1999 (setcar (nthcdr 4 vip-d-com) vip-last-insertion)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2000 (or (null vip-command-ring) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2001 (ring-empty-p vip-command-ring) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2002 (progn |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2003 (setcar (nthcdr 4 (vip-current-ring-item vip-command-ring)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2004 vip-last-insertion) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2005 ;; del most recent elt, if identical to the second most-recent |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2006 (vip-cleanup-ring vip-command-ring))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2007 ) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2008 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2009 (defsubst vip-yank-last-insertion () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2010 "Inserts the text saved by the previous vip-save-last-insertion command." |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2011 (condition-case nil |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2012 (insert vip-last-insertion) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2013 (error nil))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2014 |
10789 | 2015 |
2016 ;; define functions to be executed | |
2017 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
2018 ;; invoked by the `C' command |
10789 | 2019 (defun vip-exec-change (m-com com) |
2020 ;; handle C cmd at the eol and at eob. | |
2021 (if (or (and (eolp) (= vip-com-point (point))) | |
2022 (= vip-com-point (point-max))) | |
2023 (progn | |
2024 (insert " ")(backward-char 1))) | |
2025 (if (= vip-com-point (point)) | |
2026 (vip-forward-char-carefully)) | |
2027 (if (= com ?c) | |
2028 (vip-change vip-com-point (point)) | |
2029 (vip-change-subr vip-com-point (point)))) | |
2030 | |
2031 ;; this is invoked by vip-substitute-line | |
2032 (defun vip-exec-Change (m-com com) | |
2033 (save-excursion | |
2034 (set-mark vip-com-point) | |
2035 (vip-enlarge-region (mark t) (point)) | |
2036 (if vip-use-register | |
2037 (progn | |
2038 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2039 ;;(vip-valid-register vip-use-register '(letter) | |
2040 (copy-to-register | |
2041 vip-use-register (mark t) (point) nil)) | |
2042 ((vip-valid-register vip-use-register '(Letter)) | |
2043 (vip-append-to-register | |
2044 (downcase vip-use-register) (mark t) (point))) | |
2045 (t (setq vip-use-register nil) | |
2046 (error vip-InvalidRegister vip-use-register))) | |
2047 (setq vip-use-register nil))) | |
2048 (delete-region (mark t) (point))) | |
2049 (open-line 1) | |
2050 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion))) | |
2051 | |
2052 (defun vip-exec-delete (m-com com) | |
2053 (if vip-use-register | |
2054 (progn | |
2055 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2056 ;;(vip-valid-register vip-use-register '(letter)) | |
2057 (copy-to-register | |
2058 vip-use-register vip-com-point (point) nil)) | |
2059 ((vip-valid-register vip-use-register '(Letter)) | |
2060 (vip-append-to-register | |
2061 (downcase vip-use-register) vip-com-point (point))) | |
2062 (t (setq vip-use-register nil) | |
2063 (error vip-InvalidRegister vip-use-register))) | |
2064 (setq vip-use-register nil))) | |
2065 (setq last-command | |
2066 (if (eq last-command 'd-command) 'kill-region nil)) | |
2067 (kill-region vip-com-point (point)) | |
2068 (setq this-command 'd-command) | |
2069 (if vip-ex-style-motion | |
2070 (if (and (eolp) (not (bolp))) (backward-char 1)))) | |
2071 | |
2072 (defun vip-exec-Delete (m-com com) | |
2073 (save-excursion | |
2074 (set-mark vip-com-point) | |
2075 (vip-enlarge-region (mark t) (point)) | |
2076 (if vip-use-register | |
2077 (progn | |
2078 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2079 ;;(vip-valid-register vip-use-register '(letter)) | |
2080 (copy-to-register | |
2081 vip-use-register (mark t) (point) nil)) | |
2082 ((vip-valid-register vip-use-register '(Letter)) | |
2083 (vip-append-to-register | |
2084 (downcase vip-use-register) (mark t) (point))) | |
2085 (t (setq vip-use-register nil) | |
2086 (error vip-InvalidRegister vip-use-register))) | |
2087 (setq vip-use-register nil))) | |
2088 (setq last-command | |
2089 (if (eq last-command 'D-command) 'kill-region nil)) | |
2090 (kill-region (mark t) (point)) | |
2091 (if (eq m-com 'vip-line) (setq this-command 'D-command))) | |
2092 (back-to-indentation)) | |
2093 | |
2094 (defun vip-exec-yank (m-com com) | |
2095 (if vip-use-register | |
2096 (progn | |
2097 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2098 ;; (vip-valid-register vip-use-register '(letter)) | |
2099 (copy-to-register | |
2100 vip-use-register vip-com-point (point) nil)) | |
2101 ((vip-valid-register vip-use-register '(Letter)) | |
2102 (vip-append-to-register | |
2103 (downcase vip-use-register) vip-com-point (point))) | |
2104 (t (setq vip-use-register nil) | |
2105 (error vip-InvalidRegister vip-use-register))) | |
2106 (setq vip-use-register nil))) | |
2107 (setq last-command nil) | |
2108 (copy-region-as-kill vip-com-point (point)) | |
2109 (goto-char vip-com-point)) | |
2110 | |
2111 (defun vip-exec-Yank (m-com com) | |
2112 (save-excursion | |
2113 (set-mark vip-com-point) | |
2114 (vip-enlarge-region (mark t) (point)) | |
2115 (if vip-use-register | |
2116 (progn | |
2117 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2118 (copy-to-register | |
2119 vip-use-register (mark t) (point) nil)) | |
2120 ((vip-valid-register vip-use-register '(Letter)) | |
2121 (vip-append-to-register | |
2122 (downcase vip-use-register) (mark t) (point))) | |
2123 (t (setq vip-use-register nil) | |
2124 (error vip-InvalidRegister vip-use-register))) | |
2125 (setq vip-use-register nil))) | |
2126 (setq last-command nil) | |
2127 (copy-region-as-kill (mark t) (point))) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
2128 (vip-deactivate-mark) |
10789 | 2129 (goto-char vip-com-point)) |
2130 | |
2131 (defun vip-exec-bang (m-com com) | |
2132 (save-excursion | |
2133 (set-mark vip-com-point) | |
2134 (vip-enlarge-region (mark t) (point)) | |
2135 (shell-command-on-region | |
2136 (mark t) (point) | |
2137 (if (= com ?!) | |
2138 (setq vip-last-shell-com | |
2139 (vip-read-string-with-history | |
2140 "!" | |
2141 nil | |
2142 'vip-shell-history | |
2143 (car vip-shell-history) | |
2144 )) | |
2145 vip-last-shell-com) | |
2146 t))) | |
2147 | |
2148 (defun vip-exec-equals (m-com com) | |
2149 (save-excursion | |
2150 (set-mark vip-com-point) | |
2151 (vip-enlarge-region (mark t) (point)) | |
2152 (if (> (mark t) (point)) (exchange-point-and-mark)) | |
2153 (indent-region (mark t) (point) nil))) | |
2154 | |
2155 (defun vip-exec-shift (m-com com) | |
2156 (save-excursion | |
2157 (set-mark vip-com-point) | |
2158 (vip-enlarge-region (mark t) (point)) | |
2159 (if (> (mark t) (point)) (exchange-point-and-mark)) | |
2160 (indent-rigidly (mark t) (point) | |
2161 (if (= com ?>) | |
2162 vip-shift-width | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2163 (- vip-shift-width)))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2164 ;; return point to where it was before shift |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2165 (goto-char vip-com-point)) |
10789 | 2166 |
2167 ;; this is needed because some commands fake com by setting it to ?r, which | |
2168 ;; denotes repeated insert command. | |
2169 (defsubst vip-exec-dummy (m-com com) | |
2170 nil) | |
2171 | |
2172 (defun vip-exec-buffer-search (m-com com) | |
2173 (setq vip-s-string (buffer-substring (point) vip-com-point)) | |
2174 (setq vip-s-forward t) | |
2175 (setq vip-search-history (cons vip-s-string vip-search-history)) | |
2176 (vip-search vip-s-string vip-s-forward 1)) | |
2177 | |
2178 (defvar vip-exec-array (make-vector 128 nil)) | |
2179 | |
2180 ;; Using a dispatch array allows adding functions like buffer search | |
2181 ;; without affecting other functions. Buffer search can now be bound | |
2182 ;; to any character. | |
2183 | |
2184 (aset vip-exec-array ?c 'vip-exec-change) | |
2185 (aset vip-exec-array ?C 'vip-exec-Change) | |
2186 (aset vip-exec-array ?d 'vip-exec-delete) | |
2187 (aset vip-exec-array ?D 'vip-exec-Delete) | |
2188 (aset vip-exec-array ?y 'vip-exec-yank) | |
2189 (aset vip-exec-array ?Y 'vip-exec-Yank) | |
2190 (aset vip-exec-array ?r 'vip-exec-dummy) | |
2191 (aset vip-exec-array ?! 'vip-exec-bang) | |
2192 (aset vip-exec-array ?< 'vip-exec-shift) | |
2193 (aset vip-exec-array ?> 'vip-exec-shift) | |
2194 (aset vip-exec-array ?= 'vip-exec-equals) | |
2195 | |
2196 | |
2197 | |
2198 ;; This function is called by various movement commands to execute a | |
2199 ;; destructive command on the region specified by the movement command. For | |
2200 ;; instance, if the user types cw, then the command vip-forward-word will | |
2201 ;; call vip-execute-com to execute vip-exec-change, which eventually will | |
2202 ;; call vip-change to invoke the replace mode on the region. | |
2203 ;; | |
2204 ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to | |
2205 ;; vip-d-com for later use by vip-repeat. | |
2206 (defun vip-execute-com (m-com val com) | |
2207 (let ((reg vip-use-register)) | |
2208 ;; this is the special command `#' | |
2209 (if (> com 128) | |
2210 (vip-special-prefix-com (- com 128)) | |
2211 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com)))) | |
2212 (if (null fn) | |
2213 (error "%c: %s" com vip-InvalidViCommand) | |
2214 (funcall fn m-com com)))) | |
2215 (if (vip-dotable-command-p com) | |
2216 (vip-set-destructive-command | |
2217 (list m-com val | |
2218 (if (memq com (list ?c ?C ?!)) (- com) com) | |
2219 reg nil nil))) | |
2220 )) | |
2221 | |
2222 | |
2223 (defun vip-repeat (arg) | |
2224 "Re-execute last destructive command. | |
2225 Use the info in vip-d-com, which has the form | |
2226 \(com val ch reg inserted-text command-keys\), | |
2227 where `com' is the command to be re-executed, `val' is the | |
2228 argument to `com', `ch' is a flag for repeat, and `reg' is optional; | |
2229 if it exists, it is the name of the register for `com'. | |
2230 If the prefix argument, ARG, is non-nil, it is used instead of `val'." | |
2231 (interactive "P") | |
2232 (let ((save-point (point)) ; save point before repeating prev cmd | |
2233 ;; Pass along that we are repeating a destructive command | |
2234 ;; This tells vip-set-destructive-command not to update | |
2235 ;; vip-command-ring | |
2236 (vip-intermediate-command 'vip-repeat)) | |
2237 (if (eq last-command 'vip-undo) | |
2238 ;; if the last command was vip-undo, then undo-more | |
2239 (vip-undo-more) | |
2240 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil | |
2241 ;; its prefix value is used as new prefix value for the command. | |
2242 (let ((m-com (car vip-d-com)) | |
2243 (val (vip-P-val arg)) | |
2244 (com (nth 2 vip-d-com)) | |
2245 (reg (nth 3 vip-d-com))) | |
2246 (if (null val) (setq val (nth 1 vip-d-com))) | |
2247 (if (null m-com) (error "No previous command to repeat.")) | |
2248 (setq vip-use-register reg) | |
2249 (if (nth 4 vip-d-com) ; text inserted by command | |
2250 (setq vip-last-insertion (nth 4 vip-d-com) | |
2251 vip-d-char (nth 4 vip-d-com))) | |
2252 (funcall m-com (cons val com)) | |
2253 (if (and vip-keep-point-on-repeat (< save-point (point))) | |
2254 (goto-char save-point)) ; go back to before repeat. | |
2255 (if (and (eolp) (not (bolp))) | |
2256 (backward-char 1)) | |
2257 )) | |
2258 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo | |
2259 ;; If the prev cmd was rotating the command ring, this means that `.' has | |
2260 ;; just executed a command from that ring. So, push it on the ring again. | |
2261 ;; If we are just executing previous command , then don't push vip-d-com | |
2262 ;; because vip-d-com is not fully constructed in this case (its keys and | |
2263 ;; the inserted text may be nil). Besides, in this case, the command | |
2264 ;; executed by `.' is already on the ring. | |
2265 (if (eq last-command 'vip-display-current-destructive-command) | |
2266 (vip-push-onto-ring vip-d-com 'vip-command-ring)) | |
2267 (vip-deactivate-mark) | |
2268 )) | |
2269 | |
2270 (defun vip-repeat-from-history () | |
2271 "Repeat a destructive command from history. | |
2272 Doesn't change vip-command-ring in any way, so `.' will work as before | |
2273 executing this command. | |
2274 This command is supposed to be bound to a two-character Vi macro where | |
2275 the second character is a digit 0 to 9. The digit indicates which | |
2276 history command to execute. `<char>0' is equivalent to `.', `<char>1' | |
2277 invokes the command before that, etc." | |
2278 (interactive) | |
2279 (let* ((vip-intermediate-command 'repeating-display-destructive-command) | |
2280 (idx (cond (vip-this-kbd-macro | |
2281 (string-to-number | |
2282 (symbol-name (elt vip-this-kbd-macro 1)))) | |
2283 (t 0))) | |
2284 (num idx) | |
2285 (vip-d-com vip-d-com)) | |
2286 | |
2287 (or (and (numberp num) (<= 0 num) (<= num 9)) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2288 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2289 (setq idx 0 |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2290 num 0) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2291 (message |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2292 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))) |
10789 | 2293 (while (< 0 num) |
2294 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1)) | |
2295 (setq num (1- num))) | |
2296 (vip-repeat nil) | |
2297 (while (> idx num) | |
2298 (vip-special-ring-rotate1 vip-command-ring 1) | |
2299 (setq num (1+ num))) | |
2300 )) | |
2301 | |
2302 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2303 ;; This command is invoked interactively by the key sequence #<char> |
10789 | 2304 (defun vip-special-prefix-com (char) |
2305 (cond ((= char ?c) | |
2306 (downcase-region (min vip-com-point (point)) | |
2307 (max vip-com-point (point)))) | |
2308 ((= char ?C) | |
2309 (upcase-region (min vip-com-point (point)) | |
2310 (max vip-com-point (point)))) | |
2311 ((= char ?g) | |
2312 (push-mark vip-com-point t) | |
2313 (vip-global-execute)) | |
2314 ((= char ?q) | |
2315 (push-mark vip-com-point t) | |
2316 (vip-quote-region)) | |
2317 ((= char ?s) (funcall vip-spell-function vip-com-point (point))) | |
2318 (t (error "#%c: %s" char vip-InvalidViCommand)))) | |
2319 | |
2320 | |
2321 ;; undoing | |
2322 | |
2323 (defun vip-undo () | |
2324 "Undo previous change." | |
2325 (interactive) | |
2326 (message "undo!") | |
2327 (let ((modified (buffer-modified-p)) | |
2328 (before-undo-pt (point-marker)) | |
2329 (after-change-functions after-change-functions) | |
2330 undo-beg-posn undo-end-posn) | |
2331 | |
2332 ;; no need to remove this hook, since this var has scope inside a let. | |
2333 (add-hook 'after-change-functions | |
2334 '(lambda (beg end len) | |
2335 (setq undo-beg-posn beg | |
2336 undo-end-posn (or end beg)))) | |
2337 | |
2338 (undo-start) | |
2339 (undo-more 2) | |
2340 (setq undo-beg-posn (or undo-beg-posn before-undo-pt) | |
2341 undo-end-posn (or undo-end-posn undo-beg-posn)) | |
2342 | |
2343 (goto-char undo-beg-posn) | |
2344 (sit-for 0) | |
2345 (if (and vip-keep-point-on-undo | |
2346 (pos-visible-in-window-p before-undo-pt)) | |
2347 (progn | |
2348 (push-mark (point-marker) t) | |
2349 (vip-sit-for-short 300) | |
2350 (goto-char undo-end-posn) | |
2351 (vip-sit-for-short 300) | |
2352 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1) | |
2353 (> (abs (- undo-end-posn before-undo-pt)) 1)) | |
2354 (goto-char before-undo-pt) | |
2355 (goto-char undo-beg-posn))) | |
2356 (push-mark before-undo-pt t)) | |
2357 (if (and (eolp) (not (bolp))) (backward-char 1)) | |
2358 (if (not modified) (set-buffer-modified-p t))) | |
2359 (setq this-command 'vip-undo)) | |
2360 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2361 ;; Continue undoing previous changes. |
10789 | 2362 (defun vip-undo-more () |
2363 (message "undo more!") | |
2364 (condition-case nil | |
2365 (undo-more 1) | |
2366 (error (beep) | |
2367 (message "No further undo information in this buffer"))) | |
2368 (if (and (eolp) (not (bolp))) (backward-char 1)) | |
2369 (setq this-command 'vip-undo)) | |
2370 | |
2371 ;; The following two functions are used to set up undo properly. | |
2372 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, | |
2373 ;; they are undone all at once. | |
2374 (defun vip-adjust-undo () | |
2375 (let ((inhibit-quit t) | |
2376 tmp tmp2) | |
2377 (setq vip-undo-needs-adjustment nil) | |
2378 (if (listp buffer-undo-list) | |
2379 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list)) | |
2380 (progn | |
2381 (setq tmp2 (cdr tmp)) ; the part after mark | |
2382 | |
2383 ;; cut tail from buffer-undo-list temporarily by direct | |
2384 ;; manipulation with pointers in buffer-undo-list | |
2385 (setcdr tmp nil) | |
2386 | |
2387 (setq buffer-undo-list (delq nil buffer-undo-list)) | |
2388 (setq buffer-undo-list | |
2389 (delq vip-buffer-undo-list-mark buffer-undo-list)) | |
2390 ;; restore tail of buffer-undo-list | |
2391 (setq buffer-undo-list (nconc buffer-undo-list tmp2))) | |
2392 (setq buffer-undo-list (delq nil buffer-undo-list)))))) | |
2393 | |
2394 | |
2395 (defun vip-set-complex-command-for-undo () | |
2396 (if (listp buffer-undo-list) | |
2397 (if (not vip-undo-needs-adjustment) | |
2398 (let ((inhibit-quit t)) | |
2399 (setq buffer-undo-list | |
2400 (cons vip-buffer-undo-list-mark buffer-undo-list)) | |
2401 (setq vip-undo-needs-adjustment t))))) | |
2402 | |
2403 | |
2404 | |
2405 | |
2406 (defun vip-display-current-destructive-command () | |
2407 (let ((text (nth 4 vip-d-com)) | |
2408 (keys (nth 5 vip-d-com)) | |
2409 (max-text-len 30)) | |
2410 | |
2411 (setq this-command 'vip-display-current-destructive-command) | |
2412 | |
2413 (message " `.' runs %s%s" | |
2414 (concat "`" (vip-array-to-string keys) "'") | |
2415 (vip-abbreviate-string text max-text-len | |
2416 " inserting `" "'" " .......")) | |
2417 )) | |
2418 | |
2419 | |
2420 ;; don't change vip-d-com if it was vip-repeat command invoked with `.' | |
2421 ;; or in some other way (non-interactively). | |
2422 (defun vip-set-destructive-command (list) | |
2423 (or (eq vip-intermediate-command 'vip-repeat) | |
2424 (progn | |
2425 (setq vip-d-com list) | |
2426 (setcar (nthcdr 5 vip-d-com) | |
2427 (vip-array-to-string (this-command-keys))) | |
2428 (vip-push-onto-ring vip-d-com 'vip-command-ring)))) | |
2429 | |
2430 (defun vip-prev-destructive-command (next) | |
2431 "Find previous destructive command in the history of destructive commands. | |
2432 With prefix argument, find next destructive command." | |
2433 (interactive "P") | |
2434 (let (cmd vip-intermediate-command) | |
2435 (if (eq last-command 'vip-display-current-destructive-command) | |
2436 ;; repeated search through command history | |
2437 (setq vip-intermediate-command 'repeating-display-destructive-command) | |
2438 ;; first search through command history--set temp ring | |
2439 (setq vip-temp-command-ring (copy-list vip-command-ring))) | |
2440 (setq cmd (if next | |
2441 (vip-special-ring-rotate1 vip-temp-command-ring 1) | |
2442 (vip-special-ring-rotate1 vip-temp-command-ring -1))) | |
2443 (if (null cmd) | |
2444 () | |
2445 (setq vip-d-com cmd)) | |
2446 (vip-display-current-destructive-command))) | |
2447 | |
2448 (defun vip-next-destructive-command () | |
2449 "Find next destructive command in the history of destructive commands." | |
2450 (interactive) | |
2451 (vip-prev-destructive-command 'next)) | |
2452 | |
2453 (defun vip-insert-prev-from-insertion-ring (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2454 "Cycle through insertion ring in the direction of older insertions. |
10789 | 2455 Undoes previous insertion and inserts new. |
2456 With prefix argument, cycles in the direction of newer elements. | |
2457 In minibuffer, this command executes whatever the invocation key is bound | |
2458 to in the global map, instead of cycling through the insertion ring." | |
2459 (interactive "P") | |
2460 (let (vip-intermediate-command) | |
2461 (if (eq last-command 'vip-insert-from-insertion-ring) | |
2462 (progn ; repeated search through insertion history | |
2463 (setq vip-intermediate-command 'repeating-insertion-from-ring) | |
2464 (if (eq vip-current-state 'replace-state) | |
2465 (undo 1) | |
2466 (if vip-last-inserted-string-from-insertion-ring | |
2467 (backward-delete-char | |
2468 (length vip-last-inserted-string-from-insertion-ring)))) | |
2469 ) | |
2470 ;;first search through insertion history | |
2471 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring))) | |
2472 (setq this-command 'vip-insert-from-insertion-ring) | |
2473 ;; so that things will be undone properly | |
2474 (setq buffer-undo-list (cons nil buffer-undo-list)) | |
2475 (setq vip-last-inserted-string-from-insertion-ring | |
2476 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1))) | |
2477 | |
2478 ;; this change of vip-intermediate-command must come after | |
2479 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the | |
2480 ;; insertion. | |
2481 (setq vip-intermediate-command nil) | |
2482 (if vip-last-inserted-string-from-insertion-ring | |
2483 (insert vip-last-inserted-string-from-insertion-ring)) | |
2484 )) | |
2485 | |
2486 (defun vip-insert-next-from-insertion-ring () | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2487 "Cycle through insertion ring in the direction of older insertions. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2488 Undo previous insertion and inserts new." |
10789 | 2489 (interactive) |
2490 (vip-insert-prev-from-insertion-ring 'next)) | |
2491 | |
2492 | |
2493 ;; some region utilities | |
2494 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2495 ;; If at the last line of buffer, add \\n before eob, if newline is missing. |
10789 | 2496 (defun vip-add-newline-at-eob-if-necessary () |
2497 (save-excursion | |
2498 (end-of-line) | |
2499 ;; make sure all lines end with newline, unless in the minibuffer or | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
2500 ;; when requested otherwise (require-final-newline is nil) |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2501 (if (and (eobp) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2502 (not (bolp)) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2503 require-final-newline |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2504 (not (vip-is-in-minibuffer)) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2505 (not buffer-read-only)) |
10789 | 2506 (insert "\n")))) |
2507 | |
2508 (defun vip-yank-defun () | |
2509 (mark-defun) | |
2510 (copy-region-as-kill (point) (mark t))) | |
2511 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2512 ;; Enlarge region between BEG and END. |
10789 | 2513 (defun vip-enlarge-region (beg end) |
2514 (or beg (setq beg end)) ; if beg is nil, set to end | |
2515 (or end (setq end beg)) ; if end is nil, set to beg | |
2516 | |
2517 (if (< beg end) | |
2518 (progn (goto-char beg) (set-mark end)) | |
2519 (goto-char end) | |
2520 (set-mark beg)) | |
2521 (beginning-of-line) | |
2522 (exchange-point-and-mark) | |
2523 (if (or (not (eobp)) (not (bolp))) (forward-line 1)) | |
2524 (if (not (eobp)) (beginning-of-line)) | |
2525 (if (> beg end) (exchange-point-and-mark))) | |
2526 | |
2527 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2528 ;; Quote region by each line with a user supplied string. |
10789 | 2529 (defun vip-quote-region () |
2530 (setq vip-quote-string | |
2531 (vip-read-string-with-history | |
2532 "Quote string: " | |
2533 nil | |
2534 'vip-quote-region-history | |
2535 vip-quote-string)) | |
2536 (vip-enlarge-region (point) (mark t)) | |
2537 (if (> (point) (mark t)) (exchange-point-and-mark)) | |
2538 (insert vip-quote-string) | |
2539 (beginning-of-line) | |
2540 (forward-line 1) | |
2541 (while (and (< (point) (mark t)) (bolp)) | |
2542 (insert vip-quote-string) | |
2543 (beginning-of-line) | |
2544 (forward-line 1))) | |
2545 | |
2546 ;; Tells whether BEG is on the same line as END. | |
2547 ;; If one of the args is nil, it'll return nil. | |
2548 (defun vip-same-line (beg end) | |
2549 (let ((selective-display nil)) | |
2550 (cond ((and beg end) | |
2551 ;; This 'if' is needed because Emacs treats the next empty line | |
2552 ;; as part of the previous line. | |
2553 (if (or (> beg (point-max)) (> end (point-max))) ; out of range | |
2554 () | |
2555 (if (and (> end beg) (= (vip-line-pos 'start) end)) | |
2556 (setq end (min (1+ end) (point-max)))) | |
2557 (if (and (> beg end) (= (vip-line-pos 'start) beg)) | |
2558 (setq beg (min (1+ beg) (point-max)))) | |
2559 (<= (count-lines beg end) 1) )) | |
2560 | |
2561 (t nil)) | |
2562 )) | |
2563 | |
2564 | |
2565 ;; Check if the string ends with a newline. | |
2566 (defun vip-end-with-a-newline-p (string) | |
2567 (or (string= string "") | |
2568 (= (vip-seq-last-elt string) ?\n))) | |
2569 | |
2570 (defun vip-tmp-insert-at-eob (msg) | |
2571 (let ((savemax (point-max))) | |
2572 (goto-char savemax) | |
2573 (insert msg) | |
2574 (sit-for 2) | |
2575 (goto-char savemax) (delete-region (point) (point-max)) | |
2576 )) | |
2577 | |
2578 | |
2579 | |
2580 ;;; Minibuffer business | |
2581 | |
2582 (defsubst vip-set-minibuffer-style () | |
2583 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel)) | |
2584 | |
2585 | |
2586 (defun vip-minibuffer-setup-sentinel () | |
2587 (let ((hook (if vip-vi-style-in-minibuffer | |
2588 'vip-change-state-to-insert | |
2589 'vip-change-state-to-emacs))) | |
2590 (funcall hook) | |
2591 )) | |
2592 | |
2593 ;; Interpret last event in the local map | |
2594 (defun vip-exit-minibuffer () | |
2595 (interactive) | |
2596 (let (command) | |
2597 (setq command (local-key-binding (char-to-string last-command-char))) | |
2598 (if command | |
2599 (command-execute command) | |
2600 (exit-minibuffer)))) | |
2601 | |
2602 | |
2603 (defun vip-set-search-face () | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2604 (if (vip-has-face-support-p) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2605 (defvar vip-search-face |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2606 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2607 (make-face 'vip-search-face) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2608 (vip-hide-face 'vip-search-face) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2609 (or (face-differs-from-default-p 'vip-search-face) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2610 ;; face wasn't set in .vip or .Xdefaults |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2611 (if (vip-can-use-colors "Black" "khaki") |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2612 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2613 (set-face-background 'vip-search-face "khaki") |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2614 (set-face-foreground 'vip-search-face "Black")) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
2615 (set-face-underline-p 'vip-search-face t) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
2616 (vip-set-face-pixmap 'vip-search-face vip-search-face-pixmap))) |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2617 'vip-search-face) |
10789 | 2618 "*Face used to flash out the search pattern.") |
2619 )) | |
2620 | |
2621 | |
2622 (defun vip-set-minibuffer-faces () | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2623 (if (not (vip-has-face-support-p)) |
10789 | 2624 () |
2625 (defvar vip-minibuffer-emacs-face | |
2626 (progn | |
2627 (make-face 'vip-minibuffer-emacs-face) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2628 (vip-hide-face 'vip-minibuffer-emacs-face) |
10789 | 2629 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face) |
2630 ;; face wasn't set in .vip or .Xdefaults | |
2631 (if vip-vi-style-in-minibuffer | |
2632 ;; emacs state is an exception in the minibuffer | |
2633 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2634 (progn | |
2635 (set-face-background | |
2636 'vip-minibuffer-emacs-face "darkseagreen2") | |
2637 (set-face-foreground | |
2638 'vip-minibuffer-emacs-face "Black")) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2639 (copy-face 'modeline 'vip-minibuffer-emacs-face)) |
10789 | 2640 ;; emacs state is the main state in the minibuffer |
2641 (if (vip-can-use-colors "Black" "pink") | |
2642 (progn | |
2643 (set-face-background 'vip-minibuffer-emacs-face "pink") | |
2644 (set-face-foreground | |
2645 'vip-minibuffer-emacs-face "Black")) | |
2646 (copy-face 'italic 'vip-minibuffer-emacs-face)) | |
2647 )) | |
2648 'vip-minibuffer-emacs-face) | |
2649 "Face used in the Minibuffer when it is in Emacs state.") | |
2650 | |
2651 (defvar vip-minibuffer-insert-face | |
2652 (progn | |
2653 (make-face 'vip-minibuffer-insert-face) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2654 (vip-hide-face 'vip-minibuffer-insert-face) |
10789 | 2655 (or (face-differs-from-default-p 'vip-minibuffer-insert-face) |
2656 (if vip-vi-style-in-minibuffer | |
2657 (if (vip-can-use-colors "Black" "pink") | |
2658 (progn | |
2659 (set-face-background 'vip-minibuffer-insert-face "pink") | |
2660 (set-face-foreground | |
2661 'vip-minibuffer-insert-face "Black")) | |
2662 (copy-face 'italic 'vip-minibuffer-insert-face)) | |
2663 ;; If Insert state is an exception | |
2664 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2665 (progn | |
2666 (set-face-background | |
2667 'vip-minibuffer-insert-face "darkseagreen2") | |
2668 (set-face-foreground | |
2669 'vip-minibuffer-insert-face "Black")) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2670 (copy-face 'modeline 'vip-minibuffer-insert-face)) |
10789 | 2671 (vip-italicize-face 'vip-minibuffer-insert-face))) |
2672 'vip-minibuffer-insert-face) | |
2673 "Face used in the Minibuffer when it is in Insert state.") | |
2674 | |
2675 (defvar vip-minibuffer-vi-face | |
2676 (progn | |
2677 (make-face 'vip-minibuffer-vi-face) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2678 (vip-hide-face 'vip-minibuffer-vi-face) |
10789 | 2679 (or (face-differs-from-default-p 'vip-minibuffer-vi-face) |
2680 (if vip-vi-style-in-minibuffer | |
2681 (if (vip-can-use-colors "Black" "grey") | |
2682 (progn | |
2683 (set-face-background 'vip-minibuffer-vi-face "grey") | |
2684 (set-face-foreground 'vip-minibuffer-vi-face "Black")) | |
2685 (copy-face 'bold 'vip-minibuffer-vi-face)) | |
2686 (copy-face 'bold 'vip-minibuffer-vi-face) | |
2687 (invert-face 'vip-minibuffer-vi-face))) | |
2688 'vip-minibuffer-vi-face) | |
2689 "Face used in the Minibuffer when it is in Vi state.") | |
2690 | |
2691 ;; the current face used in the minibuffer | |
2692 (vip-deflocalvar vip-minibuffer-current-face vip-minibuffer-emacs-face "") | |
2693 )) | |
2694 | |
2695 | |
2696 | |
2697 ;;; Reading string with history | |
2698 | |
2699 (defun vip-read-string-with-history (prompt &optional initial | |
2700 history-var default keymap) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2701 ;; Read string, prompting with PROMPT and inserting the INITIAL |
10789 | 2702 ;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2703 ;; input is an empty string. Use KEYMAP, if given, or the |
10789 | 2704 ;; minibuffer-local-map. |
2705 ;; Default value is displayed until the user types something in the | |
2706 ;; minibuffer. | |
2707 (let ((minibuffer-setup-hook | |
2708 '(lambda () | |
2709 (if (stringp initial) | |
2710 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
2711 ;; don't wait if we have unread events or in kbd macro |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
2712 (or unread-command-events |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
2713 executing-kbd-macro |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
2714 (sit-for 840)) |
10789 | 2715 (erase-buffer) |
2716 (insert initial))) | |
2717 (vip-minibuffer-setup-sentinel))) | |
2718 (val "") | |
2719 (padding "") | |
2720 temp-msg) | |
2721 | |
2722 (setq keymap (or keymap minibuffer-local-map) | |
2723 initial (or initial "") | |
2724 temp-msg (if default | |
2725 (format "(default: %s) " default) | |
2726 "")) | |
2727 | |
2728 (setq vip-incomplete-ex-cmd nil) | |
2729 (setq val (read-from-minibuffer prompt | |
2730 (concat temp-msg initial val padding) | |
2731 keymap nil history-var)) | |
2732 (setq minibuffer-setup-hook nil | |
2733 padding (vip-array-to-string (this-command-keys)) | |
2734 temp-msg "") | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2735 ;; the following tries to be smart about what to put in history |
10789 | 2736 (if (not (string= val (car (eval history-var)))) |
2737 (set history-var (cons val (eval history-var)))) | |
2738 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) | |
2739 (string= (nth 0 (eval history-var)) "")) | |
2740 (set history-var (cdr (eval history-var)))) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2741 ;; If the user enters nothing but the prev cmd wasn't vip-ex, |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2742 ;; vip-command-argument, or `! shell-command', this probably means |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2743 ;; that the user typed something then erased. Return "" in this case, not |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2744 ;; the default---the default is too confusing in this case. |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2745 (cond ((and (string= val "") |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2746 (not (string= prompt "!")) ; was a `! shell-command' |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2747 (not (memq last-command |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2748 '(vip-ex |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2749 vip-command-argument |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2750 t) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2751 ))) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2752 "") |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2753 ((string= val "") (or default "")) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2754 (t val)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2755 )) |
10789 | 2756 |
2757 | |
2758 | |
2759 ;; insertion commands | |
2760 | |
2761 ;; Called when state changes from Insert Vi command mode. | |
2762 ;; Repeats the insertion command if Insert state was entered with prefix | |
2763 ;; argument > 1. | |
2764 (defun vip-repeat-insert-command () | |
2765 (let ((i-com (car vip-d-com)) | |
2766 (val (nth 1 vip-d-com)) | |
2767 (char (nth 2 vip-d-com))) | |
2768 (if (and val (> val 1)) ; first check that val is non-nil | |
2769 (progn | |
2770 (setq vip-d-com (list i-com (1- val) ?r nil nil nil)) | |
2771 (vip-repeat nil) | |
2772 (setq vip-d-com (list i-com val char nil nil nil)) | |
2773 )))) | |
2774 | |
2775 (defun vip-insert (arg) | |
2776 "Insert before point." | |
2777 (interactive "P") | |
2778 (vip-set-complex-command-for-undo) | |
2779 (let ((val (vip-p-val arg)) | |
2780 (com (vip-getcom arg))) | |
2781 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil)) | |
2782 (if com | |
2783 (vip-loop val (vip-yank-last-insertion)) | |
2784 (vip-change-state-to-insert)))) | |
2785 | |
2786 (defun vip-append (arg) | |
2787 "Append after point." | |
2788 (interactive "P") | |
2789 (vip-set-complex-command-for-undo) | |
2790 (let ((val (vip-p-val arg)) | |
2791 (com (vip-getcom arg))) | |
2792 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil)) | |
2793 (if (not (eolp)) (forward-char)) | |
2794 (if (equal com ?r) | |
2795 (vip-loop val (vip-yank-last-insertion)) | |
2796 (vip-change-state-to-insert)))) | |
2797 | |
2798 (defun vip-Append (arg) | |
2799 "Append at end of line." | |
2800 (interactive "P") | |
2801 (vip-set-complex-command-for-undo) | |
2802 (let ((val (vip-p-val arg)) | |
2803 (com (vip-getcom arg))) | |
2804 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil)) | |
2805 (end-of-line) | |
2806 (if (equal com ?r) | |
2807 (vip-loop val (vip-yank-last-insertion)) | |
2808 (vip-change-state-to-insert)))) | |
2809 | |
2810 (defun vip-Insert (arg) | |
2811 "Insert before first non-white." | |
2812 (interactive "P") | |
2813 (vip-set-complex-command-for-undo) | |
2814 (let ((val (vip-p-val arg)) | |
2815 (com (vip-getcom arg))) | |
2816 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil)) | |
2817 (back-to-indentation) | |
2818 (if (equal com ?r) | |
2819 (vip-loop val (vip-yank-last-insertion)) | |
2820 (vip-change-state-to-insert)))) | |
2821 | |
2822 (defun vip-open-line (arg) | |
2823 "Open line below." | |
2824 (interactive "P") | |
2825 (vip-set-complex-command-for-undo) | |
2826 (let ((val (vip-p-val arg)) | |
2827 (com (vip-getcom arg))) | |
2828 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil)) | |
2829 (let ((col (current-indentation))) | |
2830 (if (equal com ?r) | |
2831 (vip-loop val | |
2832 (progn | |
2833 (end-of-line) | |
2834 (newline 1) | |
2835 (if vip-auto-indent | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2836 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2837 (setq vip-cted t) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2838 (if vip-electric-mode |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2839 (indent-according-to-mode) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2840 (indent-to col)) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2841 )) |
10789 | 2842 (vip-yank-last-insertion))) |
2843 (end-of-line) | |
2844 (newline 1) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2845 (if vip-auto-indent |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2846 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2847 (setq vip-cted t) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2848 (if vip-electric-mode |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2849 (indent-according-to-mode) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2850 (indent-to col)) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2851 )) |
10789 | 2852 (vip-change-state-to-insert) |
2853 )))) | |
2854 | |
2855 (defun vip-Open-line (arg) | |
2856 "Open line above." | |
2857 (interactive "P") | |
2858 (vip-set-complex-command-for-undo) | |
2859 (let ((val (vip-p-val arg)) | |
2860 (com (vip-getcom arg))) | |
2861 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil)) | |
2862 (let ((col (current-indentation))) | |
2863 (if (equal com ?r) | |
2864 (vip-loop val | |
2865 (progn | |
2866 (beginning-of-line) | |
2867 (open-line 1) | |
2868 (if vip-auto-indent | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2869 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2870 (setq vip-cted t) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2871 (if vip-electric-mode |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2872 (indent-according-to-mode) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2873 (indent-to col)) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2874 )) |
10789 | 2875 (vip-yank-last-insertion))) |
2876 (beginning-of-line) | |
2877 (open-line 1) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2878 (if vip-auto-indent |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2879 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2880 (setq vip-cted t) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2881 (if vip-electric-mode |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2882 (indent-according-to-mode) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2883 (indent-to col)) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2884 )) |
10789 | 2885 (vip-change-state-to-insert))))) |
2886 | |
2887 (defun vip-open-line-at-point (arg) | |
2888 "Open line at point." | |
2889 (interactive "P") | |
2890 (vip-set-complex-command-for-undo) | |
2891 (let ((val (vip-p-val arg)) | |
2892 (com (vip-getcom arg))) | |
2893 (vip-set-destructive-command | |
2894 (list 'vip-open-line-at-point val ?r nil nil nil)) | |
2895 (if (equal com ?r) | |
2896 (vip-loop val | |
2897 (progn | |
2898 (open-line 1) | |
2899 (vip-yank-last-insertion))) | |
2900 (open-line 1) | |
2901 (vip-change-state-to-insert)))) | |
2902 | |
2903 (defun vip-substitute (arg) | |
2904 "Substitute characters." | |
2905 (interactive "P") | |
2906 (let ((val (vip-p-val arg)) | |
2907 (com (vip-getcom arg))) | |
2908 (push-mark nil t) | |
2909 (forward-char val) | |
2910 (if (equal com ?r) | |
2911 (vip-change-subr (mark t) (point)) | |
2912 (vip-change (mark t) (point))) | |
2913 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil)) | |
2914 )) | |
2915 | |
2916 (defun vip-substitute-line (arg) | |
2917 "Substitute lines." | |
2918 (interactive "p") | |
2919 (vip-set-complex-command-for-undo) | |
2920 (vip-line (cons arg ?C))) | |
2921 | |
2922 ;; Prepare for replace | |
2923 (defun vip-start-replace () | |
2924 (setq vip-began-as-replace t | |
2925 vip-sitting-in-replace t | |
2926 vip-replace-chars-to-delete 0 | |
2927 vip-replace-chars-deleted 0) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2928 (vip-add-hook 'vip-after-change-functions 'vip-replace-mode-spy-after t) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2929 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t) |
10789 | 2930 ;; this will get added repeatedly, but no harm |
2931 (add-hook 'after-change-functions 'vip-after-change-sentinel t) | |
2932 (add-hook 'before-change-functions 'vip-before-change-sentinel t) | |
2933 (vip-move-marker-locally 'vip-last-posn-in-replace-region | |
2934 (vip-replace-start)) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2935 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2936 'vip-post-command-hooks 'vip-replace-state-post-command-sentinel t) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2937 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2938 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
10789 | 2939 ) |
2940 | |
2941 | |
2942 ;; checks how many chars were deleted by the last change | |
2943 (defun vip-replace-mode-spy-before (beg end) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2944 (setq vip-replace-chars-deleted |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2945 (- end beg |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2946 (max 0 (- end (vip-replace-end))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2947 (max 0 (- (vip-replace-start) beg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2948 ))) |
10789 | 2949 |
2950 ;; Invoked as an after-change-function to set up parameters of the last change | |
2951 (defun vip-replace-mode-spy-after (beg end length) | |
2952 (if (memq vip-intermediate-command '(repeating-insertion-from-ring)) | |
2953 (progn | |
2954 (setq vip-replace-chars-to-delete 0) | |
2955 (vip-move-marker-locally | |
2956 'vip-last-posn-in-replace-region (point))) | |
2957 | |
2958 (let (beg-col end-col real-end chars-to-delete) | |
2959 (setq real-end (min end (vip-replace-end))) | |
2960 (save-excursion | |
2961 (goto-char beg) | |
2962 (setq beg-col (current-column)) | |
2963 (goto-char real-end) | |
2964 (setq end-col (current-column))) | |
2965 | |
2966 ;; If beg of change is outside the replacement region, then don't | |
2967 ;; delete anything in the repl region (set chars-to-delete to 0). | |
2968 ;; | |
2969 ;; This works fine except that we have to take special care of | |
2970 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which | |
2971 ;; sometimes simply shifts the repl region rightwards, without | |
2972 ;; deleting an equal amount of characters. | |
2973 ;; | |
2974 ;; The reason why new-dabbrev.el causes this are this: | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2975 ;; if one dinamically completes a partial word that starts before the |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2976 ;; replacement region (but ends inside) then new-dabbrev.el first |
10789 | 2977 ;; moves cursor backwards, to the beginning of the word to be |
2978 ;; completed (say, pt A). Then it inserts the | |
2979 ;; completed word and then deletes the old, incomplete part. | |
2980 ;; Since the complete word is inserted at position before the repl | |
2981 ;; region, the next If-statement would have set chars-to-delete to 0 | |
2982 ;; unless we check for the current command, which must be | |
2983 ;; dabbrev-expand. | |
2984 ;; | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2985 ;; In fact, it might be also useful to have overlays for insert |
10789 | 2986 ;; regions as well, since this will let us capture the situation when |
2987 ;; dabbrev-expand goes back past the insertion point to find the | |
2988 ;; beginning of the word to be expanded. | |
2989 (if (or (and (<= (vip-replace-start) beg) | |
2990 (<= beg (vip-replace-end))) | |
2991 (and (= length 0) (eq this-command 'dabbrev-expand))) | |
2992 (setq chars-to-delete | |
2993 (max (- end-col beg-col) (- real-end beg) 0)) | |
2994 (setq chars-to-delete 0)) | |
2995 | |
2996 ;; if beg = last change position, it means that we are within the | |
2997 ;; same command that does multiple changes. Moreover, it means | |
2998 ;; that we have two subsequent changes (insert/delete) that | |
2999 ;; complement each other. | |
3000 (if (= beg (marker-position vip-last-posn-in-replace-region)) | |
3001 (setq vip-replace-chars-to-delete | |
3002 (- (+ chars-to-delete vip-replace-chars-to-delete) | |
3003 vip-replace-chars-deleted)) | |
3004 (setq vip-replace-chars-to-delete chars-to-delete)) | |
3005 | |
3006 (vip-move-marker-locally | |
3007 'vip-last-posn-in-replace-region | |
3008 (max (if (> end (vip-replace-end)) (vip-replace-start) end) | |
3009 (or (marker-position vip-last-posn-in-replace-region) | |
3010 (vip-replace-start)) | |
3011 )) | |
3012 | |
3013 (setq vip-replace-chars-to-delete | |
3014 (max 0 (min vip-replace-chars-to-delete | |
3015 (- (vip-replace-end) | |
3016 vip-last-posn-in-replace-region)))) | |
3017 ))) | |
3018 | |
3019 | |
3020 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if | |
3021 ;; posn is within the overlay. | |
3022 (defun vip-finish-change (posn) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3023 (vip-remove-hook 'vip-after-change-functions 'vip-replace-mode-spy-after) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3024 (vip-remove-hook 'vip-before-change-functions 'vip-replace-mode-spy-before) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3025 (vip-remove-hook 'vip-post-command-hooks |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3026 'vip-replace-state-post-command-sentinel) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3027 (vip-remove-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3028 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) |
10789 | 3029 (vip-restore-cursor-color) |
3030 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it | |
3031 (save-excursion | |
3032 (if (and | |
3033 vip-replace-overlay | |
3034 (>= posn (vip-replace-start)) | |
3035 (< posn (vip-replace-end))) | |
3036 (delete-region posn (vip-replace-end))) | |
3037 ) | |
3038 | |
3039 (if (eq vip-current-state 'replace-state) | |
3040 (vip-downgrade-to-insert)) | |
3041 ;; replace mode ended => nullify vip-last-posn-in-replace-region | |
3042 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil) | |
3043 (vip-hide-replace-overlay) | |
3044 (vip-refresh-mode-line) | |
3045 (vip-put-string-on-kill-ring vip-last-replace-region) | |
3046 ) | |
3047 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3048 ;; Make STRING be the first element of the kill ring. |
10789 | 3049 (defun vip-put-string-on-kill-ring (string) |
3050 (setq kill-ring (cons string kill-ring)) | |
3051 (if (> (length kill-ring) kill-ring-max) | |
3052 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) | |
3053 (setq kill-ring-yank-pointer kill-ring)) | |
3054 | |
3055 (defun vip-finish-R-mode () | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3056 (vip-remove-hook 'vip-post-command-hooks 'vip-R-state-post-command-sentinel) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3057 (vip-remove-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3058 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) |
10789 | 3059 (vip-downgrade-to-insert)) |
3060 | |
3061 (defun vip-start-R-mode () | |
3062 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number | |
3063 (overwrite-mode 1) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3064 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3065 'vip-post-command-hooks 'vip-R-state-post-command-sentinel t) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3066 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3067 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
10789 | 3068 ) |
3069 | |
3070 | |
3071 | |
3072 (defun vip-replace-state-exit-cmd () | |
3073 "Binding for keys that cause Replace state to switch to Vi or to Insert. | |
3074 These keys are ESC, RET, and LineFeed" | |
3075 (interactive) | |
3076 (if overwrite-mode ;; If you are in replace mode invoked via 'R' | |
3077 (vip-finish-R-mode) | |
3078 (vip-finish-change vip-last-posn-in-replace-region)) | |
3079 (let (com) | |
3080 (if (eq this-command 'vip-intercept-ESC-key) | |
3081 (setq com 'vip-exit-insert-state) | |
3082 (vip-set-unread-command-events last-input-char) | |
3083 (setq com (key-binding (read-key-sequence nil)))) | |
3084 | |
3085 (condition-case conds | |
3086 (command-execute com) | |
3087 (error | |
3088 (vip-message-conditions conds))) | |
3089 ) | |
3090 (vip-hide-replace-overlay)) | |
3091 | |
3092 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3093 ;; This is the function bound to 'R'---unlimited replace. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3094 ;; Similar to Emacs's own overwrite-mode. |
10789 | 3095 (defun vip-overwrite (arg) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3096 "Begin overwrite mode." |
10789 | 3097 (interactive "P") |
3098 (let ((val (vip-p-val arg)) | |
3099 (com (vip-getcom arg)) (len)) | |
3100 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil)) | |
3101 (if com | |
3102 (progn | |
3103 ;; Viper saves inserted text in vip-last-insertion | |
3104 (setq len (length vip-last-insertion)) | |
3105 (delete-char len) | |
3106 (vip-loop val (vip-yank-last-insertion))) | |
3107 (setq last-command 'vip-overwrite) | |
3108 (vip-set-complex-command-for-undo) | |
3109 (vip-set-replace-overlay (point) (vip-line-pos 'end)) | |
3110 (vip-change-state-to-replace) | |
3111 ))) | |
3112 | |
3113 | |
3114 ;; line commands | |
3115 | |
3116 (defun vip-line (arg) | |
3117 (let ((val (car arg)) | |
3118 (com (cdr arg))) | |
3119 (vip-move-marker-locally 'vip-com-point (point)) | |
3120 (if (not (eobp)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3121 (vip-next-line-carefully (1- val))) |
10789 | 3122 ;; this ensures that dd, cc, D, yy will do the right thing on the last |
3123 ;; line of buffer when this line has no \n. | |
3124 (vip-add-newline-at-eob-if-necessary) | |
3125 (vip-execute-com 'vip-line val com)) | |
3126 (if (and (eobp) (not (bobp))) (forward-line -1)) | |
3127 ) | |
3128 | |
3129 (defun vip-yank-line (arg) | |
3130 "Yank ARG lines (in Vi's sense)." | |
3131 (interactive "P") | |
3132 (let ((val (vip-p-val arg))) | |
3133 (vip-line (cons val ?Y)))) | |
3134 | |
3135 | |
3136 ;; region commands | |
3137 | |
3138 (defun vip-region (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3139 "Execute command on a region." |
10789 | 3140 (interactive "P") |
3141 (let ((val (vip-P-val arg)) | |
3142 (com (vip-getcom arg))) | |
3143 (vip-move-marker-locally 'vip-com-point (point)) | |
3144 (exchange-point-and-mark) | |
3145 (vip-execute-com 'vip-region val com))) | |
3146 | |
3147 (defun vip-Region (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3148 "Execute command on a Region." |
10789 | 3149 (interactive "P") |
3150 (let ((val (vip-P-val arg)) | |
3151 (com (vip-getCom arg))) | |
3152 (vip-move-marker-locally 'vip-com-point (point)) | |
3153 (exchange-point-and-mark) | |
3154 (vip-execute-com 'vip-Region val com))) | |
3155 | |
3156 (defun vip-replace-char (arg) | |
3157 "Replace the following ARG chars by the character read." | |
3158 (interactive "P") | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3159 (if (and (eolp) (bolp)) (error "No character to replace here")) |
10789 | 3160 (let ((val (vip-p-val arg)) |
3161 (com (vip-getcom arg))) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3162 (vip-replace-char-subr com val) |
10789 | 3163 (if (and (eolp) (not (bolp))) (forward-char 1)) |
3164 (vip-set-destructive-command | |
3165 (list 'vip-replace-char val ?r nil vip-d-char nil)) | |
3166 )) | |
3167 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3168 (defun vip-replace-char-subr (com arg) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3169 (let ((take-care-of-iso-accents |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3170 (and (boundp 'iso-accents-mode) vip-automatic-iso-accents)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3171 char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3172 (setq char (if (equal com ?r) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3173 vip-d-char |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3174 (read-char))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3175 (if (and take-care-of-iso-accents (memq char '(?' ?\" ?^ ?~))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3176 ;; get European characters |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3177 (progn |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3178 (iso-accents-mode 1) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3179 (vip-set-unread-command-events char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3180 (setq char (aref (read-key-sequence nil) 0)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3181 (iso-accents-mode -1))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3182 (delete-char arg t) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3183 (setq vip-d-char char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3184 (vip-loop (if (> arg 0) arg (- arg)) |
10789 | 3185 (if (eq char ?\C-m) (insert "\n") (insert char))) |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3186 (backward-char arg))) |
10789 | 3187 |
3188 | |
3189 ;; basic cursor movement. j, k, l, h commands. | |
3190 | |
3191 (defun vip-forward-char (arg) | |
3192 "Move point right ARG characters (left if ARG negative). | |
3193 On reaching end of line, stop and signal error." | |
3194 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3195 (vip-leave-region-active) |
10789 | 3196 (let ((val (vip-p-val arg)) |
3197 (com (vip-getcom arg))) | |
3198 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3199 (if vip-ex-style-motion | |
3200 (progn | |
3201 ;; the boundary condition check gets weird here because | |
3202 ;; forward-char may be the parameter of a delete, and 'dl' works | |
3203 ;; just like 'x' for the last char on a line, so we have to allow | |
3204 ;; the forward motion before the 'vip-execute-com', but, of | |
3205 ;; course, 'dl' doesn't work on an empty line, so we have to | |
3206 ;; catch that condition before 'vip-execute-com' | |
3207 (if (and (eolp) (bolp)) (error "") (forward-char val)) | |
3208 (if com (vip-execute-com 'vip-forward-char val com)) | |
3209 (if (eolp) (progn (backward-char 1) (error "")))) | |
3210 (forward-char val) | |
3211 (if com (vip-execute-com 'vip-forward-char val com))))) | |
3212 | |
3213 (defun vip-backward-char (arg) | |
3214 "Move point left ARG characters (right if ARG negative). | |
3215 On reaching beginning of line, stop and signal error." | |
3216 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3217 (vip-leave-region-active) |
10789 | 3218 (let ((val (vip-p-val arg)) |
3219 (com (vip-getcom arg))) | |
3220 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3221 (if vip-ex-style-motion | |
3222 (progn | |
3223 (if (bolp) (error "") (backward-char val)) | |
3224 (if com (vip-execute-com 'vip-backward-char val com))) | |
3225 (backward-char val) | |
3226 (if com (vip-execute-com 'vip-backward-char val com))))) | |
3227 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3228 ;; Like forward-char, but doesn't move at end of buffer. |
10789 | 3229 (defun vip-forward-char-carefully (&optional arg) |
3230 (setq arg (or arg 1)) | |
3231 (if (>= (point-max) (+ (point) arg)) | |
3232 (forward-char arg) | |
3233 (goto-char (point-max)))) | |
3234 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3235 ;; Like backward-char, but doesn't move at end of buffer. |
10789 | 3236 (defun vip-backward-char-carefully (&optional arg) |
3237 (setq arg (or arg 1)) | |
3238 (if (<= (point-min) (- (point) arg)) | |
3239 (backward-char arg) | |
3240 (goto-char (point-min)))) | |
3241 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3242 (defun vip-next-line-carefully (arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3243 (condition-case nil |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3244 (next-line arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3245 (error nil))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3246 |
10789 | 3247 |
3248 | |
3249 ;;; Word command | |
3250 | |
3251 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators | |
3252 ;; for word movement. When executed with a destructive command, \n is | |
3253 ;; usually left untouched for the last word. | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3254 ;; Viper uses syntax table to determine what is a word and what is a |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3255 ;; separator. However, \n is always a separator. Also, if vip-syntax-preference |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3256 ;; is 'vi, then `_' is part of the word. |
10789 | 3257 |
3258 ;; skip only one \n | |
3259 (defun vip-skip-separators (forward) | |
3260 (if forward | |
3261 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3262 (vip-skip-all-separators-forward 'within-line) |
10789 | 3263 (if (looking-at "\n") |
3264 (progn | |
3265 (forward-char) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3266 (vip-skip-all-separators-forward 'within-line)))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3267 (vip-skip-all-separators-backward 'within-line) |
10789 | 3268 (backward-char) |
3269 (if (looking-at "\n") | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3270 (vip-skip-all-separators-backward 'within-line) |
10789 | 3271 (forward-char)))) |
3272 | |
3273 (defun vip-forward-word-kernel (val) | |
3274 (while (> val 0) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3275 (cond ((vip-looking-at-alpha) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3276 (vip-skip-alpha-forward "_") |
10789 | 3277 (vip-skip-separators t)) |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3278 ((vip-looking-at-separator) |
10789 | 3279 (vip-skip-separators t)) |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3280 ((not (vip-looking-at-alphasep)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3281 (vip-skip-nonalphasep-forward) |
10789 | 3282 (vip-skip-separators t))) |
3283 (setq val (1- val)))) | |
3284 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3285 ;; first search backward for pat. Then skip chars backwards using aux-pat |
10789 | 3286 (defun vip-fwd-skip (pat aux-pat lim) |
3287 (if (and (save-excursion | |
3288 (re-search-backward pat lim t)) | |
3289 (= (point) (match-end 0))) | |
3290 (goto-char (match-beginning 0))) | |
3291 (skip-chars-backward aux-pat lim) | |
3292 (if (= (point) lim) | |
3293 (vip-forward-char-carefully)) | |
3294 ) | |
3295 | |
3296 | |
3297 (defun vip-forward-word (arg) | |
3298 "Forward word." | |
3299 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3300 (vip-leave-region-active) |
10789 | 3301 (let ((val (vip-p-val arg)) |
3302 (com (vip-getcom arg))) | |
3303 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3304 (vip-forward-word-kernel val) | |
3305 (if com (progn | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3306 (cond ((memq com (list ?c (- ?c))) |
10789 | 3307 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3308 ;; Yank words including the whitespace, but not newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3309 ((memq com (list ?y (- ?y))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3310 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) |
10789 | 3311 ((vip-dotable-command-p com) |
3312 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | |
3313 (vip-execute-com 'vip-forward-word val com))))) | |
3314 | |
3315 | |
3316 (defun vip-forward-Word (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3317 "Forward word delimited by white characters." |
10789 | 3318 (interactive "P") |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3319 (vip-leave-region-active) |
10789 | 3320 (let ((val (vip-p-val arg)) |
3321 (com (vip-getcom arg))) | |
3322 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3323 (vip-loop val | |
3324 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3325 (vip-skip-nonseparators 'forward) |
10789 | 3326 (vip-skip-separators t))) |
3327 (if com (progn | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3328 (cond ((memq com (list ?c (- ?c))) |
10789 | 3329 (vip-fwd-skip "\n[ \t]*" " \t" vip-com-point)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3330 ;; Yank words including the whitespace, but not newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3331 ((memq com (list ?y (- ?y))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3332 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) |
10789 | 3333 ((vip-dotable-command-p com) |
3334 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | |
3335 (vip-execute-com 'vip-forward-Word val com))))) | |
3336 | |
3337 | |
3338 ;; this is a bit different from Vi, but Vi's end of word | |
3339 ;; makes no sense whatsoever | |
3340 (defun vip-end-of-word-kernel () | |
3341 (if (vip-end-of-word-p) (forward-char)) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3342 (if (vip-looking-at-separator) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3343 (vip-skip-all-separators-forward)) |
10789 | 3344 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3345 (cond ((vip-looking-at-alpha) (vip-skip-alpha-forward "_")) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3346 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward))) |
10789 | 3347 (vip-backward-char-carefully)) |
3348 | |
3349 (defun vip-end-of-word-p () | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3350 (or (eobp) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3351 (save-excursion |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3352 (cond ((vip-looking-at-alpha) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3353 (forward-char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3354 (not (vip-looking-at-alpha))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3355 ((not (vip-looking-at-alphasep)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3356 (forward-char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3357 (vip-looking-at-alphasep)))))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3358 |
10789 | 3359 |
3360 (defun vip-end-of-word (arg &optional careful) | |
3361 "Move point to end of current word." | |
3362 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3363 (vip-leave-region-active) |
10789 | 3364 (let ((val (vip-p-val arg)) |
3365 (com (vip-getcom arg))) | |
3366 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3367 (vip-loop val (vip-end-of-word-kernel)) | |
3368 (if com | |
3369 (progn | |
3370 (forward-char) | |
3371 (vip-execute-com 'vip-end-of-word val com))))) | |
3372 | |
3373 (defun vip-end-of-Word (arg) | |
3374 "Forward to end of word delimited by white character." | |
3375 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3376 (vip-leave-region-active) |
10789 | 3377 (let ((val (vip-p-val arg)) |
3378 (com (vip-getcom arg))) | |
3379 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3380 (vip-loop val | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3381 (progn |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3382 (vip-end-of-word-kernel) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3383 (vip-skip-nonseparators 'forward) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3384 (backward-char))) |
10789 | 3385 (if com |
3386 (progn | |
3387 (forward-char) | |
3388 (vip-execute-com 'vip-end-of-Word val com))))) | |
3389 | |
3390 (defun vip-backward-word-kernel (val) | |
3391 (while (> val 0) | |
3392 (backward-char) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3393 (cond ((vip-looking-at-alpha) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3394 (vip-skip-alpha-backward "_")) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3395 ((vip-looking-at-separator) |
10789 | 3396 (forward-char) |
3397 (vip-skip-separators nil) | |
3398 (backward-char) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3399 (cond ((vip-looking-at-alpha) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3400 (vip-skip-alpha-backward "_")) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3401 ((not (vip-looking-at-alphasep)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3402 (vip-skip-nonalphasep-backward)) |
10789 | 3403 (t (forward-char)))) |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3404 ((not (vip-looking-at-alphasep)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3405 (vip-skip-nonalphasep-backward))) |
10789 | 3406 (setq val (1- val)))) |
3407 | |
3408 (defun vip-backward-word (arg) | |
3409 "Backward word." | |
3410 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3411 (vip-leave-region-active) |
10789 | 3412 (let ((val (vip-p-val arg)) |
3413 (com (vip-getcom arg))) | |
3414 (if com | |
3415 (let (i) | |
3416 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
3417 (backward-char)) | |
3418 (vip-move-marker-locally 'vip-com-point (point)) | |
3419 (if i (forward-char)))) | |
3420 (vip-backward-word-kernel val) | |
3421 (if com (vip-execute-com 'vip-backward-word val com)))) | |
3422 | |
3423 (defun vip-backward-Word (arg) | |
3424 "Backward word delimited by white character." | |
3425 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3426 (vip-leave-region-active) |
10789 | 3427 (let ((val (vip-p-val arg)) |
3428 (com (vip-getcom arg))) | |
3429 (if com | |
3430 (let (i) | |
3431 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
3432 (backward-char)) | |
3433 (vip-move-marker-locally 'vip-com-point (point)) | |
3434 (if i (forward-char)))) | |
3435 (vip-loop val | |
3436 (progn | |
3437 (vip-skip-separators nil) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3438 (vip-skip-nonseparators 'backward))) |
10789 | 3439 (if com (vip-execute-com 'vip-backward-Word val com)))) |
3440 | |
3441 | |
3442 | |
3443 ;; line commands | |
3444 | |
3445 (defun vip-beginning-of-line (arg) | |
3446 "Go to beginning of line." | |
3447 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3448 (vip-leave-region-active) |
10789 | 3449 (let ((val (vip-p-val arg)) |
3450 (com (vip-getcom arg))) | |
3451 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3452 (beginning-of-line val) | |
3453 (if com (vip-execute-com 'vip-beginning-of-line val com)))) | |
3454 | |
3455 (defun vip-bol-and-skip-white (arg) | |
3456 "Beginning of line at first non-white character." | |
3457 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3458 (vip-leave-region-active) |
10789 | 3459 (let ((val (vip-p-val arg)) |
3460 (com (vip-getcom arg))) | |
3461 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3462 (forward-to-indentation (1- val)) | |
3463 (if com (vip-execute-com 'vip-bol-and-skip-white val com)))) | |
3464 | |
3465 (defun vip-goto-eol (arg) | |
3466 "Go to end of line." | |
3467 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3468 (vip-leave-region-active) |
10789 | 3469 (let ((val (vip-p-val arg)) |
3470 (com (vip-getcom arg))) | |
3471 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3472 (end-of-line val) | |
3473 (if com (vip-execute-com 'vip-goto-eol val com)) | |
3474 (if vip-ex-style-motion | |
3475 (if (and (eolp) (not (bolp)) | |
3476 ;; a fix for vip-change-to-eol | |
3477 (not (equal vip-current-state 'insert-state))) | |
3478 (backward-char 1) | |
3479 )))) | |
3480 | |
3481 | |
3482 (defun vip-goto-col (arg) | |
3483 "Go to ARG's column." | |
3484 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3485 (vip-leave-region-active) |
10789 | 3486 (let ((val (vip-p-val arg)) |
3487 (com (vip-getcom arg))) | |
3488 (save-excursion | |
3489 (end-of-line) | |
3490 (if (> val (1+ (current-column))) (error ""))) | |
3491 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3492 (beginning-of-line) | |
3493 (forward-char (1- val)) | |
3494 (if com (vip-execute-com 'vip-goto-col val com)))) | |
3495 | |
3496 | |
3497 (defun vip-next-line (arg) | |
3498 "Go to next line." | |
3499 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3500 (vip-leave-region-active) |
10789 | 3501 (let ((val (vip-p-val arg)) |
3502 (com (vip-getCom arg))) | |
3503 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3504 (next-line val) | |
3505 (if vip-ex-style-motion | |
3506 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
3507 (setq this-command 'next-line) | |
3508 (if com (vip-execute-com 'vip-next-line val com)))) | |
3509 | |
3510 (defun vip-next-line-at-bol (arg) | |
3511 "Next line at beginning of line." | |
3512 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3513 (vip-leave-region-active) |
10789 | 3514 (save-excursion |
3515 (end-of-line) | |
3516 (if (eobp) (error "Last line in buffer"))) | |
3517 (let ((val (vip-p-val arg)) | |
3518 (com (vip-getCom arg))) | |
3519 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3520 (forward-line val) | |
3521 (back-to-indentation) | |
3522 (if com (vip-execute-com 'vip-next-line-at-bol val com)))) | |
3523 | |
3524 (defun vip-previous-line (arg) | |
3525 "Go to previous line." | |
3526 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3527 (vip-leave-region-active) |
10789 | 3528 (let ((val (vip-p-val arg)) |
3529 (com (vip-getCom arg))) | |
3530 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3531 (previous-line val) | |
3532 (if vip-ex-style-motion | |
3533 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
3534 (setq this-command 'previous-line) | |
3535 (if com (vip-execute-com 'vip-previous-line val com)))) | |
3536 | |
3537 | |
3538 (defun vip-previous-line-at-bol (arg) | |
3539 "Previous line at beginning of line." | |
3540 (interactive "P") | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
3541 (vip-leave-region-active) |
10789 | 3542 (save-excursion |
3543 (beginning-of-line) | |
3544 (if (bobp) (error "First line in buffer"))) | |
3545 (let ((val (vip-p-val arg)) | |
3546 (com (vip-getCom arg))) | |
3547 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3548 (forward-line (- val)) | |
3549 (back-to-indentation) | |
3550 (if com (vip-execute-com 'vip-previous-line val com)))) | |
3551 | |
3552 (defun vip-change-to-eol (arg) | |
3553 "Change to end of line." | |
3554 (interactive "P") | |
3555 (vip-goto-eol (cons arg ?c))) | |
3556 | |
3557 (defun vip-kill-line (arg) | |
3558 "Delete line." | |
3559 (interactive "P") | |
3560 (vip-goto-eol (cons arg ?d))) | |
3561 | |
3562 (defun vip-erase-line (arg) | |
3563 "Erase line." | |
3564 (interactive "P") | |
3565 (vip-beginning-of-line (cons arg ?d))) | |
3566 | |
3567 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3568 ;;; Moving around |
10789 | 3569 |
3570 (defun vip-goto-line (arg) | |
3571 "Go to ARG's line. Without ARG go to end of buffer." | |
3572 (interactive "P") | |
3573 (let ((val (vip-P-val arg)) | |
3574 (com (vip-getCom arg))) | |
3575 (vip-move-marker-locally 'vip-com-point (point)) | |
3576 (vip-deactivate-mark) | |
3577 (push-mark nil t) | |
3578 (if (null val) | |
3579 (goto-char (point-max)) | |
3580 (goto-char (point-min)) | |
3581 (forward-line (1- val))) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3582 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3583 ;; positioning is done twice: before and after command execution |
10789 | 3584 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
3585 (back-to-indentation) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3586 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3587 (if com (vip-execute-com 'vip-goto-line val com)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3588 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3589 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3590 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3591 )) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3592 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3593 ;; Find ARG's occurrence of CHAR on the current line. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3594 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3595 ;; adjust point after search. |
10789 | 3596 (defun vip-find-char (arg char forward offset) |
3597 (or (char-or-string-p char) (error "")) | |
3598 (let ((arg (if forward arg (- arg))) | |
3599 (cmd (if (eq vip-intermediate-command 'vip-repeat) | |
3600 (nth 5 vip-d-com) | |
3601 (vip-array-to-string (this-command-keys)))) | |
3602 point) | |
3603 (save-excursion | |
3604 (save-restriction | |
3605 (if (> arg 0) | |
3606 (narrow-to-region | |
3607 ;; forward search begins here | |
3608 (if (eolp) (error "Command `%s': At end of line" cmd) (point)) | |
3609 ;; forward search ends here | |
3610 (progn (end-of-line) (point))) | |
3611 (narrow-to-region | |
3612 ;; backward search begins from here | |
3613 (if (bolp) | |
3614 (error "Command `%s': At beginning of line" cmd) (point)) | |
3615 ;; backward search ends here | |
3616 (progn (beginning-of-line) (point)))) | |
3617 ;; if arg > 0, point is forwarded before search. | |
3618 (if (> arg 0) (goto-char (1+ (point-min))) | |
3619 (goto-char (point-max))) | |
3620 (if (let ((case-fold-search nil)) | |
3621 (search-forward (char-to-string char) nil 0 arg)) | |
3622 (setq point (point)) | |
3623 (error "Command `%s': `%c' not found" cmd char)))) | |
3624 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) | |
3625 | |
3626 (defun vip-find-char-forward (arg) | |
3627 "Find char on the line. | |
3628 If called interactively read the char to find from the terminal, and if | |
3629 called from vip-repeat, the char last used is used. This behaviour is | |
3630 controlled by the sign of prefix numeric value." | |
3631 (interactive "P") | |
3632 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3633 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3634 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3635 (if (> val 0) |
3636 ;; this means that the function was called interactively | |
3637 (setq vip-f-char (read-char) | |
3638 vip-f-forward t | |
3639 vip-f-offset nil) | |
3640 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3641 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3642 (vip-seq-last-elt cmd-representation) |
10789 | 3643 vip-F-char) |
3644 vip-f-char vip-F-char) | |
3645 (setq val (- val))) | |
3646 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3647 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil) | |
3648 (setq val (- val)) | |
3649 (if com | |
3650 (progn | |
3651 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3652 (forward-char) | |
3653 (vip-execute-com 'vip-find-char-forward val com))))) | |
3654 | |
3655 (defun vip-goto-char-forward (arg) | |
3656 "Go up to char ARG forward on line." | |
3657 (interactive "P") | |
3658 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3659 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3660 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3661 (if (> val 0) |
3662 ;; this means that the function was called interactively | |
3663 (setq vip-f-char (read-char) | |
3664 vip-f-forward t | |
3665 vip-f-offset t) | |
3666 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3667 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3668 (vip-seq-last-elt cmd-representation) |
10789 | 3669 vip-F-char) |
3670 vip-f-char vip-F-char) | |
3671 (setq val (- val))) | |
3672 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3673 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t) | |
3674 (setq val (- val)) | |
3675 (if com | |
3676 (progn | |
3677 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3678 (forward-char) | |
3679 (vip-execute-com 'vip-goto-char-forward val com))))) | |
3680 | |
3681 (defun vip-find-char-backward (arg) | |
3682 "Find char ARG on line backward." | |
3683 (interactive "P") | |
3684 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3685 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3686 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3687 (if (> val 0) |
3688 ;; this means that the function was called interactively | |
3689 (setq vip-f-char (read-char) | |
3690 vip-f-forward nil | |
3691 vip-f-offset nil) | |
3692 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3693 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3694 (vip-seq-last-elt cmd-representation) |
10789 | 3695 vip-F-char) |
3696 vip-f-char vip-F-char) | |
3697 (setq val (- val))) | |
3698 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3699 (vip-find-char | |
3700 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil) | |
3701 (setq val (- val)) | |
3702 (if com | |
3703 (progn | |
3704 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3705 (vip-execute-com 'vip-find-char-backward val com))))) | |
3706 | |
3707 (defun vip-goto-char-backward (arg) | |
3708 "Go up to char ARG backward on line." | |
3709 (interactive "P") | |
3710 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3711 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3712 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3713 (if (> val 0) |
3714 ;; this means that the function was called interactively | |
3715 (setq vip-f-char (read-char) | |
3716 vip-f-forward nil | |
3717 vip-f-offset t) | |
3718 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3719 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3720 (vip-seq-last-elt cmd-representation) |
10789 | 3721 vip-F-char) |
3722 vip-f-char vip-F-char) | |
3723 (setq val (- val))) | |
3724 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3725 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t) | |
3726 (setq val (- val)) | |
3727 (if com | |
3728 (progn | |
3729 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3730 (vip-execute-com 'vip-goto-char-backward val com))))) | |
3731 | |
3732 (defun vip-repeat-find (arg) | |
3733 "Repeat previous find command." | |
3734 (interactive "P") | |
3735 (let ((val (vip-p-val arg)) | |
3736 (com (vip-getcom arg))) | |
3737 (vip-deactivate-mark) | |
3738 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3739 (vip-find-char val vip-f-char vip-f-forward vip-f-offset) | |
3740 (if com | |
3741 (progn | |
3742 (if vip-f-forward (forward-char)) | |
3743 (vip-execute-com 'vip-repeat-find val com))))) | |
3744 | |
3745 (defun vip-repeat-find-opposite (arg) | |
3746 "Repeat previous find command in the opposite direction." | |
3747 (interactive "P") | |
3748 (let ((val (vip-p-val arg)) | |
3749 (com (vip-getcom arg))) | |
3750 (vip-deactivate-mark) | |
3751 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3752 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset) | |
3753 (if com | |
3754 (progn | |
3755 (if vip-f-forward (forward-char)) | |
3756 (vip-execute-com 'vip-repeat-find-opposite val com))))) | |
3757 | |
3758 | |
3759 ;; window scrolling etc. | |
3760 | |
3761 (defun vip-other-window (arg) | |
3762 "Switch to other window." | |
3763 (interactive "p") | |
3764 (other-window arg) | |
3765 (or (not (eq vip-current-state 'emacs-state)) | |
3766 (string= (buffer-name (current-buffer)) " *Minibuf-1*") | |
3767 (vip-change-state-to-vi))) | |
3768 | |
3769 (defun vip-window-top (arg) | |
3770 "Go to home window line." | |
3771 (interactive "P") | |
3772 (let ((val (vip-p-val arg)) | |
3773 (com (vip-getCom arg))) | |
3774 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3775 (push-mark nil t) | |
3776 (move-to-window-line (1- val)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3777 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3778 ;; positioning is done twice: before and after command execution |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3779 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3780 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3781 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3782 (if com (vip-execute-com 'vip-window-top val com)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3783 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3784 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3785 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3786 )) |
10789 | 3787 |
3788 (defun vip-window-middle (arg) | |
3789 "Go to middle window line." | |
3790 (interactive "P") | |
3791 (let ((val (vip-p-val arg)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3792 (com (vip-getCom arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3793 lines) |
10789 | 3794 (if com (vip-move-marker-locally 'vip-com-point (point))) |
3795 (push-mark nil t) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3796 (if (not (pos-visible-in-window-p (point-max))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3797 (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3798 (setq lines (count-lines (window-start) (point-max))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3799 (move-to-window-line (+ (/ lines 2) (1- val)))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3800 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3801 ;; positioning is done twice: before and after command execution |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3802 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3803 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3804 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3805 (if com (vip-execute-com 'vip-window-middle val com)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3806 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3807 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3808 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3809 )) |
10789 | 3810 |
3811 (defun vip-window-bottom (arg) | |
3812 "Go to last window line." | |
3813 (interactive "P") | |
3814 (let ((val (vip-p-val arg)) | |
3815 (com (vip-getCom arg))) | |
3816 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3817 (push-mark nil t) | |
3818 (move-to-window-line (- val)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3819 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3820 ;; positioning is done twice: before and after command execution |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3821 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3822 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3823 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3824 (if com (vip-execute-com 'vip-window-bottom val com)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3825 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3826 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3827 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3828 )) |
10789 | 3829 |
3830 (defun vip-line-to-top (arg) | |
3831 "Put current line on the home line." | |
3832 (interactive "p") | |
3833 (recenter (1- arg))) | |
3834 | |
3835 (defun vip-line-to-middle (arg) | |
3836 "Put current line on the middle line." | |
3837 (interactive "p") | |
3838 (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) | |
3839 | |
3840 (defun vip-line-to-bottom (arg) | |
3841 "Put current line on the last line." | |
3842 (interactive "p") | |
3843 (recenter (- (window-height) (1+ arg)))) | |
3844 | |
3845 | |
3846 ;; paren match | |
3847 ;; must correct this to only match ( to ) etc. On the other hand | |
3848 ;; it is good that paren match gets confused, because that way you | |
3849 ;; catch _all_ imbalances. | |
3850 | |
3851 (defun vip-paren-match (arg) | |
3852 "Go to the matching parenthesis." | |
3853 (interactive "P") | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3854 (let ((com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3855 anchor-point) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3856 (if (integerp arg) |
10789 | 3857 (if (or (> arg 99) (< arg 1)) |
3858 (error "Prefix must be between 1 and 99") | |
3859 (goto-char | |
3860 (if (> (point-max) 80000) | |
3861 (* (/ (point-max) 100) arg) | |
3862 (/ (* (point-max) arg) 100))) | |
3863 (back-to-indentation)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3864 (let (beg-lim end-lim) |
10789 | 3865 (if (and (eolp) (not (bolp))) (forward-char -1)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3866 (if (not (looking-at "[][(){}]")) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3867 (setq anchor-point (point))) |
10789 | 3868 (save-excursion |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3869 (beginning-of-line) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3870 (setq beg-lim (point)) |
10789 | 3871 (end-of-line) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3872 (setq end-lim (point))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3873 (cond ((re-search-forward "[][(){}]" end-lim t) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3874 (backward-char) ) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3875 ((re-search-backward "[][(){}]" beg-lim t)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3876 (t |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3877 (error "No matching character on line")))) |
10789 | 3878 (cond ((looking-at "[\(\[{]") |
3879 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3880 (forward-sexp 1) | |
3881 (if com | |
3882 (vip-execute-com 'vip-paren-match nil com) | |
3883 (backward-char))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3884 (anchor-point |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3885 (if com |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3886 (progn |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3887 (vip-move-marker-locally 'vip-com-point anchor-point) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3888 (forward-char 1) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3889 (vip-execute-com 'vip-paren-match nil com) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3890 ))) |
10789 | 3891 ((looking-at "[])}]") |
3892 (forward-char) | |
3893 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3894 (backward-sexp 1) | |
3895 (if com (vip-execute-com 'vip-paren-match nil com))) | |
3896 (t (error "")))))) | |
3897 | |
3898 | |
3899 ;; sentence ,paragraph and heading | |
3900 | |
3901 (defun vip-forward-sentence (arg) | |
3902 "Forward sentence." | |
3903 (interactive "P") | |
3904 (push-mark nil t) | |
3905 (let ((val (vip-p-val arg)) | |
3906 (com (vip-getcom arg))) | |
3907 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3908 (forward-sentence val) | |
3909 (if com (vip-execute-com 'vip-forward-sentence nil com)))) | |
3910 | |
3911 (defun vip-backward-sentence (arg) | |
3912 "Backward sentence." | |
3913 (interactive "P") | |
3914 (push-mark nil t) | |
3915 (let ((val (vip-p-val arg)) | |
3916 (com (vip-getcom arg))) | |
3917 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3918 (backward-sentence val) | |
3919 (if com (vip-execute-com 'vip-backward-sentence nil com)))) | |
3920 | |
3921 (defun vip-forward-paragraph (arg) | |
3922 "Forward paragraph." | |
3923 (interactive "P") | |
3924 (push-mark nil t) | |
3925 (let ((val (vip-p-val arg)) | |
3926 (com (vip-getCom arg))) | |
3927 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3928 (forward-paragraph val) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3929 (if com |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3930 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3931 (backward-char 1) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3932 (vip-execute-com 'vip-forward-paragraph nil com))))) |
10789 | 3933 |
3934 (defun vip-backward-paragraph (arg) | |
3935 "Backward paragraph." | |
3936 (interactive "P") | |
3937 (push-mark nil t) | |
3938 (let ((val (vip-p-val arg)) | |
3939 (com (vip-getCom arg))) | |
3940 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3941 (backward-paragraph val) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3942 (if com |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3943 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3944 (forward-char 1) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3945 (vip-execute-com 'vip-backward-paragraph nil com) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3946 (backward-char 1))))) |
10789 | 3947 |
3948 ;; should be mode-specific etc. | |
3949 | |
3950 (defun vip-prev-heading (arg) | |
3951 (interactive "P") | |
3952 (let ((val (vip-p-val arg)) | |
3953 (com (vip-getCom arg))) | |
3954 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3955 (re-search-backward vip-heading-start nil t val) | |
3956 (goto-char (match-beginning 0)) | |
3957 (if com (vip-execute-com 'vip-prev-heading nil com)))) | |
3958 | |
3959 (defun vip-heading-end (arg) | |
3960 (interactive "P") | |
3961 (let ((val (vip-p-val arg)) | |
3962 (com (vip-getCom arg))) | |
3963 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3964 (re-search-forward vip-heading-end nil t val) | |
3965 (goto-char (match-beginning 0)) | |
3966 (if com (vip-execute-com 'vip-heading-end nil com)))) | |
3967 | |
3968 (defun vip-next-heading (arg) | |
3969 (interactive "P") | |
3970 (let ((val (vip-p-val arg)) | |
3971 (com (vip-getCom arg))) | |
3972 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3973 (end-of-line) | |
3974 (re-search-forward vip-heading-start nil t val) | |
3975 (goto-char (match-beginning 0)) | |
3976 (if com (vip-execute-com 'vip-next-heading nil com)))) | |
3977 | |
3978 | |
3979 ;; scrolling | |
3980 | |
3981 (setq scroll-step 1) | |
3982 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3983 (defun vip-scroll-screen (arg) |
10789 | 3984 "Scroll to next screen." |
3985 (interactive "p") | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3986 (condition-case nil |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3987 (if (> arg 0) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3988 (while (> arg 0) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3989 (scroll-up) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3990 (setq arg (1- arg))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3991 (while (> 0 arg) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3992 (scroll-down) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3993 (setq arg (1+ arg)))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3994 (error (beep 1) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3995 (if (> arg 0) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3996 (progn |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3997 (message "End of buffer") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3998 (goto-char (point-max))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3999 (message "Beginning of buffer") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4000 (goto-char (point-min)))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4001 )) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4002 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4003 (defun vip-scroll-screen-back (arg) |
10789 | 4004 "Scroll to previous screen." |
4005 (interactive "p") | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4006 (vip-scroll-screen (- arg))) |
10789 | 4007 |
4008 (defun vip-scroll-down (arg) | |
4009 "Pull down half screen." | |
4010 (interactive "P") | |
4011 (condition-case nil | |
4012 (if (null arg) | |
4013 (scroll-down (/ (window-height) 2)) | |
4014 (scroll-down arg)) | |
4015 (error (beep 1) | |
4016 (message "Beginning of buffer") | |
4017 (goto-char (point-min))))) | |
4018 | |
4019 (defun vip-scroll-down-one (arg) | |
4020 "Scroll up one line." | |
4021 (interactive "p") | |
4022 (scroll-down arg)) | |
4023 | |
4024 (defun vip-scroll-up (arg) | |
4025 "Pull up half screen." | |
4026 (interactive "P") | |
4027 (condition-case nil | |
4028 (if (null arg) | |
4029 (scroll-up (/ (window-height) 2)) | |
4030 (scroll-up arg)) | |
4031 (error (beep 1) | |
4032 (message "End of buffer") | |
4033 (goto-char (point-max))))) | |
4034 | |
4035 (defun vip-scroll-up-one (arg) | |
4036 "Scroll down one line." | |
4037 (interactive "p") | |
4038 (scroll-up arg)) | |
4039 | |
4040 | |
4041 ;; searching | |
4042 | |
4043 (defun vip-if-string (prompt) | |
4044 (let ((s (vip-read-string-with-history | |
4045 prompt | |
4046 nil ; no initial | |
4047 'vip-search-history | |
4048 (car vip-search-history)))) | |
4049 (if (not (string= s "")) | |
4050 (setq vip-s-string s)))) | |
4051 | |
4052 | |
4053 (defun vip-toggle-search-style (arg) | |
4054 "Toggle the value of vip-case-fold-search/vip-re-search. | |
4055 Without prefix argument, will ask which search style to toggle. With prefix | |
4056 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search. | |
4057 | |
4058 Although this function is bound to \\[vip-toggle-search-style], the most | |
4059 convenient way to use it is to bind `//' to the macro | |
4060 `1 M-x vip-toggle-search-style' and `///' to | |
4061 `2 M-x vip-toggle-search-style'. In this way, hitting `//' quickly will | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4062 toggle case-fold-search and hitting `/' three times witth toggle regexp |
10789 | 4063 search. Macros are more convenient in this case because they don't affect |
4064 the Emacs binding of `/'." | |
4065 (interactive "P") | |
4066 (let (msg) | |
4067 (cond ((or (eq arg 1) | |
4068 (and (null arg) | |
4069 (y-or-n-p (format "Search style: '%s'. Want '%s'? " | |
4070 (if vip-case-fold-search | |
4071 "case-insensitive" "case-sensitive") | |
4072 (if vip-case-fold-search | |
4073 "case-sensitive" | |
4074 "case-insensitive"))))) | |
4075 (setq vip-case-fold-search (null vip-case-fold-search)) | |
4076 (if vip-case-fold-search | |
4077 (setq msg "Search becomes case-insensitive") | |
4078 (setq msg "Search becomes case-sensitive"))) | |
4079 ((or (eq arg 2) | |
4080 (and (null arg) | |
4081 (y-or-n-p (format "Search style: '%s'. Want '%s'? " | |
4082 (if vip-re-search | |
4083 "regexp-search" "vanilla-search") | |
4084 (if vip-re-search | |
4085 "vanilla-search" | |
4086 "regexp-search"))))) | |
4087 (setq vip-re-search (null vip-re-search)) | |
4088 (if vip-re-search | |
4089 (setq msg "Search becomes regexp-style") | |
4090 (setq msg "Search becomes vanilla-style"))) | |
4091 (t | |
4092 (setq msg "Search style remains unchanged"))) | |
4093 (prin1 msg t))) | |
4094 | |
4095 | |
4096 (defun vip-search-forward (arg) | |
4097 "Search a string forward. | |
4098 ARG is used to find the ARG's occurrence of the string. | |
4099 Null string will repeat previous search." | |
4100 (interactive "P") | |
4101 (let ((val (vip-P-val arg)) | |
4102 (com (vip-getcom arg)) | |
4103 (old-str vip-s-string)) | |
4104 (setq vip-s-forward t) | |
4105 (vip-if-string "/") | |
4106 ;; this is not used at present, but may be used later | |
4107 (if (or (not (equal old-str vip-s-string)) | |
4108 (not (markerp vip-local-search-start-marker)) | |
4109 (not (marker-buffer vip-local-search-start-marker))) | |
4110 (setq vip-local-search-start-marker (point-marker))) | |
4111 (vip-search vip-s-string t val) | |
4112 (if com | |
4113 (progn | |
4114 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4115 (vip-execute-com 'vip-search-next val com))))) | |
4116 | |
4117 (defun vip-search-backward (arg) | |
4118 "Search a string backward. | |
4119 ARG is used to find the ARG's occurrence of the string. | |
4120 Null string will repeat previous search." | |
4121 (interactive "P") | |
4122 (let ((val (vip-P-val arg)) | |
4123 (com (vip-getcom arg)) | |
4124 (old-str vip-s-string)) | |
4125 (setq vip-s-forward nil) | |
4126 (vip-if-string "?") | |
4127 ;; this is not used at present, but may be used later | |
4128 (if (or (not (equal old-str vip-s-string)) | |
4129 (not (markerp vip-local-search-start-marker)) | |
4130 (not (marker-buffer vip-local-search-start-marker))) | |
4131 (setq vip-local-search-start-marker (point-marker))) | |
4132 (vip-search vip-s-string nil val) | |
4133 (if com | |
4134 (progn | |
4135 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4136 (vip-execute-com 'vip-search-next val com))))) | |
4137 | |
4138 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4139 ;; Search for COUNT's occurrence of STRING. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4140 ;; Search is forward if FORWARD is non-nil, otherwise backward. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4141 ;; INIT-POINT is the position where search is to start. |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4142 ;; Arguments: |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4143 ;; (STRING FORW COUNT &optional NO-OFFSET INIT-POINT LIMIT FAIL-IF-NOT-FOUND) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4144 (defun vip-search (string forward arg |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4145 &optional no-offset init-point fail-if-not-found) |
10789 | 4146 (if (not (equal string "")) |
4147 (let ((val (vip-p-val arg)) | |
4148 (com (vip-getcom arg)) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4149 (offset (not no-offset)) |
10789 | 4150 (case-fold-search vip-case-fold-search) |
4151 (start-point (or init-point (point)))) | |
4152 (vip-deactivate-mark) | |
4153 (if forward | |
4154 (condition-case nil | |
4155 (progn | |
4156 (if offset (vip-forward-char-carefully)) | |
4157 (if vip-re-search | |
4158 (progn | |
4159 (re-search-forward string nil nil val) | |
4160 (re-search-backward string)) | |
4161 (search-forward string nil nil val) | |
4162 (search-backward string)) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4163 ;; don't wait and don't flash in macros |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4164 (or executing-kbd-macro |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4165 (vip-flash-search-pattern)) |
10789 | 4166 (if (not (equal start-point (point))) |
4167 (push-mark start-point t))) | |
4168 (search-failed | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4169 (if (and (not fail-if-not-found) vip-search-wrap-around-t) |
10789 | 4170 (progn |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4171 (message "Search wrapped around BOTTOM of buffer") |
10789 | 4172 (goto-char (point-min)) |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4173 (vip-search string forward (cons 1 com) t start-point 'fail) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4174 ;; don't wait in macros |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4175 (or executing-kbd-macro (sit-for 2)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4176 ;; delete the wrap-around message |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4177 (message "") |
10789 | 4178 ) |
4179 (goto-char start-point) | |
4180 (error "`%s': %s not found" | |
4181 string | |
4182 (if vip-re-search "Pattern" "String")) | |
4183 ))) | |
4184 ;; backward | |
4185 (condition-case nil | |
4186 (progn | |
4187 (if vip-re-search | |
4188 (re-search-backward string nil nil val) | |
4189 (search-backward string nil nil val)) | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4190 ;; don't wait and don't flash in macros |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4191 (or executing-kbd-macro |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4192 (vip-flash-search-pattern)) |
10789 | 4193 (if (not (equal start-point (point))) |
4194 (push-mark start-point t))) | |
4195 (search-failed | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4196 (if (and (not fail-if-not-found) vip-search-wrap-around-t) |
10789 | 4197 (progn |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4198 (message "Search wrapped around TOP of buffer") |
10789 | 4199 (goto-char (point-max)) |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4200 (vip-search string forward (cons 1 com) t start-point 'fail) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4201 ;; don't wait in macros |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4202 (or executing-kbd-macro (sit-for 2)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4203 ;; delete the wrap-around message |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4204 (message "") |
10789 | 4205 ) |
4206 (goto-char start-point) | |
4207 (error "`%s': %s not found" | |
4208 string | |
4209 (if vip-re-search "Pattern" "String")) | |
4210 ))))))) | |
4211 | |
4212 (defun vip-search-next (arg) | |
4213 "Repeat previous search." | |
4214 (interactive "P") | |
4215 (let ((val (vip-p-val arg)) | |
4216 (com (vip-getcom arg))) | |
4217 (if (null vip-s-string) (error vip-NoPrevSearch)) | |
4218 (vip-search vip-s-string vip-s-forward arg) | |
4219 (if com | |
4220 (progn | |
4221 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4222 (vip-execute-com 'vip-search-next val com))))) | |
4223 | |
4224 (defun vip-search-Next (arg) | |
4225 "Repeat previous search in the reverse direction." | |
4226 (interactive "P") | |
4227 (let ((val (vip-p-val arg)) | |
4228 (com (vip-getcom arg))) | |
4229 (if (null vip-s-string) (error vip-NoPrevSearch)) | |
4230 (vip-search vip-s-string (not vip-s-forward) arg) | |
4231 (if com | |
4232 (progn | |
4233 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4234 (vip-execute-com 'vip-search-Next val com))))) | |
4235 | |
4236 | |
4237 ;; Search contents of buffer defined by one of Viper's motion commands. | |
4238 ;; Repeatable via `n' and `N'. | |
4239 (defun vip-buffer-search-enable (&optional c) | |
4240 (cond (c (setq vip-buffer-search-char c)) | |
4241 ((null vip-buffer-search-char) | |
4242 (setq vip-buffer-search-char ?g))) | |
4243 (define-key vip-vi-basic-map | |
4244 (char-to-string vip-buffer-search-char) 'vip-command-argument) | |
4245 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) | |
4246 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) | |
4247 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4248 ;; This is a Viper wraper for isearch-forward. |
10789 | 4249 (defun vip-isearch-forward (arg) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4250 "Do incremental search forward." |
10789 | 4251 (interactive "P") |
4252 ;; emacs bug workaround | |
4253 (if (listp arg) (setq arg (car arg))) | |
4254 (vip-exec-form-in-emacs (list 'isearch-forward arg))) | |
4255 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4256 ;; This is a Viper wraper for isearch-backward." |
10789 | 4257 (defun vip-isearch-backward (arg) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4258 "Do incremental search backward." |
10789 | 4259 (interactive "P") |
4260 ;; emacs bug workaround | |
4261 (if (listp arg) (setq arg (car arg))) | |
4262 (vip-exec-form-in-emacs (list 'isearch-backward arg))) | |
4263 | |
4264 | |
4265 ;; visiting and killing files, buffers | |
4266 | |
4267 (defun vip-switch-to-buffer () | |
4268 "Switch to buffer in the current window." | |
4269 (interactive) | |
4270 (let (buffer) | |
4271 (setq buffer | |
4272 (read-buffer | |
4273 (format "Switch to buffer in this window \(%s\): " | |
4274 (buffer-name (other-buffer (current-buffer)))))) | |
4275 (switch-to-buffer buffer) | |
4276 )) | |
4277 | |
4278 (defun vip-switch-to-buffer-other-window () | |
4279 "Switch to buffer in another window." | |
4280 (interactive) | |
4281 (let (buffer) | |
4282 (setq buffer | |
4283 (read-buffer | |
4284 (format "Switch to buffer in another window \(%s\): " | |
4285 (buffer-name (other-buffer (current-buffer)))))) | |
4286 (switch-to-buffer-other-window buffer) | |
4287 )) | |
4288 | |
4289 (defun vip-kill-buffer () | |
4290 "Kill a buffer." | |
4291 (interactive) | |
4292 (let (buffer buffer-name) | |
4293 (setq buffer-name | |
4294 (read-buffer | |
4295 (format "Kill buffer \(%s\): " | |
4296 (buffer-name (current-buffer))))) | |
4297 (setq buffer | |
4298 (if (null buffer-name) | |
4299 (current-buffer) | |
4300 (get-buffer buffer-name))) | |
4301 (if (null buffer) (error "`%s': No such buffer" buffer-name)) | |
4302 (if (or (not (buffer-modified-p buffer)) | |
4303 (y-or-n-p | |
4304 (format | |
4305 "Buffer `%s' is modified, are you sure you want to kill it? " | |
4306 buffer-name))) | |
4307 (kill-buffer buffer) | |
4308 (error "Buffer not killed")))) | |
4309 | |
4310 | |
4311 (defvar vip-smart-suffix-list '("" "tex" "c" "cc" "el" "p") | |
4312 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. | |
4313 This is useful when you the current directory contains files with the same | |
4314 prefix and many different suffixes. Usually, only one of the suffixes | |
4315 represents an editable file. However, file completion will stop at the `.' | |
4316 The smart suffix feature lets you hit RET in such a case, and Viper will | |
4317 select the appropriate suffix. | |
4318 | |
4319 Suffixes are tried in the order given and the first suffix for which a | |
4320 corresponding file exists is selected. If no file exists for any of the | |
4321 suffixes, the user is asked to confirm. | |
4322 | |
4323 To turn this feature off, set this variable to nil.") | |
4324 | |
4325 ;; Try to add suffix to files ending with a `.' | |
4326 ;; Useful when the user hits RET on a non-completed file name. | |
4327 (defun vip-file-add-suffix () | |
4328 (let ((count 0) | |
4329 (len (length vip-smart-suffix-list)) | |
4330 (file (buffer-string)) | |
4331 found key cmd suff) | |
4332 (goto-char (point-max)) | |
4333 (if (and vip-smart-suffix-list (string-match "\\.$" file)) | |
4334 (progn | |
4335 (while (and (not found) (< count len)) | |
4336 (setq suff (nth count vip-smart-suffix-list) | |
4337 count (1+ count)) | |
4338 (if (file-exists-p (format "%s%s" file suff)) | |
4339 (progn | |
4340 (setq found t) | |
4341 (insert suff)))) | |
4342 | |
4343 (if found | |
4344 () | |
4345 (vip-tmp-insert-at-eob " [Please complete file name]") | |
4346 (unwind-protect | |
4347 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer))) | |
4348 (setq cmd | |
4349 (key-binding (setq key (read-key-sequence nil)))) | |
4350 (cond ((eq cmd 'self-insert-command) | |
4351 (if vip-xemacs-p | |
4352 (insert (events-to-keys key)) | |
4353 (insert key))) | |
4354 ((memq cmd '(exit-minibuffer vip-exit-minibuffer)) | |
4355 nil) | |
4356 (t (command-execute cmd))) | |
4357 ))) | |
4358 )) | |
4359 )) | |
4360 | |
4361 | |
4362 ;; Advice for use in find-file and read-file-name commands. | |
4363 (defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4364 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer." |
10789 | 4365 (run-hooks 'vip-minibuffer-exit-hook)) |
4366 | |
4367 (defadvice find-file (before vip-add-suffix-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4368 "Use `read-file-name' for reading arguments." |
10789 | 4369 (interactive (list (read-file-name "Find file: " |
4370 nil default-directory)))) | |
4371 | |
4372 (defadvice find-file-other-window (before vip-add-suffix-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4373 "Use `read-file-name' for reading arguments." |
10789 | 4374 (interactive (list (read-file-name "Find file in other window: " |
4375 nil default-directory)))) | |
4376 | |
4377 (defadvice find-file-other-frame (before vip-add-suffix-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4378 "Use `read-file-name' for reading arguments." |
10789 | 4379 (interactive (list (read-file-name "Find file in other frame: " |
4380 nil default-directory)))) | |
4381 | |
4382 (defadvice read-file-name (around vip-suffix-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4383 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." |
10789 | 4384 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) |
4385 ad-do-it)) | |
4386 | |
4387 | |
4388 | |
4389 ;; yank and pop | |
4390 | |
4391 (defsubst vip-yank (text) | |
4392 "Yank TEXT silently. This works correctly with Emacs's yank-pop command." | |
4393 (insert text) | |
4394 (setq this-command 'yank)) | |
4395 | |
4396 (defun vip-put-back (arg) | |
4397 "Put back after point/below line." | |
4398 (interactive "P") | |
4399 (let ((val (vip-p-val arg)) | |
4400 (text (if vip-use-register | |
4401 (cond ((vip-valid-register vip-use-register '(digit)) | |
4402 (current-kill (- vip-use-register ?1) 'do-not-rotate)) | |
4403 ((vip-valid-register vip-use-register) | |
4404 (get-register (downcase vip-use-register))) | |
4405 (t (error vip-InvalidRegister vip-use-register))) | |
4406 (current-kill 0)))) | |
4407 (if (null text) | |
4408 (if vip-use-register | |
4409 (let ((reg vip-use-register)) | |
4410 (setq vip-use-register nil) | |
4411 (error vip-EmptyRegister reg)) | |
4412 (error ""))) | |
4413 (setq vip-use-register nil) | |
4414 (if (vip-end-with-a-newline-p text) | |
4415 (progn | |
4416 (if (eobp) | |
4417 (insert "\n") | |
4418 (forward-line 1)) | |
4419 (beginning-of-line)) | |
4420 (if (not (eolp)) (vip-forward-char-carefully))) | |
4421 (set-marker (vip-mark-marker) (point) (current-buffer)) | |
4422 (vip-set-destructive-command | |
4423 (list 'vip-put-back val nil vip-use-register nil nil)) | |
4424 (vip-loop val (vip-yank text))) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4425 ;; Vi puts cursor on the last char when the yanked text doesn't contain a |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4426 ;; newline; it leaves the cursor at the beginning when the text contains |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4427 ;; a newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4428 (if (vip-same-line (point) (mark)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4429 (or (= (point) (mark)) (vip-backward-char-carefully)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4430 (exchange-point-and-mark) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4431 (if (bolp) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4432 (back-to-indentation))) |
10789 | 4433 (vip-deactivate-mark)) |
4434 | |
4435 (defun vip-Put-back (arg) | |
4436 "Put back at point/above line." | |
4437 (interactive "P") | |
4438 (let ((val (vip-p-val arg)) | |
4439 (text (if vip-use-register | |
4440 (cond ((vip-valid-register vip-use-register '(digit)) | |
4441 (current-kill (- vip-use-register ?1) 'do-not-rotate)) | |
4442 ((vip-valid-register vip-use-register) | |
4443 (get-register (downcase vip-use-register))) | |
4444 (t (error vip-InvalidRegister vip-use-register))) | |
4445 (current-kill 0)))) | |
4446 (if (null text) | |
4447 (if vip-use-register | |
4448 (let ((reg vip-use-register)) | |
4449 (setq vip-use-register nil) | |
4450 (error vip-EmptyRegister reg)) | |
4451 (error ""))) | |
4452 (setq vip-use-register nil) | |
4453 (if (vip-end-with-a-newline-p text) (beginning-of-line)) | |
4454 (vip-set-destructive-command | |
4455 (list 'vip-Put-back val nil vip-use-register nil nil)) | |
4456 (set-marker (vip-mark-marker) (point) (current-buffer)) | |
4457 (vip-loop val (vip-yank text))) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4458 ;; Vi puts cursor on the last char when the yanked text doesn't contain a |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4459 ;; newline; it leaves the cursor at the beginning when the text contains |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4460 ;; a newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4461 (if (vip-same-line (point) (mark)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4462 (or (= (point) (mark)) (vip-backward-char-carefully)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4463 (exchange-point-and-mark) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4464 (if (bolp) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4465 (back-to-indentation))) |
10789 | 4466 (vip-deactivate-mark)) |
4467 | |
4468 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4469 ;; Copy region to kill-ring. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4470 ;; If BEG and END do not belong to the same buffer, copy empty region. |
10789 | 4471 (defun vip-copy-region-as-kill (beg end) |
4472 (condition-case nil | |
4473 (copy-region-as-kill beg end) | |
4474 (error (copy-region-as-kill beg beg)))) | |
4475 | |
4476 | |
4477 (defun vip-delete-char (arg) | |
4478 "Delete character." | |
4479 (interactive "P") | |
4480 (let ((val (vip-p-val arg))) | |
4481 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil)) | |
4482 (if (> val 1) | |
4483 (save-excursion | |
4484 (let ((here (point))) | |
4485 (end-of-line) | |
4486 (if (> val (- (point) here)) | |
4487 (setq val (- (point) here)))))) | |
4488 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1)) | |
4489 (if (and vip-ex-style-motion (eolp)) | |
4490 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch | |
4491 (if vip-use-register | |
4492 (progn | |
4493 (cond ((vip-valid-register vip-use-register '((Letter))) | |
4494 (vip-append-to-register | |
4495 (downcase vip-use-register) (point) (- (point) val))) | |
4496 ((vip-valid-register vip-use-register) | |
4497 (copy-to-register | |
4498 vip-use-register (point) (- (point) val) nil)) | |
4499 (t (error vip-InvalidRegister vip-use-register))) | |
4500 (setq vip-use-register nil))) | |
4501 (if vip-ex-style-motion | |
4502 (progn | |
4503 (delete-char val t) | |
4504 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
4505 (if (eolp) | |
4506 (delete-backward-char val t) | |
4507 (delete-char val t))))) | |
4508 | |
4509 (defun vip-delete-backward-char (arg) | |
4510 "Delete previous character. On reaching beginning of line, stop and beep." | |
4511 (interactive "P") | |
4512 (let ((val (vip-p-val arg))) | |
4513 (vip-set-destructive-command | |
4514 (list 'vip-delete-backward-char val nil nil nil nil)) | |
4515 (if (> val 1) | |
4516 (save-excursion | |
4517 (let ((here (point))) | |
4518 (beginning-of-line) | |
4519 (if (> val (- here (point))) | |
4520 (setq val (- here (point))))))) | |
4521 (if vip-use-register | |
4522 (progn | |
4523 (cond ((vip-valid-register vip-use-register '(Letter)) | |
4524 (vip-append-to-register | |
4525 (downcase vip-use-register) (point) (+ (point) val))) | |
4526 ((vip-valid-register vip-use-register) | |
4527 (copy-to-register | |
4528 vip-use-register (point) (+ (point) val) nil)) | |
4529 (t (error vip-InvalidRegister vip-use-register))) | |
4530 (setq vip-use-register nil))) | |
4531 (if (bolp) (ding) | |
4532 (delete-backward-char val t)))) | |
4533 | |
4534 (defun vip-del-backward-char-in-insert () | |
4535 "Delete 1 char backwards while in insert mode." | |
4536 (interactive) | |
4537 (if (and vip-ex-style-editing-in-insert (bolp)) | |
4538 (beep 1) | |
4539 (delete-backward-char 1 t))) | |
4540 | |
4541 (defun vip-del-backward-char-in-replace () | |
4542 "Delete one character in replace mode. | |
4543 If `vip-delete-backwards-in-replace' is t, then DEL key actually deletes | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4544 charecters. If it is nil, then the cursor just moves backwards, similarly |
10789 | 4545 to Vi. The variable `vip-ex-style-editing-in-insert', if t, doesn't let the |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4546 cursor move past the beginning of line." |
10789 | 4547 (interactive) |
4548 (cond (vip-delete-backwards-in-replace | |
4549 (cond ((not (bolp)) | |
4550 (delete-backward-char 1 t)) | |
4551 (vip-ex-style-editing-in-insert | |
4552 (beep 1)) | |
4553 ((bobp) | |
4554 (beep 1)) | |
4555 (t | |
4556 (delete-backward-char 1 t)))) | |
4557 (vip-ex-style-editing-in-insert | |
4558 (if (bolp) | |
4559 (beep 1) | |
4560 (backward-char 1))) | |
4561 (t | |
4562 (backward-char 1)))) | |
4563 | |
4564 | |
4565 | |
4566 ;; join lines. | |
4567 | |
4568 (defun vip-join-lines (arg) | |
4569 "Join this line to next, if ARG is nil. Otherwise, join ARG lines." | |
4570 (interactive "*P") | |
4571 (let ((val (vip-P-val arg))) | |
4572 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil)) | |
4573 (vip-loop (if (null val) 1 (1- val)) | |
4574 (progn | |
4575 (end-of-line) | |
4576 (if (not (eobp)) | |
4577 (progn | |
4578 (forward-line 1) | |
4579 (delete-region (point) (1- (point))) | |
4580 (fixup-whitespace))))))) | |
4581 | |
4582 | |
4583 ;; Replace state | |
4584 | |
4585 (defun vip-change (beg end) | |
4586 (if (markerp beg) (setq beg (marker-position beg))) | |
4587 (if (markerp end) (setq end (marker-position end))) | |
4588 ;; beg is sometimes (mark t), which may be nil | |
4589 (or beg (setq beg end)) | |
4590 | |
4591 (vip-set-complex-command-for-undo) | |
4592 (if vip-use-register | |
4593 (progn | |
4594 (copy-to-register vip-use-register beg end nil) | |
4595 (setq vip-use-register nil))) | |
4596 (vip-set-replace-overlay beg end) | |
4597 (setq last-command nil) ; separate repl text from prev kills | |
4598 | |
4599 (if (= (vip-replace-start) (point-max)) | |
4600 (error "End of buffer")) | |
4601 | |
4602 (setq vip-last-replace-region | |
4603 (buffer-substring (vip-replace-start) | |
4604 (vip-replace-end))) | |
4605 | |
4606 ;; protect against error while inserting "@" and other disasters | |
4607 ;; (e.g., read-only buff) | |
4608 (condition-case conds | |
4609 (if (vip-same-line (vip-replace-start) | |
4610 (vip-replace-end)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4611 (progn |
10789 | 4612 ;; tabs cause problems in replace, so untabify |
4613 (goto-char (vip-replace-end)) | |
4614 (insert-before-markers "@") ; put placeholder after the TAB | |
4615 (untabify (vip-replace-start) (point)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4616 ;; del @, don't put on kill ring |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4617 (delete-backward-char 1) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4618 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4619 (vip-set-replace-overlay-glyphs |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4620 vip-replace-region-start-delimiter |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4621 vip-replace-region-end-delimiter) |
10789 | 4622 ;; this move takes care of the last posn in the overlay, which |
4623 ;; has to be shifted because of insert. We can't simply insert | |
4624 ;; "$" before-markers because then overlay-start will shift the | |
4625 ;; beginning of the overlay in case we are replacing a single | |
4626 ;; character. This fixes the bug with `s' and `cl' commands. | |
4627 (vip-move-replace-overlay (vip-replace-start) (point)) | |
4628 (goto-char (vip-replace-start)) | |
4629 (vip-change-state-to-replace t)) | |
4630 (kill-region (vip-replace-start) | |
4631 (vip-replace-end)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
4632 (vip-hide-replace-overlay) |
10789 | 4633 (vip-change-state-to-insert)) |
4634 (error ;; make sure that the overlay doesn't stay. | |
4635 ;; go back to the original point | |
4636 (goto-char (vip-replace-start)) | |
4637 (vip-hide-replace-overlay) | |
4638 (vip-message-conditions conds)))) | |
4639 | |
4640 | |
4641 (defun vip-change-subr (beg end) | |
4642 ;; beg is sometimes (mark t), which may be nil | |
4643 (or beg (setq beg end)) | |
4644 | |
4645 (if vip-use-register | |
4646 (progn | |
4647 (copy-to-register vip-use-register beg end nil) | |
4648 (setq vip-use-register nil))) | |
4649 (kill-region beg end) | |
4650 (setq this-command 'vip-change) | |
4651 (vip-yank-last-insertion)) | |
4652 | |
4653 (defun vip-toggle-case (arg) | |
4654 "Toggle character case." | |
4655 (interactive "P") | |
4656 (let ((val (vip-p-val arg)) (c)) | |
4657 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil)) | |
4658 (while (> val 0) | |
4659 (setq c (following-char)) | |
4660 (delete-char 1 nil) | |
4661 (if (eq c (upcase c)) | |
4662 (insert-char (downcase c) 1) | |
4663 (insert-char (upcase c) 1)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4664 (if (eolp) (backward-char 1)) |
10789 | 4665 (setq val (1- val))))) |
4666 | |
4667 | |
4668 ;; query replace | |
4669 | |
4670 (defun vip-query-replace () | |
4671 "Query replace. | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4672 If a null string is suplied as the string to be replaced, |
10789 | 4673 the query replace mode will toggle between string replace |
4674 and regexp replace." | |
4675 (interactive) | |
4676 (let (str) | |
4677 (setq str (vip-read-string-with-history | |
4678 (if vip-re-query-replace "Query replace regexp: " | |
4679 "Query replace: ") | |
4680 nil ; no initial | |
4681 'vip-replace1-history | |
4682 (car vip-replace1-history) ; default | |
4683 )) | |
4684 (if (string= str "") | |
4685 (progn | |
4686 (setq vip-re-query-replace (not vip-re-query-replace)) | |
4687 (message "Query replace mode changed to %s" | |
4688 (if vip-re-query-replace "regexp replace" | |
4689 "string replace"))) | |
4690 (if vip-re-query-replace | |
4691 (query-replace-regexp | |
4692 str | |
4693 (vip-read-string-with-history | |
4694 (format "Query replace regexp `%s' with: " str) | |
4695 nil ; no initial | |
4696 'vip-replace1-history | |
4697 (car vip-replace1-history) ; default | |
4698 )) | |
4699 (query-replace | |
4700 str | |
4701 (vip-read-string-with-history | |
4702 (format "Query replace `%s' with: " str) | |
4703 nil ; no initial | |
4704 'vip-replace1-history | |
4705 (car vip-replace1-history) ; default | |
4706 )))))) | |
4707 | |
4708 | |
4709 ;; marking | |
4710 | |
4711 (defun vip-mark-beginning-of-buffer () | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4712 "Mark beginning of buffer." |
10789 | 4713 (interactive) |
4714 (push-mark (point)) | |
4715 (goto-char (point-min)) | |
4716 (exchange-point-and-mark) | |
4717 (message "Mark set at the beginning of buffer")) | |
4718 | |
4719 (defun vip-mark-end-of-buffer () | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4720 "Mark end of buffer." |
10789 | 4721 (interactive) |
4722 (push-mark (point)) | |
4723 (goto-char (point-max)) | |
4724 (exchange-point-and-mark) | |
4725 (message "Mark set at the end of buffer")) | |
4726 | |
4727 (defun vip-mark-point () | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4728 "Set mark at point of buffer." |
10789 | 4729 (interactive) |
4730 (let ((char (vip-read-char-exclusive))) | |
4731 (cond ((and (<= ?a char) (<= char ?z)) | |
4732 (point-to-register (1+ (- char ?a)))) | |
4733 ((= char ?<) (vip-mark-beginning-of-buffer)) | |
4734 ((= char ?>) (vip-mark-end-of-buffer)) | |
4735 ((= char ?.) (vip-set-mark-if-necessary)) | |
4736 ((= char ?,) (vip-cycle-through-mark-ring)) | |
4737 ((= char ?D) (mark-defun)) | |
4738 (t (error "")) | |
4739 ))) | |
4740 | |
4741 ;; Algorithm: If first invocation of this command save mark on ring, goto | |
4742 ;; mark, M0, and pop the most recent elt from the mark ring into mark, | |
4743 ;; making it into the new mark, M1. | |
4744 ;; Push this mark back and set mark to the original point position, p1. | |
4745 ;; So, if you hit '' or `` then you can return to p1. | |
4746 ;; | |
4747 ;; If repeated command, pop top elt from the ring into mark and | |
4748 ;; jump there. This forgets the position, p1, and puts M1 back into mark. | |
4749 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from | |
4750 ;; the ring into mark. Push M2 back on the ring and set mark to M0. | |
4751 ;; etc. | |
4752 (defun vip-cycle-through-mark-ring () | |
4753 "Visit previous locations on the mark ring. | |
4754 One can use `` and '' to temporarily jump 1 step back." | |
4755 (let* ((sv-pt (point))) | |
4756 ;; if repeated `m,' command, pop the previously saved mark. | |
4757 ;; Prev saved mark is actually prev saved point. It is used if the | |
4758 ;; user types `` or '' and is discarded | |
4759 ;; from the mark ring by the next `m,' command. | |
4760 ;; In any case, go to the previous or previously saved mark. | |
4761 ;; Then push the current mark (popped off the ring) and set current | |
4762 ;; point to be the mark. Current pt as mark is discarded by the next | |
4763 ;; m, command. | |
4764 (if (eq last-command 'vip-cycle-through-mark-ring) | |
4765 () | |
4766 ;; save current mark if the first iteration | |
4767 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
4768 (if (mark t) | |
4769 (push-mark (mark t) t)) ) | |
4770 (pop-mark) | |
4771 (set-mark-command 1) | |
4772 ;; don't duplicate mark on the ring | |
4773 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
4774 (push-mark sv-pt t) | |
4775 (vip-deactivate-mark) | |
4776 (setq this-command 'vip-cycle-through-mark-ring) | |
4777 )) | |
4778 | |
4779 | |
4780 (defun vip-goto-mark (arg) | |
4781 "Go to mark." | |
4782 (interactive "P") | |
4783 (let ((char (read-char)) | |
4784 (com (vip-getcom arg))) | |
4785 (vip-goto-mark-subr char com nil))) | |
4786 | |
4787 (defun vip-goto-mark-and-skip-white (arg) | |
4788 "Go to mark and skip to first non-white character on line." | |
4789 (interactive "P") | |
4790 (let ((char (read-char)) | |
4791 (com (vip-getCom arg))) | |
4792 (vip-goto-mark-subr char com t))) | |
4793 | |
4794 (defun vip-goto-mark-subr (char com skip-white) | |
4795 (if (eobp) | |
4796 (if (bobp) | |
4797 (error "Empty buffer") | |
4798 (backward-char 1))) | |
4799 (cond ((vip-valid-register char '(letter)) | |
4800 (let* ((buff (current-buffer)) | |
4801 (reg (1+ (- char ?a))) | |
4802 (text-marker (get-register reg))) | |
4803 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4804 (if (not (vip-valid-marker text-marker)) | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14580
diff
changeset
|
4805 (error vip-EmptyTextmarker char)) |
10789 | 4806 (if (and (vip-same-line (point) vip-last-jump) |
4807 (= (point) vip-last-jump-ignore)) | |
4808 (push-mark vip-last-jump t) | |
4809 (push-mark nil t)) ; no msg | |
4810 (vip-register-to-point reg) | |
4811 (setq vip-last-jump (point-marker)) | |
4812 (cond (skip-white | |
4813 (back-to-indentation) | |
4814 (setq vip-last-jump-ignore (point)))) | |
4815 (if com | |
4816 (if (equal buff (current-buffer)) | |
4817 (vip-execute-com (if skip-white | |
4818 'vip-goto-mark-and-skip-white | |
4819 'vip-goto-mark) | |
4820 nil com) | |
4821 (switch-to-buffer buff) | |
4822 (goto-char vip-com-point) | |
4823 (vip-change-state-to-vi) | |
4824 (error ""))))) | |
4825 ((and (not skip-white) (= char ?`)) | |
4826 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4827 (if (and (vip-same-line (point) vip-last-jump) | |
4828 (= (point) vip-last-jump-ignore)) | |
4829 (goto-char vip-last-jump)) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4830 (if (null (mark t)) (error "Mark is not set in this buffer")) |
10789 | 4831 (if (= (point) (mark t)) (pop-mark)) |
4832 (exchange-point-and-mark) | |
4833 (setq vip-last-jump (point-marker) | |
4834 vip-last-jump-ignore 0) | |
4835 (if com (vip-execute-com 'vip-goto-mark nil com))) | |
4836 ((and skip-white (= char ?')) | |
4837 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4838 (if (and (vip-same-line (point) vip-last-jump) | |
4839 (= (point) vip-last-jump-ignore)) | |
4840 (goto-char vip-last-jump)) | |
4841 (if (= (point) (mark t)) (pop-mark)) | |
4842 (exchange-point-and-mark) | |
4843 (setq vip-last-jump (point)) | |
4844 (back-to-indentation) | |
4845 (setq vip-last-jump-ignore (point)) | |
4846 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com))) | |
4847 (t (error vip-InvalidTextmarker char)))) | |
4848 | |
4849 (defun vip-insert-tab () | |
4850 (interactive) | |
4851 (insert-tab)) | |
4852 | |
4853 (defun vip-exchange-point-and-mark () | |
4854 (interactive) | |
4855 (exchange-point-and-mark) | |
4856 (back-to-indentation)) | |
4857 | |
4858 ;; Input Mode Indentation | |
4859 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4860 ;; Returns t, if the string before point matches the regexp STR. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4861 (defsubst vip-looking-back (str) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4862 (and (save-excursion (re-search-backward str nil t)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4863 (= (point) (match-end 0)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4864 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4865 |
10789 | 4866 (defun vip-forward-indent () |
4867 "Indent forward -- `C-t' in Vi." | |
4868 (interactive) | |
4869 (setq vip-cted t) | |
4870 (indent-to (+ (current-column) vip-shift-width))) | |
4871 | |
4872 (defun vip-backward-indent () | |
4873 "Backtab, C-d in VI" | |
4874 (interactive) | |
4875 (if vip-cted | |
4876 (let ((p (point)) (c (current-column)) bol (indent t)) | |
4877 (if (vip-looking-back "[0^]") | |
4878 (progn | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4879 (if (eq ?^ (preceding-char)) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4880 (setq vip-preserve-indent t)) |
10789 | 4881 (delete-backward-char 1) |
4882 (setq p (point)) | |
4883 (setq indent nil))) | |
4884 (save-excursion | |
4885 (beginning-of-line) | |
4886 (setq bol (point))) | |
4887 (if (re-search-backward "[^ \t]" bol 1) (forward-char)) | |
4888 (delete-region (point) p) | |
4889 (if indent | |
4890 (indent-to (- c vip-shift-width))) | |
4891 (if (or (bolp) (vip-looking-back "[^ \t]")) | |
4892 (setq vip-cted nil))))) | |
4893 | |
4894 (defun vip-autoindent () | |
4895 "Auto Indentation, Vi-style." | |
4896 (interactive) | |
4897 (let ((col (current-indentation))) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4898 (if vip-preserve-indent |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4899 (setq vip-preserve-indent nil) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4900 (setq vip-current-indent col)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4901 ;; don't leave whitespace lines around |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4902 (if (memq last-command |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4903 '(vip-autoindent |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4904 vip-open-line vip-Open-line |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4905 vip-replace-state-exit-cmd)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4906 (indent-to-left-margin)) |
10789 | 4907 (newline 1) |
4908 (if vip-auto-indent | |
4909 (progn | |
4910 (setq vip-cted t) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4911 (if vip-electric-mode |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4912 (indent-according-to-mode) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4913 (indent-to vip-current-indent)) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4914 )) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4915 )) |
10789 | 4916 |
4917 | |
4918 ;; Viewing registers | |
4919 | |
4920 (defun vip-ket-function (arg) | |
4921 "Function called by \], the ket. View registers and call \]\]." | |
4922 (interactive "P") | |
4923 (let ((reg (read-char))) | |
4924 (cond ((vip-valid-register reg '(letter Letter)) | |
4925 (view-register (downcase reg))) | |
4926 ((vip-valid-register reg '(digit)) | |
4927 (let ((text (current-kill (- reg ?1) 'do-not-rotate))) | |
4928 (save-excursion | |
4929 (set-buffer (get-buffer-create "*Output*")) | |
4930 (delete-region (point-min) (point-max)) | |
4931 (insert (format "Register %c contains the string:\n" reg)) | |
4932 (insert text) | |
4933 (goto-char (point-min))) | |
4934 (display-buffer "*Output*"))) | |
4935 ((= ?\] reg) | |
4936 (vip-next-heading arg)) | |
4937 (t (error | |
4938 vip-InvalidRegister reg))))) | |
4939 | |
4940 (defun vip-brac-function (arg) | |
4941 "Function called by \[, the brac. View textmarkers and call \[\[" | |
4942 (interactive "P") | |
4943 (let ((reg (read-char))) | |
4944 (cond ((= ?\[ reg) | |
4945 (vip-prev-heading arg)) | |
4946 ((= ?\] reg) | |
4947 (vip-heading-end arg)) | |
4948 ((vip-valid-register reg '(letter)) | |
4949 (let* ((val (get-register (1+ (- reg ?a)))) | |
4950 (buf (if (not val) | |
14580
1883960762e0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14579
diff
changeset
|
4951 (error vip-EmptyTextmarker reg) |
10789 | 4952 (marker-buffer val))) |
4953 (pos (marker-position val)) | |
4954 line-no text (s pos) (e pos)) | |
4955 (save-excursion | |
4956 (set-buffer (get-buffer-create "*Output*")) | |
4957 (delete-region (point-min) (point-max)) | |
4958 (if (and buf pos) | |
4959 (progn | |
4960 (save-excursion | |
4961 (set-buffer buf) | |
4962 (setq line-no (1+ (count-lines (point-min) val))) | |
4963 (goto-char pos) | |
4964 (beginning-of-line) | |
4965 (if (re-search-backward "[^ \t]" nil t) | |
4966 (progn | |
4967 (beginning-of-line) | |
4968 (setq s (point)))) | |
4969 (goto-char pos) | |
4970 (forward-line 1) | |
4971 (if (re-search-forward "[^ \t]" nil t) | |
4972 (progn | |
4973 (end-of-line) | |
4974 (setq e (point)))) | |
4975 (setq text (buffer-substring s e)) | |
4976 (setq text (format "%s<%c>%s" | |
4977 (substring text 0 (- pos s)) | |
4978 reg (substring text (- pos s))))) | |
4979 (insert | |
4980 (format | |
4981 "Textmarker `%c' is in buffer `%s' at line %d.\n" | |
4982 reg (buffer-name buf) line-no)) | |
4983 (insert (format "Here is some text around %c:\n\n %s" | |
4984 reg text))) | |
4985 (insert (format vip-EmptyTextmarker reg))) | |
4986 (goto-char (point-min))) | |
4987 (display-buffer "*Output*"))) | |
4988 (t (error vip-InvalidTextmarker reg))))) | |
4989 | |
4990 | |
4991 | |
4992 ;; commands in insertion mode | |
4993 | |
4994 (defun vip-delete-backward-word (arg) | |
4995 "Delete previous word." | |
4996 (interactive "p") | |
4997 (save-excursion | |
4998 (push-mark nil t) | |
4999 (backward-word arg) | |
5000 (delete-region (point) (mark t)) | |
5001 (pop-mark))) | |
5002 | |
5003 | |
5004 (defun vip-set-expert-level (&optional dont-change-unless) | |
5005 "Sets the expert level for a Viper user. | |
5006 Can be called interactively to change (temporarily or permanently) the | |
5007 current expert level. | |
5008 | |
5009 The optional argument DONT-CHANGE-UNLESS if not nil, says that | |
5010 the level should not be changed, unless its current value is | |
5011 meaningless (i.e., not one of 1,2,3,4,5). | |
5012 | |
5013 User level determines the setting of Viper variables that are most | |
5014 sensitive for VI-style look-and-feel." | |
5015 | |
5016 (interactive) | |
5017 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5018 (if (not (natnump vip-expert-level)) (setq vip-expert-level 0)) |
10789 | 5019 |
5020 (save-window-excursion | |
5021 (delete-other-windows) | |
5022 ;; if 0 < vip-expert-level < vip-max-expert-level | |
5023 ;; & dont-change-unless = t -- use it; else ask | |
5024 (vip-ask-level dont-change-unless)) | |
5025 | |
5026 (setq vip-always t | |
5027 vip-ex-style-motion t | |
5028 vip-ex-style-editing-in-insert t | |
5029 vip-want-ctl-h-help nil) | |
5030 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5031 (cond ((eq vip-expert-level 1) ; novice or beginner |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5032 (global-set-key ; in emacs-state |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5033 vip-toggle-key |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5034 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs)) |
10789 | 5035 (setq vip-no-multiple-ESC t |
5036 vip-re-search t | |
5037 vip-vi-style-in-minibuffer t | |
5038 vip-search-wrap-around-t t | |
5039 vip-want-emacs-keys-in-vi nil | |
5040 vip-want-emacs-keys-in-insert nil)) | |
5041 | |
5042 ((and (> vip-expert-level 1) (< vip-expert-level 5)) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5043 ;; intermediate to guru |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5044 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) |
10789 | 5045 vip-want-emacs-keys-in-vi t |
5046 vip-want-emacs-keys-in-insert (> vip-expert-level 2)) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5047 |
10789 | 5048 (if (eq vip-expert-level 4) ; respect user's ex-style motions |
5049 ; and vip-no-multiple-ESC | |
5050 (progn | |
5051 (setq-default vip-ex-style-editing-in-insert | |
5052 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5053 vip-saved-user-settings)) | |
5054 vip-ex-style-motion | |
5055 (cdr (assoc 'vip-ex-style-motion | |
5056 vip-saved-user-settings))) | |
5057 (setq vip-ex-style-motion | |
5058 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings)) | |
5059 vip-ex-style-editing-in-insert | |
5060 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5061 vip-saved-user-settings)) | |
5062 vip-re-search | |
5063 (cdr (assoc 'vip-re-search vip-saved-user-settings)) | |
5064 vip-no-multiple-ESC | |
5065 (cdr (assoc 'vip-no-multiple-ESC | |
5066 vip-saved-user-settings)))))) | |
5067 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5068 ;; A wizard!! |
10789 | 5069 ;; Ideally, if 5 is selected, a buffer should pop up to let the |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5070 ;; user toggle the values of variables. |
10789 | 5071 (t (setq-default vip-ex-style-editing-in-insert |
5072 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5073 vip-saved-user-settings)) | |
5074 vip-ex-style-motion | |
5075 (cdr (assoc 'vip-ex-style-motion | |
5076 vip-saved-user-settings))) | |
5077 (setq vip-want-ctl-h-help | |
5078 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings)) | |
5079 vip-always | |
5080 (cdr (assoc 'vip-always vip-saved-user-settings)) | |
5081 vip-no-multiple-ESC | |
5082 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings)) | |
5083 vip-ex-style-motion | |
5084 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings)) | |
5085 vip-ex-style-editing-in-insert | |
5086 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5087 vip-saved-user-settings)) | |
5088 vip-re-search | |
5089 (cdr (assoc 'vip-re-search vip-saved-user-settings)) | |
5090 vip-want-emacs-keys-in-vi | |
5091 (cdr (assoc 'vip-want-emacs-keys-in-vi | |
5092 vip-saved-user-settings)) | |
5093 vip-want-emacs-keys-in-insert | |
5094 (cdr (assoc 'vip-want-emacs-keys-in-insert | |
5095 vip-saved-user-settings))))) | |
5096 (vip-set-mode-vars-for vip-current-state) | |
5097 (if (or vip-always | |
5098 (and (> vip-expert-level 0) (> 5 vip-expert-level))) | |
5099 (vip-set-hooks))) | |
5100 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5101 ;; Ask user expert level. |
10789 | 5102 (defun vip-ask-level (dont-change-unless) |
5103 (let ((ask-buffer " *vip-ask-level*") | |
5104 level-changed repeated) | |
5105 (save-window-excursion | |
5106 (switch-to-buffer ask-buffer) | |
5107 | |
5108 (or (eq this-command 'vip-set-expert-level) | |
5109 (and | |
5110 (<= vip-expert-level vip-max-expert-level) | |
5111 (>= vip-expert-level 1)) | |
5112 (progn | |
5113 (insert " | |
5114 | |
5115 *** Important Notice for VIP users*** | |
5116 | |
5117 This is VIPER | |
5118 | |
5119 @joke | |
5120 Viper Is a Package for Emacs Rebels, | |
5121 a VI Plan for Emacs Rescue, | |
5122 and a venomous VI PERil. | |
5123 @end joke | |
5124 | |
5125 Technically speaking, Viper is a new Vi emulator that replaces | |
5126 the old VIP package. | |
5127 | |
5128 Viper emulates Vi much better than VIP. It also significantly | |
5129 extends and improves upon Vi in many useful ways. | |
5130 | |
5131 Although many VIP settings in your ~/.vip are compatible with Viper, | |
5132 you may have to change some of them. Please refer to the documentation, | |
5133 which can be obtained by executing | |
5134 | |
5135 :help | |
5136 | |
5137 when Viper is in Vi state. | |
5138 | |
5139 If you will be so lucky as to find a bug, report it via the command | |
5140 | |
5141 :submitReport | |
5142 | |
5143 Type any key to continue... ") | |
5144 | |
5145 (read-char) | |
5146 (erase-buffer))) | |
5147 | |
5148 (while (or (> vip-expert-level vip-max-expert-level) | |
5149 (< vip-expert-level 1) | |
5150 (null dont-change-unless)) | |
5151 (erase-buffer) | |
5152 (if repeated | |
5153 (progn | |
5154 (message "Invalid user level") | |
5155 (beep 1)) | |
5156 (setq repeated t)) | |
5157 (setq dont-change-unless t | |
5158 level-changed t) | |
5159 (insert " | |
5160 Please specify your level of familiarity with the venomous VI PERil | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
5161 (and the VI Plan for Emacs Rescue). |
10789 | 5162 You can change it at any time by typing `M-x vip-set-expert-level RET' |
5163 | |
5164 1 -- BEGINNER: Almost all Emacs features are suppressed. | |
5165 Feels almost like straight Vi. File name completion and | |
5166 command history in the minibuffer are thrown in as a bonus. | |
5167 To use Emacs productively, you must reach level 3 or higher. | |
5168 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state, | |
5169 so most Emacs commands can be used when Viper is in Vi state. | |
5170 Good progress---you are well on the way to level 3! | |
5171 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also | |
5172 in Viper's insert state. | |
5173 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC, | |
5174 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert | |
5175 variables. Adjust these settings to your taste. | |
5176 5 -- WIZARD: Like 4, but user settings are also respected for vip-always, | |
5177 vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, and | |
5178 vip-want-emacs-keys-in-insert. Adjust these to your taste. | |
5179 | |
5180 Please, specify your level now: ") | |
5181 | |
5182 (setq vip-expert-level (- (vip-read-char-exclusive) ?0)) | |
5183 ) ; end while | |
5184 | |
5185 ;; tell the user if level was changed | |
5186 (and level-changed | |
5187 (progn | |
5188 (insert | |
5189 (format "\n\n\n\n\n\t\tYou have selected user level %d" | |
5190 vip-expert-level)) | |
5191 (if (y-or-n-p "Do you wish to make this change permanent? ") | |
5192 ;; save the setting for vip-expert-level | |
5193 (vip-save-setting | |
5194 'vip-expert-level | |
5195 (format "Saving user level %d ..." vip-expert-level) | |
5196 vip-custom-file-name)) | |
5197 )) | |
5198 (bury-buffer) ; remove ask-buffer from screen | |
5199 (message "") | |
5200 ))) | |
5201 | |
5202 | |
5203 (defun viper-version () | |
5204 (interactive) | |
5205 (message "Viper version is %s" viper-version)) | |
5206 | |
5207 (defalias 'vip-version 'viper-version) | |
5208 | |
5209 (defun vip-nil () | |
5210 (interactive) | |
5211 (beep 1)) | |
5212 | |
5213 | |
5214 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer | |
5215 (defun vip-register-to-point (char &optional enforce-buffer) | |
5216 "Like jump-to-register, but switches to another buffer in another window." | |
5217 (interactive "cViper register to point: ") | |
5218 (let ((val (get-register char))) | |
5219 (cond | |
5220 ((and (fboundp 'frame-configuration-p) | |
5221 (frame-configuration-p val)) | |
5222 (set-frame-configuration val)) | |
5223 ((window-configuration-p val) | |
5224 (set-window-configuration val)) | |
5225 ((vip-valid-marker val) | |
5226 (if (and enforce-buffer | |
5227 (not (equal (current-buffer) (marker-buffer val)))) | |
5228 (error (concat vip-EmptyTextmarker " in this buffer") | |
5229 (1- (+ char ?a)))) | |
5230 (pop-to-buffer (marker-buffer val)) | |
5231 (goto-char val)) | |
5232 ((and (consp val) (eq (car val) 'file)) | |
5233 (find-file (cdr val))) | |
5234 (t | |
5235 (error vip-EmptyTextmarker (1- (+ char ?a))))))) | |
5236 | |
5237 | |
5238 (defun vip-save-kill-buffer () | |
5239 "Save then kill current buffer. " | |
5240 (interactive) | |
5241 (if (< vip-expert-level 2) | |
5242 (save-buffers-kill-emacs) | |
5243 (save-buffer) | |
5244 (kill-buffer (current-buffer)))) | |
5245 | |
5246 | |
5247 | |
5248 ;;; Bug Report | |
5249 | |
5250 (defun vip-submit-report () | |
5251 "Submit bug report on Viper." | |
5252 (interactive) | |
5253 (let ((reporter-prompt-for-summary-p t) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5254 (vip-device-type (vip-device-type)) |
10789 | 5255 color-display-p frame-parameters |
5256 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face | |
5257 varlist salutation window-config) | |
5258 | |
5259 ;; If mode info is needed, add variable to `let' and then set it below, | |
5260 ;; like we did with color-display-p. | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5261 (setq color-display-p (if (vip-window-display-p) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5262 (vip-color-display-p) |
10789 | 5263 'non-x) |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5264 minibuffer-vi-face (if (vip-has-face-support-p) |
10789 | 5265 (vip-get-face vip-minibuffer-vi-face) |
5266 'non-x) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5267 minibuffer-insert-face (if (vip-has-face-support-p) |
10789 | 5268 (vip-get-face vip-minibuffer-insert-face) |
5269 'non-x) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5270 minibuffer-emacs-face (if (vip-has-face-support-p) |
10789 | 5271 (vip-get-face vip-minibuffer-emacs-face) |
5272 'non-x) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5273 frame-parameters (if (fboundp 'frame-parameters) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5274 (frame-parameters (selected-frame)))) |
10789 | 5275 |
5276 (setq varlist (list 'vip-vi-minibuffer-minor-mode | |
5277 'vip-insert-minibuffer-minor-mode | |
5278 'vip-vi-intercept-minor-mode | |
5279 'vip-vi-local-user-minor-mode | |
5280 'vip-vi-kbd-minor-mode | |
5281 'vip-vi-global-user-minor-mode | |
5282 'vip-vi-state-modifier-minor-mode | |
5283 'vip-vi-diehard-minor-mode | |
5284 'vip-vi-basic-minor-mode | |
5285 'vip-replace-minor-mode | |
5286 'vip-insert-intercept-minor-mode | |
5287 'vip-insert-local-user-minor-mode | |
5288 'vip-insert-kbd-minor-mode | |
5289 'vip-insert-global-user-minor-mode | |
5290 'vip-insert-state-modifier-minor-mode | |
5291 'vip-insert-diehard-minor-mode | |
5292 'vip-insert-basic-minor-mode | |
5293 'vip-emacs-intercept-minor-mode | |
5294 'vip-emacs-local-user-minor-mode | |
5295 'vip-emacs-kbd-minor-mode | |
5296 'vip-emacs-global-user-minor-mode | |
5297 'vip-emacs-state-modifier-minor-mode | |
5298 'vip-automatic-iso-accents | |
5299 'vip-want-emacs-keys-in-insert | |
5300 'vip-want-emacs-keys-in-vi | |
5301 'vip-keep-point-on-undo | |
5302 'vip-no-multiple-ESC | |
5303 'vip-ESC-key | |
5304 'vip-want-ctl-h-help | |
5305 'vip-ex-style-editing-in-insert | |
5306 'vip-delete-backwards-in-replace | |
5307 'vip-vi-style-in-minibuffer | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5308 'vip-vi-state-hook |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5309 'vip-insert-state-hook |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5310 'vip-replace-state-hook |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5311 'vip-emacs-state-hook |
10789 | 5312 'ex-cycle-other-window |
5313 'ex-cycle-through-non-files | |
5314 'vip-expert-level | |
5315 'major-mode | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5316 'vip-device-type |
10789 | 5317 'color-display-p |
5318 'frame-parameters | |
5319 'minibuffer-vi-face | |
5320 'minibuffer-insert-face | |
5321 'minibuffer-emacs-face | |
5322 )) | |
5323 (setq salutation " | |
5324 Congratulations! You may have unearthed a bug in Viper! | |
5325 Please mail a concise, accurate summary of the problem to the address above. | |
5326 | |
5327 -------------------------------------------------------------------") | |
5328 (setq window-config (current-window-configuration)) | |
5329 (with-output-to-temp-buffer " *vip-info*" | |
5330 (switch-to-buffer " *vip-info*") | |
5331 (delete-other-windows) | |
5332 (princ " | |
5333 PLEASE FOLLOW THESE PROCEDURES | |
5334 ------------------------------ | |
5335 | |
5336 Before reporting a bug, please verify that it is related to Viper, and is | |
5337 not cause by other packages you are using. | |
5338 | |
5339 Don't report compilation warnings, unless you are certain that there is a | |
5340 problem. These warnings are normal and unavoidable. | |
5341 | |
5342 Please note that users should not modify variables and keymaps other than | |
5343 those advertised in the manual. Such `customization' is likely to crash | |
5344 Viper, as it would any other improperly customized Emacs package. | |
5345 | |
5346 If you are reporting an error message received while executing one of the | |
5347 Viper commands, type: | |
5348 | |
5349 M-x set-variable <Return> debug-on-error <Return> t <Return> | |
5350 | |
5351 Then reproduce the error. The above command will cause Emacs to produce a | |
5352 back trace of the execution that leads to the error. Please include this | |
5353 trace in your bug report. | |
5354 | |
5355 If you believe that one of Viper's commands goes into an infinite loop | |
5356 \(e.g., Emacs freezes\), type: | |
5357 | |
5358 M-x set-variable <Return> debug-on-quit <Return> t <Return> | |
5359 | |
5360 Then reproduce the problem. Wait for a few seconds, then type C-g to abort | |
5361 the current command. Include the resulting back trace in the bug report. | |
5362 | |
5363 Mail anyway (y or n)? ") | |
5364 (if (y-or-n-p "Mail anyway? ") | |
5365 () | |
5366 (set-window-configuration window-config) | |
5367 (error "Bug report aborted"))) | |
5368 | |
5369 (require 'reporter) | |
5370 (set-window-configuration window-config) | |
5371 | |
5372 (reporter-submit-bug-report "kifer@cs.sunysb.edu" | |
5373 (vip-version) | |
5374 varlist | |
5375 nil 'delete-other-windows | |
5376 salutation) | |
5377 )) | |
5378 | |
5379 | |
5380 | |
5381 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5382 ;; Smoothes out the difference between Emacs' unread-command-events |
10789 | 5383 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of |
5384 ;; events or a sequence of keys. | |
5385 ;; | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5386 ;; Due to the way unread-command-events in Emacs (not XEmacs), a non-event |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5387 ;; symbol in unread-command-events list may cause Emacs to turn this symbol |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5388 ;; into an event. Below, we delete nil from event lists, since nil is the most |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5389 ;; common symbol that might appear in this wrong context. |
10789 | 5390 (defun vip-set-unread-command-events (arg) |
5391 (if vip-emacs-p | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5392 (setq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5393 unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5394 (let ((new-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5395 (cond ((eventp arg) (list arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5396 ((listp arg) arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5397 ((sequencep arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5398 (listify-key-sequence arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5399 (t (error |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5400 "vip-set-unread-command-events: Invalid argument, %S" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5401 arg))))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5402 (if (not (eventp nil)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5403 (setq new-events (delq nil new-events))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5404 (append new-events unread-command-events))) |
10789 | 5405 ;; XEmacs |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5406 (setq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5407 unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5408 (append |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5409 (cond ((vip-characterp arg) (list (character-to-event arg))) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5410 ((eventp arg) (list arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5411 ((stringp arg) (mapcar 'character-to-event arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5412 ((vectorp arg) (append arg nil)) ; turn into list |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5413 ((listp arg) (vip-eventify-list-xemacs arg)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5414 (t (error |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5415 "vip-set-unread-command-events: Invalid argument, %S" arg))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5416 unread-command-events)))) |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5417 |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5418 ;; list is assumed to be a list of events of characters |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5419 (defun vip-eventify-list-xemacs (lis) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5420 (mapcar |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5421 (function (lambda (elt) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5422 (cond ((vip-characterp elt) (character-to-event elt)) |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5423 ((eventp elt) elt) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5424 (t (error |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5425 "vip-eventify-list-xemacs: can't convert to event, %S" |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5426 elt))))) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5427 lis)) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5428 |
10789 | 5429 |
5430 | |
5431 ;;; Bring in the rest of the files | |
5432 (require 'viper-mous) | |
5433 (require 'viper-macs) | |
5434 (require 'viper-ex) | |
5435 | |
5436 | |
5437 | |
5438 ;; The following is provided for compatibility with older VIP's | |
5439 | |
5440 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) | |
5441 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) | |
5442 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) | |
5443 | |
5444 | |
5445 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5446 ;;; Load .vip and set up hooks |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5447 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5448 ;; This hook designed to enable Vi-style editing in comint-based modes." |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5449 (defun vip-comint-mode-hook () |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5450 (setq require-final-newline nil |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5451 vip-ex-style-editing-in-insert nil |
10789 | 5452 vip-ex-style-motion nil) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5453 (vip-change-state-to-insert)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5454 |
10789 | 5455 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5456 ;; This sets major mode hooks to make them come up in vi-state. |
10789 | 5457 (defun vip-set-hooks () |
5458 | |
5459 ;; It is of course a misnomer to call viper-mode a `major mode'. | |
5460 ;; However, this has the effect that if the user didn't specify the | |
5461 ;; default mode, new buffers that fall back on the default will come up | |
5462 ;; in Fundamental Mode and Vi state. | |
5463 (setq default-major-mode 'viper-mode) | |
5464 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5465 ;; The following major modes should come up in vi-state |
10789 | 5466 (defadvice fundamental-mode (after vip-fundamental-mode-ad activate) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5467 "Run `vip-change-state-to-vi' on entry." |
10789 | 5468 (vip-change-state-to-vi)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5469 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5470 (defvar makefile-mode-hook) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5471 (add-hook 'makefile-mode-hook 'viper-mode) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5472 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5473 (defvar help-mode-hook) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5474 (add-hook 'help-mode-hook 'viper-mode) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5475 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5476 (defvar awk-mode-hook) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5477 (add-hook 'awk-mode-hook 'viper-mode) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5478 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5479 (defvar html-mode-hook) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5480 (add-hook 'html-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5481 (defvar html-helper-mode-hook) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5482 (add-hook 'html-helper-mode-hook 'viper-mode) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5483 (defvar java-mode-hook) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5484 (add-hook 'java-mode-hook 'viper-mode) |
10789 | 5485 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5486 (defvar emacs-lisp-mode-hook) |
10789 | 5487 (add-hook 'emacs-lisp-mode-hook 'viper-mode) |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5488 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5489 (defvar lisp-mode-hook) |
10789 | 5490 (add-hook 'lisp-mode-hook 'viper-mode) |
5491 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5492 (defvar bibtex-mode-hook) |
10789 | 5493 (add-hook 'bibtex-mode-hook 'viper-mode) |
5494 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5495 (defvar cc-mode-hook) |
10789 | 5496 (add-hook 'cc-mode-hook 'viper-mode) |
5497 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5498 (defvar c-mode-hook) |
10789 | 5499 (add-hook 'c-mode-hook 'viper-mode) |
5500 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5501 (defvar c++-mode-hook) |
10789 | 5502 (add-hook 'c++-mode-hook 'viper-mode) |
5503 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5504 (defvar lisp-interaction-mode-hook) |
10789 | 5505 (add-hook 'lisp-interaction-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5506 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5507 (defvar fortran-mode-hook) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5508 (add-hook 'fortran-mode-hook 'vip-mode) |
10789 | 5509 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5510 (defvar text-mode-hook) |
10789 | 5511 (add-hook 'text-mode-hook 'viper-mode) |
5512 | |
5513 (add-hook 'completion-list-mode-hook 'viper-mode) | |
5514 (add-hook 'compilation-mode-hook 'viper-mode) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5515 |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5516 (add-hook 'perl-mode-hook 'viper-mode) |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5517 (add-hook 'tcl-mode-hook 'viper-mode) |
10789 | 5518 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5519 (defvar emerge-startup-hook) |
10789 | 5520 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5521 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5522 ;; Tell vc-diff to put *vc* in Vi mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5523 (if (featurep 'vc) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5524 (defadvice vc-diff (after vip-vc-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5525 "Force Vi state in VC diff buffer." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5526 (vip-change-state-to-vi)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5527 (vip-eval-after-load |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5528 "vc" |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5529 '(defadvice vc-diff (after vip-vc-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5530 "Force Vi state in VC diff buffer." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5531 (vip-change-state-to-vi)))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5532 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5533 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5534 "emerge" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5535 '(defadvice emerge-quit (after vip-emerge-advice activate) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5536 "Run `vip-change-state-to-vi' after quitting emerge." |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5537 (vip-change-state-to-vi))) |
10789 | 5538 ;; In case Emerge was loaded before Viper. |
5539 (defadvice emerge-quit (after vip-emerge-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5540 "Run `vip-change-state-to-vi' after quitting emerge." |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5541 (vip-change-state-to-vi)) |
10789 | 5542 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5543 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5544 "asm-mode" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5545 '(defadvice asm-mode (after vip-asm-mode-ad activate) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5546 "Run `vip-change-state-to-vi' on entry." |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5547 (vip-change-state-to-vi))) |
10789 | 5548 |
5549 ;; passwd.el sets up its own buffer, which turns up in Vi mode, | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5550 ;; thus overriding the local map. We don't need Vi mode here. |
10789 | 5551 (vip-eval-after-load |
5552 "passwd" | |
5553 '(defadvice read-passwd-1 (before vip-passwd-ad activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5554 "Switch to emacs state while reading password." |
10789 | 5555 (vip-change-state-to-emacs))) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5556 |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5557 (vip-eval-after-load |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5558 "prolog" |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5559 '(defadvice prolog-mode (after vip-prolog-ad activate) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5560 "Switch to Vi state in Prolog mode." |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5561 (vip-change-state-to-vi))) |
10789 | 5562 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5563 ;; Emacs shell, ange-ftp, and comint-based modes |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5564 (defvar comint-mode-hook) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5565 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5566 'comint-mode 'insert-state vip-comint-mode-modifier-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5567 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5568 'comint-mode 'vi-state vip-comint-mode-modifier-map) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5569 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) |
10789 | 5570 |
5571 ;; Shell scripts | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5572 (defvar sh-mode-hook) |
10789 | 5573 (add-hook 'sh-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5574 (defvar ksh-mode-hook) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5575 (add-hook 'ksh-mode-hook 'viper-mode) |
10789 | 5576 |
5577 ;; Dired | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5578 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map) |
10789 | 5579 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) |
5580 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5581 ;; MH-E |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5582 (vip-modify-major-mode 'mh-folder-mode 'emacs-state vip-slash-and-colon-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5583 ;; changing state to emacs is needed so the preceding will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5584 (add-hook 'mh-folder-mode-hook 'vip-change-state-to-emacs) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5585 (add-hook 'mh-show-mode-hook 'viper-mode) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5586 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5587 ;; Gnus |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5588 (vip-modify-major-mode 'gnus-group-mode 'emacs-state vip-slash-and-colon-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5589 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5590 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5591 ;; changing state to emacs is needed so the preceding will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5592 (add-hook 'gnus-group-mode-hook 'vip-change-state-to-emacs) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5593 (add-hook 'gnus-summary-mode-hook 'vip-change-state-to-emacs) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5594 (add-hook 'gnus-article-mode-hook 'viper-mode) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5595 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5596 ;; Info |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5597 (vip-modify-major-mode 'Info-mode 'emacs-state vip-slash-and-colon-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5598 ;; Switching to emacs is needed so the above will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5599 (defadvice Info-mode (after vip-Info-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5600 "Switch to emacs mode." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5601 (vip-change-state-to-emacs)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5602 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5603 ;; Buffer menu |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5604 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5605 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5606 ;; Switching to emacs is needed so the above will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5607 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5608 "Switch to emacs mode." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5609 (vip-change-state-to-emacs)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5610 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5611 ;; View mode |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5612 (if vip-emacs-p |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5613 (progn |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5614 (defvar view-mode-hook) |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5615 (add-hook 'view-mode-hook 'vip-change-state-to-emacs)) |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5616 (defadvice view-minor-mode (after vip-view-ad activate) |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5617 "Switch to Emacs state in View mode." |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5618 (vip-change-state-to-emacs)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5619 (defvar view-hook) |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5620 (add-hook 'view-hook 'vip-change-state-to-emacs)) |
10789 | 5621 |
5622 ;; For VM users. | |
5623 ;; Put summary and other VM buffers in Emacs state. | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5624 (defvar vm-mode-hooks) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5625 (defvar vm-summary-mode-hooks) |
10789 | 5626 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs) |
5627 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs) | |
5628 | |
5629 ;; For RMAIL users. | |
5630 ;; Put buf in Emacs state after edit. | |
5631 (vip-eval-after-load | |
5632 "rmailedit" | |
5633 '(defadvice rmail-cease-edit (after vip-rmail-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5634 "Switch to emacs state when done editing message." |
10789 | 5635 (vip-change-state-to-emacs))) |
5636 ;; In case RMAIL was loaded before Viper. | |
5637 (defadvice rmail-cease-edit (after vip-rmail-advice activate) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5638 "Switch to emacs state when done editing message." |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5639 (vip-change-state-to-emacs)) |
10789 | 5640 ) ; vip-set-hooks |
5641 | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5642 ;; Set some useful macros |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5643 ;; These must be before we load .vip, so the user can unrecord them. |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5644 |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5645 ;; repeat the 2nd previous command without rotating the command history |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5646 (vip-record-kbd-macro |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5647 (vector vip-repeat-from-history-key '\1) 'vi-state |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5648 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5649 ;; repeat the 3d previous command without rotating the command history |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5650 (vip-record-kbd-macro |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5651 (vector vip-repeat-from-history-key '\2) 'vi-state |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5652 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5653 |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5654 ;; toggle case sensitivity in search |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5655 (vip-record-kbd-macro |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5656 "//" 'vi-state |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5657 [1 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5658 ;; toggle regexp/vanila search |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5659 (vip-record-kbd-macro |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5660 "///" 'vi-state |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5661 [2 (meta x) v i p - t o g g l e - s e a r c h - s t y l e return] 't) |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5662 |
10789 | 5663 |
5664 ;; ~/.vip is loaded if it exists | |
5665 (if (and (file-exists-p vip-custom-file-name) | |
5666 (not noninteractive)) | |
5667 (load vip-custom-file-name)) | |
5668 | |
5669 ;; VIP compatibility: merge whatever the user has in vip-mode-map into | |
5670 ;; Viper's basic map. | |
5671 (vip-add-keymap vip-mode-map vip-vi-global-user-map) | |
5672 | |
5673 | |
5674 ;; Applying Viper customization -- runs after (load .vip) | |
5675 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5676 ;; Save user settings or Viper defaults for vars controled by vip-expert-level |
10789 | 5677 (setq vip-saved-user-settings |
5678 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) | |
5679 (cons 'vip-always vip-always) | |
5680 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) | |
5681 (cons 'vip-ex-style-motion vip-ex-style-motion) | |
5682 (cons 'vip-ex-style-editing-in-insert | |
5683 vip-ex-style-editing-in-insert) | |
5684 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi) | |
5685 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) | |
5686 (cons 'vip-re-search vip-re-search))) | |
5687 | |
5688 | |
5689 (vip-set-minibuffer-style) | |
5690 (vip-set-minibuffer-faces) | |
5691 (vip-set-search-face) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5692 (vip-set-replace-overlay-face) |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5693 (if vip-buffer-search-char |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5694 (vip-buffer-search-enable)) |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5695 (vip-update-alphanumeric-class) |
10789 | 5696 |
5697 ;;; Familiarize Viper with some minor modes that have their own keymaps | |
5698 (vip-harness-minor-mode "compile") | |
5699 (vip-harness-minor-mode "outline") | |
5700 (vip-harness-minor-mode "allout") | |
5701 (vip-harness-minor-mode "xref") | |
5702 (vip-harness-minor-mode "lmenu") | |
5703 (vip-harness-minor-mode "vc") | |
5704 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5705 (vip-harness-minor-mode "latex") ; which is in one of these two files |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5706 (vip-harness-minor-mode "cyrillic") |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5707 (vip-harness-minor-mode "russian") |
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5708 (vip-harness-minor-mode "view-less") |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5709 (vip-harness-minor-mode "view") |
10789 | 5710 |
5711 | |
5712 ;; Intercept maps could go in viper-keym.el | |
5713 ;; We keep them here in case someone redefines them in ~/.vip | |
5714 | |
5715 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
5716 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
5717 | |
5718 ;; This is taken care of by vip-insert-global-user-map. | |
5719 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key) | |
5720 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5721 |
10789 | 5722 ;; The default vip-toggle-key is \C-z; for the novice, it suspends or |
5723 ;; iconifies Emacs | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5724 (define-key vip-vi-intercept-map vip-toggle-key 'vip-toggle-key-action) |
10789 | 5725 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) |
5726 | |
5727 | |
5728 (if (or vip-always | |
5729 (and (< vip-expert-level 5) (> vip-expert-level 0))) | |
5730 (vip-set-hooks)) | |
5731 | |
5732 ;; Let all minor modes take effect after loading | |
5733 ;; this may not be enough, so we also set default minor-mode-alist. | |
5734 ;; Without setting the default, new buffers that come up in emacs mode have | |
5735 ;; minor-mode-map-alist = nil, unless we call vip-change-state-* | |
5736 (if (eq vip-current-state 'emacs-state) | |
5737 (progn | |
5738 (vip-change-state-to-emacs) | |
5739 (setq-default minor-mode-map-alist minor-mode-map-alist) | |
5740 )) | |
5741 | |
12900
7a7b8d42bdec
* viper.el (vip-set-hooks): Use view-mode-hook in emacs and view hook in xemacs.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12855
diff
changeset
|
5742 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5743 (run-hooks 'vip-load-hook) ; the last chance to change something |
10789 | 5744 |
5745 (provide 'viper) | |
5746 (provide 'vip19) | |
5747 (provide 'vip) | |
5748 | |
5749 ;;; viper.el ends here |