Mercurial > emacs
annotate lisp/emulation/viper.el @ 16652:eb3f3934a185
(normal-top-level, command-line, command-line-1):
User w32 instead of ms-windows for window-system symbol.
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Mon, 09 Dec 1996 23:38:03 +0000 |
parents | b2fae8abc5b0 |
children | beb94a5271e2 |
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 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
824 (defvar vip-custom-file-name (vip-convert-standard-file-name "~/.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) |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
2850 (indent-to col)))) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
2851 (vip-change-state-to-insert))))) |
10789 | 2852 |
2853 (defun vip-Open-line (arg) | |
2854 "Open line above." | |
2855 (interactive "P") | |
2856 (vip-set-complex-command-for-undo) | |
2857 (let ((val (vip-p-val arg)) | |
2858 (com (vip-getcom arg))) | |
2859 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil)) | |
2860 (let ((col (current-indentation))) | |
2861 (if (equal com ?r) | |
2862 (vip-loop val | |
2863 (progn | |
2864 (beginning-of-line) | |
2865 (open-line 1) | |
2866 (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
|
2867 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2868 (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
|
2869 (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
|
2870 (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
|
2871 (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
|
2872 )) |
10789 | 2873 (vip-yank-last-insertion))) |
2874 (beginning-of-line) | |
2875 (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
|
2876 (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
|
2877 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2878 (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
|
2879 (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
|
2880 (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
|
2881 (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
|
2882 )) |
10789 | 2883 (vip-change-state-to-insert))))) |
2884 | |
2885 (defun vip-open-line-at-point (arg) | |
2886 "Open line at point." | |
2887 (interactive "P") | |
2888 (vip-set-complex-command-for-undo) | |
2889 (let ((val (vip-p-val arg)) | |
2890 (com (vip-getcom arg))) | |
2891 (vip-set-destructive-command | |
2892 (list 'vip-open-line-at-point val ?r nil nil nil)) | |
2893 (if (equal com ?r) | |
2894 (vip-loop val | |
2895 (progn | |
2896 (open-line 1) | |
2897 (vip-yank-last-insertion))) | |
2898 (open-line 1) | |
2899 (vip-change-state-to-insert)))) | |
2900 | |
2901 (defun vip-substitute (arg) | |
2902 "Substitute characters." | |
2903 (interactive "P") | |
2904 (let ((val (vip-p-val arg)) | |
2905 (com (vip-getcom arg))) | |
2906 (push-mark nil t) | |
2907 (forward-char val) | |
2908 (if (equal com ?r) | |
2909 (vip-change-subr (mark t) (point)) | |
2910 (vip-change (mark t) (point))) | |
2911 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil)) | |
2912 )) | |
2913 | |
2914 (defun vip-substitute-line (arg) | |
2915 "Substitute lines." | |
2916 (interactive "p") | |
2917 (vip-set-complex-command-for-undo) | |
2918 (vip-line (cons arg ?C))) | |
2919 | |
2920 ;; Prepare for replace | |
2921 (defun vip-start-replace () | |
2922 (setq vip-began-as-replace t | |
2923 vip-sitting-in-replace t | |
2924 vip-replace-chars-to-delete 0 | |
2925 vip-replace-chars-deleted 0) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2926 (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
|
2927 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t) |
10789 | 2928 ;; this will get added repeatedly, but no harm |
2929 (add-hook 'after-change-functions 'vip-after-change-sentinel t) | |
2930 (add-hook 'before-change-functions 'vip-before-change-sentinel t) | |
2931 (vip-move-marker-locally 'vip-last-posn-in-replace-region | |
2932 (vip-replace-start)) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2933 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2934 '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
|
2935 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2936 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
10789 | 2937 ) |
2938 | |
2939 | |
2940 ;; checks how many chars were deleted by the last change | |
2941 (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
|
2942 (setq vip-replace-chars-deleted |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2943 (- end beg |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2944 (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
|
2945 (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
|
2946 ))) |
10789 | 2947 |
2948 ;; Invoked as an after-change-function to set up parameters of the last change | |
2949 (defun vip-replace-mode-spy-after (beg end length) | |
2950 (if (memq vip-intermediate-command '(repeating-insertion-from-ring)) | |
2951 (progn | |
2952 (setq vip-replace-chars-to-delete 0) | |
2953 (vip-move-marker-locally | |
2954 'vip-last-posn-in-replace-region (point))) | |
2955 | |
2956 (let (beg-col end-col real-end chars-to-delete) | |
2957 (setq real-end (min end (vip-replace-end))) | |
2958 (save-excursion | |
2959 (goto-char beg) | |
2960 (setq beg-col (current-column)) | |
2961 (goto-char real-end) | |
2962 (setq end-col (current-column))) | |
2963 | |
2964 ;; If beg of change is outside the replacement region, then don't | |
2965 ;; delete anything in the repl region (set chars-to-delete to 0). | |
2966 ;; | |
2967 ;; This works fine except that we have to take special care of | |
2968 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which | |
2969 ;; sometimes simply shifts the repl region rightwards, without | |
2970 ;; deleting an equal amount of characters. | |
2971 ;; | |
2972 ;; 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
|
2973 ;; 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
|
2974 ;; replacement region (but ends inside) then new-dabbrev.el first |
10789 | 2975 ;; moves cursor backwards, to the beginning of the word to be |
2976 ;; completed (say, pt A). Then it inserts the | |
2977 ;; completed word and then deletes the old, incomplete part. | |
2978 ;; Since the complete word is inserted at position before the repl | |
2979 ;; region, the next If-statement would have set chars-to-delete to 0 | |
2980 ;; unless we check for the current command, which must be | |
2981 ;; dabbrev-expand. | |
2982 ;; | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2983 ;; In fact, it might be also useful to have overlays for insert |
10789 | 2984 ;; regions as well, since this will let us capture the situation when |
2985 ;; dabbrev-expand goes back past the insertion point to find the | |
2986 ;; beginning of the word to be expanded. | |
2987 (if (or (and (<= (vip-replace-start) beg) | |
2988 (<= beg (vip-replace-end))) | |
2989 (and (= length 0) (eq this-command 'dabbrev-expand))) | |
2990 (setq chars-to-delete | |
2991 (max (- end-col beg-col) (- real-end beg) 0)) | |
2992 (setq chars-to-delete 0)) | |
2993 | |
2994 ;; if beg = last change position, it means that we are within the | |
2995 ;; same command that does multiple changes. Moreover, it means | |
2996 ;; that we have two subsequent changes (insert/delete) that | |
2997 ;; complement each other. | |
2998 (if (= beg (marker-position vip-last-posn-in-replace-region)) | |
2999 (setq vip-replace-chars-to-delete | |
3000 (- (+ chars-to-delete vip-replace-chars-to-delete) | |
3001 vip-replace-chars-deleted)) | |
3002 (setq vip-replace-chars-to-delete chars-to-delete)) | |
3003 | |
3004 (vip-move-marker-locally | |
3005 'vip-last-posn-in-replace-region | |
3006 (max (if (> end (vip-replace-end)) (vip-replace-start) end) | |
3007 (or (marker-position vip-last-posn-in-replace-region) | |
3008 (vip-replace-start)) | |
3009 )) | |
3010 | |
3011 (setq vip-replace-chars-to-delete | |
3012 (max 0 (min vip-replace-chars-to-delete | |
3013 (- (vip-replace-end) | |
3014 vip-last-posn-in-replace-region)))) | |
3015 ))) | |
3016 | |
3017 | |
3018 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if | |
3019 ;; posn is within the overlay. | |
3020 (defun vip-finish-change (posn) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3021 (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
|
3022 (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
|
3023 (vip-remove-hook 'vip-post-command-hooks |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3024 'vip-replace-state-post-command-sentinel) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3025 (vip-remove-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3026 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) |
10789 | 3027 (vip-restore-cursor-color) |
3028 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it | |
3029 (save-excursion | |
3030 (if (and | |
3031 vip-replace-overlay | |
3032 (>= posn (vip-replace-start)) | |
3033 (< posn (vip-replace-end))) | |
3034 (delete-region posn (vip-replace-end))) | |
3035 ) | |
3036 | |
3037 (if (eq vip-current-state 'replace-state) | |
3038 (vip-downgrade-to-insert)) | |
3039 ;; replace mode ended => nullify vip-last-posn-in-replace-region | |
3040 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil) | |
3041 (vip-hide-replace-overlay) | |
3042 (vip-refresh-mode-line) | |
3043 (vip-put-string-on-kill-ring vip-last-replace-region) | |
3044 ) | |
3045 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3046 ;; Make STRING be the first element of the kill ring. |
10789 | 3047 (defun vip-put-string-on-kill-ring (string) |
3048 (setq kill-ring (cons string kill-ring)) | |
3049 (if (> (length kill-ring) kill-ring-max) | |
3050 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) | |
3051 (setq kill-ring-yank-pointer kill-ring)) | |
3052 | |
3053 (defun vip-finish-R-mode () | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3054 (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
|
3055 (vip-remove-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3056 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) |
10789 | 3057 (vip-downgrade-to-insert)) |
3058 | |
3059 (defun vip-start-R-mode () | |
3060 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number | |
3061 (overwrite-mode 1) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3062 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3063 '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
|
3064 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3065 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
10789 | 3066 ) |
3067 | |
3068 | |
3069 | |
3070 (defun vip-replace-state-exit-cmd () | |
3071 "Binding for keys that cause Replace state to switch to Vi or to Insert. | |
3072 These keys are ESC, RET, and LineFeed" | |
3073 (interactive) | |
3074 (if overwrite-mode ;; If you are in replace mode invoked via 'R' | |
3075 (vip-finish-R-mode) | |
3076 (vip-finish-change vip-last-posn-in-replace-region)) | |
3077 (let (com) | |
3078 (if (eq this-command 'vip-intercept-ESC-key) | |
3079 (setq com 'vip-exit-insert-state) | |
3080 (vip-set-unread-command-events last-input-char) | |
3081 (setq com (key-binding (read-key-sequence nil)))) | |
3082 | |
3083 (condition-case conds | |
3084 (command-execute com) | |
3085 (error | |
3086 (vip-message-conditions conds))) | |
3087 ) | |
3088 (vip-hide-replace-overlay)) | |
3089 | |
3090 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3091 ;; 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
|
3092 ;; Similar to Emacs's own overwrite-mode. |
10789 | 3093 (defun vip-overwrite (arg) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3094 "Begin overwrite mode." |
10789 | 3095 (interactive "P") |
3096 (let ((val (vip-p-val arg)) | |
3097 (com (vip-getcom arg)) (len)) | |
3098 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil)) | |
3099 (if com | |
3100 (progn | |
3101 ;; Viper saves inserted text in vip-last-insertion | |
3102 (setq len (length vip-last-insertion)) | |
3103 (delete-char len) | |
3104 (vip-loop val (vip-yank-last-insertion))) | |
3105 (setq last-command 'vip-overwrite) | |
3106 (vip-set-complex-command-for-undo) | |
3107 (vip-set-replace-overlay (point) (vip-line-pos 'end)) | |
3108 (vip-change-state-to-replace) | |
3109 ))) | |
3110 | |
3111 | |
3112 ;; line commands | |
3113 | |
3114 (defun vip-line (arg) | |
3115 (let ((val (car arg)) | |
3116 (com (cdr arg))) | |
3117 (vip-move-marker-locally 'vip-com-point (point)) | |
3118 (if (not (eobp)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3119 (vip-next-line-carefully (1- val))) |
10789 | 3120 ;; this ensures that dd, cc, D, yy will do the right thing on the last |
3121 ;; line of buffer when this line has no \n. | |
3122 (vip-add-newline-at-eob-if-necessary) | |
3123 (vip-execute-com 'vip-line val com)) | |
3124 (if (and (eobp) (not (bobp))) (forward-line -1)) | |
3125 ) | |
3126 | |
3127 (defun vip-yank-line (arg) | |
3128 "Yank ARG lines (in Vi's sense)." | |
3129 (interactive "P") | |
3130 (let ((val (vip-p-val arg))) | |
3131 (vip-line (cons val ?Y)))) | |
3132 | |
3133 | |
3134 ;; region commands | |
3135 | |
3136 (defun vip-region (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3137 "Execute command on a region." |
10789 | 3138 (interactive "P") |
3139 (let ((val (vip-P-val arg)) | |
3140 (com (vip-getcom arg))) | |
3141 (vip-move-marker-locally 'vip-com-point (point)) | |
3142 (exchange-point-and-mark) | |
3143 (vip-execute-com 'vip-region val com))) | |
3144 | |
3145 (defun vip-Region (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3146 "Execute command on a Region." |
10789 | 3147 (interactive "P") |
3148 (let ((val (vip-P-val arg)) | |
3149 (com (vip-getCom arg))) | |
3150 (vip-move-marker-locally 'vip-com-point (point)) | |
3151 (exchange-point-and-mark) | |
3152 (vip-execute-com 'vip-Region val com))) | |
3153 | |
3154 (defun vip-replace-char (arg) | |
3155 "Replace the following ARG chars by the character read." | |
3156 (interactive "P") | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3157 (if (and (eolp) (bolp)) (error "No character to replace here")) |
10789 | 3158 (let ((val (vip-p-val arg)) |
3159 (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
|
3160 (vip-replace-char-subr com val) |
10789 | 3161 (if (and (eolp) (not (bolp))) (forward-char 1)) |
3162 (vip-set-destructive-command | |
3163 (list 'vip-replace-char val ?r nil vip-d-char nil)) | |
3164 )) | |
3165 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3166 (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
|
3167 (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
|
3168 (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
|
3169 char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3170 (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
|
3171 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
|
3172 (read-char))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3173 (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
|
3174 ;; 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
|
3175 (progn |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3176 (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
|
3177 (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
|
3178 (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
|
3179 (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
|
3180 (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
|
3181 (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
|
3182 (vip-loop (if (> arg 0) arg (- arg)) |
10789 | 3183 (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
|
3184 (backward-char arg))) |
10789 | 3185 |
3186 | |
3187 ;; basic cursor movement. j, k, l, h commands. | |
3188 | |
3189 (defun vip-forward-char (arg) | |
3190 "Move point right ARG characters (left if ARG negative). | |
3191 On reaching end of line, stop and signal error." | |
3192 (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
|
3193 (vip-leave-region-active) |
10789 | 3194 (let ((val (vip-p-val arg)) |
3195 (com (vip-getcom arg))) | |
3196 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3197 (if vip-ex-style-motion | |
3198 (progn | |
3199 ;; the boundary condition check gets weird here because | |
3200 ;; forward-char may be the parameter of a delete, and 'dl' works | |
3201 ;; just like 'x' for the last char on a line, so we have to allow | |
3202 ;; the forward motion before the 'vip-execute-com', but, of | |
3203 ;; course, 'dl' doesn't work on an empty line, so we have to | |
3204 ;; catch that condition before 'vip-execute-com' | |
3205 (if (and (eolp) (bolp)) (error "") (forward-char val)) | |
3206 (if com (vip-execute-com 'vip-forward-char val com)) | |
3207 (if (eolp) (progn (backward-char 1) (error "")))) | |
3208 (forward-char val) | |
3209 (if com (vip-execute-com 'vip-forward-char val com))))) | |
3210 | |
3211 (defun vip-backward-char (arg) | |
3212 "Move point left ARG characters (right if ARG negative). | |
3213 On reaching beginning of line, stop and signal error." | |
3214 (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
|
3215 (vip-leave-region-active) |
10789 | 3216 (let ((val (vip-p-val arg)) |
3217 (com (vip-getcom arg))) | |
3218 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3219 (if vip-ex-style-motion | |
3220 (progn | |
3221 (if (bolp) (error "") (backward-char val)) | |
3222 (if com (vip-execute-com 'vip-backward-char val com))) | |
3223 (backward-char val) | |
3224 (if com (vip-execute-com 'vip-backward-char val com))))) | |
3225 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3226 ;; Like forward-char, but doesn't move at end of buffer. |
10789 | 3227 (defun vip-forward-char-carefully (&optional arg) |
3228 (setq arg (or arg 1)) | |
3229 (if (>= (point-max) (+ (point) arg)) | |
3230 (forward-char arg) | |
3231 (goto-char (point-max)))) | |
3232 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3233 ;; Like backward-char, but doesn't move at end of buffer. |
10789 | 3234 (defun vip-backward-char-carefully (&optional arg) |
3235 (setq arg (or arg 1)) | |
3236 (if (<= (point-min) (- (point) arg)) | |
3237 (backward-char arg) | |
3238 (goto-char (point-min)))) | |
3239 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3240 (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
|
3241 (condition-case nil |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3242 (next-line arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3243 (error nil))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3244 |
10789 | 3245 |
3246 | |
3247 ;;; Word command | |
3248 | |
3249 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators | |
3250 ;; for word movement. When executed with a destructive command, \n is | |
3251 ;; 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
|
3252 ;; 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
|
3253 ;; 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
|
3254 ;; is 'vi, then `_' is part of the word. |
10789 | 3255 |
3256 ;; skip only one \n | |
3257 (defun vip-skip-separators (forward) | |
3258 (if forward | |
3259 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3260 (vip-skip-all-separators-forward 'within-line) |
10789 | 3261 (if (looking-at "\n") |
3262 (progn | |
3263 (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
|
3264 (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
|
3265 (vip-skip-all-separators-backward 'within-line) |
10789 | 3266 (backward-char) |
3267 (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
|
3268 (vip-skip-all-separators-backward 'within-line) |
10789 | 3269 (forward-char)))) |
3270 | |
3271 (defun vip-forward-word-kernel (val) | |
3272 (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
|
3273 (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
|
3274 (vip-skip-alpha-forward "_") |
10789 | 3275 (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
|
3276 ((vip-looking-at-separator) |
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 ((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
|
3279 (vip-skip-nonalphasep-forward) |
10789 | 3280 (vip-skip-separators t))) |
3281 (setq val (1- val)))) | |
3282 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3283 ;; first search backward for pat. Then skip chars backwards using aux-pat |
10789 | 3284 (defun vip-fwd-skip (pat aux-pat lim) |
3285 (if (and (save-excursion | |
3286 (re-search-backward pat lim t)) | |
3287 (= (point) (match-end 0))) | |
3288 (goto-char (match-beginning 0))) | |
3289 (skip-chars-backward aux-pat lim) | |
3290 (if (= (point) lim) | |
3291 (vip-forward-char-carefully)) | |
3292 ) | |
3293 | |
3294 | |
3295 (defun vip-forward-word (arg) | |
3296 "Forward word." | |
3297 (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
|
3298 (vip-leave-region-active) |
10789 | 3299 (let ((val (vip-p-val arg)) |
3300 (com (vip-getcom arg))) | |
3301 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3302 (vip-forward-word-kernel val) | |
3303 (if com (progn | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3304 (cond ((memq com (list ?c (- ?c))) |
10789 | 3305 (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
|
3306 ;; 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
|
3307 ((memq com (list ?y (- ?y))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3308 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) |
10789 | 3309 ((vip-dotable-command-p com) |
3310 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | |
3311 (vip-execute-com 'vip-forward-word val com))))) | |
3312 | |
3313 | |
3314 (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
|
3315 "Forward word delimited by white characters." |
10789 | 3316 (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
|
3317 (vip-leave-region-active) |
10789 | 3318 (let ((val (vip-p-val arg)) |
3319 (com (vip-getcom arg))) | |
3320 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3321 (vip-loop val | |
3322 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3323 (vip-skip-nonseparators 'forward) |
10789 | 3324 (vip-skip-separators t))) |
3325 (if com (progn | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3326 (cond ((memq com (list ?c (- ?c))) |
10789 | 3327 (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
|
3328 ;; 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
|
3329 ((memq com (list ?y (- ?y))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3330 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) |
10789 | 3331 ((vip-dotable-command-p com) |
3332 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | |
3333 (vip-execute-com 'vip-forward-Word val com))))) | |
3334 | |
3335 | |
3336 ;; this is a bit different from Vi, but Vi's end of word | |
3337 ;; makes no sense whatsoever | |
3338 (defun vip-end-of-word-kernel () | |
3339 (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
|
3340 (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
|
3341 (vip-skip-all-separators-forward)) |
10789 | 3342 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3343 (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
|
3344 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward))) |
10789 | 3345 (vip-backward-char-carefully)) |
3346 | |
3347 (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
|
3348 (or (eobp) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3349 (save-excursion |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3350 (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
|
3351 (forward-char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3352 (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
|
3353 ((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
|
3354 (forward-char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3355 (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 |
10789 | 3357 |
3358 (defun vip-end-of-word (arg &optional careful) | |
3359 "Move point to end of current word." | |
3360 (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
|
3361 (vip-leave-region-active) |
10789 | 3362 (let ((val (vip-p-val arg)) |
3363 (com (vip-getcom arg))) | |
3364 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3365 (vip-loop val (vip-end-of-word-kernel)) | |
3366 (if com | |
3367 (progn | |
3368 (forward-char) | |
3369 (vip-execute-com 'vip-end-of-word val com))))) | |
3370 | |
3371 (defun vip-end-of-Word (arg) | |
3372 "Forward to end of word delimited by white character." | |
3373 (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
|
3374 (vip-leave-region-active) |
10789 | 3375 (let ((val (vip-p-val arg)) |
3376 (com (vip-getcom arg))) | |
3377 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3378 (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
|
3379 (progn |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3380 (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
|
3381 (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
|
3382 (backward-char))) |
10789 | 3383 (if com |
3384 (progn | |
3385 (forward-char) | |
3386 (vip-execute-com 'vip-end-of-Word val com))))) | |
3387 | |
3388 (defun vip-backward-word-kernel (val) | |
3389 (while (> val 0) | |
3390 (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
|
3391 (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
|
3392 (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
|
3393 ((vip-looking-at-separator) |
10789 | 3394 (forward-char) |
3395 (vip-skip-separators nil) | |
3396 (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
|
3397 (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
|
3398 (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
|
3399 ((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
|
3400 (vip-skip-nonalphasep-backward)) |
10789 | 3401 (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
|
3402 ((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
|
3403 (vip-skip-nonalphasep-backward))) |
10789 | 3404 (setq val (1- val)))) |
3405 | |
3406 (defun vip-backward-word (arg) | |
3407 "Backward word." | |
3408 (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
|
3409 (vip-leave-region-active) |
10789 | 3410 (let ((val (vip-p-val arg)) |
3411 (com (vip-getcom arg))) | |
3412 (if com | |
3413 (let (i) | |
3414 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
3415 (backward-char)) | |
3416 (vip-move-marker-locally 'vip-com-point (point)) | |
3417 (if i (forward-char)))) | |
3418 (vip-backward-word-kernel val) | |
3419 (if com (vip-execute-com 'vip-backward-word val com)))) | |
3420 | |
3421 (defun vip-backward-Word (arg) | |
3422 "Backward word delimited by white character." | |
3423 (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
|
3424 (vip-leave-region-active) |
10789 | 3425 (let ((val (vip-p-val arg)) |
3426 (com (vip-getcom arg))) | |
3427 (if com | |
3428 (let (i) | |
3429 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
3430 (backward-char)) | |
3431 (vip-move-marker-locally 'vip-com-point (point)) | |
3432 (if i (forward-char)))) | |
3433 (vip-loop val | |
3434 (progn | |
3435 (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
|
3436 (vip-skip-nonseparators 'backward))) |
10789 | 3437 (if com (vip-execute-com 'vip-backward-Word val com)))) |
3438 | |
3439 | |
3440 | |
3441 ;; line commands | |
3442 | |
3443 (defun vip-beginning-of-line (arg) | |
3444 "Go to beginning of line." | |
3445 (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
|
3446 (vip-leave-region-active) |
10789 | 3447 (let ((val (vip-p-val arg)) |
3448 (com (vip-getcom arg))) | |
3449 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3450 (beginning-of-line val) | |
3451 (if com (vip-execute-com 'vip-beginning-of-line val com)))) | |
3452 | |
3453 (defun vip-bol-and-skip-white (arg) | |
3454 "Beginning of line at first non-white character." | |
3455 (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
|
3456 (vip-leave-region-active) |
10789 | 3457 (let ((val (vip-p-val arg)) |
3458 (com (vip-getcom arg))) | |
3459 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3460 (forward-to-indentation (1- val)) | |
3461 (if com (vip-execute-com 'vip-bol-and-skip-white val com)))) | |
3462 | |
3463 (defun vip-goto-eol (arg) | |
3464 "Go to end of line." | |
3465 (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
|
3466 (vip-leave-region-active) |
10789 | 3467 (let ((val (vip-p-val arg)) |
3468 (com (vip-getcom arg))) | |
3469 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3470 (end-of-line val) | |
3471 (if com (vip-execute-com 'vip-goto-eol val com)) | |
3472 (if vip-ex-style-motion | |
3473 (if (and (eolp) (not (bolp)) | |
3474 ;; a fix for vip-change-to-eol | |
3475 (not (equal vip-current-state 'insert-state))) | |
3476 (backward-char 1) | |
3477 )))) | |
3478 | |
3479 | |
3480 (defun vip-goto-col (arg) | |
3481 "Go to ARG's column." | |
3482 (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
|
3483 (vip-leave-region-active) |
10789 | 3484 (let ((val (vip-p-val arg)) |
3485 (com (vip-getcom arg))) | |
3486 (save-excursion | |
3487 (end-of-line) | |
3488 (if (> val (1+ (current-column))) (error ""))) | |
3489 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3490 (beginning-of-line) | |
3491 (forward-char (1- val)) | |
3492 (if com (vip-execute-com 'vip-goto-col val com)))) | |
3493 | |
3494 | |
3495 (defun vip-next-line (arg) | |
3496 "Go to next line." | |
3497 (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
|
3498 (vip-leave-region-active) |
10789 | 3499 (let ((val (vip-p-val arg)) |
3500 (com (vip-getCom arg))) | |
3501 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3502 (next-line val) | |
3503 (if vip-ex-style-motion | |
3504 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
3505 (setq this-command 'next-line) | |
3506 (if com (vip-execute-com 'vip-next-line val com)))) | |
3507 | |
3508 (defun vip-next-line-at-bol (arg) | |
3509 "Next line at beginning of line." | |
3510 (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
|
3511 (vip-leave-region-active) |
10789 | 3512 (save-excursion |
3513 (end-of-line) | |
3514 (if (eobp) (error "Last line in buffer"))) | |
3515 (let ((val (vip-p-val arg)) | |
3516 (com (vip-getCom arg))) | |
3517 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3518 (forward-line val) | |
3519 (back-to-indentation) | |
3520 (if com (vip-execute-com 'vip-next-line-at-bol val com)))) | |
3521 | |
3522 (defun vip-previous-line (arg) | |
3523 "Go to previous line." | |
3524 (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
|
3525 (vip-leave-region-active) |
10789 | 3526 (let ((val (vip-p-val arg)) |
3527 (com (vip-getCom arg))) | |
3528 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3529 (previous-line val) | |
3530 (if vip-ex-style-motion | |
3531 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
3532 (setq this-command 'previous-line) | |
3533 (if com (vip-execute-com 'vip-previous-line val com)))) | |
3534 | |
3535 | |
3536 (defun vip-previous-line-at-bol (arg) | |
3537 "Previous line at beginning of line." | |
3538 (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
|
3539 (vip-leave-region-active) |
10789 | 3540 (save-excursion |
3541 (beginning-of-line) | |
3542 (if (bobp) (error "First line in buffer"))) | |
3543 (let ((val (vip-p-val arg)) | |
3544 (com (vip-getCom arg))) | |
3545 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3546 (forward-line (- val)) | |
3547 (back-to-indentation) | |
3548 (if com (vip-execute-com 'vip-previous-line val com)))) | |
3549 | |
3550 (defun vip-change-to-eol (arg) | |
3551 "Change to end of line." | |
3552 (interactive "P") | |
3553 (vip-goto-eol (cons arg ?c))) | |
3554 | |
3555 (defun vip-kill-line (arg) | |
3556 "Delete line." | |
3557 (interactive "P") | |
3558 (vip-goto-eol (cons arg ?d))) | |
3559 | |
3560 (defun vip-erase-line (arg) | |
3561 "Erase line." | |
3562 (interactive "P") | |
3563 (vip-beginning-of-line (cons arg ?d))) | |
3564 | |
3565 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3566 ;;; Moving around |
10789 | 3567 |
3568 (defun vip-goto-line (arg) | |
3569 "Go to ARG's line. Without ARG go to end of buffer." | |
3570 (interactive "P") | |
3571 (let ((val (vip-P-val arg)) | |
3572 (com (vip-getCom arg))) | |
3573 (vip-move-marker-locally 'vip-com-point (point)) | |
3574 (vip-deactivate-mark) | |
3575 (push-mark nil t) | |
3576 (if (null val) | |
3577 (goto-char (point-max)) | |
3578 (goto-char (point-min)) | |
3579 (forward-line (1- val))) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3580 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3581 ;; positioning is done twice: before and after command execution |
10789 | 3582 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
3583 (back-to-indentation) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3584 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3585 (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
|
3586 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3587 (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
|
3588 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3589 )) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3590 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3591 ;; 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
|
3592 ;; 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
|
3593 ;; adjust point after search. |
10789 | 3594 (defun vip-find-char (arg char forward offset) |
3595 (or (char-or-string-p char) (error "")) | |
3596 (let ((arg (if forward arg (- arg))) | |
3597 (cmd (if (eq vip-intermediate-command 'vip-repeat) | |
3598 (nth 5 vip-d-com) | |
3599 (vip-array-to-string (this-command-keys)))) | |
3600 point) | |
3601 (save-excursion | |
3602 (save-restriction | |
3603 (if (> arg 0) | |
3604 (narrow-to-region | |
3605 ;; forward search begins here | |
3606 (if (eolp) (error "Command `%s': At end of line" cmd) (point)) | |
3607 ;; forward search ends here | |
3608 (progn (end-of-line) (point))) | |
3609 (narrow-to-region | |
3610 ;; backward search begins from here | |
3611 (if (bolp) | |
3612 (error "Command `%s': At beginning of line" cmd) (point)) | |
3613 ;; backward search ends here | |
3614 (progn (beginning-of-line) (point)))) | |
3615 ;; if arg > 0, point is forwarded before search. | |
3616 (if (> arg 0) (goto-char (1+ (point-min))) | |
3617 (goto-char (point-max))) | |
3618 (if (let ((case-fold-search nil)) | |
3619 (search-forward (char-to-string char) nil 0 arg)) | |
3620 (setq point (point)) | |
3621 (error "Command `%s': `%c' not found" cmd char)))) | |
3622 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) | |
3623 | |
3624 (defun vip-find-char-forward (arg) | |
3625 "Find char on the line. | |
3626 If called interactively read the char to find from the terminal, and if | |
3627 called from vip-repeat, the char last used is used. This behaviour is | |
3628 controlled by the sign of prefix numeric value." | |
3629 (interactive "P") | |
3630 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3631 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3632 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3633 (if (> val 0) |
3634 ;; this means that the function was called interactively | |
3635 (setq vip-f-char (read-char) | |
3636 vip-f-forward t | |
3637 vip-f-offset nil) | |
3638 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3639 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3640 (vip-seq-last-elt cmd-representation) |
10789 | 3641 vip-F-char) |
3642 vip-f-char vip-F-char) | |
3643 (setq val (- val))) | |
3644 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3645 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil) | |
3646 (setq val (- val)) | |
3647 (if com | |
3648 (progn | |
3649 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3650 (forward-char) | |
3651 (vip-execute-com 'vip-find-char-forward val com))))) | |
3652 | |
3653 (defun vip-goto-char-forward (arg) | |
3654 "Go up to char ARG forward on line." | |
3655 (interactive "P") | |
3656 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3657 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3658 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3659 (if (> val 0) |
3660 ;; this means that the function was called interactively | |
3661 (setq vip-f-char (read-char) | |
3662 vip-f-forward t | |
3663 vip-f-offset t) | |
3664 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3665 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3666 (vip-seq-last-elt cmd-representation) |
10789 | 3667 vip-F-char) |
3668 vip-f-char vip-F-char) | |
3669 (setq val (- val))) | |
3670 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3671 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t) | |
3672 (setq val (- val)) | |
3673 (if com | |
3674 (progn | |
3675 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3676 (forward-char) | |
3677 (vip-execute-com 'vip-goto-char-forward val com))))) | |
3678 | |
3679 (defun vip-find-char-backward (arg) | |
3680 "Find char ARG on line backward." | |
3681 (interactive "P") | |
3682 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3683 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3684 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3685 (if (> val 0) |
3686 ;; this means that the function was called interactively | |
3687 (setq vip-f-char (read-char) | |
3688 vip-f-forward nil | |
3689 vip-f-offset nil) | |
3690 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3691 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3692 (vip-seq-last-elt cmd-representation) |
10789 | 3693 vip-F-char) |
3694 vip-f-char vip-F-char) | |
3695 (setq val (- val))) | |
3696 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3697 (vip-find-char | |
3698 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil) | |
3699 (setq val (- val)) | |
3700 (if com | |
3701 (progn | |
3702 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3703 (vip-execute-com 'vip-find-char-backward val com))))) | |
3704 | |
3705 (defun vip-goto-char-backward (arg) | |
3706 "Go up to char ARG backward on line." | |
3707 (interactive "P") | |
3708 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3709 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3710 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3711 (if (> val 0) |
3712 ;; this means that the function was called interactively | |
3713 (setq vip-f-char (read-char) | |
3714 vip-f-forward nil | |
3715 vip-f-offset t) | |
3716 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3717 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3718 (vip-seq-last-elt cmd-representation) |
10789 | 3719 vip-F-char) |
3720 vip-f-char vip-F-char) | |
3721 (setq val (- val))) | |
3722 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3723 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t) | |
3724 (setq val (- val)) | |
3725 (if com | |
3726 (progn | |
3727 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3728 (vip-execute-com 'vip-goto-char-backward val com))))) | |
3729 | |
3730 (defun vip-repeat-find (arg) | |
3731 "Repeat previous find command." | |
3732 (interactive "P") | |
3733 (let ((val (vip-p-val arg)) | |
3734 (com (vip-getcom arg))) | |
3735 (vip-deactivate-mark) | |
3736 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3737 (vip-find-char val vip-f-char vip-f-forward vip-f-offset) | |
3738 (if com | |
3739 (progn | |
3740 (if vip-f-forward (forward-char)) | |
3741 (vip-execute-com 'vip-repeat-find val com))))) | |
3742 | |
3743 (defun vip-repeat-find-opposite (arg) | |
3744 "Repeat previous find command in the opposite direction." | |
3745 (interactive "P") | |
3746 (let ((val (vip-p-val arg)) | |
3747 (com (vip-getcom arg))) | |
3748 (vip-deactivate-mark) | |
3749 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3750 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset) | |
3751 (if com | |
3752 (progn | |
3753 (if vip-f-forward (forward-char)) | |
3754 (vip-execute-com 'vip-repeat-find-opposite val com))))) | |
3755 | |
3756 | |
3757 ;; window scrolling etc. | |
3758 | |
3759 (defun vip-other-window (arg) | |
3760 "Switch to other window." | |
3761 (interactive "p") | |
3762 (other-window arg) | |
3763 (or (not (eq vip-current-state 'emacs-state)) | |
3764 (string= (buffer-name (current-buffer)) " *Minibuf-1*") | |
3765 (vip-change-state-to-vi))) | |
3766 | |
3767 (defun vip-window-top (arg) | |
3768 "Go to home window line." | |
3769 (interactive "P") | |
3770 (let ((val (vip-p-val arg)) | |
3771 (com (vip-getCom arg))) | |
3772 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3773 (push-mark nil t) | |
3774 (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
|
3775 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3776 ;; 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
|
3777 (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
|
3778 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3779 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3780 (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
|
3781 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3782 (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
|
3783 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3784 )) |
10789 | 3785 |
3786 (defun vip-window-middle (arg) | |
3787 "Go to middle window line." | |
3788 (interactive "P") | |
3789 (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
|
3790 (com (vip-getCom arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3791 lines) |
10789 | 3792 (if com (vip-move-marker-locally 'vip-com-point (point))) |
3793 (push-mark nil t) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3794 (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
|
3795 (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
|
3796 (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
|
3797 (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
|
3798 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3799 ;; 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
|
3800 (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
|
3801 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3802 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3803 (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
|
3804 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3805 (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
|
3806 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3807 )) |
10789 | 3808 |
3809 (defun vip-window-bottom (arg) | |
3810 "Go to last window line." | |
3811 (interactive "P") | |
3812 (let ((val (vip-p-val arg)) | |
3813 (com (vip-getCom arg))) | |
3814 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3815 (push-mark nil t) | |
3816 (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
|
3817 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3818 ;; 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
|
3819 (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
|
3820 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3821 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3822 (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
|
3823 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3824 (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
|
3825 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3826 )) |
10789 | 3827 |
3828 (defun vip-line-to-top (arg) | |
3829 "Put current line on the home line." | |
3830 (interactive "p") | |
3831 (recenter (1- arg))) | |
3832 | |
3833 (defun vip-line-to-middle (arg) | |
3834 "Put current line on the middle line." | |
3835 (interactive "p") | |
3836 (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) | |
3837 | |
3838 (defun vip-line-to-bottom (arg) | |
3839 "Put current line on the last line." | |
3840 (interactive "p") | |
3841 (recenter (- (window-height) (1+ arg)))) | |
3842 | |
3843 | |
3844 ;; paren match | |
3845 ;; must correct this to only match ( to ) etc. On the other hand | |
3846 ;; it is good that paren match gets confused, because that way you | |
3847 ;; catch _all_ imbalances. | |
3848 | |
3849 (defun vip-paren-match (arg) | |
3850 "Go to the matching parenthesis." | |
3851 (interactive "P") | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
3852 (vip-leave-region-active) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3853 (let ((com (vip-getcom arg)) |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
3854 parse-sexp-ignore-comments anchor-point) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3855 (if (integerp arg) |
10789 | 3856 (if (or (> arg 99) (< arg 1)) |
3857 (error "Prefix must be between 1 and 99") | |
3858 (goto-char | |
3859 (if (> (point-max) 80000) | |
3860 (* (/ (point-max) 100) arg) | |
3861 (/ (* (point-max) arg) 100))) | |
3862 (back-to-indentation)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3863 (let (beg-lim end-lim) |
10789 | 3864 (if (and (eolp) (not (bolp))) (forward-char -1)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3865 (if (not (looking-at "[][(){}]")) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3866 (setq anchor-point (point))) |
10789 | 3867 (save-excursion |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3868 (beginning-of-line) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3869 (setq beg-lim (point)) |
10789 | 3870 (end-of-line) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3871 (setq end-lim (point))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3872 (cond ((re-search-forward "[][(){}]" end-lim t) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3873 (backward-char) ) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3874 ((re-search-backward "[][(){}]" beg-lim t)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3875 (t |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3876 (error "No matching character on line")))) |
10789 | 3877 (cond ((looking-at "[\(\[{]") |
3878 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3879 (forward-sexp 1) | |
3880 (if com | |
3881 (vip-execute-com 'vip-paren-match nil com) | |
3882 (backward-char))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3883 (anchor-point |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3884 (if com |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3885 (progn |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3886 (vip-move-marker-locally 'vip-com-point anchor-point) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3887 (forward-char 1) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3888 (vip-execute-com 'vip-paren-match nil com) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3889 ))) |
10789 | 3890 ((looking-at "[])}]") |
3891 (forward-char) | |
3892 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3893 (backward-sexp 1) | |
3894 (if com (vip-execute-com 'vip-paren-match nil com))) | |
3895 (t (error "")))))) | |
3896 | |
3897 | |
3898 ;; sentence ,paragraph and heading | |
3899 | |
3900 (defun vip-forward-sentence (arg) | |
3901 "Forward sentence." | |
3902 (interactive "P") | |
3903 (push-mark nil t) | |
3904 (let ((val (vip-p-val arg)) | |
3905 (com (vip-getcom arg))) | |
3906 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3907 (forward-sentence val) | |
3908 (if com (vip-execute-com 'vip-forward-sentence nil com)))) | |
3909 | |
3910 (defun vip-backward-sentence (arg) | |
3911 "Backward sentence." | |
3912 (interactive "P") | |
3913 (push-mark nil t) | |
3914 (let ((val (vip-p-val arg)) | |
3915 (com (vip-getcom arg))) | |
3916 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3917 (backward-sentence val) | |
3918 (if com (vip-execute-com 'vip-backward-sentence nil com)))) | |
3919 | |
3920 (defun vip-forward-paragraph (arg) | |
3921 "Forward paragraph." | |
3922 (interactive "P") | |
3923 (push-mark nil t) | |
3924 (let ((val (vip-p-val arg)) | |
3925 (com (vip-getCom arg))) | |
3926 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3927 (forward-paragraph val) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3928 (if com |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3929 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3930 (backward-char 1) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3931 (vip-execute-com 'vip-forward-paragraph nil com))))) |
10789 | 3932 |
3933 (defun vip-backward-paragraph (arg) | |
3934 "Backward paragraph." | |
3935 (interactive "P") | |
3936 (push-mark nil t) | |
3937 (let ((val (vip-p-val arg)) | |
3938 (com (vip-getCom arg))) | |
3939 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3940 (backward-paragraph val) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3941 (if com |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3942 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3943 (forward-char 1) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3944 (vip-execute-com 'vip-backward-paragraph nil com) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3945 (backward-char 1))))) |
10789 | 3946 |
3947 ;; should be mode-specific etc. | |
3948 | |
3949 (defun vip-prev-heading (arg) | |
3950 (interactive "P") | |
3951 (let ((val (vip-p-val arg)) | |
3952 (com (vip-getCom arg))) | |
3953 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3954 (re-search-backward vip-heading-start nil t val) | |
3955 (goto-char (match-beginning 0)) | |
3956 (if com (vip-execute-com 'vip-prev-heading nil com)))) | |
3957 | |
3958 (defun vip-heading-end (arg) | |
3959 (interactive "P") | |
3960 (let ((val (vip-p-val arg)) | |
3961 (com (vip-getCom arg))) | |
3962 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3963 (re-search-forward vip-heading-end nil t val) | |
3964 (goto-char (match-beginning 0)) | |
3965 (if com (vip-execute-com 'vip-heading-end nil com)))) | |
3966 | |
3967 (defun vip-next-heading (arg) | |
3968 (interactive "P") | |
3969 (let ((val (vip-p-val arg)) | |
3970 (com (vip-getCom arg))) | |
3971 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3972 (end-of-line) | |
3973 (re-search-forward vip-heading-start nil t val) | |
3974 (goto-char (match-beginning 0)) | |
3975 (if com (vip-execute-com 'vip-next-heading nil com)))) | |
3976 | |
3977 | |
3978 ;; scrolling | |
3979 | |
3980 (setq scroll-step 1) | |
3981 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3982 (defun vip-scroll-screen (arg) |
10789 | 3983 "Scroll to next screen." |
3984 (interactive "p") | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3985 (condition-case nil |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3986 (if (> arg 0) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3987 (while (> arg 0) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3988 (scroll-up) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3989 (setq arg (1- arg))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3990 (while (> 0 arg) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3991 (scroll-down) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3992 (setq arg (1+ arg)))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3993 (error (beep 1) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3994 (if (> arg 0) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3995 (progn |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3996 (message "End of buffer") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3997 (goto-char (point-max))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3998 (message "Beginning of buffer") |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
3999 (goto-char (point-min)))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4000 )) |
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 (defun vip-scroll-screen-back (arg) |
10789 | 4003 "Scroll to previous screen." |
4004 (interactive "p") | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4005 (vip-scroll-screen (- arg))) |
10789 | 4006 |
4007 (defun vip-scroll-down (arg) | |
4008 "Pull down half screen." | |
4009 (interactive "P") | |
4010 (condition-case nil | |
4011 (if (null arg) | |
4012 (scroll-down (/ (window-height) 2)) | |
4013 (scroll-down arg)) | |
4014 (error (beep 1) | |
4015 (message "Beginning of buffer") | |
4016 (goto-char (point-min))))) | |
4017 | |
4018 (defun vip-scroll-down-one (arg) | |
4019 "Scroll up one line." | |
4020 (interactive "p") | |
4021 (scroll-down arg)) | |
4022 | |
4023 (defun vip-scroll-up (arg) | |
4024 "Pull up half screen." | |
4025 (interactive "P") | |
4026 (condition-case nil | |
4027 (if (null arg) | |
4028 (scroll-up (/ (window-height) 2)) | |
4029 (scroll-up arg)) | |
4030 (error (beep 1) | |
4031 (message "End of buffer") | |
4032 (goto-char (point-max))))) | |
4033 | |
4034 (defun vip-scroll-up-one (arg) | |
4035 "Scroll down one line." | |
4036 (interactive "p") | |
4037 (scroll-up arg)) | |
4038 | |
4039 | |
4040 ;; searching | |
4041 | |
4042 (defun vip-if-string (prompt) | |
4043 (let ((s (vip-read-string-with-history | |
4044 prompt | |
4045 nil ; no initial | |
4046 'vip-search-history | |
4047 (car vip-search-history)))) | |
4048 (if (not (string= s "")) | |
4049 (setq vip-s-string s)))) | |
4050 | |
4051 | |
4052 (defun vip-toggle-search-style (arg) | |
4053 "Toggle the value of vip-case-fold-search/vip-re-search. | |
4054 Without prefix argument, will ask which search style to toggle. With prefix | |
4055 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search. | |
4056 | |
4057 Although this function is bound to \\[vip-toggle-search-style], the most | |
4058 convenient way to use it is to bind `//' to the macro | |
4059 `1 M-x vip-toggle-search-style' and `///' to | |
4060 `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
|
4061 toggle case-fold-search and hitting `/' three times witth toggle regexp |
10789 | 4062 search. Macros are more convenient in this case because they don't affect |
4063 the Emacs binding of `/'." | |
4064 (interactive "P") | |
4065 (let (msg) | |
4066 (cond ((or (eq arg 1) | |
4067 (and (null arg) | |
4068 (y-or-n-p (format "Search style: '%s'. Want '%s'? " | |
4069 (if vip-case-fold-search | |
4070 "case-insensitive" "case-sensitive") | |
4071 (if vip-case-fold-search | |
4072 "case-sensitive" | |
4073 "case-insensitive"))))) | |
4074 (setq vip-case-fold-search (null vip-case-fold-search)) | |
4075 (if vip-case-fold-search | |
4076 (setq msg "Search becomes case-insensitive") | |
4077 (setq msg "Search becomes case-sensitive"))) | |
4078 ((or (eq arg 2) | |
4079 (and (null arg) | |
4080 (y-or-n-p (format "Search style: '%s'. Want '%s'? " | |
4081 (if vip-re-search | |
4082 "regexp-search" "vanilla-search") | |
4083 (if vip-re-search | |
4084 "vanilla-search" | |
4085 "regexp-search"))))) | |
4086 (setq vip-re-search (null vip-re-search)) | |
4087 (if vip-re-search | |
4088 (setq msg "Search becomes regexp-style") | |
4089 (setq msg "Search becomes vanilla-style"))) | |
4090 (t | |
4091 (setq msg "Search style remains unchanged"))) | |
4092 (prin1 msg t))) | |
4093 | |
4094 | |
4095 (defun vip-search-forward (arg) | |
4096 "Search a string forward. | |
4097 ARG is used to find the ARG's occurrence of the string. | |
4098 Null string will repeat previous search." | |
4099 (interactive "P") | |
4100 (let ((val (vip-P-val arg)) | |
4101 (com (vip-getcom arg)) | |
4102 (old-str vip-s-string)) | |
4103 (setq vip-s-forward t) | |
4104 (vip-if-string "/") | |
4105 ;; this is not used at present, but may be used later | |
4106 (if (or (not (equal old-str vip-s-string)) | |
4107 (not (markerp vip-local-search-start-marker)) | |
4108 (not (marker-buffer vip-local-search-start-marker))) | |
4109 (setq vip-local-search-start-marker (point-marker))) | |
4110 (vip-search vip-s-string t val) | |
4111 (if com | |
4112 (progn | |
4113 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4114 (vip-execute-com 'vip-search-next val com))))) | |
4115 | |
4116 (defun vip-search-backward (arg) | |
4117 "Search a string backward. | |
4118 ARG is used to find the ARG's occurrence of the string. | |
4119 Null string will repeat previous search." | |
4120 (interactive "P") | |
4121 (let ((val (vip-P-val arg)) | |
4122 (com (vip-getcom arg)) | |
4123 (old-str vip-s-string)) | |
4124 (setq vip-s-forward nil) | |
4125 (vip-if-string "?") | |
4126 ;; this is not used at present, but may be used later | |
4127 (if (or (not (equal old-str vip-s-string)) | |
4128 (not (markerp vip-local-search-start-marker)) | |
4129 (not (marker-buffer vip-local-search-start-marker))) | |
4130 (setq vip-local-search-start-marker (point-marker))) | |
4131 (vip-search vip-s-string nil val) | |
4132 (if com | |
4133 (progn | |
4134 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4135 (vip-execute-com 'vip-search-next val com))))) | |
4136 | |
4137 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4138 ;; 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
|
4139 ;; 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
|
4140 ;; 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
|
4141 ;; Arguments: |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4142 ;; (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
|
4143 (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
|
4144 &optional no-offset init-point fail-if-not-found) |
10789 | 4145 (if (not (equal string "")) |
4146 (let ((val (vip-p-val arg)) | |
4147 (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
|
4148 (offset (not no-offset)) |
10789 | 4149 (case-fold-search vip-case-fold-search) |
4150 (start-point (or init-point (point)))) | |
4151 (vip-deactivate-mark) | |
4152 (if forward | |
4153 (condition-case nil | |
4154 (progn | |
4155 (if offset (vip-forward-char-carefully)) | |
4156 (if vip-re-search | |
4157 (progn | |
4158 (re-search-forward string nil nil val) | |
4159 (re-search-backward string)) | |
4160 (search-forward string nil nil val) | |
4161 (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
|
4162 ;; 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
|
4163 (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
|
4164 (vip-flash-search-pattern)) |
10789 | 4165 (if (not (equal start-point (point))) |
4166 (push-mark start-point t))) | |
4167 (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
|
4168 (if (and (not fail-if-not-found) vip-search-wrap-around-t) |
10789 | 4169 (progn |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4170 (message "Search wrapped around BOTTOM of buffer") |
10789 | 4171 (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
|
4172 (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
|
4173 ;; 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
|
4174 (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
|
4175 ;; 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
|
4176 (message "") |
10789 | 4177 ) |
4178 (goto-char start-point) | |
4179 (error "`%s': %s not found" | |
4180 string | |
4181 (if vip-re-search "Pattern" "String")) | |
4182 ))) | |
4183 ;; backward | |
4184 (condition-case nil | |
4185 (progn | |
4186 (if vip-re-search | |
4187 (re-search-backward string nil nil val) | |
4188 (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
|
4189 ;; 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
|
4190 (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
|
4191 (vip-flash-search-pattern)) |
10789 | 4192 (if (not (equal start-point (point))) |
4193 (push-mark start-point t))) | |
4194 (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
|
4195 (if (and (not fail-if-not-found) vip-search-wrap-around-t) |
10789 | 4196 (progn |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4197 (message "Search wrapped around TOP of buffer") |
10789 | 4198 (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
|
4199 (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
|
4200 ;; 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
|
4201 (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
|
4202 ;; 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
|
4203 (message "") |
10789 | 4204 ) |
4205 (goto-char start-point) | |
4206 (error "`%s': %s not found" | |
4207 string | |
4208 (if vip-re-search "Pattern" "String")) | |
4209 ))))))) | |
4210 | |
4211 (defun vip-search-next (arg) | |
4212 "Repeat previous search." | |
4213 (interactive "P") | |
4214 (let ((val (vip-p-val arg)) | |
4215 (com (vip-getcom arg))) | |
4216 (if (null vip-s-string) (error vip-NoPrevSearch)) | |
4217 (vip-search vip-s-string vip-s-forward arg) | |
4218 (if com | |
4219 (progn | |
4220 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4221 (vip-execute-com 'vip-search-next val com))))) | |
4222 | |
4223 (defun vip-search-Next (arg) | |
4224 "Repeat previous search in the reverse direction." | |
4225 (interactive "P") | |
4226 (let ((val (vip-p-val arg)) | |
4227 (com (vip-getcom arg))) | |
4228 (if (null vip-s-string) (error vip-NoPrevSearch)) | |
4229 (vip-search vip-s-string (not vip-s-forward) arg) | |
4230 (if com | |
4231 (progn | |
4232 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4233 (vip-execute-com 'vip-search-Next val com))))) | |
4234 | |
4235 | |
4236 ;; Search contents of buffer defined by one of Viper's motion commands. | |
4237 ;; Repeatable via `n' and `N'. | |
4238 (defun vip-buffer-search-enable (&optional c) | |
4239 (cond (c (setq vip-buffer-search-char c)) | |
4240 ((null vip-buffer-search-char) | |
4241 (setq vip-buffer-search-char ?g))) | |
4242 (define-key vip-vi-basic-map | |
4243 (char-to-string vip-buffer-search-char) 'vip-command-argument) | |
4244 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) | |
4245 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) | |
4246 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4247 ;; This is a Viper wraper for isearch-forward. |
10789 | 4248 (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
|
4249 "Do incremental search forward." |
10789 | 4250 (interactive "P") |
4251 ;; emacs bug workaround | |
4252 (if (listp arg) (setq arg (car arg))) | |
4253 (vip-exec-form-in-emacs (list 'isearch-forward arg))) | |
4254 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4255 ;; This is a Viper wraper for isearch-backward." |
10789 | 4256 (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
|
4257 "Do incremental search backward." |
10789 | 4258 (interactive "P") |
4259 ;; emacs bug workaround | |
4260 (if (listp arg) (setq arg (car arg))) | |
4261 (vip-exec-form-in-emacs (list 'isearch-backward arg))) | |
4262 | |
4263 | |
4264 ;; visiting and killing files, buffers | |
4265 | |
4266 (defun vip-switch-to-buffer () | |
4267 "Switch to buffer in the current window." | |
4268 (interactive) | |
4269 (let (buffer) | |
4270 (setq buffer | |
4271 (read-buffer | |
4272 (format "Switch to buffer in this window \(%s\): " | |
4273 (buffer-name (other-buffer (current-buffer)))))) | |
4274 (switch-to-buffer buffer) | |
4275 )) | |
4276 | |
4277 (defun vip-switch-to-buffer-other-window () | |
4278 "Switch to buffer in another window." | |
4279 (interactive) | |
4280 (let (buffer) | |
4281 (setq buffer | |
4282 (read-buffer | |
4283 (format "Switch to buffer in another window \(%s\): " | |
4284 (buffer-name (other-buffer (current-buffer)))))) | |
4285 (switch-to-buffer-other-window buffer) | |
4286 )) | |
4287 | |
4288 (defun vip-kill-buffer () | |
4289 "Kill a buffer." | |
4290 (interactive) | |
4291 (let (buffer buffer-name) | |
4292 (setq buffer-name | |
4293 (read-buffer | |
4294 (format "Kill buffer \(%s\): " | |
4295 (buffer-name (current-buffer))))) | |
4296 (setq buffer | |
4297 (if (null buffer-name) | |
4298 (current-buffer) | |
4299 (get-buffer buffer-name))) | |
4300 (if (null buffer) (error "`%s': No such buffer" buffer-name)) | |
4301 (if (or (not (buffer-modified-p buffer)) | |
4302 (y-or-n-p | |
4303 (format | |
4304 "Buffer `%s' is modified, are you sure you want to kill it? " | |
4305 buffer-name))) | |
4306 (kill-buffer buffer) | |
4307 (error "Buffer not killed")))) | |
4308 | |
4309 | |
4310 (defvar vip-smart-suffix-list '("" "tex" "c" "cc" "el" "p") | |
4311 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. | |
4312 This is useful when you the current directory contains files with the same | |
4313 prefix and many different suffixes. Usually, only one of the suffixes | |
4314 represents an editable file. However, file completion will stop at the `.' | |
4315 The smart suffix feature lets you hit RET in such a case, and Viper will | |
4316 select the appropriate suffix. | |
4317 | |
4318 Suffixes are tried in the order given and the first suffix for which a | |
4319 corresponding file exists is selected. If no file exists for any of the | |
4320 suffixes, the user is asked to confirm. | |
4321 | |
4322 To turn this feature off, set this variable to nil.") | |
4323 | |
4324 ;; Try to add suffix to files ending with a `.' | |
4325 ;; Useful when the user hits RET on a non-completed file name. | |
4326 (defun vip-file-add-suffix () | |
4327 (let ((count 0) | |
4328 (len (length vip-smart-suffix-list)) | |
4329 (file (buffer-string)) | |
4330 found key cmd suff) | |
4331 (goto-char (point-max)) | |
4332 (if (and vip-smart-suffix-list (string-match "\\.$" file)) | |
4333 (progn | |
4334 (while (and (not found) (< count len)) | |
4335 (setq suff (nth count vip-smart-suffix-list) | |
4336 count (1+ count)) | |
4337 (if (file-exists-p (format "%s%s" file suff)) | |
4338 (progn | |
4339 (setq found t) | |
4340 (insert suff)))) | |
4341 | |
4342 (if found | |
4343 () | |
4344 (vip-tmp-insert-at-eob " [Please complete file name]") | |
4345 (unwind-protect | |
4346 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer))) | |
4347 (setq cmd | |
4348 (key-binding (setq key (read-key-sequence nil)))) | |
4349 (cond ((eq cmd 'self-insert-command) | |
4350 (if vip-xemacs-p | |
4351 (insert (events-to-keys key)) | |
4352 (insert key))) | |
4353 ((memq cmd '(exit-minibuffer vip-exit-minibuffer)) | |
4354 nil) | |
4355 (t (command-execute cmd))) | |
4356 ))) | |
4357 )) | |
4358 )) | |
4359 | |
4360 | |
4361 ;; Advice for use in find-file and read-file-name commands. | |
4362 (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
|
4363 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer." |
10789 | 4364 (run-hooks 'vip-minibuffer-exit-hook)) |
4365 | |
4366 (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
|
4367 "Use `read-file-name' for reading arguments." |
10789 | 4368 (interactive (list (read-file-name "Find file: " |
4369 nil default-directory)))) | |
4370 | |
4371 (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
|
4372 "Use `read-file-name' for reading arguments." |
10789 | 4373 (interactive (list (read-file-name "Find file in other window: " |
4374 nil default-directory)))) | |
4375 | |
4376 (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
|
4377 "Use `read-file-name' for reading arguments." |
10789 | 4378 (interactive (list (read-file-name "Find file in other frame: " |
4379 nil default-directory)))) | |
4380 | |
4381 (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
|
4382 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." |
10789 | 4383 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) |
4384 ad-do-it)) | |
4385 | |
4386 | |
4387 | |
4388 ;; yank and pop | |
4389 | |
4390 (defsubst vip-yank (text) | |
4391 "Yank TEXT silently. This works correctly with Emacs's yank-pop command." | |
4392 (insert text) | |
4393 (setq this-command 'yank)) | |
4394 | |
4395 (defun vip-put-back (arg) | |
4396 "Put back after point/below line." | |
4397 (interactive "P") | |
4398 (let ((val (vip-p-val arg)) | |
4399 (text (if vip-use-register | |
4400 (cond ((vip-valid-register vip-use-register '(digit)) | |
4401 (current-kill (- vip-use-register ?1) 'do-not-rotate)) | |
4402 ((vip-valid-register vip-use-register) | |
4403 (get-register (downcase vip-use-register))) | |
4404 (t (error vip-InvalidRegister vip-use-register))) | |
4405 (current-kill 0)))) | |
4406 (if (null text) | |
4407 (if vip-use-register | |
4408 (let ((reg vip-use-register)) | |
4409 (setq vip-use-register nil) | |
4410 (error vip-EmptyRegister reg)) | |
4411 (error ""))) | |
4412 (setq vip-use-register nil) | |
4413 (if (vip-end-with-a-newline-p text) | |
4414 (progn | |
4415 (if (eobp) | |
4416 (insert "\n") | |
4417 (forward-line 1)) | |
4418 (beginning-of-line)) | |
4419 (if (not (eolp)) (vip-forward-char-carefully))) | |
4420 (set-marker (vip-mark-marker) (point) (current-buffer)) | |
4421 (vip-set-destructive-command | |
4422 (list 'vip-put-back val nil vip-use-register nil nil)) | |
4423 (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
|
4424 ;; 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
|
4425 ;; 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
|
4426 ;; a newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4427 (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
|
4428 (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
|
4429 (exchange-point-and-mark) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4430 (if (bolp) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4431 (back-to-indentation))) |
10789 | 4432 (vip-deactivate-mark)) |
4433 | |
4434 (defun vip-Put-back (arg) | |
4435 "Put back at point/above line." | |
4436 (interactive "P") | |
4437 (let ((val (vip-p-val arg)) | |
4438 (text (if vip-use-register | |
4439 (cond ((vip-valid-register vip-use-register '(digit)) | |
4440 (current-kill (- vip-use-register ?1) 'do-not-rotate)) | |
4441 ((vip-valid-register vip-use-register) | |
4442 (get-register (downcase vip-use-register))) | |
4443 (t (error vip-InvalidRegister vip-use-register))) | |
4444 (current-kill 0)))) | |
4445 (if (null text) | |
4446 (if vip-use-register | |
4447 (let ((reg vip-use-register)) | |
4448 (setq vip-use-register nil) | |
4449 (error vip-EmptyRegister reg)) | |
4450 (error ""))) | |
4451 (setq vip-use-register nil) | |
4452 (if (vip-end-with-a-newline-p text) (beginning-of-line)) | |
4453 (vip-set-destructive-command | |
4454 (list 'vip-Put-back val nil vip-use-register nil nil)) | |
4455 (set-marker (vip-mark-marker) (point) (current-buffer)) | |
4456 (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
|
4457 ;; 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
|
4458 ;; 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
|
4459 ;; a newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4460 (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
|
4461 (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
|
4462 (exchange-point-and-mark) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4463 (if (bolp) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4464 (back-to-indentation))) |
10789 | 4465 (vip-deactivate-mark)) |
4466 | |
4467 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4468 ;; Copy region to kill-ring. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4469 ;; If BEG and END do not belong to the same buffer, copy empty region. |
10789 | 4470 (defun vip-copy-region-as-kill (beg end) |
4471 (condition-case nil | |
4472 (copy-region-as-kill beg end) | |
4473 (error (copy-region-as-kill beg beg)))) | |
4474 | |
4475 | |
4476 (defun vip-delete-char (arg) | |
4477 "Delete character." | |
4478 (interactive "P") | |
4479 (let ((val (vip-p-val arg))) | |
4480 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil)) | |
4481 (if (> val 1) | |
4482 (save-excursion | |
4483 (let ((here (point))) | |
4484 (end-of-line) | |
4485 (if (> val (- (point) here)) | |
4486 (setq val (- (point) here)))))) | |
4487 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1)) | |
4488 (if (and vip-ex-style-motion (eolp)) | |
4489 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch | |
4490 (if vip-use-register | |
4491 (progn | |
4492 (cond ((vip-valid-register vip-use-register '((Letter))) | |
4493 (vip-append-to-register | |
4494 (downcase vip-use-register) (point) (- (point) val))) | |
4495 ((vip-valid-register vip-use-register) | |
4496 (copy-to-register | |
4497 vip-use-register (point) (- (point) val) nil)) | |
4498 (t (error vip-InvalidRegister vip-use-register))) | |
4499 (setq vip-use-register nil))) | |
4500 (if vip-ex-style-motion | |
4501 (progn | |
4502 (delete-char val t) | |
4503 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
4504 (if (eolp) | |
4505 (delete-backward-char val t) | |
4506 (delete-char val t))))) | |
4507 | |
4508 (defun vip-delete-backward-char (arg) | |
4509 "Delete previous character. On reaching beginning of line, stop and beep." | |
4510 (interactive "P") | |
4511 (let ((val (vip-p-val arg))) | |
4512 (vip-set-destructive-command | |
4513 (list 'vip-delete-backward-char val nil nil nil nil)) | |
4514 (if (> val 1) | |
4515 (save-excursion | |
4516 (let ((here (point))) | |
4517 (beginning-of-line) | |
4518 (if (> val (- here (point))) | |
4519 (setq val (- here (point))))))) | |
4520 (if vip-use-register | |
4521 (progn | |
4522 (cond ((vip-valid-register vip-use-register '(Letter)) | |
4523 (vip-append-to-register | |
4524 (downcase vip-use-register) (point) (+ (point) val))) | |
4525 ((vip-valid-register vip-use-register) | |
4526 (copy-to-register | |
4527 vip-use-register (point) (+ (point) val) nil)) | |
4528 (t (error vip-InvalidRegister vip-use-register))) | |
4529 (setq vip-use-register nil))) | |
4530 (if (bolp) (ding) | |
4531 (delete-backward-char val t)))) | |
4532 | |
4533 (defun vip-del-backward-char-in-insert () | |
4534 "Delete 1 char backwards while in insert mode." | |
4535 (interactive) | |
4536 (if (and vip-ex-style-editing-in-insert (bolp)) | |
4537 (beep 1) | |
4538 (delete-backward-char 1 t))) | |
4539 | |
4540 (defun vip-del-backward-char-in-replace () | |
4541 "Delete one character in replace mode. | |
4542 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
|
4543 charecters. If it is nil, then the cursor just moves backwards, similarly |
10789 | 4544 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
|
4545 cursor move past the beginning of line." |
10789 | 4546 (interactive) |
4547 (cond (vip-delete-backwards-in-replace | |
4548 (cond ((not (bolp)) | |
4549 (delete-backward-char 1 t)) | |
4550 (vip-ex-style-editing-in-insert | |
4551 (beep 1)) | |
4552 ((bobp) | |
4553 (beep 1)) | |
4554 (t | |
4555 (delete-backward-char 1 t)))) | |
4556 (vip-ex-style-editing-in-insert | |
4557 (if (bolp) | |
4558 (beep 1) | |
4559 (backward-char 1))) | |
4560 (t | |
4561 (backward-char 1)))) | |
4562 | |
4563 | |
4564 | |
4565 ;; join lines. | |
4566 | |
4567 (defun vip-join-lines (arg) | |
4568 "Join this line to next, if ARG is nil. Otherwise, join ARG lines." | |
4569 (interactive "*P") | |
4570 (let ((val (vip-P-val arg))) | |
4571 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil)) | |
4572 (vip-loop (if (null val) 1 (1- val)) | |
4573 (progn | |
4574 (end-of-line) | |
4575 (if (not (eobp)) | |
4576 (progn | |
4577 (forward-line 1) | |
4578 (delete-region (point) (1- (point))) | |
4579 (fixup-whitespace))))))) | |
4580 | |
4581 | |
4582 ;; Replace state | |
4583 | |
4584 (defun vip-change (beg end) | |
4585 (if (markerp beg) (setq beg (marker-position beg))) | |
4586 (if (markerp end) (setq end (marker-position end))) | |
4587 ;; beg is sometimes (mark t), which may be nil | |
4588 (or beg (setq beg end)) | |
4589 | |
4590 (vip-set-complex-command-for-undo) | |
4591 (if vip-use-register | |
4592 (progn | |
4593 (copy-to-register vip-use-register beg end nil) | |
4594 (setq vip-use-register nil))) | |
4595 (vip-set-replace-overlay beg end) | |
4596 (setq last-command nil) ; separate repl text from prev kills | |
4597 | |
4598 (if (= (vip-replace-start) (point-max)) | |
4599 (error "End of buffer")) | |
4600 | |
4601 (setq vip-last-replace-region | |
4602 (buffer-substring (vip-replace-start) | |
4603 (vip-replace-end))) | |
4604 | |
4605 ;; protect against error while inserting "@" and other disasters | |
4606 ;; (e.g., read-only buff) | |
4607 (condition-case conds | |
4608 (if (vip-same-line (vip-replace-start) | |
4609 (vip-replace-end)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4610 (progn |
10789 | 4611 ;; tabs cause problems in replace, so untabify |
4612 (goto-char (vip-replace-end)) | |
4613 (insert-before-markers "@") ; put placeholder after the TAB | |
4614 (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
|
4615 ;; 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
|
4616 (delete-backward-char 1) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4617 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4618 (vip-set-replace-overlay-glyphs |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4619 vip-replace-region-start-delimiter |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4620 vip-replace-region-end-delimiter) |
10789 | 4621 ;; this move takes care of the last posn in the overlay, which |
4622 ;; has to be shifted because of insert. We can't simply insert | |
4623 ;; "$" before-markers because then overlay-start will shift the | |
4624 ;; beginning of the overlay in case we are replacing a single | |
4625 ;; character. This fixes the bug with `s' and `cl' commands. | |
4626 (vip-move-replace-overlay (vip-replace-start) (point)) | |
4627 (goto-char (vip-replace-start)) | |
4628 (vip-change-state-to-replace t)) | |
4629 (kill-region (vip-replace-start) | |
4630 (vip-replace-end)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
4631 (vip-hide-replace-overlay) |
10789 | 4632 (vip-change-state-to-insert)) |
4633 (error ;; make sure that the overlay doesn't stay. | |
4634 ;; go back to the original point | |
4635 (goto-char (vip-replace-start)) | |
4636 (vip-hide-replace-overlay) | |
4637 (vip-message-conditions conds)))) | |
4638 | |
4639 | |
4640 (defun vip-change-subr (beg end) | |
4641 ;; beg is sometimes (mark t), which may be nil | |
4642 (or beg (setq beg end)) | |
4643 | |
4644 (if vip-use-register | |
4645 (progn | |
4646 (copy-to-register vip-use-register beg end nil) | |
4647 (setq vip-use-register nil))) | |
4648 (kill-region beg end) | |
4649 (setq this-command 'vip-change) | |
4650 (vip-yank-last-insertion)) | |
4651 | |
4652 (defun vip-toggle-case (arg) | |
4653 "Toggle character case." | |
4654 (interactive "P") | |
4655 (let ((val (vip-p-val arg)) (c)) | |
4656 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil)) | |
4657 (while (> val 0) | |
4658 (setq c (following-char)) | |
4659 (delete-char 1 nil) | |
4660 (if (eq c (upcase c)) | |
4661 (insert-char (downcase c) 1) | |
4662 (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
|
4663 (if (eolp) (backward-char 1)) |
10789 | 4664 (setq val (1- val))))) |
4665 | |
4666 | |
4667 ;; query replace | |
4668 | |
4669 (defun vip-query-replace () | |
4670 "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
|
4671 If a null string is suplied as the string to be replaced, |
10789 | 4672 the query replace mode will toggle between string replace |
4673 and regexp replace." | |
4674 (interactive) | |
4675 (let (str) | |
4676 (setq str (vip-read-string-with-history | |
4677 (if vip-re-query-replace "Query replace regexp: " | |
4678 "Query replace: ") | |
4679 nil ; no initial | |
4680 'vip-replace1-history | |
4681 (car vip-replace1-history) ; default | |
4682 )) | |
4683 (if (string= str "") | |
4684 (progn | |
4685 (setq vip-re-query-replace (not vip-re-query-replace)) | |
4686 (message "Query replace mode changed to %s" | |
4687 (if vip-re-query-replace "regexp replace" | |
4688 "string replace"))) | |
4689 (if vip-re-query-replace | |
4690 (query-replace-regexp | |
4691 str | |
4692 (vip-read-string-with-history | |
4693 (format "Query replace regexp `%s' with: " str) | |
4694 nil ; no initial | |
4695 'vip-replace1-history | |
4696 (car vip-replace1-history) ; default | |
4697 )) | |
4698 (query-replace | |
4699 str | |
4700 (vip-read-string-with-history | |
4701 (format "Query replace `%s' with: " str) | |
4702 nil ; no initial | |
4703 'vip-replace1-history | |
4704 (car vip-replace1-history) ; default | |
4705 )))))) | |
4706 | |
4707 | |
4708 ;; marking | |
4709 | |
4710 (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
|
4711 "Mark beginning of buffer." |
10789 | 4712 (interactive) |
4713 (push-mark (point)) | |
4714 (goto-char (point-min)) | |
4715 (exchange-point-and-mark) | |
4716 (message "Mark set at the beginning of buffer")) | |
4717 | |
4718 (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
|
4719 "Mark end of buffer." |
10789 | 4720 (interactive) |
4721 (push-mark (point)) | |
4722 (goto-char (point-max)) | |
4723 (exchange-point-and-mark) | |
4724 (message "Mark set at the end of buffer")) | |
4725 | |
4726 (defun vip-mark-point () | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4727 "Set mark at point of buffer." |
10789 | 4728 (interactive) |
4729 (let ((char (vip-read-char-exclusive))) | |
4730 (cond ((and (<= ?a char) (<= char ?z)) | |
4731 (point-to-register (1+ (- char ?a)))) | |
4732 ((= char ?<) (vip-mark-beginning-of-buffer)) | |
4733 ((= char ?>) (vip-mark-end-of-buffer)) | |
4734 ((= char ?.) (vip-set-mark-if-necessary)) | |
4735 ((= char ?,) (vip-cycle-through-mark-ring)) | |
4736 ((= char ?D) (mark-defun)) | |
4737 (t (error "")) | |
4738 ))) | |
4739 | |
4740 ;; Algorithm: If first invocation of this command save mark on ring, goto | |
4741 ;; mark, M0, and pop the most recent elt from the mark ring into mark, | |
4742 ;; making it into the new mark, M1. | |
4743 ;; Push this mark back and set mark to the original point position, p1. | |
4744 ;; So, if you hit '' or `` then you can return to p1. | |
4745 ;; | |
4746 ;; If repeated command, pop top elt from the ring into mark and | |
4747 ;; jump there. This forgets the position, p1, and puts M1 back into mark. | |
4748 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from | |
4749 ;; the ring into mark. Push M2 back on the ring and set mark to M0. | |
4750 ;; etc. | |
4751 (defun vip-cycle-through-mark-ring () | |
4752 "Visit previous locations on the mark ring. | |
4753 One can use `` and '' to temporarily jump 1 step back." | |
4754 (let* ((sv-pt (point))) | |
4755 ;; if repeated `m,' command, pop the previously saved mark. | |
4756 ;; Prev saved mark is actually prev saved point. It is used if the | |
4757 ;; user types `` or '' and is discarded | |
4758 ;; from the mark ring by the next `m,' command. | |
4759 ;; In any case, go to the previous or previously saved mark. | |
4760 ;; Then push the current mark (popped off the ring) and set current | |
4761 ;; point to be the mark. Current pt as mark is discarded by the next | |
4762 ;; m, command. | |
4763 (if (eq last-command 'vip-cycle-through-mark-ring) | |
4764 () | |
4765 ;; save current mark if the first iteration | |
4766 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
4767 (if (mark t) | |
4768 (push-mark (mark t) t)) ) | |
4769 (pop-mark) | |
4770 (set-mark-command 1) | |
4771 ;; don't duplicate mark on the ring | |
4772 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
4773 (push-mark sv-pt t) | |
4774 (vip-deactivate-mark) | |
4775 (setq this-command 'vip-cycle-through-mark-ring) | |
4776 )) | |
4777 | |
4778 | |
4779 (defun vip-goto-mark (arg) | |
4780 "Go to mark." | |
4781 (interactive "P") | |
4782 (let ((char (read-char)) | |
4783 (com (vip-getcom arg))) | |
4784 (vip-goto-mark-subr char com nil))) | |
4785 | |
4786 (defun vip-goto-mark-and-skip-white (arg) | |
4787 "Go to mark and skip to first non-white character on line." | |
4788 (interactive "P") | |
4789 (let ((char (read-char)) | |
4790 (com (vip-getCom arg))) | |
4791 (vip-goto-mark-subr char com t))) | |
4792 | |
4793 (defun vip-goto-mark-subr (char com skip-white) | |
4794 (if (eobp) | |
4795 (if (bobp) | |
4796 (error "Empty buffer") | |
4797 (backward-char 1))) | |
4798 (cond ((vip-valid-register char '(letter)) | |
4799 (let* ((buff (current-buffer)) | |
4800 (reg (1+ (- char ?a))) | |
4801 (text-marker (get-register reg))) | |
4802 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4803 (if (not (vip-valid-marker text-marker)) | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14580
diff
changeset
|
4804 (error vip-EmptyTextmarker char)) |
10789 | 4805 (if (and (vip-same-line (point) vip-last-jump) |
4806 (= (point) vip-last-jump-ignore)) | |
4807 (push-mark vip-last-jump t) | |
4808 (push-mark nil t)) ; no msg | |
4809 (vip-register-to-point reg) | |
4810 (setq vip-last-jump (point-marker)) | |
4811 (cond (skip-white | |
4812 (back-to-indentation) | |
4813 (setq vip-last-jump-ignore (point)))) | |
4814 (if com | |
4815 (if (equal buff (current-buffer)) | |
4816 (vip-execute-com (if skip-white | |
4817 'vip-goto-mark-and-skip-white | |
4818 'vip-goto-mark) | |
4819 nil com) | |
4820 (switch-to-buffer buff) | |
4821 (goto-char vip-com-point) | |
4822 (vip-change-state-to-vi) | |
4823 (error ""))))) | |
4824 ((and (not skip-white) (= char ?`)) | |
4825 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4826 (if (and (vip-same-line (point) vip-last-jump) | |
4827 (= (point) vip-last-jump-ignore)) | |
4828 (goto-char vip-last-jump)) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
4829 (if (null (mark t)) (error "Mark is not set in this buffer")) |
10789 | 4830 (if (= (point) (mark t)) (pop-mark)) |
4831 (exchange-point-and-mark) | |
4832 (setq vip-last-jump (point-marker) | |
4833 vip-last-jump-ignore 0) | |
4834 (if com (vip-execute-com 'vip-goto-mark nil com))) | |
4835 ((and skip-white (= char ?')) | |
4836 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4837 (if (and (vip-same-line (point) vip-last-jump) | |
4838 (= (point) vip-last-jump-ignore)) | |
4839 (goto-char vip-last-jump)) | |
4840 (if (= (point) (mark t)) (pop-mark)) | |
4841 (exchange-point-and-mark) | |
4842 (setq vip-last-jump (point)) | |
4843 (back-to-indentation) | |
4844 (setq vip-last-jump-ignore (point)) | |
4845 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com))) | |
4846 (t (error vip-InvalidTextmarker char)))) | |
4847 | |
4848 (defun vip-insert-tab () | |
4849 (interactive) | |
4850 (insert-tab)) | |
4851 | |
4852 (defun vip-exchange-point-and-mark () | |
4853 (interactive) | |
4854 (exchange-point-and-mark) | |
4855 (back-to-indentation)) | |
4856 | |
4857 ;; Input Mode Indentation | |
4858 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4859 ;; 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
|
4860 (defsubst vip-looking-back (str) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4861 (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
|
4862 (= (point) (match-end 0)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4863 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4864 |
10789 | 4865 (defun vip-forward-indent () |
4866 "Indent forward -- `C-t' in Vi." | |
4867 (interactive) | |
4868 (setq vip-cted t) | |
4869 (indent-to (+ (current-column) vip-shift-width))) | |
4870 | |
4871 (defun vip-backward-indent () | |
4872 "Backtab, C-d in VI" | |
4873 (interactive) | |
4874 (if vip-cted | |
4875 (let ((p (point)) (c (current-column)) bol (indent t)) | |
4876 (if (vip-looking-back "[0^]") | |
4877 (progn | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4878 (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
|
4879 (setq vip-preserve-indent t)) |
10789 | 4880 (delete-backward-char 1) |
4881 (setq p (point)) | |
4882 (setq indent nil))) | |
4883 (save-excursion | |
4884 (beginning-of-line) | |
4885 (setq bol (point))) | |
4886 (if (re-search-backward "[^ \t]" bol 1) (forward-char)) | |
4887 (delete-region (point) p) | |
4888 (if indent | |
4889 (indent-to (- c vip-shift-width))) | |
4890 (if (or (bolp) (vip-looking-back "[^ \t]")) | |
4891 (setq vip-cted nil))))) | |
4892 | |
4893 (defun vip-autoindent () | |
4894 "Auto Indentation, Vi-style." | |
4895 (interactive) | |
4896 (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
|
4897 (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
|
4898 (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
|
4899 (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
|
4900 ;; don't leave whitespace lines around |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4901 (if (memq last-command |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4902 '(vip-autoindent |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4903 vip-open-line vip-Open-line |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4904 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
|
4905 (indent-to-left-margin)) |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
4906 ;; use \n instead of newline, or else <Return> will move the insert point |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
4907 ;;(newline 1) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16136
diff
changeset
|
4908 (insert "\n") |
10789 | 4909 (if vip-auto-indent |
4910 (progn | |
4911 (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
|
4912 (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
|
4913 (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
|
4914 (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
|
4915 )) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4916 )) |
10789 | 4917 |
4918 | |
4919 ;; Viewing registers | |
4920 | |
4921 (defun vip-ket-function (arg) | |
4922 "Function called by \], the ket. View registers and call \]\]." | |
4923 (interactive "P") | |
4924 (let ((reg (read-char))) | |
4925 (cond ((vip-valid-register reg '(letter Letter)) | |
4926 (view-register (downcase reg))) | |
4927 ((vip-valid-register reg '(digit)) | |
4928 (let ((text (current-kill (- reg ?1) 'do-not-rotate))) | |
4929 (save-excursion | |
4930 (set-buffer (get-buffer-create "*Output*")) | |
4931 (delete-region (point-min) (point-max)) | |
4932 (insert (format "Register %c contains the string:\n" reg)) | |
4933 (insert text) | |
4934 (goto-char (point-min))) | |
4935 (display-buffer "*Output*"))) | |
4936 ((= ?\] reg) | |
4937 (vip-next-heading arg)) | |
4938 (t (error | |
4939 vip-InvalidRegister reg))))) | |
4940 | |
4941 (defun vip-brac-function (arg) | |
4942 "Function called by \[, the brac. View textmarkers and call \[\[" | |
4943 (interactive "P") | |
4944 (let ((reg (read-char))) | |
4945 (cond ((= ?\[ reg) | |
4946 (vip-prev-heading arg)) | |
4947 ((= ?\] reg) | |
4948 (vip-heading-end arg)) | |
4949 ((vip-valid-register reg '(letter)) | |
4950 (let* ((val (get-register (1+ (- reg ?a)))) | |
4951 (buf (if (not val) | |
14580
1883960762e0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14579
diff
changeset
|
4952 (error vip-EmptyTextmarker reg) |
10789 | 4953 (marker-buffer val))) |
4954 (pos (marker-position val)) | |
4955 line-no text (s pos) (e pos)) | |
4956 (save-excursion | |
4957 (set-buffer (get-buffer-create "*Output*")) | |
4958 (delete-region (point-min) (point-max)) | |
4959 (if (and buf pos) | |
4960 (progn | |
4961 (save-excursion | |
4962 (set-buffer buf) | |
4963 (setq line-no (1+ (count-lines (point-min) val))) | |
4964 (goto-char pos) | |
4965 (beginning-of-line) | |
4966 (if (re-search-backward "[^ \t]" nil t) | |
4967 (progn | |
4968 (beginning-of-line) | |
4969 (setq s (point)))) | |
4970 (goto-char pos) | |
4971 (forward-line 1) | |
4972 (if (re-search-forward "[^ \t]" nil t) | |
4973 (progn | |
4974 (end-of-line) | |
4975 (setq e (point)))) | |
4976 (setq text (buffer-substring s e)) | |
4977 (setq text (format "%s<%c>%s" | |
4978 (substring text 0 (- pos s)) | |
4979 reg (substring text (- pos s))))) | |
4980 (insert | |
4981 (format | |
4982 "Textmarker `%c' is in buffer `%s' at line %d.\n" | |
4983 reg (buffer-name buf) line-no)) | |
4984 (insert (format "Here is some text around %c:\n\n %s" | |
4985 reg text))) | |
4986 (insert (format vip-EmptyTextmarker reg))) | |
4987 (goto-char (point-min))) | |
4988 (display-buffer "*Output*"))) | |
4989 (t (error vip-InvalidTextmarker reg))))) | |
4990 | |
4991 | |
4992 | |
4993 ;; commands in insertion mode | |
4994 | |
4995 (defun vip-delete-backward-word (arg) | |
4996 "Delete previous word." | |
4997 (interactive "p") | |
4998 (save-excursion | |
4999 (push-mark nil t) | |
5000 (backward-word arg) | |
5001 (delete-region (point) (mark t)) | |
5002 (pop-mark))) | |
5003 | |
5004 | |
5005 (defun vip-set-expert-level (&optional dont-change-unless) | |
5006 "Sets the expert level for a Viper user. | |
5007 Can be called interactively to change (temporarily or permanently) the | |
5008 current expert level. | |
5009 | |
5010 The optional argument DONT-CHANGE-UNLESS if not nil, says that | |
5011 the level should not be changed, unless its current value is | |
5012 meaningless (i.e., not one of 1,2,3,4,5). | |
5013 | |
5014 User level determines the setting of Viper variables that are most | |
5015 sensitive for VI-style look-and-feel." | |
5016 | |
5017 (interactive) | |
5018 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5019 (if (not (natnump vip-expert-level)) (setq vip-expert-level 0)) |
10789 | 5020 |
5021 (save-window-excursion | |
5022 (delete-other-windows) | |
5023 ;; if 0 < vip-expert-level < vip-max-expert-level | |
5024 ;; & dont-change-unless = t -- use it; else ask | |
5025 (vip-ask-level dont-change-unless)) | |
5026 | |
5027 (setq vip-always t | |
5028 vip-ex-style-motion t | |
5029 vip-ex-style-editing-in-insert t | |
5030 vip-want-ctl-h-help nil) | |
5031 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5032 (cond ((eq vip-expert-level 1) ; novice or beginner |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5033 (global-set-key ; in emacs-state |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5034 vip-toggle-key |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5035 (if (vip-window-display-p) 'vip-iconify 'suspend-emacs)) |
10789 | 5036 (setq vip-no-multiple-ESC t |
5037 vip-re-search t | |
5038 vip-vi-style-in-minibuffer t | |
5039 vip-search-wrap-around-t t | |
5040 vip-want-emacs-keys-in-vi nil | |
5041 vip-want-emacs-keys-in-insert nil)) | |
5042 | |
5043 ((and (> vip-expert-level 1) (< vip-expert-level 5)) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5044 ;; intermediate to guru |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5045 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) |
10789 | 5046 vip-want-emacs-keys-in-vi t |
5047 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
|
5048 |
10789 | 5049 (if (eq vip-expert-level 4) ; respect user's ex-style motions |
5050 ; and vip-no-multiple-ESC | |
5051 (progn | |
5052 (setq-default vip-ex-style-editing-in-insert | |
5053 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5054 vip-saved-user-settings)) | |
5055 vip-ex-style-motion | |
5056 (cdr (assoc 'vip-ex-style-motion | |
5057 vip-saved-user-settings))) | |
5058 (setq vip-ex-style-motion | |
5059 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings)) | |
5060 vip-ex-style-editing-in-insert | |
5061 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5062 vip-saved-user-settings)) | |
5063 vip-re-search | |
5064 (cdr (assoc 'vip-re-search vip-saved-user-settings)) | |
5065 vip-no-multiple-ESC | |
5066 (cdr (assoc 'vip-no-multiple-ESC | |
5067 vip-saved-user-settings)))))) | |
5068 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5069 ;; A wizard!! |
10789 | 5070 ;; 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
|
5071 ;; user toggle the values of variables. |
10789 | 5072 (t (setq-default vip-ex-style-editing-in-insert |
5073 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5074 vip-saved-user-settings)) | |
5075 vip-ex-style-motion | |
5076 (cdr (assoc 'vip-ex-style-motion | |
5077 vip-saved-user-settings))) | |
5078 (setq vip-want-ctl-h-help | |
5079 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings)) | |
5080 vip-always | |
5081 (cdr (assoc 'vip-always vip-saved-user-settings)) | |
5082 vip-no-multiple-ESC | |
5083 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings)) | |
5084 vip-ex-style-motion | |
5085 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings)) | |
5086 vip-ex-style-editing-in-insert | |
5087 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5088 vip-saved-user-settings)) | |
5089 vip-re-search | |
5090 (cdr (assoc 'vip-re-search vip-saved-user-settings)) | |
5091 vip-want-emacs-keys-in-vi | |
5092 (cdr (assoc 'vip-want-emacs-keys-in-vi | |
5093 vip-saved-user-settings)) | |
5094 vip-want-emacs-keys-in-insert | |
5095 (cdr (assoc 'vip-want-emacs-keys-in-insert | |
5096 vip-saved-user-settings))))) | |
5097 (vip-set-mode-vars-for vip-current-state) | |
5098 (if (or vip-always | |
5099 (and (> vip-expert-level 0) (> 5 vip-expert-level))) | |
5100 (vip-set-hooks))) | |
5101 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5102 ;; Ask user expert level. |
10789 | 5103 (defun vip-ask-level (dont-change-unless) |
5104 (let ((ask-buffer " *vip-ask-level*") | |
5105 level-changed repeated) | |
5106 (save-window-excursion | |
5107 (switch-to-buffer ask-buffer) | |
5108 | |
5109 (or (eq this-command 'vip-set-expert-level) | |
5110 (and | |
5111 (<= vip-expert-level vip-max-expert-level) | |
5112 (>= vip-expert-level 1)) | |
5113 (progn | |
5114 (insert " | |
5115 | |
5116 *** Important Notice for VIP users*** | |
5117 | |
5118 This is VIPER | |
5119 | |
5120 @joke | |
5121 Viper Is a Package for Emacs Rebels, | |
5122 a VI Plan for Emacs Rescue, | |
5123 and a venomous VI PERil. | |
5124 @end joke | |
5125 | |
5126 Technically speaking, Viper is a new Vi emulator that replaces | |
5127 the old VIP package. | |
5128 | |
5129 Viper emulates Vi much better than VIP. It also significantly | |
5130 extends and improves upon Vi in many useful ways. | |
5131 | |
5132 Although many VIP settings in your ~/.vip are compatible with Viper, | |
5133 you may have to change some of them. Please refer to the documentation, | |
5134 which can be obtained by executing | |
5135 | |
5136 :help | |
5137 | |
5138 when Viper is in Vi state. | |
5139 | |
5140 If you will be so lucky as to find a bug, report it via the command | |
5141 | |
5142 :submitReport | |
5143 | |
5144 Type any key to continue... ") | |
5145 | |
5146 (read-char) | |
5147 (erase-buffer))) | |
5148 | |
5149 (while (or (> vip-expert-level vip-max-expert-level) | |
5150 (< vip-expert-level 1) | |
5151 (null dont-change-unless)) | |
5152 (erase-buffer) | |
5153 (if repeated | |
5154 (progn | |
5155 (message "Invalid user level") | |
5156 (beep 1)) | |
5157 (setq repeated t)) | |
5158 (setq dont-change-unless t | |
5159 level-changed t) | |
5160 (insert " | |
5161 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
|
5162 (and the VI Plan for Emacs Rescue). |
10789 | 5163 You can change it at any time by typing `M-x vip-set-expert-level RET' |
5164 | |
5165 1 -- BEGINNER: Almost all Emacs features are suppressed. | |
5166 Feels almost like straight Vi. File name completion and | |
5167 command history in the minibuffer are thrown in as a bonus. | |
5168 To use Emacs productively, you must reach level 3 or higher. | |
5169 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state, | |
5170 so most Emacs commands can be used when Viper is in Vi state. | |
5171 Good progress---you are well on the way to level 3! | |
5172 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also | |
5173 in Viper's insert state. | |
5174 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC, | |
5175 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert | |
5176 variables. Adjust these settings to your taste. | |
5177 5 -- WIZARD: Like 4, but user settings are also respected for vip-always, | |
5178 vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, and | |
5179 vip-want-emacs-keys-in-insert. Adjust these to your taste. | |
5180 | |
5181 Please, specify your level now: ") | |
5182 | |
5183 (setq vip-expert-level (- (vip-read-char-exclusive) ?0)) | |
5184 ) ; end while | |
5185 | |
5186 ;; tell the user if level was changed | |
5187 (and level-changed | |
5188 (progn | |
5189 (insert | |
5190 (format "\n\n\n\n\n\t\tYou have selected user level %d" | |
5191 vip-expert-level)) | |
5192 (if (y-or-n-p "Do you wish to make this change permanent? ") | |
5193 ;; save the setting for vip-expert-level | |
5194 (vip-save-setting | |
5195 'vip-expert-level | |
5196 (format "Saving user level %d ..." vip-expert-level) | |
5197 vip-custom-file-name)) | |
5198 )) | |
5199 (bury-buffer) ; remove ask-buffer from screen | |
5200 (message "") | |
5201 ))) | |
5202 | |
5203 | |
5204 (defun viper-version () | |
5205 (interactive) | |
5206 (message "Viper version is %s" viper-version)) | |
5207 | |
5208 (defalias 'vip-version 'viper-version) | |
5209 | |
5210 (defun vip-nil () | |
5211 (interactive) | |
5212 (beep 1)) | |
5213 | |
5214 | |
5215 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer | |
5216 (defun vip-register-to-point (char &optional enforce-buffer) | |
5217 "Like jump-to-register, but switches to another buffer in another window." | |
5218 (interactive "cViper register to point: ") | |
5219 (let ((val (get-register char))) | |
5220 (cond | |
5221 ((and (fboundp 'frame-configuration-p) | |
5222 (frame-configuration-p val)) | |
5223 (set-frame-configuration val)) | |
5224 ((window-configuration-p val) | |
5225 (set-window-configuration val)) | |
5226 ((vip-valid-marker val) | |
5227 (if (and enforce-buffer | |
5228 (not (equal (current-buffer) (marker-buffer val)))) | |
5229 (error (concat vip-EmptyTextmarker " in this buffer") | |
5230 (1- (+ char ?a)))) | |
5231 (pop-to-buffer (marker-buffer val)) | |
5232 (goto-char val)) | |
5233 ((and (consp val) (eq (car val) 'file)) | |
5234 (find-file (cdr val))) | |
5235 (t | |
5236 (error vip-EmptyTextmarker (1- (+ char ?a))))))) | |
5237 | |
5238 | |
5239 (defun vip-save-kill-buffer () | |
5240 "Save then kill current buffer. " | |
5241 (interactive) | |
5242 (if (< vip-expert-level 2) | |
5243 (save-buffers-kill-emacs) | |
5244 (save-buffer) | |
5245 (kill-buffer (current-buffer)))) | |
5246 | |
5247 | |
5248 | |
5249 ;;; Bug Report | |
5250 | |
5251 (defun vip-submit-report () | |
5252 "Submit bug report on Viper." | |
5253 (interactive) | |
5254 (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
|
5255 (vip-device-type (vip-device-type)) |
10789 | 5256 color-display-p frame-parameters |
5257 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face | |
5258 varlist salutation window-config) | |
5259 | |
5260 ;; If mode info is needed, add variable to `let' and then set it below, | |
5261 ;; 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
|
5262 (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
|
5263 (vip-color-display-p) |
10789 | 5264 'non-x) |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5265 minibuffer-vi-face (if (vip-has-face-support-p) |
10789 | 5266 (vip-get-face vip-minibuffer-vi-face) |
5267 'non-x) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5268 minibuffer-insert-face (if (vip-has-face-support-p) |
10789 | 5269 (vip-get-face vip-minibuffer-insert-face) |
5270 'non-x) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5271 minibuffer-emacs-face (if (vip-has-face-support-p) |
10789 | 5272 (vip-get-face vip-minibuffer-emacs-face) |
5273 'non-x) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5274 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
|
5275 (frame-parameters (selected-frame)))) |
10789 | 5276 |
5277 (setq varlist (list 'vip-vi-minibuffer-minor-mode | |
5278 'vip-insert-minibuffer-minor-mode | |
5279 'vip-vi-intercept-minor-mode | |
5280 'vip-vi-local-user-minor-mode | |
5281 'vip-vi-kbd-minor-mode | |
5282 'vip-vi-global-user-minor-mode | |
5283 'vip-vi-state-modifier-minor-mode | |
5284 'vip-vi-diehard-minor-mode | |
5285 'vip-vi-basic-minor-mode | |
5286 'vip-replace-minor-mode | |
5287 'vip-insert-intercept-minor-mode | |
5288 'vip-insert-local-user-minor-mode | |
5289 'vip-insert-kbd-minor-mode | |
5290 'vip-insert-global-user-minor-mode | |
5291 'vip-insert-state-modifier-minor-mode | |
5292 'vip-insert-diehard-minor-mode | |
5293 'vip-insert-basic-minor-mode | |
5294 'vip-emacs-intercept-minor-mode | |
5295 'vip-emacs-local-user-minor-mode | |
5296 'vip-emacs-kbd-minor-mode | |
5297 'vip-emacs-global-user-minor-mode | |
5298 'vip-emacs-state-modifier-minor-mode | |
5299 'vip-automatic-iso-accents | |
5300 'vip-want-emacs-keys-in-insert | |
5301 'vip-want-emacs-keys-in-vi | |
5302 'vip-keep-point-on-undo | |
5303 'vip-no-multiple-ESC | |
5304 'vip-ESC-key | |
5305 'vip-want-ctl-h-help | |
5306 'vip-ex-style-editing-in-insert | |
5307 'vip-delete-backwards-in-replace | |
5308 '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
|
5309 '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
|
5310 '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
|
5311 '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
|
5312 'vip-emacs-state-hook |
10789 | 5313 'ex-cycle-other-window |
5314 'ex-cycle-through-non-files | |
5315 'vip-expert-level | |
5316 'major-mode | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5317 'vip-device-type |
10789 | 5318 'color-display-p |
5319 'frame-parameters | |
5320 'minibuffer-vi-face | |
5321 'minibuffer-insert-face | |
5322 'minibuffer-emacs-face | |
5323 )) | |
5324 (setq salutation " | |
5325 Congratulations! You may have unearthed a bug in Viper! | |
5326 Please mail a concise, accurate summary of the problem to the address above. | |
5327 | |
5328 -------------------------------------------------------------------") | |
5329 (setq window-config (current-window-configuration)) | |
5330 (with-output-to-temp-buffer " *vip-info*" | |
5331 (switch-to-buffer " *vip-info*") | |
5332 (delete-other-windows) | |
5333 (princ " | |
5334 PLEASE FOLLOW THESE PROCEDURES | |
5335 ------------------------------ | |
5336 | |
5337 Before reporting a bug, please verify that it is related to Viper, and is | |
5338 not cause by other packages you are using. | |
5339 | |
5340 Don't report compilation warnings, unless you are certain that there is a | |
5341 problem. These warnings are normal and unavoidable. | |
5342 | |
5343 Please note that users should not modify variables and keymaps other than | |
5344 those advertised in the manual. Such `customization' is likely to crash | |
5345 Viper, as it would any other improperly customized Emacs package. | |
5346 | |
5347 If you are reporting an error message received while executing one of the | |
5348 Viper commands, type: | |
5349 | |
5350 M-x set-variable <Return> debug-on-error <Return> t <Return> | |
5351 | |
5352 Then reproduce the error. The above command will cause Emacs to produce a | |
5353 back trace of the execution that leads to the error. Please include this | |
5354 trace in your bug report. | |
5355 | |
5356 If you believe that one of Viper's commands goes into an infinite loop | |
5357 \(e.g., Emacs freezes\), type: | |
5358 | |
5359 M-x set-variable <Return> debug-on-quit <Return> t <Return> | |
5360 | |
5361 Then reproduce the problem. Wait for a few seconds, then type C-g to abort | |
5362 the current command. Include the resulting back trace in the bug report. | |
5363 | |
5364 Mail anyway (y or n)? ") | |
5365 (if (y-or-n-p "Mail anyway? ") | |
5366 () | |
5367 (set-window-configuration window-config) | |
5368 (error "Bug report aborted"))) | |
5369 | |
5370 (require 'reporter) | |
5371 (set-window-configuration window-config) | |
5372 | |
5373 (reporter-submit-bug-report "kifer@cs.sunysb.edu" | |
5374 (vip-version) | |
5375 varlist | |
5376 nil 'delete-other-windows | |
5377 salutation) | |
5378 )) | |
5379 | |
5380 | |
5381 | |
5382 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5383 ;; Smoothes out the difference between Emacs' unread-command-events |
10789 | 5384 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of |
5385 ;; events or a sequence of keys. | |
5386 ;; | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5387 ;; 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
|
5388 ;; 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
|
5389 ;; 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
|
5390 ;; common symbol that might appear in this wrong context. |
10789 | 5391 (defun vip-set-unread-command-events (arg) |
5392 (if vip-emacs-p | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5393 (setq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5394 unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5395 (let ((new-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5396 (cond ((eventp arg) (list arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5397 ((listp arg) arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5398 ((sequencep arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5399 (listify-key-sequence arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5400 (t (error |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5401 "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
|
5402 arg))))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5403 (if (not (eventp nil)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5404 (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
|
5405 (append new-events unread-command-events))) |
10789 | 5406 ;; XEmacs |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5407 (setq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5408 unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5409 (append |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5410 (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
|
5411 ((eventp arg) (list arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5412 ((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
|
5413 ((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
|
5414 ((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
|
5415 (t (error |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5416 "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
|
5417 unread-command-events)))) |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5418 |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5419 ;; 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
|
5420 (defun vip-eventify-list-xemacs (lis) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5421 (mapcar |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5422 (function (lambda (elt) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5423 (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
|
5424 ((eventp elt) elt) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5425 (t (error |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5426 "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
|
5427 elt))))) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5428 lis)) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5429 |
10789 | 5430 |
5431 | |
5432 ;;; Bring in the rest of the files | |
5433 (require 'viper-mous) | |
5434 (require 'viper-macs) | |
5435 (require 'viper-ex) | |
5436 | |
5437 | |
5438 | |
5439 ;; The following is provided for compatibility with older VIP's | |
5440 | |
5441 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) | |
5442 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) | |
5443 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) | |
5444 | |
5445 | |
5446 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5447 ;;; 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
|
5448 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5449 ;; 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
|
5450 (defun vip-comint-mode-hook () |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5451 (setq require-final-newline nil |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5452 vip-ex-style-editing-in-insert nil |
10789 | 5453 vip-ex-style-motion nil) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5454 (vip-change-state-to-insert)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5455 |
10789 | 5456 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5457 ;; This sets major mode hooks to make them come up in vi-state. |
10789 | 5458 (defun vip-set-hooks () |
5459 | |
5460 ;; It is of course a misnomer to call viper-mode a `major mode'. | |
5461 ;; However, this has the effect that if the user didn't specify the | |
5462 ;; default mode, new buffers that fall back on the default will come up | |
5463 ;; in Fundamental Mode and Vi state. | |
5464 (setq default-major-mode 'viper-mode) | |
5465 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5466 ;; The following major modes should come up in vi-state |
10789 | 5467 (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
|
5468 "Run `vip-change-state-to-vi' on entry." |
10789 | 5469 (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
|
5470 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5471 (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
|
5472 (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
|
5473 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5474 (defvar help-mode-hook) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5475 (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
|
5476 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5477 (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
|
5478 (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
|
5479 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5480 (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
|
5481 (add-hook 'html-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5482 (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
|
5483 (add-hook 'html-helper-mode-hook 'viper-mode) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5484 (defvar java-mode-hook) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5485 (add-hook 'java-mode-hook 'viper-mode) |
10789 | 5486 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5487 (defvar emacs-lisp-mode-hook) |
10789 | 5488 (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
|
5489 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5490 (defvar lisp-mode-hook) |
10789 | 5491 (add-hook 'lisp-mode-hook 'viper-mode) |
5492 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5493 (defvar bibtex-mode-hook) |
10789 | 5494 (add-hook 'bibtex-mode-hook 'viper-mode) |
5495 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5496 (defvar cc-mode-hook) |
10789 | 5497 (add-hook 'cc-mode-hook 'viper-mode) |
5498 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5499 (defvar c-mode-hook) |
10789 | 5500 (add-hook 'c-mode-hook 'viper-mode) |
5501 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5502 (defvar c++-mode-hook) |
10789 | 5503 (add-hook 'c++-mode-hook 'viper-mode) |
5504 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5505 (defvar lisp-interaction-mode-hook) |
10789 | 5506 (add-hook 'lisp-interaction-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5507 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5508 (defvar fortran-mode-hook) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5509 (add-hook 'fortran-mode-hook 'vip-mode) |
10789 | 5510 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5511 (defvar text-mode-hook) |
10789 | 5512 (add-hook 'text-mode-hook 'viper-mode) |
5513 | |
5514 (add-hook 'completion-list-mode-hook 'viper-mode) | |
5515 (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
|
5516 |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5517 (add-hook 'perl-mode-hook 'viper-mode) |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5518 (add-hook 'tcl-mode-hook 'viper-mode) |
10789 | 5519 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5520 (defvar emerge-startup-hook) |
10789 | 5521 (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
|
5522 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5523 ;; Tell vc-diff to put *vc* in Vi mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5524 (if (featurep 'vc) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5525 (defadvice vc-diff (after vip-vc-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5526 "Force Vi state in VC diff buffer." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5527 (vip-change-state-to-vi)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5528 (vip-eval-after-load |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5529 "vc" |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5530 '(defadvice vc-diff (after vip-vc-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5531 "Force Vi state in VC diff buffer." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5532 (vip-change-state-to-vi)))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5533 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5534 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5535 "emerge" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5536 '(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
|
5537 "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
|
5538 (vip-change-state-to-vi))) |
10789 | 5539 ;; In case Emerge was loaded before Viper. |
5540 (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
|
5541 "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
|
5542 (vip-change-state-to-vi)) |
10789 | 5543 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5544 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5545 "asm-mode" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5546 '(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
|
5547 "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
|
5548 (vip-change-state-to-vi))) |
10789 | 5549 |
5550 ;; 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
|
5551 ;; thus overriding the local map. We don't need Vi mode here. |
10789 | 5552 (vip-eval-after-load |
5553 "passwd" | |
5554 '(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
|
5555 "Switch to emacs state while reading password." |
10789 | 5556 (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
|
5557 |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5558 (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
|
5559 "prolog" |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5560 '(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
|
5561 "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
|
5562 (vip-change-state-to-vi))) |
10789 | 5563 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5564 ;; Emacs shell, ange-ftp, and comint-based modes |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5565 (defvar comint-mode-hook) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5566 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5567 'comint-mode 'insert-state vip-comint-mode-modifier-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5568 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5569 '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
|
5570 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) |
10789 | 5571 |
5572 ;; Shell scripts | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5573 (defvar sh-mode-hook) |
10789 | 5574 (add-hook 'sh-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5575 (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
|
5576 (add-hook 'ksh-mode-hook 'viper-mode) |
10789 | 5577 |
5578 ;; Dired | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5579 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map) |
10789 | 5580 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) |
5581 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5582 ;; MH-E |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5583 (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
|
5584 ;; 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
|
5585 (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
|
5586 (add-hook 'mh-show-mode-hook 'viper-mode) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5587 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5588 ;; Gnus |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5589 (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
|
5590 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5591 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5592 ;; 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
|
5593 (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
|
5594 (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
|
5595 (add-hook 'gnus-article-mode-hook 'viper-mode) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5596 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5597 ;; Info |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5598 (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
|
5599 ;; 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
|
5600 (defadvice Info-mode (after vip-Info-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5601 "Switch to emacs mode." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5602 (vip-change-state-to-emacs)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5603 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5604 ;; Buffer menu |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5605 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5606 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5607 ;; 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
|
5608 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5609 "Switch to emacs mode." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5610 (vip-change-state-to-emacs)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5611 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5612 ;; 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
|
5613 (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
|
5614 (progn |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5615 (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
|
5616 (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
|
5617 (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
|
5618 "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
|
5619 (vip-change-state-to-emacs)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5620 (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
|
5621 (add-hook 'view-hook 'vip-change-state-to-emacs)) |
10789 | 5622 |
5623 ;; For VM users. | |
5624 ;; Put summary and other VM buffers in Emacs state. | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5625 (defvar vm-mode-hooks) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5626 (defvar vm-summary-mode-hooks) |
10789 | 5627 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs) |
5628 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs) | |
5629 | |
5630 ;; For RMAIL users. | |
5631 ;; Put buf in Emacs state after edit. | |
5632 (vip-eval-after-load | |
5633 "rmailedit" | |
5634 '(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
|
5635 "Switch to emacs state when done editing message." |
10789 | 5636 (vip-change-state-to-emacs))) |
5637 ;; In case RMAIL was loaded before Viper. | |
5638 (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
|
5639 "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
|
5640 (vip-change-state-to-emacs)) |
10789 | 5641 ) ; vip-set-hooks |
5642 | |
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
|
5643 ;; 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
|
5644 ;; 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
|
5645 |
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 ;; 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
|
5647 (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
|
5648 (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
|
5649 [(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
|
5650 ;; 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
|
5651 (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
|
5652 (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
|
5653 [(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
|
5654 |
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 ;; 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
|
5656 (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
|
5657 "//" '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
|
5658 [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
|
5659 ;; 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
|
5660 (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
|
5661 "///" '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
|
5662 [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
|
5663 |
10789 | 5664 |
5665 ;; ~/.vip is loaded if it exists | |
5666 (if (and (file-exists-p vip-custom-file-name) | |
5667 (not noninteractive)) | |
5668 (load vip-custom-file-name)) | |
5669 | |
5670 ;; VIP compatibility: merge whatever the user has in vip-mode-map into | |
5671 ;; Viper's basic map. | |
5672 (vip-add-keymap vip-mode-map vip-vi-global-user-map) | |
5673 | |
5674 | |
5675 ;; Applying Viper customization -- runs after (load .vip) | |
5676 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5677 ;; Save user settings or Viper defaults for vars controled by vip-expert-level |
10789 | 5678 (setq vip-saved-user-settings |
5679 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) | |
5680 (cons 'vip-always vip-always) | |
5681 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) | |
5682 (cons 'vip-ex-style-motion vip-ex-style-motion) | |
5683 (cons 'vip-ex-style-editing-in-insert | |
5684 vip-ex-style-editing-in-insert) | |
5685 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi) | |
5686 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) | |
5687 (cons 'vip-re-search vip-re-search))) | |
5688 | |
5689 | |
5690 (vip-set-minibuffer-style) | |
5691 (vip-set-minibuffer-faces) | |
5692 (vip-set-search-face) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5693 (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
|
5694 (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
|
5695 (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
|
5696 (vip-update-alphanumeric-class) |
10789 | 5697 |
5698 ;;; Familiarize Viper with some minor modes that have their own keymaps | |
5699 (vip-harness-minor-mode "compile") | |
5700 (vip-harness-minor-mode "outline") | |
5701 (vip-harness-minor-mode "allout") | |
5702 (vip-harness-minor-mode "xref") | |
5703 (vip-harness-minor-mode "lmenu") | |
5704 (vip-harness-minor-mode "vc") | |
5705 (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
|
5706 (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
|
5707 (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
|
5708 (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
|
5709 (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
|
5710 (vip-harness-minor-mode "view") |
10789 | 5711 |
5712 | |
5713 ;; Intercept maps could go in viper-keym.el | |
5714 ;; We keep them here in case someone redefines them in ~/.vip | |
5715 | |
5716 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
5717 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
5718 | |
5719 ;; This is taken care of by vip-insert-global-user-map. | |
5720 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key) | |
5721 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5722 |
10789 | 5723 ;; The default vip-toggle-key is \C-z; for the novice, it suspends or |
5724 ;; iconifies Emacs | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
5725 (define-key vip-vi-intercept-map vip-toggle-key 'vip-toggle-key-action) |
10789 | 5726 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) |
5727 | |
5728 | |
5729 (if (or vip-always | |
5730 (and (< vip-expert-level 5) (> vip-expert-level 0))) | |
5731 (vip-set-hooks)) | |
5732 | |
5733 ;; Let all minor modes take effect after loading | |
5734 ;; this may not be enough, so we also set default minor-mode-alist. | |
5735 ;; Without setting the default, new buffers that come up in emacs mode have | |
5736 ;; minor-mode-map-alist = nil, unless we call vip-change-state-* | |
5737 (if (eq vip-current-state 'emacs-state) | |
5738 (progn | |
5739 (vip-change-state-to-emacs) | |
5740 (setq-default minor-mode-map-alist minor-mode-map-alist) | |
5741 )) | |
5742 | |
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
|
5743 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5744 (run-hooks 'vip-load-hook) ; the last chance to change something |
10789 | 5745 |
5746 (provide 'viper) | |
5747 (provide 'vip19) | |
5748 (provide 'vip) | |
5749 | |
5750 ;;; viper.el ends here |