Mercurial > emacs
annotate lisp/emulation/viper.el @ 16118:4580dcf4e0d1
Include config.h.
[HAVE_TERMIOS_H]: Include termios.h.
(ospeed) [HAVE_TERMIOS_H]: Use ospeed_t.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 04 Sep 1996 15:12:18 +0000 |
parents | 8cd162ceb1dc |
children | 102e7d27c135 |
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 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
11 (defconst viper-version "2.90 of June 19, 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. |
10789 | 341 (make-variable-buffer-local 'minor-mode-map-alist) |
342 | |
343 ;; Mode for vital things like \e, C-z. | |
344 (vip-deflocalvar vip-vi-intercept-minor-mode nil) | |
345 | |
346 (vip-deflocalvar vip-vi-basic-minor-mode nil | |
347 "Viper's minor mode for Vi bindings.") | |
348 | |
349 (vip-deflocalvar vip-vi-local-user-minor-mode nil | |
350 "Auxiliary minor mode for user-defined local bindings in Vi state.") | |
351 | |
352 (vip-deflocalvar vip-vi-global-user-minor-mode nil | |
353 "Auxiliary minor mode for user-defined global bindings in Vi state.") | |
354 | |
355 (vip-deflocalvar vip-vi-state-modifier-minor-mode nil | |
356 "Minor mode used to make major-mode-specific modification to Vi state.") | |
357 | |
358 (vip-deflocalvar vip-vi-diehard-minor-mode nil | |
359 "This minor mode is in effect when the user wants Viper to be Vi.") | |
360 | |
361 (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
|
362 "Minor mode for Ex command macros in Vi state. |
10789 | 363 The corresponding keymap stores key bindings of Vi macros defined with |
364 the Ex command :map.") | |
365 | |
366 ;; Mode for vital things like \e, C-z. | |
367 (vip-deflocalvar vip-insert-intercept-minor-mode nil) | |
368 | |
369 (vip-deflocalvar vip-insert-basic-minor-mode nil | |
370 "Viper's minor mode for bindings in Insert mode.") | |
371 | |
372 (vip-deflocalvar vip-insert-local-user-minor-mode nil | |
373 "Auxiliary minor mode for buffer-local user-defined bindings in Insert state. | |
374 This is a way to overshadow normal Insert mode bindings locally to certain | |
375 designated buffers.") | |
376 | |
377 (vip-deflocalvar vip-insert-global-user-minor-mode nil | |
378 "Auxiliary minor mode for global user-defined bindings in Insert state.") | |
379 | |
380 (vip-deflocalvar vip-insert-state-modifier-minor-mode nil | |
381 "Minor mode used to make major-mode-specific modification to Insert state.") | |
382 | |
383 (vip-deflocalvar vip-insert-diehard-minor-mode nil | |
384 "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
|
385 Not recommened, except for the novice user.") |
10789 | 386 |
387 (vip-deflocalvar vip-insert-kbd-minor-mode nil | |
388 "Minor mode for Ex command macros Insert state. | |
389 The corresponding keymap stores key bindings of Vi macros defined with | |
390 the Ex command :map!.") | |
391 | |
392 (vip-deflocalvar vip-replace-minor-mode nil | |
393 "Minor mode in effect in replace state (cw, C, and the like commands).") | |
394 | |
395 ;; Mode for vital things like \C-z and \C-x) | |
396 ;; This is t, by default. So, any new buffer will have C-z defined as | |
397 ;; switch to Vi, unless we switched states in this buffer | |
398 (vip-deflocalvar vip-emacs-intercept-minor-mode t) | |
399 | |
400 (vip-deflocalvar vip-emacs-local-user-minor-mode t | |
401 "Minor mode for local user bindings effective in Emacs state. | |
402 Users can use it to override Emacs bindings when Viper is in its Emacs | |
403 state.") | |
404 | |
405 (vip-deflocalvar vip-emacs-global-user-minor-mode t | |
406 "Minor mode for global user bindings in effect in Emacs state. | |
407 Users can use it to override Emacs bindings when Viper is in its Emacs | |
408 state.") | |
409 | |
410 (vip-deflocalvar vip-emacs-kbd-minor-mode t | |
411 "Minor mode for Vi style macros in Emacs state. | |
412 The corresponding keymap stores key bindings of Vi macros defined with | |
413 `vip-record-kbd-macro' command. There is no Ex-level command to do this | |
414 interactively.") | |
415 | |
416 (vip-deflocalvar vip-emacs-state-modifier-minor-mode t | |
417 "Minor mode used to make major-mode-specific modification to Emacs state. | |
418 For instance, a Vi purist may want to bind `dd' in Dired mode to a function | |
419 that deletes a file.") | |
420 | |
421 | |
422 | |
423 ;;; ISO characters | |
424 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
425 (vip-deflocalvar vip-automatic-iso-accents nil |
10789 | 426 "*If non-nil, ISO accents will be turned on in insert/replace emacs states and turned off in vi-state. |
427 For some users, this behavior may be too primitive. In this case, use | |
428 insert/emacs/vi state hooks.") | |
429 | |
430 | |
431 ;;; Emacs keys in other states. | |
432 | |
433 (defvar vip-want-emacs-keys-in-insert t | |
434 "*Set to nil if you want complete Vi compatibility in insert mode. | |
435 Complete compatibility with Vi is not recommended for power use of Viper.") | |
436 | |
437 (defvar vip-want-emacs-keys-in-vi t | |
438 "*Set to nil if you want complete Vi compatibility in Vi mode. | |
439 Full Vi compatibility is not recommended for power use of Viper.") | |
440 | |
441 | |
442 | |
443 ;; VI-style Undo | |
444 | |
445 ;; Used to 'undo' complex commands, such as replace and insert commands. | |
446 (vip-deflocalvar vip-undo-needs-adjustment nil) | |
447 (put 'vip-undo-needs-adjustment 'permanent-local t) | |
448 | |
449 ;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a | |
450 ;; complex command that must be undone atomically. If inserted, it is | |
451 ;; erased by vip-change-state-to-vi and vip-repeat. | |
452 (defconst vip-buffer-undo-list-mark 'viper) | |
453 | |
454 (defvar vip-keep-point-on-undo nil | |
455 "*Non-nil means not to move point while undoing commands. | |
456 This style is different from Emacs and Vi. Try it to see if | |
457 it better fits your working style.") | |
458 | |
459 ;; Replace mode and changing text | |
460 | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
461 ;; 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
|
462 ;; Emacs's |
10789 | 463 (vip-deflocalvar vip-after-change-functions nil "") |
464 (vip-deflocalvar vip-before-change-functions nil "") | |
465 (vip-deflocalvar vip-post-command-hooks nil "") | |
466 (vip-deflocalvar vip-pre-command-hooks nil "") | |
467 | |
468 ;; Can be used to pass global states around for short period of time | |
469 (vip-deflocalvar vip-intermediate-command nil "") | |
470 | |
471 ;; Indicates that the current destructive command has started in replace mode. | |
472 (vip-deflocalvar vip-began-as-replace nil "") | |
473 | |
474 (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
|
475 "*Cursor color to use in Replace state") |
10789 | 476 |
477 | |
478 (vip-deflocalvar vip-replace-overlay nil "") | |
479 (put 'vip-replace-overlay 'permanent-local t) | |
480 | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
481 (if (vip-has-face-support-p) |
10789 | 482 (progn |
483 (make-face 'vip-replace-overlay-face) | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
484 (vip-hide-face 'vip-replace-overlay-face) |
10789 | 485 (or (face-differs-from-default-p 'vip-replace-overlay-face) |
486 (progn | |
487 (if (vip-can-use-colors "darkseagreen2" "Black") | |
488 (progn | |
489 (set-face-background | |
490 'vip-replace-overlay-face "darkseagreen2") | |
491 (set-face-foreground 'vip-replace-overlay-face "Black"))) | |
492 (set-face-underline-p 'vip-replace-overlay-face t)) | |
493 ))) | |
494 | |
495 (defvar vip-replace-overlay-face 'vip-replace-overlay-face | |
496 "*Face for highlighting replace regions on a window display.") | |
497 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
498 (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
|
499 "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
|
500 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
|
501 is non-nil.") |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
502 (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
|
503 "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
|
504 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
|
505 is non-nil.") |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
506 (defvar vip-use-replace-region-delimiters |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
507 (or (not (vip-has-face-support-p)) (not (vip-color-display-p))) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
508 "*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
|
509 `vip-replace-region-start-delimiter' to delimit replacement regions, even on |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
510 color displays. By default, the delimiters are used only on TTYs or |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
511 monochrome displays.") |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
512 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
513 ;; XEmacs requires glyphs |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
514 (if vip-xemacs-p |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
515 (progn |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
516 (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
|
517 (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
|
518 (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
|
519 (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
|
520 (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
|
521 (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
|
522 )) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
523 |
10789 | 524 |
525 ;; These are local marker that must be initialized to nil and moved with | |
526 ;; `vip-move-marker-locally' | |
527 ;; | |
528 ;; Remember the last position inside the replace region. | |
529 (vip-deflocalvar vip-last-posn-in-replace-region nil) | |
530 ;; Remember the last position while inserting | |
531 (vip-deflocalvar vip-last-posn-while-in-insert-state nil) | |
532 (put 'vip-last-posn-in-replace-region 'permanent-local t) | |
533 (put 'vip-last-posn-while-in-insert-state 'permanent-local t) | |
534 | |
535 (vip-deflocalvar vip-sitting-in-replace nil "") | |
536 (put 'vip-sitting-in-replace 'permanent-local t) | |
537 | |
538 ;; Remember the number of characters that have to be deleted in replace | |
539 ;; mode to compensate for the inserted characters. | |
540 (vip-deflocalvar vip-replace-chars-to-delete 0 "") | |
541 (vip-deflocalvar vip-replace-chars-deleted 0 "") | |
542 | |
543 ;; Insertion ring and command ring | |
544 (defvar vip-insertion-ring-size 14 | |
545 "The size of the insertion ring.") | |
546 ;; The insertion ring. | |
547 (defvar vip-insertion-ring nil) | |
548 ;; This is temp insertion ring. Used to do rotation for display purposes. | |
549 ;; When rotation just started, it is initialized to vip-insertion-ring. | |
550 (defvar vip-temp-insertion-ring nil) | |
551 (defvar vip-last-inserted-string-from-insertion-ring "") | |
552 | |
553 (defvar vip-command-ring-size 14 | |
554 "The size of the command ring.") | |
555 ;; The command ring. | |
556 (defvar vip-command-ring nil) | |
557 ;; This is temp command ring. Used to do rotation for display purposes. | |
558 ;; When rotation just started, it is initialized to vip-command-ring. | |
559 (defvar vip-temp-command-ring nil) | |
560 | |
561 ;; Modes and related variables | |
562 | |
563 ;; Current mode. One of: `emacs-state', `vi-state', `insert-state' | |
564 (vip-deflocalvar vip-current-state 'emacs-state) | |
565 | |
566 | |
567 (defvar vip-toggle-key "\C-z" | |
568 "The key used to change states from emacs to Vi and back. | |
569 In insert mode, this key also functions as Meta. | |
570 Must be set in .vip file or prior to loading Viper. | |
571 This setting cannot be changed interactively.") | |
572 | |
573 (defvar vip-ESC-key "\e" | |
574 "Key used to ESC. | |
575 Must be set in .vip file or prior to loading Viper. | |
576 This setting cannot be changed interactively.") | |
577 | |
578 (defvar vip-no-multiple-ESC t | |
579 "*If true, multiple ESC in Vi mode will cause bell to ring. | |
580 \_ is then mapped to Meta. | |
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 | |
16038
8cd162ceb1dc
(vip-custom-file-name): Use convert-standard-filename.
Richard M. Stallman <rms@gnu.org>
parents:
15748
diff
changeset
|
824 (defvar vip-custom-file-name |
8cd162ceb1dc
(vip-custom-file-name): Use convert-standard-filename.
Richard M. Stallman <rms@gnu.org>
parents:
15748
diff
changeset
|
825 (convert-standard-filename "~/.vip") |
10789 | 826 "Viper customisation file. |
827 This variable must be set _before_ loading Viper.") | |
828 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
829 |
10789 | 830 (defvar vip-spell-function 'ispell-region |
831 "Spell function used by #s<move> command to spell.") | |
832 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
833 (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
|
834 "The tags file used by Viper.") |
10789 | 835 |
836 ;; Minibuffer | |
837 | |
838 (defvar vip-vi-style-in-minibuffer t | |
839 "If t, use vi-style editing in minibuffer. | |
840 Should be set in `~/.vip' file.") | |
841 | |
842 ;; overlay used in the minibuffer to indicate which state it is in | |
843 (vip-deflocalvar vip-minibuffer-overlay nil) | |
844 | |
845 ;; Hook, specific to Viper, which is run just *before* exiting the minibuffer. | |
846 ;; Beginning with Emacs 19.26, the standard `minibuffer-exit-hook' is run | |
847 ;; *after* exiting the minibuffer | |
848 (defvar vip-minibuffer-exit-hook nil) | |
849 | |
850 (vip-deflocalvar vip-vi-minibuffer-minor-mode nil | |
851 "Minor mode that forces Vi-style when the Minibuffer is in Vi state.") | |
852 (vip-deflocalvar vip-insert-minibuffer-minor-mode nil | |
853 "Minor mode that forces Vi-style when the Minibuffer is in Insert state.") | |
854 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
855 ;; 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
|
856 (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
|
857 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
|
858 |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
859 (make-variable-buffer-local 'require-final-newline) |
10789 | 860 |
861 | |
862 ;; Mode line | |
863 (defconst vip-vi-state-id "<V> " | |
864 "Mode line tag identifying the Vi mode of Viper.") | |
865 (defconst vip-emacs-state-id "<E> " | |
866 "Mode line tag identifying the Emacs mode of Viper.") | |
867 (defconst vip-insert-state-id "<I> " | |
868 "Mode line tag identifying the Insert mode of Viper.") | |
869 (defconst vip-replace-state-id "<R> " | |
870 "Mode line tag identifying the Replace mode of Viper.") | |
871 | |
872 ;; Viper changes the default mode-line-buffer-identification | |
873 (setq-default mode-line-buffer-identification '(" %b")) | |
874 | |
875 ;; Variable displaying the current Viper state in the mode line. | |
876 (vip-deflocalvar vip-mode-string vip-emacs-state-id) | |
877 (or (memq 'vip-mode-string global-mode-string) | |
878 (setq global-mode-string | |
879 (append '("" vip-mode-string) (cdr global-mode-string)))) | |
880 | |
881 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
882 (defvar vip-vi-state-hook nil |
10789 | 883 "*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
|
884 (defvar vip-insert-state-hook nil |
10789 | 885 "*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
|
886 (defvar vip-replace-state-hook nil |
10789 | 887 "*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
|
888 (defvar vip-emacs-state-hook nil |
10789 | 889 "*Hooks run just before the switch to Emacs mode is completed.") |
890 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
891 (defvar vip-load-hook nil |
10789 | 892 "Hooks run just after loading Viper.") |
893 | |
894 | |
895 ;; Generic predicates | |
896 | |
897 ;; These test functions are shamelessly lifted from vip 4.4.2 by Aamod Sane | |
898 | |
899 ;; generate test functions | |
900 ;; given symbol foo, foo-p is the test function, foos is the set of | |
901 ;; Viper command keys | |
902 ;; (macroexpand '(vip-test-com-defun foo)) | |
903 ;; (defun foo-p (com) (consp (memq (if (< com 0) (- com) com) foos))) | |
904 | |
905 (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
|
906 (let* ((snm (symbol-name name)) |
10789 | 907 (nm-p (intern (concat snm "-p"))) |
908 (nms (intern (concat snm "s")))) | |
909 (` (defun (, nm-p) (com) | |
910 (consp (memq (if (< com 0) (- com) com) (, nms))))))) | |
911 | |
912 ;; Variables for defining VI commands | |
913 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
914 ;; 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
|
915 (defconst vip-prefix-commands '(?c ?d ?y ?! ?= ?# ?< ?> ?\")) |
10789 | 916 (vip-test-com-defun vip-prefix-command) |
917 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
918 ;; 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
|
919 (defconst vip-charpair-commands '(?c ?d ?y ?! ?= ?< ?> ?r ?R)) |
10789 | 920 (vip-test-com-defun vip-charpair-command) |
921 | |
922 (defconst vip-movement-commands '(?b ?B ?e ?E ?f ?F ?G ?h ?H ?j ?k ?l | |
923 ?H ?M ?n ?t ?T ?w ?W ?$ ?% | |
924 ?^ ?( ?) ?- ?+ ?| ?{ ?} ?[ ?] ?' ?` | |
925 ?; ?, ?0 ?? ?/ | |
926 ) | |
927 "Movement commands") | |
928 (vip-test-com-defun vip-movement-command) | |
929 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
930 ;; Commands that can be repeated by .(dotted) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
931 (defconst vip-dotable-commands '(?c ?d ?C ?D ?> ?<)) |
10789 | 932 (vip-test-com-defun vip-dotable-command) |
933 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
934 ;; Commands that can follow a # |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
935 (defconst vip-hash-cmds '(?c ?C ?g ?q ?S)) |
10789 | 936 (vip-test-com-defun vip-hash-cmd) |
937 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
938 ;; 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
|
939 (defconst vip-regsuffix-commands '(?d ?y ?Y ?D ?p ?P ?x ?X)) |
10789 | 940 (vip-test-com-defun vip-regsuffix-command) |
941 | |
942 | |
943 | |
944 ;;; Arrange the keymaps | |
945 (require 'viper-keym) | |
946 | |
947 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
948 ;;; CODE |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
949 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
950 ;; sentinels |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
951 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
952 ;; 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
|
953 (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
|
954 (let ((list vip-after-change-functions)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
955 (while list |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
956 (funcall (car list) beg end len) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
957 (setq list (cdr list))))) |
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-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
|
960 (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
|
961 (let ((list vip-before-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) |
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 (defsubst vip-post-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
967 (run-hooks 'vip-post-command-hooks)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
968 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
969 (defsubst vip-pre-command-sentinel () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
970 (run-hooks 'vip-pre-command-hooks)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
971 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
972 ;; 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
|
973 ;; chunk of text with reasonable accuracy. |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
974 (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
|
975 (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
|
976 vip-insert-point |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
977 (>= (point) vip-insert-point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
978 (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
|
979 (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
|
980 (integerp vip-pre-command-point) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
981 (> 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
|
982 (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
|
983 ) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
984 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
985 (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
|
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 (markerp vip-insert-point) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
988 (marker-position vip-insert-point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
989 (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
|
990 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
991 (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
|
992 ;; Restoring cursor color is needed despite |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
993 ;; 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
|
994 ;; 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
|
995 ;; 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
|
996 ;; 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
|
997 ;; 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
|
998 (if (and (<= (vip-replace-start) (point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
999 (<= (point) (vip-replace-end))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1000 (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
|
1001 (vip-restore-cursor-color) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1002 )) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1003 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1004 ;; 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
|
1005 ;; and common move commands |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1006 (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
|
1007 (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
|
1008 (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
|
1009 '(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
|
1010 (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
|
1011 (vip-restore-cursor-color))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1012 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1013 (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
|
1014 ;; Restoring cursor color is needed despite |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1015 ;; 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
|
1016 ;; 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
|
1017 ;; 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
|
1018 ;; 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
|
1019 ;; 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
|
1020 ;; |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1021 ;; 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
|
1022 ;; 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
|
1023 ;; in vip-finish-change |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1024 (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
|
1025 (vip-restore-cursor-color)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1026 (cond |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1027 ((eq vip-current-state 'replace-state) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1028 ;; 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
|
1029 (let ((replace-boundary (vip-replace-end))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1030 (save-excursion |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1031 (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
|
1032 (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
|
1033 (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
|
1034 vip-replace-chars-deleted 0) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1035 ;; 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
|
1036 (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
|
1037 (vip-replace-end)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1038 (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
|
1039 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1040 (if (and (<= (vip-replace-start) (point)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1041 (<= (point) replace-boundary)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1042 (progn |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1043 ;; 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
|
1044 (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
|
1045 (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
|
1046 (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
|
1047 )) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1048 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1049 (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
|
1050 (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
|
1051 |
10789 | 1052 |
1053 ;; changing mode | |
1054 | |
1055 ;; Change state to NEW-STATE---either emacs-state, vi-state, or insert-state. | |
1056 (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
|
1057 ;; 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
|
1058 ;; 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
|
1059 ;; 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
|
1060 ;; 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
|
1061 (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
|
1062 (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
|
1063 (remove-hook 'pre-command-hook 'vip-pre-command-sentinel) |
10789 | 1064 (add-hook 'pre-command-hook 'vip-pre-command-sentinel t) |
1065 ;; 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
|
1066 (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
|
1067 'vip-insert-state-post-command-sentinel) |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1068 (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
|
1069 'vip-insert-state-pre-command-sentinel) |
10789 | 1070 (cond ((eq new-state 'vi-state) |
1071 (cond ((member vip-current-state '(insert-state replace-state)) | |
1072 | |
1073 ;; move vip-last-posn-while-in-insert-state | |
1074 ;; This is a normal hook that is executed in insert/replace | |
1075 ;; states after each command. In Vi/Emacs state, it does | |
1076 ;; nothing. We need to execute it here to make sure that | |
1077 ;; the last posn was recorded when we hit ESC. | |
1078 ;; It may be left unrecorded if the last thing done in | |
1079 ;; insert/repl state was dabbrev-expansion or abbrev | |
1080 ;; expansion caused by hitting ESC | |
1081 (vip-insert-state-post-command-sentinel) | |
1082 | |
1083 (condition-case conds | |
1084 (progn | |
1085 (vip-save-last-insertion | |
1086 vip-insert-point | |
1087 vip-last-posn-while-in-insert-state) | |
1088 (if vip-began-as-replace | |
1089 (setq vip-began-as-replace nil) | |
1090 ;; repeat insert commands if numerical arg > 1 | |
1091 (save-excursion | |
1092 (vip-repeat-insert-command)))) | |
1093 (error | |
1094 (vip-message-conditions conds))) | |
1095 | |
1096 (if (> (length vip-last-insertion) 0) | |
1097 (vip-push-onto-ring vip-last-insertion | |
1098 'vip-insertion-ring)) | |
1099 | |
1100 (if vip-ex-style-editing-in-insert | |
1101 (or (bolp) (backward-char 1)))) | |
1102 )) | |
1103 | |
1104 ;; insert or replace | |
1105 ((memq new-state '(insert-state replace-state)) | |
1106 (if (memq vip-current-state '(emacs-state vi-state)) | |
1107 (vip-move-marker-locally 'vip-insert-point (point))) | |
1108 (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
|
1109 (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
|
1110 '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
|
1111 (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
|
1112 'vip-insert-state-pre-command-sentinel t)) |
10789 | 1113 ) ; outermost cond |
1114 | |
1115 ;; 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
|
1116 ;; variables, which is already done in vip-change-state-to-emacs! |
10789 | 1117 |
1118 (setq vip-current-state new-state) | |
1119 (vip-normalize-minor-mode-map-alist) | |
1120 (vip-adjust-keys-for new-state) | |
1121 (vip-set-mode-vars-for new-state) | |
1122 (vip-refresh-mode-line) | |
1123 ) | |
1124 | |
1125 | |
1126 | |
1127 (defun vip-adjust-keys-for (state) | |
1128 "Make necessary adjustments to keymaps before entering STATE." | |
1129 (cond ((memq state '(insert-state replace-state)) | |
1130 (if vip-auto-indent | |
1131 (progn | |
1132 (define-key vip-insert-basic-map "\C-m" 'vip-autoindent) | |
1133 (if vip-want-emacs-keys-in-insert | |
1134 ;; expert | |
1135 (define-key vip-insert-basic-map "\C-j" nil) | |
1136 ;; novice | |
1137 (define-key vip-insert-basic-map "\C-j" 'vip-autoindent)))) | |
1138 | |
1139 (setq vip-insert-diehard-minor-mode | |
1140 (not vip-want-emacs-keys-in-insert)) | |
1141 | |
1142 (if vip-want-ctl-h-help | |
1143 (progn | |
1144 (define-key vip-insert-basic-map "\C-h" 'help-command) | |
1145 (define-key vip-replace-map "\C-h" 'help-command)) | |
1146 (define-key vip-insert-basic-map | |
1147 "\C-h" 'vip-del-backward-char-in-insert) | |
1148 (define-key vip-replace-map | |
1149 "\C-h" 'vip-del-backward-char-in-replace))) | |
1150 | |
1151 (t | |
1152 (setq vip-vi-diehard-minor-mode (not vip-want-emacs-keys-in-vi)) | |
1153 (if vip-want-ctl-h-help | |
1154 (define-key vip-vi-basic-map "\C-h" 'help-command) | |
1155 (define-key vip-vi-basic-map "\C-h" 'vip-backward-char))) | |
1156 )) | |
1157 | |
1158 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1159 ;; 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
|
1160 ;; 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
|
1161 ;; 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
|
1162 (defun vip-normalize-minor-mode-map-alist () |
10789 | 1163 (setq minor-mode-map-alist |
1164 (vip-append-filter-alist | |
1165 (list | |
1166 (cons 'vip-vi-intercept-minor-mode vip-vi-intercept-map) | |
1167 (cons 'vip-vi-minibuffer-minor-mode vip-minibuffer-map) | |
1168 (cons 'vip-vi-local-user-minor-mode vip-vi-local-user-map) | |
1169 (cons 'vip-vi-kbd-minor-mode vip-vi-kbd-map) | |
1170 (cons 'vip-vi-global-user-minor-mode vip-vi-global-user-map) | |
1171 (cons 'vip-vi-state-modifier-minor-mode | |
1172 (if (keymapp | |
1173 (cdr (assoc major-mode vip-vi-state-modifier-alist))) | |
1174 (cdr (assoc major-mode vip-vi-state-modifier-alist)) | |
1175 vip-empty-keymap)) | |
1176 (cons 'vip-vi-diehard-minor-mode vip-vi-diehard-map) | |
1177 (cons 'vip-vi-basic-minor-mode vip-vi-basic-map) | |
1178 (cons 'vip-insert-intercept-minor-mode vip-insert-intercept-map) | |
1179 (cons 'vip-replace-minor-mode vip-replace-map) | |
1180 ;; vip-insert-minibuffer-minor-mode must come after | |
1181 ;; vip-replace-minor-mode | |
1182 (cons 'vip-insert-minibuffer-minor-mode | |
1183 vip-minibuffer-map) | |
1184 (cons 'vip-insert-local-user-minor-mode | |
1185 vip-insert-local-user-map) | |
1186 (cons 'vip-insert-kbd-minor-mode vip-insert-kbd-map) | |
1187 (cons 'vip-insert-global-user-minor-mode | |
1188 vip-insert-global-user-map) | |
1189 (cons 'vip-insert-state-modifier-minor-mode | |
1190 (if (keymapp | |
1191 (cdr | |
1192 (assoc major-mode vip-insert-state-modifier-alist))) | |
1193 (cdr | |
1194 (assoc major-mode vip-insert-state-modifier-alist)) | |
1195 vip-empty-keymap)) | |
1196 (cons 'vip-insert-diehard-minor-mode vip-insert-diehard-map) | |
1197 (cons 'vip-insert-basic-minor-mode vip-insert-basic-map) | |
1198 (cons 'vip-emacs-intercept-minor-mode | |
1199 vip-emacs-intercept-map) | |
1200 (cons 'vip-emacs-local-user-minor-mode | |
1201 vip-emacs-local-user-map) | |
1202 (cons 'vip-emacs-kbd-minor-mode vip-emacs-kbd-map) | |
1203 (cons 'vip-emacs-global-user-minor-mode | |
1204 vip-emacs-global-user-map) | |
1205 (cons 'vip-emacs-state-modifier-minor-mode | |
1206 (if (keymapp | |
1207 (cdr | |
1208 (assoc major-mode vip-emacs-state-modifier-alist))) | |
1209 (cdr | |
1210 (assoc major-mode vip-emacs-state-modifier-alist)) | |
1211 vip-empty-keymap)) | |
1212 ) | |
1213 minor-mode-map-alist))) | |
1214 | |
1215 | |
1216 | |
1217 | |
1218 | |
1219 ;; Viper mode-changing commands and utilities | |
1220 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1221 ;; Modifies mode-line-buffer-identification. |
10789 | 1222 (defun vip-refresh-mode-line () |
1223 (setq vip-mode-string | |
1224 (cond ((eq vip-current-state 'emacs-state) vip-emacs-state-id) | |
1225 ((eq vip-current-state 'vi-state) vip-vi-state-id) | |
1226 ((eq vip-current-state 'replace-state) vip-replace-state-id) | |
1227 ((eq vip-current-state 'insert-state) vip-insert-state-id))) | |
1228 | |
1229 ;; Sets Viper mode string in global-mode-string | |
1230 (force-mode-line-update)) | |
1231 | |
1232 ;;;###autoload | |
1233 (defun viper-mode () | |
1234 "Turn on Viper emulation of Vi." | |
1235 (interactive) | |
1236 (if (not noninteractive) | |
1237 (progn | |
1238 (if vip-first-time ; This check is important. Without it, startup and | |
1239 (progn ; expert-level msgs mix up when viper-mode recurses | |
1240 (setq vip-first-time nil) | |
1241 (if (not vip-inhibit-startup-message) | |
1242 (save-window-excursion | |
1243 (setq vip-inhibit-startup-message t) | |
1244 (delete-other-windows) | |
1245 (switch-to-buffer "Viper Startup Message") | |
1246 (erase-buffer) | |
1247 (insert | |
1248 (substitute-command-keys | |
1249 "Viper Is a Package for Emacs Rebels. | |
1250 It is also a VI Plan for Emacs Rescue and a venomous VI PERil. | |
1251 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1252 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and |
10789 | 1253 XEmacs 19. It supports virtually all of Vi and Ex functionality, extending |
1254 and improving upon much of it. | |
1255 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1256 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
|
1257 level 5 provides the most flexibility to depart from many Vi conventions. |
10789 | 1258 |
1259 You will be asked to specify your user level in a following screen. | |
1260 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1261 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
|
1262 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
|
1263 use Emacs productively, you are advised to reach user level 3 or higher. |
10789 | 1264 |
1265 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
|
1266 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and |
10789 | 1267 ^G will be the usual Emacs's keyboard-quit (something like ^C in VI). |
1268 | |
1269 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they | |
1270 do not cause Emacs to quit, except at user level 1 (a novice). | |
1271 3. ^X^C EXITS EMACS. | |
1272 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat | |
1273 undo. Another `u' changes direction. | |
1274 | |
1275 6. Emacs Meta functions are invoked by typing `_' or `\\ ESC'. | |
1276 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
|
1277 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1278 something funny happens. This would abort the current editing command. |
10789 | 1279 |
1280 You can get more information on Viper by: | |
1281 | |
1282 a. Typing `:help' in Vi state | |
1283 b. Printing Viper manual, found in ./etc/viper.dvi | |
1284 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi | |
1285 | |
1286 This startup message appears whenever you load Viper, unless you type `y' now." | |
1287 )) | |
1288 (goto-char (point-min)) | |
1289 (if (y-or-n-p "Inhibit Viper startup message? ") | |
1290 (vip-save-setting | |
1291 'vip-inhibit-startup-message | |
1292 "Viper startup message inhibited" | |
1293 vip-custom-file-name t)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1294 ;;(kill-buffer (current-buffer)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1295 (message |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1296 "The last message is in buffer `Viper Startup Message'") |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1297 (sit-for 4) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1298 )) |
10789 | 1299 (vip-set-expert-level 'dont-change-unless))) |
1300 (vip-change-state-to-vi)))) | |
1301 | |
1302 ;;;###autoload | |
1303 (defalias 'vip-mode 'viper-mode) | |
1304 | |
1305 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1306 ;; Switch from Insert state to Vi state. |
10789 | 1307 (defun vip-exit-insert-state () |
1308 (interactive) | |
1309 (vip-change-state-to-vi)) | |
1310 | |
1311 (defun vip-set-mode-vars-for (state) | |
1312 "Sets Viper minor mode variables to put Viper's state STATE in effect." | |
1313 | |
1314 ;; Emacs state | |
1315 (setq vip-vi-minibuffer-minor-mode nil | |
1316 vip-insert-minibuffer-minor-mode nil | |
1317 vip-vi-intercept-minor-mode nil | |
1318 vip-insert-intercept-minor-mode nil | |
1319 | |
1320 vip-vi-local-user-minor-mode nil | |
1321 vip-vi-kbd-minor-mode nil | |
1322 vip-vi-global-user-minor-mode nil | |
1323 vip-vi-state-modifier-minor-mode nil | |
1324 vip-vi-diehard-minor-mode nil | |
1325 vip-vi-basic-minor-mode nil | |
1326 | |
1327 vip-replace-minor-mode nil | |
1328 | |
1329 vip-insert-local-user-minor-mode nil | |
1330 vip-insert-kbd-minor-mode nil | |
1331 vip-insert-global-user-minor-mode nil | |
1332 vip-insert-state-modifier-minor-mode nil | |
1333 vip-insert-diehard-minor-mode nil | |
1334 vip-insert-basic-minor-mode nil | |
1335 vip-emacs-intercept-minor-mode t | |
1336 vip-emacs-local-user-minor-mode t | |
1337 vip-emacs-kbd-minor-mode (not (vip-is-in-minibuffer)) | |
1338 vip-emacs-global-user-minor-mode t | |
1339 vip-emacs-state-modifier-minor-mode t | |
1340 ) | |
1341 | |
1342 ;; Vi state | |
1343 (if (eq state 'vi-state) ; adjust for vi-state | |
1344 (setq | |
1345 vip-vi-intercept-minor-mode t | |
1346 vip-vi-minibuffer-minor-mode (vip-is-in-minibuffer) | |
1347 vip-vi-local-user-minor-mode t | |
1348 vip-vi-kbd-minor-mode (not (vip-is-in-minibuffer)) | |
1349 vip-vi-global-user-minor-mode t | |
1350 vip-vi-state-modifier-minor-mode t | |
1351 ;; don't let the diehard keymap block command completion | |
1352 ;; and other things in the minibuffer | |
1353 vip-vi-diehard-minor-mode (not | |
1354 (or vip-want-emacs-keys-in-vi | |
1355 (vip-is-in-minibuffer))) | |
1356 vip-vi-basic-minor-mode t | |
1357 vip-emacs-intercept-minor-mode nil | |
1358 vip-emacs-local-user-minor-mode nil | |
1359 vip-emacs-kbd-minor-mode nil | |
1360 vip-emacs-global-user-minor-mode nil | |
1361 vip-emacs-state-modifier-minor-mode nil | |
1362 )) | |
1363 | |
1364 ;; Insert and Replace states | |
1365 (if (member state '(insert-state replace-state)) | |
1366 (setq | |
1367 vip-insert-intercept-minor-mode t | |
1368 vip-replace-minor-mode (eq state 'replace-state) | |
1369 vip-insert-minibuffer-minor-mode (vip-is-in-minibuffer) | |
1370 vip-insert-local-user-minor-mode t | |
1371 vip-insert-kbd-minor-mode (not (vip-is-in-minibuffer)) | |
1372 vip-insert-global-user-minor-mode t | |
1373 vip-insert-state-modifier-minor-mode t | |
1374 ;; don't let the diehard keymap block command completion | |
1375 ;; and other things in the minibuffer | |
1376 vip-insert-diehard-minor-mode (not | |
1377 (or vip-want-emacs-keys-in-insert | |
1378 (vip-is-in-minibuffer))) | |
1379 vip-insert-basic-minor-mode t | |
1380 vip-emacs-intercept-minor-mode nil | |
1381 vip-emacs-local-user-minor-mode nil | |
1382 vip-emacs-kbd-minor-mode nil | |
1383 vip-emacs-global-user-minor-mode nil | |
1384 vip-emacs-state-modifier-minor-mode nil | |
1385 )) | |
1386 | |
1387 ;; minibuffer faces | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
1388 (if (vip-has-face-support-p) |
10789 | 1389 (setq vip-minibuffer-current-face |
1390 (cond ((eq state 'emacs-state) vip-minibuffer-emacs-face) | |
1391 ((eq state 'vi-state) vip-minibuffer-vi-face) | |
1392 ((memq state '(insert-state replace-state)) | |
1393 vip-minibuffer-insert-face)))) | |
1394 | |
1395 (if (vip-is-in-minibuffer) | |
1396 (vip-set-minibuffer-overlay)) | |
1397 ) | |
1398 | |
1399 ;; 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
|
1400 ;; Also, this fixes `undo' to work vi-style for complex commands. |
10789 | 1401 (defun vip-change-state-to-vi () |
1402 "Change Viper state to Vi." | |
1403 (interactive) | |
1404 (if (and vip-first-time (not (vip-is-in-minibuffer))) | |
1405 (viper-mode) | |
1406 (if overwrite-mode (overwrite-mode nil)) | |
1407 (if abbrev-mode (expand-abbrev)) | |
1408 (if (and auto-fill-function (> (current-column) fill-column)) | |
1409 (funcall auto-fill-function)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1410 ;; don't leave whitespace lines around |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1411 (if (and (memq last-command |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1412 '(vip-autoindent |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1413 vip-open-line vip-Open-line |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1414 vip-replace-state-exit-cmd)) |
12203
0078571e5330
(vip-change-state-to-vi): bug fix.
Karl Heuer <kwzh@gnu.org>
parents:
12137
diff
changeset
|
1415 (vip-over-whitespace-line)) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1416 (indent-to-left-margin)) |
10789 | 1417 (vip-add-newline-at-eob-if-necessary) |
1418 (if vip-undo-needs-adjustment (vip-adjust-undo)) | |
1419 (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
|
1420 |
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
|
1421 ;; 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
|
1422 ;; 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
|
1423 (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
|
1424 (iso-accents-mode -1)) |
10789 | 1425 |
1426 ;; Protection against user errors in hooks | |
1427 (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
|
1428 (run-hooks 'vip-vi-state-hook) |
10789 | 1429 (error |
1430 (vip-message-conditions conds))))) | |
1431 | |
1432 (defun vip-change-state-to-insert () | |
1433 "Change Viper state to Insert." | |
1434 (interactive) | |
1435 (vip-change-state 'insert-state) | |
1436 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | |
1437 (iso-accents-mode 1)) ; turn iso accents on | |
1438 | |
1439 ;; Protection against user errors in hooks | |
1440 (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
|
1441 (run-hooks 'vip-insert-state-hook) |
10789 | 1442 (error |
1443 (vip-message-conditions conds)))) | |
1444 | |
1445 (defsubst vip-downgrade-to-insert () | |
1446 (setq vip-current-state 'insert-state | |
1447 vip-replace-minor-mode nil) | |
1448 ) | |
1449 | |
1450 | |
1451 | |
1452 ;; Change to replace state. When the end of replacement region is reached, | |
1453 ;; replace state changes to insert state. | |
1454 (defun vip-change-state-to-replace (&optional non-R-cmd) | |
1455 (vip-change-state 'replace-state) | |
1456 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | |
1457 (iso-accents-mode 1)) ; turn iso accents on | |
1458 ;; Run insert-state-hook | |
1459 (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
|
1460 (run-hooks 'vip-insert-state-hook 'vip-replace-state-hook) |
10789 | 1461 (error |
1462 (vip-message-conditions conds))) | |
1463 | |
1464 (if non-R-cmd | |
1465 (vip-start-replace) | |
1466 ;; 'R' is implemented using Emacs's overwrite-mode | |
1467 (vip-start-R-mode)) | |
1468 ) | |
1469 | |
1470 | |
1471 (defun vip-change-state-to-emacs () | |
1472 "Change Viper state to Emacs." | |
1473 (interactive) | |
1474 (vip-change-state 'emacs-state) | |
1475 (if (and vip-automatic-iso-accents (fboundp 'iso-accents-mode)) | |
1476 (iso-accents-mode 1)) ; turn iso accents on | |
1477 | |
1478 ;; Protection agains user errors in hooks | |
1479 (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
|
1480 (run-hooks 'vip-emacs-state-hook) |
10789 | 1481 (error |
1482 (vip-message-conditions conds)))) | |
1483 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1484 ;; escape to emacs mode termporarily |
10789 | 1485 (defun vip-escape-to-emacs (arg &optional events) |
1486 "Escape to Emacs state from Vi state for one Emacs command. | |
1487 ARG is used as the prefix value for the executed command. If | |
1488 EVENTS is a list of events, which become the beginning of the command." | |
1489 (interactive "P") | |
1490 (vip-escape-to-state arg events 'emacs-state)) | |
1491 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1492 ;; escape to Vi mode termporarily |
10789 | 1493 (defun vip-escape-to-vi () |
1494 "Escape from Emacs state to Vi state for one Vi 1-character command. | |
1495 This doesn't work with prefix arguments or most complex commands like | |
1496 cw, dw, etc. But it does work with some 2-character commands, | |
1497 like dd or dr." | |
1498 (interactive) | |
1499 (vip-escape-to-state nil nil 'vi-state)) | |
1500 | |
1501 ;; Escape to STATE mode for one Emacs command. | |
1502 (defun vip-escape-to-state (arg events state) | |
1503 (let (com key prefix-arg) | |
1504 ;; this temporarily turns off Viper's minor mode keymaps | |
1505 (vip-set-mode-vars-for state) | |
1506 (vip-normalize-minor-mode-map-alist) | |
1507 (if events (vip-set-unread-command-events events)) | |
1508 | |
1509 ;; protect against keyboard quit and other errors | |
1510 (condition-case nil | |
1511 (progn | |
1512 (unwind-protect | |
1513 (progn | |
1514 (setq com (key-binding (setq key | |
1515 (if vip-xemacs-p | |
1516 (read-key-sequence nil) | |
1517 (read-key-sequence nil t))))) | |
1518 ;; In case of indirection--chase definitions. | |
1519 ;; Have to do it here because we execute this command under | |
1520 ;; different keymaps, so command-execute may not do the | |
1521 ;; right thing there | |
1522 (while (vectorp com) (setq com (key-binding com)))) | |
1523 nil) | |
1524 ;; exec command in the right Viper state | |
1525 ;; otherwise, if we switch buffers in the escaped command, | |
1526 ;; Viper's mode vars will remain those of `state'. When we return | |
1527 ;; to the orig buffer, the bindings will be screwed up. | |
1528 (vip-set-mode-vars-for vip-current-state) | |
1529 | |
1530 ;; this-command, last-command-char, last-command-event | |
1531 (setq this-command com) | |
1532 (if vip-xemacs-p ; XEmacs represents key sequences as vectors | |
1533 (setq last-command-event (vip-seq-last-elt key) | |
1534 last-command-char (event-to-character last-command-event)) | |
1535 ;; Emacs represents them as sequences (str or vec) | |
1536 (setq last-command-event (vip-seq-last-elt key) | |
1537 last-command-char last-command-event)) | |
1538 | |
1539 (if (commandp com) | |
1540 (progn | |
1541 (setq prefix-arg arg) | |
1542 (command-execute com))) | |
1543 ) | |
1544 (quit (ding)) | |
1545 (error (beep 1)))) | |
1546 (vip-set-mode-vars-for vip-current-state)) ; set state in new buffer | |
1547 | |
1548 (defun vip-exec-form-in-emacs (form) | |
1549 "Execute FORM in Emacs, temporarily disabling Viper's minor modes. | |
1550 Similar to vip-escape-to-emacs, but accepts forms rather than keystrokes." | |
1551 (let ((buff (current-buffer)) | |
1552 result) | |
1553 (vip-set-mode-vars-for 'emacs-state) | |
1554 (setq result (eval form)) | |
1555 (if (not (equal buff (current-buffer))) ; cmd switched buffer | |
1556 (save-excursion | |
1557 (set-buffer buff) | |
1558 (vip-set-mode-vars-for vip-current-state))) | |
1559 (vip-set-mode-vars-for vip-current-state) | |
1560 result)) | |
1561 | |
1562 | |
1563 ;; This is needed because minor modes sometimes override essential Viper | |
1564 ;; bindings. By letting Viper know which files these modes are in, it will | |
1565 ;; arrange to reorganize minor-mode-map-alist so that things will work right. | |
1566 (defun vip-harness-minor-mode (load-file) | |
1567 "Familiarize Viper with a minor mode defined in LOAD_FILE. | |
1568 Minor modes that have their own keymaps may overshadow Viper keymaps. | |
1569 This function is designed to make Viper aware of the packages that define | |
1570 such minor modes. | |
1571 Usage: | |
1572 (vip-harness-minor-mode load-file) | |
1573 | |
1574 LOAD-FILE is a name of the file where the specific minor mode is defined. | |
1575 Suffixes such as .el or .elc should be stripped." | |
1576 | |
1577 (interactive "sEnter name of the load file: ") | |
1578 | |
1579 (vip-eval-after-load load-file '(vip-normalize-minor-mode-map-alist)) | |
1580 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1581 ;; 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
|
1582 ;; 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
|
1583 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1584 load-file '(setq-default minor-mode-map-alist minor-mode-map-alist)) |
10789 | 1585 ) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
1586 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1587 |
10789 | 1588 (defun vip-ESC (arg) |
1589 "Emulate ESC key in Emacs. | |
1590 Prevents multiple escape keystrokes if vip-no-multiple-ESC is true. In that | |
1591 case \@ will be bound to ESC. If vip-no-multiple-ESC is 'twice double ESC | |
1592 would dings in vi-state. Other ESC sequences are emulated via the current | |
1593 Emacs's major mode keymap. This is more convenient on dumb terminals and in | |
1594 Emacs -nw, since this won't block functional keys such as up,down, | |
1595 etc. Meta key also will work. When vip-no-multiple-ESC is nil, ESC key | |
1596 behaves as in Emacs, any number of multiple escapes is allowed." | |
1597 (interactive "P") | |
1598 (let (char) | |
1599 (cond ((and (not vip-no-multiple-ESC) (eq vip-current-state 'vi-state)) | |
1600 (setq char (vip-read-char-exclusive)) | |
1601 (vip-escape-to-emacs arg (list ?\e char) )) | |
1602 ((and (eq vip-no-multiple-ESC 'twice) | |
1603 (eq vip-current-state 'vi-state)) | |
1604 (setq char (vip-read-char-exclusive)) | |
1605 (if (= char (string-to-char vip-ESC-key)) | |
1606 (ding) | |
1607 (vip-escape-to-emacs arg (list ?\e char) ))) | |
1608 (t (ding))) | |
1609 )) | |
1610 | |
1611 (defun vip-alternate-ESC (arg) | |
1612 "ESC key without checking for multiple keystrokes." | |
1613 (interactive "P") | |
1614 (vip-escape-to-emacs arg '(?\e))) | |
1615 | |
1616 | |
1617 ;; Intercept ESC sequences on dumb terminals. | |
1618 ;; Based on the idea contributed by Marcelino Veiga Tuimil <mveiga@dit.upm.es> | |
1619 | |
1620 ;; Check if last key was ESC and if so try to reread it as a function key. | |
1621 ;; But only if there are characters to read during a very short time. | |
1622 ;; Returns the last event, if any. | |
1623 (defun vip-envelop-ESC-key () | |
1624 (let ((event last-input-event) | |
1625 (keyseq [nil]) | |
1626 inhibit-quit) | |
1627 (if (vip-ESC-event-p event) | |
1628 (progn | |
1629 (if (vip-fast-keysequence-p) | |
1630 (progn | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1631 (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
|
1632 (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
|
1633 (setq keyseq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1634 (funcall |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1635 (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
|
1636 ) ; let |
10789 | 1637 ;; 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
|
1638 ;; 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
|
1639 ;; 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
|
1640 ;; and convert them into [escape key] |
10789 | 1641 ;; |
1642 ;; This is needed for the following reason: | |
1643 ;; If ESC is the first symbol, we interpret it as if the | |
1644 ;; user typed ESC and then quickly some other symbols. | |
1645 ;; If ESC is not the first one, then the key sequence | |
1646 ;; entered was apparently translated into a function key or | |
1647 ;; something (e.g., one may have | |
1648 ;; (define-key function-key-map "\e[192z" [f11]) | |
1649 ;; which would translate the escape-sequence generated by | |
1650 ;; 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
|
1651 ;; |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
1652 ;; 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
|
1653 ;; 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
|
1654 ;; 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
|
1655 ;; 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
|
1656 ;; 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
|
1657 ;; 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
|
1658 ;; ESC-sequences). |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1659 (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
|
1660 (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
|
1661 (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
|
1662 ;; 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
|
1663 ;; 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
|
1664 (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
|
1665 (setq last-input-event event |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1666 keyseq (if vip-emacs-p |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1667 "\e" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1668 (vector (character-to-event ?\e))))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1669 ((and vip-xemacs-p |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1670 (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
|
1671 (equal '(meta) key-mod)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1672 (vip-set-unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1673 (vconcat (vector |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1674 (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
|
1675 (subseq keyseq 1))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1676 (setq last-input-event event |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1677 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
|
1678 ((eventp first-key) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1679 (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
|
1680 )) |
10789 | 1681 ) ; end progn |
1682 | |
1683 ;; this is escape event with nothing after it | |
1684 ;; put in unread-command-event and then re-read | |
1685 (vip-set-unread-command-events event) | |
1686 (setq keyseq | |
1687 (funcall (ad-get-orig-definition 'read-key-sequence) nil)) | |
1688 )) | |
1689 ;; not an escape event | |
1690 (setq keyseq (vector event))) | |
1691 keyseq)) | |
1692 | |
1693 | |
1694 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1695 (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
|
1696 "Harness to work for Viper. This advice is harmless---don't worry!" |
10789 | 1697 (let (inhibit-quit event keyseq) |
1698 (setq keyseq ad-do-it) | |
1699 (setq event (if vip-xemacs-p | |
1700 (elt keyseq 0) ; XEmacs returns vector of events | |
1701 (elt (listify-key-sequence keyseq) 0))) | |
1702 (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
|
1703 (let (unread-command-events) |
10789 | 1704 (vip-set-unread-command-events keyseq) |
1705 (if (vip-fast-keysequence-p) | |
1706 (let ((vip-vi-global-user-minor-mode nil) | |
1707 (vip-vi-local-user-minor-mode nil) | |
1708 (vip-replace-minor-mode nil) ; actually unnecessary | |
1709 (vip-insert-global-user-minor-mode nil) | |
1710 (vip-insert-local-user-minor-mode nil)) | |
1711 (setq keyseq ad-do-it)) | |
1712 (setq keyseq ad-do-it)))) | |
1713 keyseq)) | |
1714 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1715 (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
|
1716 "Force to read key via `read-key-sequence'." |
10789 | 1717 (interactive (list (vip-events-to-keys |
1718 (read-key-sequence "Describe key: "))))) | |
1719 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1720 (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
|
1721 "Force to read key via `read-key-sequence'." |
10789 | 1722 (interactive (list (vip-events-to-keys |
1723 (read-key-sequence "Describe key briefly: "))))) | |
1724 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1725 ;; Listen to ESC key. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1726 ;; 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
|
1727 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key. |
10789 | 1728 (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
|
1729 "Function that implements ESC key in Viper emulation of Vi." |
10789 | 1730 (interactive) |
1731 (let ((cmd (or (key-binding (vip-envelop-ESC-key)) | |
1732 '(lambda () (interactive) (error ""))))) | |
1733 | |
1734 ;; call the actual function to execute ESC (if no other symbols followed) | |
1735 ;; or the key bound to the ESC sequence (if the sequence was issued | |
1736 ;; with very short delay between characters. | |
1737 (if (eq cmd 'vip-intercept-ESC-key) | |
1738 (setq cmd | |
1739 (cond ((eq vip-current-state 'vi-state) | |
1740 'vip-ESC) | |
1741 ((eq vip-current-state 'insert-state) | |
1742 'vip-exit-insert-state) | |
1743 ((eq vip-current-state 'replace-state) | |
1744 'vip-replace-state-exit-cmd) | |
1745 (t 'vip-change-state-to-vi) | |
1746 ))) | |
1747 (call-interactively cmd))) | |
1748 | |
1749 | |
1750 | |
1751 ;; prefix argument for Vi mode | |
1752 | |
1753 ;; In Vi mode, prefix argument is a dotted pair (NUM . COM) where NUM | |
1754 ;; represents the numeric value of the prefix argument and COM represents | |
1755 ;; command prefix such as "c", "d", "m" and "y". | |
1756 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1757 ;; 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
|
1758 (defsubst vip-p-val (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1759 (cond ((null arg) 1) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1760 ((consp arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1761 (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
|
1762 1 (car arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1763 (t arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1764 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1765 ;; 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
|
1766 (defsubst vip-P-val (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1767 (cond ((consp arg) (car arg)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1768 (t arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1769 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1770 ;; 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
|
1771 (defsubst vip-getcom (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1772 (cond ((null arg) nil) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1773 ((consp arg) (cdr arg)) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1774 (t nil))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1775 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1776 ;; 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
|
1777 (defun vip-getCom (arg) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1778 (let ((com (vip-getcom arg))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1779 (cond ((equal com ?c) ?C) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1780 ((equal com ?d) ?D) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1781 ((equal com ?y) ?Y) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1782 (t com)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1783 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1784 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1785 ;; Compute numeric prefix arg value. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1786 ;; Invoked by CHAR. COM is the command part obtained so far. |
10789 | 1787 (defun vip-prefix-arg-value (event com) |
1788 (let (value) | |
1789 ;; read while number | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1790 (while (and (vip-characterp event) (>= event ?0) (<= event ?9)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1791 (setq value (+ (* (if (vip-characterp value) value 0) 10) (- event ?0))) |
10789 | 1792 (setq event (vip-read-event-convert-to-char))) |
1793 | |
1794 (setq prefix-arg value) | |
1795 (if com (setq prefix-arg (cons prefix-arg com))) | |
1796 (while (eq event ?U) | |
1797 (vip-describe-arg prefix-arg) | |
1798 (setq event (vip-read-event-convert-to-char))) | |
1799 (vip-set-unread-command-events event))) | |
1800 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
1801 ;; Vi operator as prefix argument." |
10789 | 1802 (defun vip-prefix-arg-com (char value com) |
1803 (let ((cont t)) | |
1804 (while (and cont | |
1805 (memq char | |
1806 (list ?c ?d ?y ?! ?< ?> ?= ?# ?r ?R ?\" | |
1807 vip-buffer-search-char))) | |
1808 (if com | |
1809 ;; this means that we already have a command character, so we | |
1810 ;; construct a com list and exit while. however, if char is " | |
1811 ;; it is an error. | |
1812 (progn | |
1813 ;; new com is (CHAR . OLDCOM) | |
1814 (if (memq char '(?# ?\")) (error "")) | |
1815 (setq com (cons char com)) | |
1816 (setq cont nil)) | |
1817 ;; If com is nil we set com as char, and read more. Again, if char | |
1818 ;; is ", we read the name of register and store it in vip-use-register. | |
1819 ;; if char is !, =, or #, a complete com is formed so we exit the | |
1820 ;; while loop. | |
1821 (cond ((memq char '(?! ?=)) | |
1822 (setq com char) | |
1823 (setq char (read-char)) | |
1824 (setq cont nil)) | |
1825 ((= char ?#) | |
1826 ;; read a char and encode it as com | |
1827 (setq com (+ 128 (read-char))) | |
1828 (setq char (read-char))) | |
1829 ((= char ?\") | |
1830 (let ((reg (read-char))) | |
1831 (if (vip-valid-register reg) | |
1832 (setq vip-use-register reg) | |
1833 (error "")) | |
1834 (setq char (read-char)))) | |
1835 (t | |
1836 (setq com char) | |
1837 (setq char (vip-read-char-exclusive))))))) | |
1838 (if (atom com) | |
1839 ;; com is a single char, so we construct prefix-arg | |
1840 ;; and if char is ?, describe prefix arg, otherwise exit by | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
1841 ;; pushing the char back into vip-set-unread-command-events |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
1842 ;; Since char is a command, the command will execute with the prefix |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
1843 ;; argument that we just constructed. |
10789 | 1844 (progn |
1845 (setq prefix-arg (cons value com)) | |
1846 (while (= char ?U) | |
1847 (vip-describe-arg prefix-arg) | |
1848 (setq char (read-char))) | |
1849 (vip-set-unread-command-events char) | |
1850 ) | |
1851 ;; as com is non-nil, this means that we have a command to execute | |
1852 (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
|
1853 ;; execute apropriate region command. |
10789 | 1854 (let ((char (car com)) (com (cdr com))) |
1855 (setq prefix-arg (cons value com)) | |
1856 (if (= char ?r) (vip-region prefix-arg) | |
1857 (vip-Region prefix-arg)) | |
1858 ;; reset prefix-arg | |
1859 (setq prefix-arg nil)) | |
1860 ;; otherwise, reset prefix arg and call appropriate command | |
1861 (setq value (if (null value) 1 value)) | |
1862 (setq prefix-arg nil) | |
1863 (cond ((equal com '(?c . ?c)) (vip-line (cons value ?C))) | |
1864 ((equal com '(?d . ?d)) (vip-line (cons value ?D))) | |
1865 ((equal com '(?d . ?y)) (vip-yank-defun)) | |
1866 ((equal com '(?y . ?y)) (vip-line (cons value ?Y))) | |
1867 ((equal com '(?< . ?<)) (vip-line (cons value ?<))) | |
1868 ((equal com '(?> . ?>)) (vip-line (cons value ?>))) | |
1869 ((equal com '(?! . ?!)) (vip-line (cons value ?!))) | |
1870 ((equal com '(?= . ?=)) (vip-line (cons value ?=))) | |
1871 (t (error "")))))) | |
1872 | |
1873 (defun vip-describe-arg (arg) | |
1874 (let (val com) | |
1875 (setq val (vip-P-val arg) | |
1876 com (vip-getcom arg)) | |
1877 (if (null val) | |
1878 (if (null com) | |
1879 (message "Value is nil, and command is nil") | |
1880 (message "Value is nil, and command is `%c'" com)) | |
1881 (if (null com) | |
1882 (message "Value is `%d', and command is nil" val) | |
1883 (message "Value is `%d', and command is `%c'" val com))))) | |
1884 | |
1885 (defun vip-digit-argument (arg) | |
1886 "Begin numeric argument for the next command." | |
1887 (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
|
1888 (vip-leave-region-active) |
10789 | 1889 (vip-prefix-arg-value last-command-char |
1890 (if (consp arg) (cdr arg) nil))) | |
1891 | |
1892 (defun vip-command-argument (arg) | |
1893 "Accept a motion command as an argument." | |
1894 (interactive "P") | |
1895 (condition-case nil | |
1896 (vip-prefix-arg-com | |
1897 last-command-char | |
1898 (cond ((null arg) nil) | |
1899 ((consp arg) (car arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1900 ((integerp arg) arg) |
10789 | 1901 (t (error vip-InvalidCommandArgument))) |
1902 (cond ((null arg) nil) | |
1903 ((consp arg) (cdr arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
1904 ((integerp arg) nil) |
10789 | 1905 (t (error vip-InvalidCommandArgument)))) |
1906 (quit (setq vip-use-register nil) | |
1907 (signal 'quit nil))) | |
1908 (vip-deactivate-mark)) | |
1909 | |
1910 | |
1911 ;; repeat last destructive command | |
1912 | |
1913 ;; Append region to text in register REG. | |
1914 ;; START and END are buffer positions indicating what to append. | |
1915 (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
|
1916 (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
|
1917 (get-register reg) "") |
10789 | 1918 (buffer-substring start end)))) |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1919 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1920 ;; 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
|
1921 (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
|
1922 (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
|
1923 (or (< (length vip-d-com) 5) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1924 (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
|
1925 (or (null vip-command-ring) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1926 (ring-empty-p vip-command-ring) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1927 (progn |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1928 (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
|
1929 vip-last-insertion) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1930 ;; 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
|
1931 (vip-cleanup-ring vip-command-ring))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1932 ) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1933 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1934 (defsubst vip-yank-last-insertion () |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1935 "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
|
1936 (condition-case nil |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1937 (insert vip-last-insertion) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1938 (error nil))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1939 |
10789 | 1940 |
1941 ;; define functions to be executed | |
1942 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
1943 ;; invoked by the `C' command |
10789 | 1944 (defun vip-exec-change (m-com com) |
1945 ;; handle C cmd at the eol and at eob. | |
1946 (if (or (and (eolp) (= vip-com-point (point))) | |
1947 (= vip-com-point (point-max))) | |
1948 (progn | |
1949 (insert " ")(backward-char 1))) | |
1950 (if (= vip-com-point (point)) | |
1951 (vip-forward-char-carefully)) | |
1952 (if (= com ?c) | |
1953 (vip-change vip-com-point (point)) | |
1954 (vip-change-subr vip-com-point (point)))) | |
1955 | |
1956 ;; this is invoked by vip-substitute-line | |
1957 (defun vip-exec-Change (m-com com) | |
1958 (save-excursion | |
1959 (set-mark vip-com-point) | |
1960 (vip-enlarge-region (mark t) (point)) | |
1961 (if vip-use-register | |
1962 (progn | |
1963 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
1964 ;;(vip-valid-register vip-use-register '(letter) | |
1965 (copy-to-register | |
1966 vip-use-register (mark t) (point) nil)) | |
1967 ((vip-valid-register vip-use-register '(Letter)) | |
1968 (vip-append-to-register | |
1969 (downcase vip-use-register) (mark t) (point))) | |
1970 (t (setq vip-use-register nil) | |
1971 (error vip-InvalidRegister vip-use-register))) | |
1972 (setq vip-use-register nil))) | |
1973 (delete-region (mark t) (point))) | |
1974 (open-line 1) | |
1975 (if (= com ?C) (vip-change-mode-to-insert) (vip-yank-last-insertion))) | |
1976 | |
1977 (defun vip-exec-delete (m-com com) | |
1978 (if vip-use-register | |
1979 (progn | |
1980 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
1981 ;;(vip-valid-register vip-use-register '(letter)) | |
1982 (copy-to-register | |
1983 vip-use-register vip-com-point (point) nil)) | |
1984 ((vip-valid-register vip-use-register '(Letter)) | |
1985 (vip-append-to-register | |
1986 (downcase vip-use-register) vip-com-point (point))) | |
1987 (t (setq vip-use-register nil) | |
1988 (error vip-InvalidRegister vip-use-register))) | |
1989 (setq vip-use-register nil))) | |
1990 (setq last-command | |
1991 (if (eq last-command 'd-command) 'kill-region nil)) | |
1992 (kill-region vip-com-point (point)) | |
1993 (setq this-command 'd-command) | |
1994 (if vip-ex-style-motion | |
1995 (if (and (eolp) (not (bolp))) (backward-char 1)))) | |
1996 | |
1997 (defun vip-exec-Delete (m-com com) | |
1998 (save-excursion | |
1999 (set-mark vip-com-point) | |
2000 (vip-enlarge-region (mark t) (point)) | |
2001 (if vip-use-register | |
2002 (progn | |
2003 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2004 ;;(vip-valid-register vip-use-register '(letter)) | |
2005 (copy-to-register | |
2006 vip-use-register (mark t) (point) nil)) | |
2007 ((vip-valid-register vip-use-register '(Letter)) | |
2008 (vip-append-to-register | |
2009 (downcase vip-use-register) (mark t) (point))) | |
2010 (t (setq vip-use-register nil) | |
2011 (error vip-InvalidRegister vip-use-register))) | |
2012 (setq vip-use-register nil))) | |
2013 (setq last-command | |
2014 (if (eq last-command 'D-command) 'kill-region nil)) | |
2015 (kill-region (mark t) (point)) | |
2016 (if (eq m-com 'vip-line) (setq this-command 'D-command))) | |
2017 (back-to-indentation)) | |
2018 | |
2019 (defun vip-exec-yank (m-com com) | |
2020 (if vip-use-register | |
2021 (progn | |
2022 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2023 ;; (vip-valid-register vip-use-register '(letter)) | |
2024 (copy-to-register | |
2025 vip-use-register vip-com-point (point) nil)) | |
2026 ((vip-valid-register vip-use-register '(Letter)) | |
2027 (vip-append-to-register | |
2028 (downcase vip-use-register) vip-com-point (point))) | |
2029 (t (setq vip-use-register nil) | |
2030 (error vip-InvalidRegister vip-use-register))) | |
2031 (setq vip-use-register nil))) | |
2032 (setq last-command nil) | |
2033 (copy-region-as-kill vip-com-point (point)) | |
2034 (goto-char vip-com-point)) | |
2035 | |
2036 (defun vip-exec-Yank (m-com com) | |
2037 (save-excursion | |
2038 (set-mark vip-com-point) | |
2039 (vip-enlarge-region (mark t) (point)) | |
2040 (if vip-use-register | |
2041 (progn | |
2042 (cond ((vip-valid-register vip-use-register '(letter digit)) | |
2043 (copy-to-register | |
2044 vip-use-register (mark t) (point) nil)) | |
2045 ((vip-valid-register vip-use-register '(Letter)) | |
2046 (vip-append-to-register | |
2047 (downcase vip-use-register) (mark t) (point))) | |
2048 (t (setq vip-use-register nil) | |
2049 (error vip-InvalidRegister vip-use-register))) | |
2050 (setq vip-use-register nil))) | |
2051 (setq last-command nil) | |
2052 (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
|
2053 (vip-deactivate-mark) |
10789 | 2054 (goto-char vip-com-point)) |
2055 | |
2056 (defun vip-exec-bang (m-com com) | |
2057 (save-excursion | |
2058 (set-mark vip-com-point) | |
2059 (vip-enlarge-region (mark t) (point)) | |
2060 (shell-command-on-region | |
2061 (mark t) (point) | |
2062 (if (= com ?!) | |
2063 (setq vip-last-shell-com | |
2064 (vip-read-string-with-history | |
2065 "!" | |
2066 nil | |
2067 'vip-shell-history | |
2068 (car vip-shell-history) | |
2069 )) | |
2070 vip-last-shell-com) | |
2071 t))) | |
2072 | |
2073 (defun vip-exec-equals (m-com com) | |
2074 (save-excursion | |
2075 (set-mark vip-com-point) | |
2076 (vip-enlarge-region (mark t) (point)) | |
2077 (if (> (mark t) (point)) (exchange-point-and-mark)) | |
2078 (indent-region (mark t) (point) nil))) | |
2079 | |
2080 (defun vip-exec-shift (m-com com) | |
2081 (save-excursion | |
2082 (set-mark vip-com-point) | |
2083 (vip-enlarge-region (mark t) (point)) | |
2084 (if (> (mark t) (point)) (exchange-point-and-mark)) | |
2085 (indent-rigidly (mark t) (point) | |
2086 (if (= com ?>) | |
2087 vip-shift-width | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2088 (- vip-shift-width)))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2089 ;; 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
|
2090 (goto-char vip-com-point)) |
10789 | 2091 |
2092 ;; this is needed because some commands fake com by setting it to ?r, which | |
2093 ;; denotes repeated insert command. | |
2094 (defsubst vip-exec-dummy (m-com com) | |
2095 nil) | |
2096 | |
2097 (defun vip-exec-buffer-search (m-com com) | |
2098 (setq vip-s-string (buffer-substring (point) vip-com-point)) | |
2099 (setq vip-s-forward t) | |
2100 (setq vip-search-history (cons vip-s-string vip-search-history)) | |
2101 (vip-search vip-s-string vip-s-forward 1)) | |
2102 | |
2103 (defvar vip-exec-array (make-vector 128 nil)) | |
2104 | |
2105 ;; Using a dispatch array allows adding functions like buffer search | |
2106 ;; without affecting other functions. Buffer search can now be bound | |
2107 ;; to any character. | |
2108 | |
2109 (aset vip-exec-array ?c 'vip-exec-change) | |
2110 (aset vip-exec-array ?C 'vip-exec-Change) | |
2111 (aset vip-exec-array ?d 'vip-exec-delete) | |
2112 (aset vip-exec-array ?D 'vip-exec-Delete) | |
2113 (aset vip-exec-array ?y 'vip-exec-yank) | |
2114 (aset vip-exec-array ?Y 'vip-exec-Yank) | |
2115 (aset vip-exec-array ?r 'vip-exec-dummy) | |
2116 (aset vip-exec-array ?! 'vip-exec-bang) | |
2117 (aset vip-exec-array ?< 'vip-exec-shift) | |
2118 (aset vip-exec-array ?> 'vip-exec-shift) | |
2119 (aset vip-exec-array ?= 'vip-exec-equals) | |
2120 | |
2121 | |
2122 | |
2123 ;; This function is called by various movement commands to execute a | |
2124 ;; destructive command on the region specified by the movement command. For | |
2125 ;; instance, if the user types cw, then the command vip-forward-word will | |
2126 ;; call vip-execute-com to execute vip-exec-change, which eventually will | |
2127 ;; call vip-change to invoke the replace mode on the region. | |
2128 ;; | |
2129 ;; The list (M-COM VAL COM REG INSETED-TEXT COMMAND-KEYS) is set to | |
2130 ;; vip-d-com for later use by vip-repeat. | |
2131 (defun vip-execute-com (m-com val com) | |
2132 (let ((reg vip-use-register)) | |
2133 ;; this is the special command `#' | |
2134 (if (> com 128) | |
2135 (vip-special-prefix-com (- com 128)) | |
2136 (let ((fn (aref vip-exec-array (if (< com 0) (- com) com)))) | |
2137 (if (null fn) | |
2138 (error "%c: %s" com vip-InvalidViCommand) | |
2139 (funcall fn m-com com)))) | |
2140 (if (vip-dotable-command-p com) | |
2141 (vip-set-destructive-command | |
2142 (list m-com val | |
2143 (if (memq com (list ?c ?C ?!)) (- com) com) | |
2144 reg nil nil))) | |
2145 )) | |
2146 | |
2147 | |
2148 (defun vip-repeat (arg) | |
2149 "Re-execute last destructive command. | |
2150 Use the info in vip-d-com, which has the form | |
2151 \(com val ch reg inserted-text command-keys\), | |
2152 where `com' is the command to be re-executed, `val' is the | |
2153 argument to `com', `ch' is a flag for repeat, and `reg' is optional; | |
2154 if it exists, it is the name of the register for `com'. | |
2155 If the prefix argument, ARG, is non-nil, it is used instead of `val'." | |
2156 (interactive "P") | |
2157 (let ((save-point (point)) ; save point before repeating prev cmd | |
2158 ;; Pass along that we are repeating a destructive command | |
2159 ;; This tells vip-set-destructive-command not to update | |
2160 ;; vip-command-ring | |
2161 (vip-intermediate-command 'vip-repeat)) | |
2162 (if (eq last-command 'vip-undo) | |
2163 ;; if the last command was vip-undo, then undo-more | |
2164 (vip-undo-more) | |
2165 ;; otherwise execute the command stored in vip-d-com. if arg is non-nil | |
2166 ;; its prefix value is used as new prefix value for the command. | |
2167 (let ((m-com (car vip-d-com)) | |
2168 (val (vip-P-val arg)) | |
2169 (com (nth 2 vip-d-com)) | |
2170 (reg (nth 3 vip-d-com))) | |
2171 (if (null val) (setq val (nth 1 vip-d-com))) | |
2172 (if (null m-com) (error "No previous command to repeat.")) | |
2173 (setq vip-use-register reg) | |
2174 (if (nth 4 vip-d-com) ; text inserted by command | |
2175 (setq vip-last-insertion (nth 4 vip-d-com) | |
2176 vip-d-char (nth 4 vip-d-com))) | |
2177 (funcall m-com (cons val com)) | |
2178 (if (and vip-keep-point-on-repeat (< save-point (point))) | |
2179 (goto-char save-point)) ; go back to before repeat. | |
2180 (if (and (eolp) (not (bolp))) | |
2181 (backward-char 1)) | |
2182 )) | |
2183 (if vip-undo-needs-adjustment (vip-adjust-undo)) ; take care of undo | |
2184 ;; If the prev cmd was rotating the command ring, this means that `.' has | |
2185 ;; just executed a command from that ring. So, push it on the ring again. | |
2186 ;; If we are just executing previous command , then don't push vip-d-com | |
2187 ;; because vip-d-com is not fully constructed in this case (its keys and | |
2188 ;; the inserted text may be nil). Besides, in this case, the command | |
2189 ;; executed by `.' is already on the ring. | |
2190 (if (eq last-command 'vip-display-current-destructive-command) | |
2191 (vip-push-onto-ring vip-d-com 'vip-command-ring)) | |
2192 (vip-deactivate-mark) | |
2193 )) | |
2194 | |
2195 (defun vip-repeat-from-history () | |
2196 "Repeat a destructive command from history. | |
2197 Doesn't change vip-command-ring in any way, so `.' will work as before | |
2198 executing this command. | |
2199 This command is supposed to be bound to a two-character Vi macro where | |
2200 the second character is a digit 0 to 9. The digit indicates which | |
2201 history command to execute. `<char>0' is equivalent to `.', `<char>1' | |
2202 invokes the command before that, etc." | |
2203 (interactive) | |
2204 (let* ((vip-intermediate-command 'repeating-display-destructive-command) | |
2205 (idx (cond (vip-this-kbd-macro | |
2206 (string-to-number | |
2207 (symbol-name (elt vip-this-kbd-macro 1)))) | |
2208 (t 0))) | |
2209 (num idx) | |
2210 (vip-d-com vip-d-com)) | |
2211 | |
2212 (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
|
2213 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2214 (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
|
2215 num 0) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2216 (message |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2217 "`vip-repeat-from-history' must be invoked as a Vi macro bound to `<key><digit>'"))) |
10789 | 2218 (while (< 0 num) |
2219 (setq vip-d-com (vip-special-ring-rotate1 vip-command-ring -1)) | |
2220 (setq num (1- num))) | |
2221 (vip-repeat nil) | |
2222 (while (> idx num) | |
2223 (vip-special-ring-rotate1 vip-command-ring 1) | |
2224 (setq num (1+ num))) | |
2225 )) | |
2226 | |
2227 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2228 ;; This command is invoked interactively by the key sequence #<char> |
10789 | 2229 (defun vip-special-prefix-com (char) |
2230 (cond ((= char ?c) | |
2231 (downcase-region (min vip-com-point (point)) | |
2232 (max vip-com-point (point)))) | |
2233 ((= char ?C) | |
2234 (upcase-region (min vip-com-point (point)) | |
2235 (max vip-com-point (point)))) | |
2236 ((= char ?g) | |
2237 (push-mark vip-com-point t) | |
2238 (vip-global-execute)) | |
2239 ((= char ?q) | |
2240 (push-mark vip-com-point t) | |
2241 (vip-quote-region)) | |
2242 ((= char ?s) (funcall vip-spell-function vip-com-point (point))) | |
2243 (t (error "#%c: %s" char vip-InvalidViCommand)))) | |
2244 | |
2245 | |
2246 ;; undoing | |
2247 | |
2248 (defun vip-undo () | |
2249 "Undo previous change." | |
2250 (interactive) | |
2251 (message "undo!") | |
2252 (let ((modified (buffer-modified-p)) | |
2253 (before-undo-pt (point-marker)) | |
2254 (after-change-functions after-change-functions) | |
2255 undo-beg-posn undo-end-posn) | |
2256 | |
2257 ;; no need to remove this hook, since this var has scope inside a let. | |
2258 (add-hook 'after-change-functions | |
2259 '(lambda (beg end len) | |
2260 (setq undo-beg-posn beg | |
2261 undo-end-posn (or end beg)))) | |
2262 | |
2263 (undo-start) | |
2264 (undo-more 2) | |
2265 (setq undo-beg-posn (or undo-beg-posn before-undo-pt) | |
2266 undo-end-posn (or undo-end-posn undo-beg-posn)) | |
2267 | |
2268 (goto-char undo-beg-posn) | |
2269 (sit-for 0) | |
2270 (if (and vip-keep-point-on-undo | |
2271 (pos-visible-in-window-p before-undo-pt)) | |
2272 (progn | |
2273 (push-mark (point-marker) t) | |
2274 (vip-sit-for-short 300) | |
2275 (goto-char undo-end-posn) | |
2276 (vip-sit-for-short 300) | |
2277 (if (and (> (abs (- undo-beg-posn before-undo-pt)) 1) | |
2278 (> (abs (- undo-end-posn before-undo-pt)) 1)) | |
2279 (goto-char before-undo-pt) | |
2280 (goto-char undo-beg-posn))) | |
2281 (push-mark before-undo-pt t)) | |
2282 (if (and (eolp) (not (bolp))) (backward-char 1)) | |
2283 (if (not modified) (set-buffer-modified-p t))) | |
2284 (setq this-command 'vip-undo)) | |
2285 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2286 ;; Continue undoing previous changes. |
10789 | 2287 (defun vip-undo-more () |
2288 (message "undo more!") | |
2289 (condition-case nil | |
2290 (undo-more 1) | |
2291 (error (beep) | |
2292 (message "No further undo information in this buffer"))) | |
2293 (if (and (eolp) (not (bolp))) (backward-char 1)) | |
2294 (setq this-command 'vip-undo)) | |
2295 | |
2296 ;; The following two functions are used to set up undo properly. | |
2297 ;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, | |
2298 ;; they are undone all at once. | |
2299 (defun vip-adjust-undo () | |
2300 (let ((inhibit-quit t) | |
2301 tmp tmp2) | |
2302 (setq vip-undo-needs-adjustment nil) | |
2303 (if (listp buffer-undo-list) | |
2304 (if (setq tmp (memq vip-buffer-undo-list-mark buffer-undo-list)) | |
2305 (progn | |
2306 (setq tmp2 (cdr tmp)) ; the part after mark | |
2307 | |
2308 ;; cut tail from buffer-undo-list temporarily by direct | |
2309 ;; manipulation with pointers in buffer-undo-list | |
2310 (setcdr tmp nil) | |
2311 | |
2312 (setq buffer-undo-list (delq nil buffer-undo-list)) | |
2313 (setq buffer-undo-list | |
2314 (delq vip-buffer-undo-list-mark buffer-undo-list)) | |
2315 ;; restore tail of buffer-undo-list | |
2316 (setq buffer-undo-list (nconc buffer-undo-list tmp2))) | |
2317 (setq buffer-undo-list (delq nil buffer-undo-list)))))) | |
2318 | |
2319 | |
2320 (defun vip-set-complex-command-for-undo () | |
2321 (if (listp buffer-undo-list) | |
2322 (if (not vip-undo-needs-adjustment) | |
2323 (let ((inhibit-quit t)) | |
2324 (setq buffer-undo-list | |
2325 (cons vip-buffer-undo-list-mark buffer-undo-list)) | |
2326 (setq vip-undo-needs-adjustment t))))) | |
2327 | |
2328 | |
2329 | |
2330 | |
2331 (defun vip-display-current-destructive-command () | |
2332 (let ((text (nth 4 vip-d-com)) | |
2333 (keys (nth 5 vip-d-com)) | |
2334 (max-text-len 30)) | |
2335 | |
2336 (setq this-command 'vip-display-current-destructive-command) | |
2337 | |
2338 (message " `.' runs %s%s" | |
2339 (concat "`" (vip-array-to-string keys) "'") | |
2340 (vip-abbreviate-string text max-text-len | |
2341 " inserting `" "'" " .......")) | |
2342 )) | |
2343 | |
2344 | |
2345 ;; don't change vip-d-com if it was vip-repeat command invoked with `.' | |
2346 ;; or in some other way (non-interactively). | |
2347 (defun vip-set-destructive-command (list) | |
2348 (or (eq vip-intermediate-command 'vip-repeat) | |
2349 (progn | |
2350 (setq vip-d-com list) | |
2351 (setcar (nthcdr 5 vip-d-com) | |
2352 (vip-array-to-string (this-command-keys))) | |
2353 (vip-push-onto-ring vip-d-com 'vip-command-ring)))) | |
2354 | |
2355 (defun vip-prev-destructive-command (next) | |
2356 "Find previous destructive command in the history of destructive commands. | |
2357 With prefix argument, find next destructive command." | |
2358 (interactive "P") | |
2359 (let (cmd vip-intermediate-command) | |
2360 (if (eq last-command 'vip-display-current-destructive-command) | |
2361 ;; repeated search through command history | |
2362 (setq vip-intermediate-command 'repeating-display-destructive-command) | |
2363 ;; first search through command history--set temp ring | |
2364 (setq vip-temp-command-ring (copy-list vip-command-ring))) | |
2365 (setq cmd (if next | |
2366 (vip-special-ring-rotate1 vip-temp-command-ring 1) | |
2367 (vip-special-ring-rotate1 vip-temp-command-ring -1))) | |
2368 (if (null cmd) | |
2369 () | |
2370 (setq vip-d-com cmd)) | |
2371 (vip-display-current-destructive-command))) | |
2372 | |
2373 (defun vip-next-destructive-command () | |
2374 "Find next destructive command in the history of destructive commands." | |
2375 (interactive) | |
2376 (vip-prev-destructive-command 'next)) | |
2377 | |
2378 (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
|
2379 "Cycle through insertion ring in the direction of older insertions. |
10789 | 2380 Undoes previous insertion and inserts new. |
2381 With prefix argument, cycles in the direction of newer elements. | |
2382 In minibuffer, this command executes whatever the invocation key is bound | |
2383 to in the global map, instead of cycling through the insertion ring." | |
2384 (interactive "P") | |
2385 (let (vip-intermediate-command) | |
2386 (if (eq last-command 'vip-insert-from-insertion-ring) | |
2387 (progn ; repeated search through insertion history | |
2388 (setq vip-intermediate-command 'repeating-insertion-from-ring) | |
2389 (if (eq vip-current-state 'replace-state) | |
2390 (undo 1) | |
2391 (if vip-last-inserted-string-from-insertion-ring | |
2392 (backward-delete-char | |
2393 (length vip-last-inserted-string-from-insertion-ring)))) | |
2394 ) | |
2395 ;;first search through insertion history | |
2396 (setq vip-temp-insertion-ring (copy-list vip-insertion-ring))) | |
2397 (setq this-command 'vip-insert-from-insertion-ring) | |
2398 ;; so that things will be undone properly | |
2399 (setq buffer-undo-list (cons nil buffer-undo-list)) | |
2400 (setq vip-last-inserted-string-from-insertion-ring | |
2401 (vip-special-ring-rotate1 vip-temp-insertion-ring (if arg 1 -1))) | |
2402 | |
2403 ;; this change of vip-intermediate-command must come after | |
2404 ;; vip-special-ring-rotate1, so that the ring will rotate, but before the | |
2405 ;; insertion. | |
2406 (setq vip-intermediate-command nil) | |
2407 (if vip-last-inserted-string-from-insertion-ring | |
2408 (insert vip-last-inserted-string-from-insertion-ring)) | |
2409 )) | |
2410 | |
2411 (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
|
2412 "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
|
2413 Undo previous insertion and inserts new." |
10789 | 2414 (interactive) |
2415 (vip-insert-prev-from-insertion-ring 'next)) | |
2416 | |
2417 | |
2418 ;; some region utilities | |
2419 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2420 ;; If at the last line of buffer, add \\n before eob, if newline is missing. |
10789 | 2421 (defun vip-add-newline-at-eob-if-necessary () |
2422 (save-excursion | |
2423 (end-of-line) | |
2424 ;; 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
|
2425 ;; when requested otherwise (require-final-newline is nil) |
14909
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2426 (if (and (eobp) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2427 (not (bolp)) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2428 require-final-newline |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2429 (not (vip-is-in-minibuffer)) |
7ff1df13b124
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14734
diff
changeset
|
2430 (not buffer-read-only)) |
10789 | 2431 (insert "\n")))) |
2432 | |
2433 (defun vip-yank-defun () | |
2434 (mark-defun) | |
2435 (copy-region-as-kill (point) (mark t))) | |
2436 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2437 ;; Enlarge region between BEG and END. |
10789 | 2438 (defun vip-enlarge-region (beg end) |
2439 (or beg (setq beg end)) ; if beg is nil, set to end | |
2440 (or end (setq end beg)) ; if end is nil, set to beg | |
2441 | |
2442 (if (< beg end) | |
2443 (progn (goto-char beg) (set-mark end)) | |
2444 (goto-char end) | |
2445 (set-mark beg)) | |
2446 (beginning-of-line) | |
2447 (exchange-point-and-mark) | |
2448 (if (or (not (eobp)) (not (bolp))) (forward-line 1)) | |
2449 (if (not (eobp)) (beginning-of-line)) | |
2450 (if (> beg end) (exchange-point-and-mark))) | |
2451 | |
2452 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2453 ;; Quote region by each line with a user supplied string. |
10789 | 2454 (defun vip-quote-region () |
2455 (setq vip-quote-string | |
2456 (vip-read-string-with-history | |
2457 "Quote string: " | |
2458 nil | |
2459 'vip-quote-region-history | |
2460 vip-quote-string)) | |
2461 (vip-enlarge-region (point) (mark t)) | |
2462 (if (> (point) (mark t)) (exchange-point-and-mark)) | |
2463 (insert vip-quote-string) | |
2464 (beginning-of-line) | |
2465 (forward-line 1) | |
2466 (while (and (< (point) (mark t)) (bolp)) | |
2467 (insert vip-quote-string) | |
2468 (beginning-of-line) | |
2469 (forward-line 1))) | |
2470 | |
2471 ;; Tells whether BEG is on the same line as END. | |
2472 ;; If one of the args is nil, it'll return nil. | |
2473 (defun vip-same-line (beg end) | |
2474 (let ((selective-display nil)) | |
2475 (cond ((and beg end) | |
2476 ;; This 'if' is needed because Emacs treats the next empty line | |
2477 ;; as part of the previous line. | |
2478 (if (or (> beg (point-max)) (> end (point-max))) ; out of range | |
2479 () | |
2480 (if (and (> end beg) (= (vip-line-pos 'start) end)) | |
2481 (setq end (min (1+ end) (point-max)))) | |
2482 (if (and (> beg end) (= (vip-line-pos 'start) beg)) | |
2483 (setq beg (min (1+ beg) (point-max)))) | |
2484 (<= (count-lines beg end) 1) )) | |
2485 | |
2486 (t nil)) | |
2487 )) | |
2488 | |
2489 | |
2490 ;; Check if the string ends with a newline. | |
2491 (defun vip-end-with-a-newline-p (string) | |
2492 (or (string= string "") | |
2493 (= (vip-seq-last-elt string) ?\n))) | |
2494 | |
2495 (defun vip-tmp-insert-at-eob (msg) | |
2496 (let ((savemax (point-max))) | |
2497 (goto-char savemax) | |
2498 (insert msg) | |
2499 (sit-for 2) | |
2500 (goto-char savemax) (delete-region (point) (point-max)) | |
2501 )) | |
2502 | |
2503 | |
2504 | |
2505 ;;; Minibuffer business | |
2506 | |
2507 (defsubst vip-set-minibuffer-style () | |
2508 (add-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel)) | |
2509 | |
2510 | |
2511 (defun vip-minibuffer-setup-sentinel () | |
2512 (let ((hook (if vip-vi-style-in-minibuffer | |
2513 'vip-change-state-to-insert | |
2514 'vip-change-state-to-emacs))) | |
2515 (funcall hook) | |
2516 )) | |
2517 | |
2518 ;; Interpret last event in the local map | |
2519 (defun vip-exit-minibuffer () | |
2520 (interactive) | |
2521 (let (command) | |
2522 (setq command (local-key-binding (char-to-string last-command-char))) | |
2523 (if command | |
2524 (command-execute command) | |
2525 (exit-minibuffer)))) | |
2526 | |
2527 | |
2528 (defun vip-set-search-face () | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2529 (if (vip-has-face-support-p) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2530 (defvar vip-search-face |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2531 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2532 (make-face 'vip-search-face) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2533 (vip-hide-face 'vip-search-face) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2534 (or (face-differs-from-default-p 'vip-search-face) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2535 ;; face wasn't set in .vip or .Xdefaults |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2536 (if (vip-can-use-colors "Black" "khaki") |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2537 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2538 (set-face-background 'vip-search-face "khaki") |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2539 (set-face-foreground 'vip-search-face "Black")) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2540 (copy-face 'italic 'vip-search-face) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2541 (set-face-underline-p 'vip-search-face t))) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2542 'vip-search-face) |
10789 | 2543 "*Face used to flash out the search pattern.") |
2544 )) | |
2545 | |
2546 | |
2547 (defun vip-set-minibuffer-faces () | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2548 (if (not (vip-has-face-support-p)) |
10789 | 2549 () |
2550 (defvar vip-minibuffer-emacs-face | |
2551 (progn | |
2552 (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
|
2553 (vip-hide-face 'vip-minibuffer-emacs-face) |
10789 | 2554 (or (face-differs-from-default-p 'vip-minibuffer-emacs-face) |
2555 ;; face wasn't set in .vip or .Xdefaults | |
2556 (if vip-vi-style-in-minibuffer | |
2557 ;; emacs state is an exception in the minibuffer | |
2558 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2559 (progn | |
2560 (set-face-background | |
2561 'vip-minibuffer-emacs-face "darkseagreen2") | |
2562 (set-face-foreground | |
2563 'vip-minibuffer-emacs-face "Black")) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2564 (copy-face 'modeline 'vip-minibuffer-emacs-face)) |
10789 | 2565 ;; emacs state is the main state in the minibuffer |
2566 (if (vip-can-use-colors "Black" "pink") | |
2567 (progn | |
2568 (set-face-background 'vip-minibuffer-emacs-face "pink") | |
2569 (set-face-foreground | |
2570 'vip-minibuffer-emacs-face "Black")) | |
2571 (copy-face 'italic 'vip-minibuffer-emacs-face)) | |
2572 )) | |
2573 'vip-minibuffer-emacs-face) | |
2574 "Face used in the Minibuffer when it is in Emacs state.") | |
2575 | |
2576 (defvar vip-minibuffer-insert-face | |
2577 (progn | |
2578 (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
|
2579 (vip-hide-face 'vip-minibuffer-insert-face) |
10789 | 2580 (or (face-differs-from-default-p 'vip-minibuffer-insert-face) |
2581 (if vip-vi-style-in-minibuffer | |
2582 (if (vip-can-use-colors "Black" "pink") | |
2583 (progn | |
2584 (set-face-background 'vip-minibuffer-insert-face "pink") | |
2585 (set-face-foreground | |
2586 'vip-minibuffer-insert-face "Black")) | |
2587 (copy-face 'italic 'vip-minibuffer-insert-face)) | |
2588 ;; If Insert state is an exception | |
2589 (if (vip-can-use-colors "darkseagreen2" "Black") | |
2590 (progn | |
2591 (set-face-background | |
2592 'vip-minibuffer-insert-face "darkseagreen2") | |
2593 (set-face-foreground | |
2594 'vip-minibuffer-insert-face "Black")) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
2595 (copy-face 'modeline 'vip-minibuffer-insert-face)) |
10789 | 2596 (vip-italicize-face 'vip-minibuffer-insert-face))) |
2597 'vip-minibuffer-insert-face) | |
2598 "Face used in the Minibuffer when it is in Insert state.") | |
2599 | |
2600 (defvar vip-minibuffer-vi-face | |
2601 (progn | |
2602 (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
|
2603 (vip-hide-face 'vip-minibuffer-vi-face) |
10789 | 2604 (or (face-differs-from-default-p 'vip-minibuffer-vi-face) |
2605 (if vip-vi-style-in-minibuffer | |
2606 (if (vip-can-use-colors "Black" "grey") | |
2607 (progn | |
2608 (set-face-background 'vip-minibuffer-vi-face "grey") | |
2609 (set-face-foreground 'vip-minibuffer-vi-face "Black")) | |
2610 (copy-face 'bold 'vip-minibuffer-vi-face)) | |
2611 (copy-face 'bold 'vip-minibuffer-vi-face) | |
2612 (invert-face 'vip-minibuffer-vi-face))) | |
2613 'vip-minibuffer-vi-face) | |
2614 "Face used in the Minibuffer when it is in Vi state.") | |
2615 | |
2616 ;; the current face used in the minibuffer | |
2617 (vip-deflocalvar vip-minibuffer-current-face vip-minibuffer-emacs-face "") | |
2618 )) | |
2619 | |
2620 | |
2621 | |
2622 ;;; Reading string with history | |
2623 | |
2624 (defun vip-read-string-with-history (prompt &optional initial | |
2625 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
|
2626 ;; Read string, prompting with PROMPT and inserting the INITIAL |
10789 | 2627 ;; 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
|
2628 ;; input is an empty string. Use KEYMAP, if given, or the |
10789 | 2629 ;; minibuffer-local-map. |
2630 ;; Default value is displayed until the user types something in the | |
2631 ;; minibuffer. | |
2632 (let ((minibuffer-setup-hook | |
2633 '(lambda () | |
2634 (if (stringp initial) | |
2635 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
2636 ;; 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
|
2637 (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
|
2638 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
|
2639 (sit-for 840)) |
10789 | 2640 (erase-buffer) |
2641 (insert initial))) | |
2642 (vip-minibuffer-setup-sentinel))) | |
2643 (val "") | |
2644 (padding "") | |
2645 temp-msg) | |
2646 | |
2647 (setq keymap (or keymap minibuffer-local-map) | |
2648 initial (or initial "") | |
2649 temp-msg (if default | |
2650 (format "(default: %s) " default) | |
2651 "")) | |
2652 | |
2653 (setq vip-incomplete-ex-cmd nil) | |
2654 (setq val (read-from-minibuffer prompt | |
2655 (concat temp-msg initial val padding) | |
2656 keymap nil history-var)) | |
2657 (setq minibuffer-setup-hook nil | |
2658 padding (vip-array-to-string (this-command-keys)) | |
2659 temp-msg "") | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2660 ;; the following tries to be smart about what to put in history |
10789 | 2661 (if (not (string= val (car (eval history-var)))) |
2662 (set history-var (cons val (eval history-var)))) | |
2663 (if (or (string= (nth 0 (eval history-var)) (nth 1 (eval history-var))) | |
2664 (string= (nth 0 (eval history-var)) "")) | |
2665 (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
|
2666 ;; 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
|
2667 ;; 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
|
2668 ;; 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
|
2669 ;; 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
|
2670 (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
|
2671 (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
|
2672 (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
|
2673 '(vip-ex |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2674 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
|
2675 t) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2676 ))) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2677 "") |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2678 ((string= val "") (or default "")) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2679 (t val)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2680 )) |
10789 | 2681 |
2682 | |
2683 | |
2684 ;; insertion commands | |
2685 | |
2686 ;; Called when state changes from Insert Vi command mode. | |
2687 ;; Repeats the insertion command if Insert state was entered with prefix | |
2688 ;; argument > 1. | |
2689 (defun vip-repeat-insert-command () | |
2690 (let ((i-com (car vip-d-com)) | |
2691 (val (nth 1 vip-d-com)) | |
2692 (char (nth 2 vip-d-com))) | |
2693 (if (and val (> val 1)) ; first check that val is non-nil | |
2694 (progn | |
2695 (setq vip-d-com (list i-com (1- val) ?r nil nil nil)) | |
2696 (vip-repeat nil) | |
2697 (setq vip-d-com (list i-com val char nil nil nil)) | |
2698 )))) | |
2699 | |
2700 (defun vip-insert (arg) | |
2701 "Insert before point." | |
2702 (interactive "P") | |
2703 (vip-set-complex-command-for-undo) | |
2704 (let ((val (vip-p-val arg)) | |
2705 (com (vip-getcom arg))) | |
2706 (vip-set-destructive-command (list 'vip-insert val ?r nil nil nil)) | |
2707 (if com | |
2708 (vip-loop val (vip-yank-last-insertion)) | |
2709 (vip-change-state-to-insert)))) | |
2710 | |
2711 (defun vip-append (arg) | |
2712 "Append after point." | |
2713 (interactive "P") | |
2714 (vip-set-complex-command-for-undo) | |
2715 (let ((val (vip-p-val arg)) | |
2716 (com (vip-getcom arg))) | |
2717 (vip-set-destructive-command (list 'vip-append val ?r nil nil nil)) | |
2718 (if (not (eolp)) (forward-char)) | |
2719 (if (equal com ?r) | |
2720 (vip-loop val (vip-yank-last-insertion)) | |
2721 (vip-change-state-to-insert)))) | |
2722 | |
2723 (defun vip-Append (arg) | |
2724 "Append at end of line." | |
2725 (interactive "P") | |
2726 (vip-set-complex-command-for-undo) | |
2727 (let ((val (vip-p-val arg)) | |
2728 (com (vip-getcom arg))) | |
2729 (vip-set-destructive-command (list 'vip-Append val ?r nil nil nil)) | |
2730 (end-of-line) | |
2731 (if (equal com ?r) | |
2732 (vip-loop val (vip-yank-last-insertion)) | |
2733 (vip-change-state-to-insert)))) | |
2734 | |
2735 (defun vip-Insert (arg) | |
2736 "Insert before first non-white." | |
2737 (interactive "P") | |
2738 (vip-set-complex-command-for-undo) | |
2739 (let ((val (vip-p-val arg)) | |
2740 (com (vip-getcom arg))) | |
2741 (vip-set-destructive-command (list 'vip-Insert val ?r nil nil nil)) | |
2742 (back-to-indentation) | |
2743 (if (equal com ?r) | |
2744 (vip-loop val (vip-yank-last-insertion)) | |
2745 (vip-change-state-to-insert)))) | |
2746 | |
2747 (defun vip-open-line (arg) | |
2748 "Open line below." | |
2749 (interactive "P") | |
2750 (vip-set-complex-command-for-undo) | |
2751 (let ((val (vip-p-val arg)) | |
2752 (com (vip-getcom arg))) | |
2753 (vip-set-destructive-command (list 'vip-open-line val ?r nil nil nil)) | |
2754 (let ((col (current-indentation))) | |
2755 (if (equal com ?r) | |
2756 (vip-loop val | |
2757 (progn | |
2758 (end-of-line) | |
2759 (newline 1) | |
2760 (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
|
2761 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2762 (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
|
2763 (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
|
2764 (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
|
2765 (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
|
2766 )) |
10789 | 2767 (vip-yank-last-insertion))) |
2768 (end-of-line) | |
2769 (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
|
2770 (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
|
2771 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2772 (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
|
2773 (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
|
2774 (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
|
2775 (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
|
2776 )) |
10789 | 2777 (vip-change-state-to-insert) |
2778 )))) | |
2779 | |
2780 (defun vip-Open-line (arg) | |
2781 "Open line above." | |
2782 (interactive "P") | |
2783 (vip-set-complex-command-for-undo) | |
2784 (let ((val (vip-p-val arg)) | |
2785 (com (vip-getcom arg))) | |
2786 (vip-set-destructive-command (list 'vip-Open-line val ?r nil nil nil)) | |
2787 (let ((col (current-indentation))) | |
2788 (if (equal com ?r) | |
2789 (vip-loop val | |
2790 (progn | |
2791 (beginning-of-line) | |
2792 (open-line 1) | |
2793 (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
|
2794 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2795 (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
|
2796 (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
|
2797 (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
|
2798 (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
|
2799 )) |
10789 | 2800 (vip-yank-last-insertion))) |
2801 (beginning-of-line) | |
2802 (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
|
2803 (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
|
2804 (progn |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2805 (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
|
2806 (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
|
2807 (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
|
2808 (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
|
2809 )) |
10789 | 2810 (vip-change-state-to-insert))))) |
2811 | |
2812 (defun vip-open-line-at-point (arg) | |
2813 "Open line at point." | |
2814 (interactive "P") | |
2815 (vip-set-complex-command-for-undo) | |
2816 (let ((val (vip-p-val arg)) | |
2817 (com (vip-getcom arg))) | |
2818 (vip-set-destructive-command | |
2819 (list 'vip-open-line-at-point val ?r nil nil nil)) | |
2820 (if (equal com ?r) | |
2821 (vip-loop val | |
2822 (progn | |
2823 (open-line 1) | |
2824 (vip-yank-last-insertion))) | |
2825 (open-line 1) | |
2826 (vip-change-state-to-insert)))) | |
2827 | |
2828 (defun vip-substitute (arg) | |
2829 "Substitute characters." | |
2830 (interactive "P") | |
2831 (let ((val (vip-p-val arg)) | |
2832 (com (vip-getcom arg))) | |
2833 (push-mark nil t) | |
2834 (forward-char val) | |
2835 (if (equal com ?r) | |
2836 (vip-change-subr (mark t) (point)) | |
2837 (vip-change (mark t) (point))) | |
2838 (vip-set-destructive-command (list 'vip-substitute val ?r nil nil nil)) | |
2839 )) | |
2840 | |
2841 (defun vip-substitute-line (arg) | |
2842 "Substitute lines." | |
2843 (interactive "p") | |
2844 (vip-set-complex-command-for-undo) | |
2845 (vip-line (cons arg ?C))) | |
2846 | |
2847 ;; Prepare for replace | |
2848 (defun vip-start-replace () | |
2849 (setq vip-began-as-replace t | |
2850 vip-sitting-in-replace t | |
2851 vip-replace-chars-to-delete 0 | |
2852 vip-replace-chars-deleted 0) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2853 (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
|
2854 (vip-add-hook 'vip-before-change-functions 'vip-replace-mode-spy-before t) |
10789 | 2855 ;; this will get added repeatedly, but no harm |
2856 (add-hook 'after-change-functions 'vip-after-change-sentinel t) | |
2857 (add-hook 'before-change-functions 'vip-before-change-sentinel t) | |
2858 (vip-move-marker-locally 'vip-last-posn-in-replace-region | |
2859 (vip-replace-start)) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2860 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2861 '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
|
2862 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2863 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
10789 | 2864 ) |
2865 | |
2866 | |
2867 ;; checks how many chars were deleted by the last change | |
2868 (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
|
2869 (setq vip-replace-chars-deleted |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2870 (- end beg |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2871 (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
|
2872 (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
|
2873 ))) |
10789 | 2874 |
2875 ;; Invoked as an after-change-function to set up parameters of the last change | |
2876 (defun vip-replace-mode-spy-after (beg end length) | |
2877 (if (memq vip-intermediate-command '(repeating-insertion-from-ring)) | |
2878 (progn | |
2879 (setq vip-replace-chars-to-delete 0) | |
2880 (vip-move-marker-locally | |
2881 'vip-last-posn-in-replace-region (point))) | |
2882 | |
2883 (let (beg-col end-col real-end chars-to-delete) | |
2884 (setq real-end (min end (vip-replace-end))) | |
2885 (save-excursion | |
2886 (goto-char beg) | |
2887 (setq beg-col (current-column)) | |
2888 (goto-char real-end) | |
2889 (setq end-col (current-column))) | |
2890 | |
2891 ;; If beg of change is outside the replacement region, then don't | |
2892 ;; delete anything in the repl region (set chars-to-delete to 0). | |
2893 ;; | |
2894 ;; This works fine except that we have to take special care of | |
2895 ;; dabbrev-expand. The problem stems from new-dabbrev.el, which | |
2896 ;; sometimes simply shifts the repl region rightwards, without | |
2897 ;; deleting an equal amount of characters. | |
2898 ;; | |
2899 ;; 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
|
2900 ;; 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
|
2901 ;; replacement region (but ends inside) then new-dabbrev.el first |
10789 | 2902 ;; moves cursor backwards, to the beginning of the word to be |
2903 ;; completed (say, pt A). Then it inserts the | |
2904 ;; completed word and then deletes the old, incomplete part. | |
2905 ;; Since the complete word is inserted at position before the repl | |
2906 ;; region, the next If-statement would have set chars-to-delete to 0 | |
2907 ;; unless we check for the current command, which must be | |
2908 ;; dabbrev-expand. | |
2909 ;; | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
2910 ;; In fact, it might be also useful to have overlays for insert |
10789 | 2911 ;; regions as well, since this will let us capture the situation when |
2912 ;; dabbrev-expand goes back past the insertion point to find the | |
2913 ;; beginning of the word to be expanded. | |
2914 (if (or (and (<= (vip-replace-start) beg) | |
2915 (<= beg (vip-replace-end))) | |
2916 (and (= length 0) (eq this-command 'dabbrev-expand))) | |
2917 (setq chars-to-delete | |
2918 (max (- end-col beg-col) (- real-end beg) 0)) | |
2919 (setq chars-to-delete 0)) | |
2920 | |
2921 ;; if beg = last change position, it means that we are within the | |
2922 ;; same command that does multiple changes. Moreover, it means | |
2923 ;; that we have two subsequent changes (insert/delete) that | |
2924 ;; complement each other. | |
2925 (if (= beg (marker-position vip-last-posn-in-replace-region)) | |
2926 (setq vip-replace-chars-to-delete | |
2927 (- (+ chars-to-delete vip-replace-chars-to-delete) | |
2928 vip-replace-chars-deleted)) | |
2929 (setq vip-replace-chars-to-delete chars-to-delete)) | |
2930 | |
2931 (vip-move-marker-locally | |
2932 'vip-last-posn-in-replace-region | |
2933 (max (if (> end (vip-replace-end)) (vip-replace-start) end) | |
2934 (or (marker-position vip-last-posn-in-replace-region) | |
2935 (vip-replace-start)) | |
2936 )) | |
2937 | |
2938 (setq vip-replace-chars-to-delete | |
2939 (max 0 (min vip-replace-chars-to-delete | |
2940 (- (vip-replace-end) | |
2941 vip-last-posn-in-replace-region)))) | |
2942 ))) | |
2943 | |
2944 | |
2945 ;; Delete stuff between posn and the end of vip-replace-overlay-marker, if | |
2946 ;; posn is within the overlay. | |
2947 (defun vip-finish-change (posn) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2948 (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
|
2949 (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
|
2950 (vip-remove-hook 'vip-post-command-hooks |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2951 'vip-replace-state-post-command-sentinel) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2952 (vip-remove-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2953 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) |
10789 | 2954 (vip-restore-cursor-color) |
2955 (setq vip-sitting-in-replace nil) ; just in case we'll need to know it | |
2956 (save-excursion | |
2957 (if (and | |
2958 vip-replace-overlay | |
2959 (>= posn (vip-replace-start)) | |
2960 (< posn (vip-replace-end))) | |
2961 (delete-region posn (vip-replace-end))) | |
2962 ) | |
2963 | |
2964 (if (eq vip-current-state 'replace-state) | |
2965 (vip-downgrade-to-insert)) | |
2966 ;; replace mode ended => nullify vip-last-posn-in-replace-region | |
2967 (vip-move-marker-locally 'vip-last-posn-in-replace-region nil) | |
2968 (vip-hide-replace-overlay) | |
2969 (vip-refresh-mode-line) | |
2970 (vip-put-string-on-kill-ring vip-last-replace-region) | |
2971 ) | |
2972 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
2973 ;; Make STRING be the first element of the kill ring. |
10789 | 2974 (defun vip-put-string-on-kill-ring (string) |
2975 (setq kill-ring (cons string kill-ring)) | |
2976 (if (> (length kill-ring) kill-ring-max) | |
2977 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) | |
2978 (setq kill-ring-yank-pointer kill-ring)) | |
2979 | |
2980 (defun vip-finish-R-mode () | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2981 (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
|
2982 (vip-remove-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2983 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel) |
10789 | 2984 (vip-downgrade-to-insert)) |
2985 | |
2986 (defun vip-start-R-mode () | |
2987 ;; Leave arg as 1, not t: XEmacs insists that it must be a pos number | |
2988 (overwrite-mode 1) | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2989 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2990 '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
|
2991 (vip-add-hook |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
2992 'vip-pre-command-hooks 'vip-replace-state-pre-command-sentinel t) |
10789 | 2993 ) |
2994 | |
2995 | |
2996 | |
2997 (defun vip-replace-state-exit-cmd () | |
2998 "Binding for keys that cause Replace state to switch to Vi or to Insert. | |
2999 These keys are ESC, RET, and LineFeed" | |
3000 (interactive) | |
3001 (if overwrite-mode ;; If you are in replace mode invoked via 'R' | |
3002 (vip-finish-R-mode) | |
3003 (vip-finish-change vip-last-posn-in-replace-region)) | |
3004 (let (com) | |
3005 (if (eq this-command 'vip-intercept-ESC-key) | |
3006 (setq com 'vip-exit-insert-state) | |
3007 (vip-set-unread-command-events last-input-char) | |
3008 (setq com (key-binding (read-key-sequence nil)))) | |
3009 | |
3010 (condition-case conds | |
3011 (command-execute com) | |
3012 (error | |
3013 (vip-message-conditions conds))) | |
3014 ) | |
3015 (vip-hide-replace-overlay)) | |
3016 | |
3017 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3018 ;; 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
|
3019 ;; Similar to Emacs's own overwrite-mode. |
10789 | 3020 (defun vip-overwrite (arg) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3021 "Begin overwrite mode." |
10789 | 3022 (interactive "P") |
3023 (let ((val (vip-p-val arg)) | |
3024 (com (vip-getcom arg)) (len)) | |
3025 (vip-set-destructive-command (list 'vip-overwrite val ?r nil nil nil)) | |
3026 (if com | |
3027 (progn | |
3028 ;; Viper saves inserted text in vip-last-insertion | |
3029 (setq len (length vip-last-insertion)) | |
3030 (delete-char len) | |
3031 (vip-loop val (vip-yank-last-insertion))) | |
3032 (setq last-command 'vip-overwrite) | |
3033 (vip-set-complex-command-for-undo) | |
3034 (vip-set-replace-overlay (point) (vip-line-pos 'end)) | |
3035 (vip-change-state-to-replace) | |
3036 ))) | |
3037 | |
3038 | |
3039 ;; line commands | |
3040 | |
3041 (defun vip-line (arg) | |
3042 (let ((val (car arg)) | |
3043 (com (cdr arg))) | |
3044 (vip-move-marker-locally 'vip-com-point (point)) | |
3045 (if (not (eobp)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3046 (vip-next-line-carefully (1- val))) |
10789 | 3047 ;; this ensures that dd, cc, D, yy will do the right thing on the last |
3048 ;; line of buffer when this line has no \n. | |
3049 (vip-add-newline-at-eob-if-necessary) | |
3050 (vip-execute-com 'vip-line val com)) | |
3051 (if (and (eobp) (not (bobp))) (forward-line -1)) | |
3052 ) | |
3053 | |
3054 (defun vip-yank-line (arg) | |
3055 "Yank ARG lines (in Vi's sense)." | |
3056 (interactive "P") | |
3057 (let ((val (vip-p-val arg))) | |
3058 (vip-line (cons val ?Y)))) | |
3059 | |
3060 | |
3061 ;; region commands | |
3062 | |
3063 (defun vip-region (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3064 "Execute command on a region." |
10789 | 3065 (interactive "P") |
3066 (let ((val (vip-P-val arg)) | |
3067 (com (vip-getcom arg))) | |
3068 (vip-move-marker-locally 'vip-com-point (point)) | |
3069 (exchange-point-and-mark) | |
3070 (vip-execute-com 'vip-region val com))) | |
3071 | |
3072 (defun vip-Region (arg) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3073 "Execute command on a Region." |
10789 | 3074 (interactive "P") |
3075 (let ((val (vip-P-val arg)) | |
3076 (com (vip-getCom arg))) | |
3077 (vip-move-marker-locally 'vip-com-point (point)) | |
3078 (exchange-point-and-mark) | |
3079 (vip-execute-com 'vip-Region val com))) | |
3080 | |
3081 (defun vip-replace-char (arg) | |
3082 "Replace the following ARG chars by the character read." | |
3083 (interactive "P") | |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
3084 (if (and (eolp) (bolp)) (error "No character to replace here")) |
10789 | 3085 (let ((val (vip-p-val arg)) |
3086 (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
|
3087 (vip-replace-char-subr com val) |
10789 | 3088 (if (and (eolp) (not (bolp))) (forward-char 1)) |
3089 (vip-set-destructive-command | |
3090 (list 'vip-replace-char val ?r nil vip-d-char nil)) | |
3091 )) | |
3092 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3093 (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
|
3094 (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
|
3095 (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
|
3096 char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3097 (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
|
3098 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
|
3099 (read-char))) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3100 (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
|
3101 ;; 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
|
3102 (progn |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3103 (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
|
3104 (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
|
3105 (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
|
3106 (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
|
3107 (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
|
3108 (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
|
3109 (vip-loop (if (> arg 0) arg (- arg)) |
10789 | 3110 (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
|
3111 (backward-char arg))) |
10789 | 3112 |
3113 | |
3114 ;; basic cursor movement. j, k, l, h commands. | |
3115 | |
3116 (defun vip-forward-char (arg) | |
3117 "Move point right ARG characters (left if ARG negative). | |
3118 On reaching end of line, stop and signal error." | |
3119 (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
|
3120 (vip-leave-region-active) |
10789 | 3121 (let ((val (vip-p-val arg)) |
3122 (com (vip-getcom arg))) | |
3123 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3124 (if vip-ex-style-motion | |
3125 (progn | |
3126 ;; the boundary condition check gets weird here because | |
3127 ;; forward-char may be the parameter of a delete, and 'dl' works | |
3128 ;; just like 'x' for the last char on a line, so we have to allow | |
3129 ;; the forward motion before the 'vip-execute-com', but, of | |
3130 ;; course, 'dl' doesn't work on an empty line, so we have to | |
3131 ;; catch that condition before 'vip-execute-com' | |
3132 (if (and (eolp) (bolp)) (error "") (forward-char val)) | |
3133 (if com (vip-execute-com 'vip-forward-char val com)) | |
3134 (if (eolp) (progn (backward-char 1) (error "")))) | |
3135 (forward-char val) | |
3136 (if com (vip-execute-com 'vip-forward-char val com))))) | |
3137 | |
3138 (defun vip-backward-char (arg) | |
3139 "Move point left ARG characters (right if ARG negative). | |
3140 On reaching beginning of line, stop and signal error." | |
3141 (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
|
3142 (vip-leave-region-active) |
10789 | 3143 (let ((val (vip-p-val arg)) |
3144 (com (vip-getcom arg))) | |
3145 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3146 (if vip-ex-style-motion | |
3147 (progn | |
3148 (if (bolp) (error "") (backward-char val)) | |
3149 (if com (vip-execute-com 'vip-backward-char val com))) | |
3150 (backward-char val) | |
3151 (if com (vip-execute-com 'vip-backward-char val com))))) | |
3152 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3153 ;; Like forward-char, but doesn't move at end of buffer. |
10789 | 3154 (defun vip-forward-char-carefully (&optional arg) |
3155 (setq arg (or arg 1)) | |
3156 (if (>= (point-max) (+ (point) arg)) | |
3157 (forward-char arg) | |
3158 (goto-char (point-max)))) | |
3159 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3160 ;; Like backward-char, but doesn't move at end of buffer. |
10789 | 3161 (defun vip-backward-char-carefully (&optional arg) |
3162 (setq arg (or arg 1)) | |
3163 (if (<= (point-min) (- (point) arg)) | |
3164 (backward-char arg) | |
3165 (goto-char (point-min)))) | |
3166 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3167 (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
|
3168 (condition-case nil |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3169 (next-line arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3170 (error nil))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3171 |
10789 | 3172 |
3173 | |
3174 ;;; Word command | |
3175 | |
3176 ;; Words are formed from alpha's and nonalphas - <sp>,\t\n are separators | |
3177 ;; for word movement. When executed with a destructive command, \n is | |
3178 ;; 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
|
3179 ;; 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
|
3180 ;; 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
|
3181 ;; is 'vi, then `_' is part of the word. |
10789 | 3182 |
3183 ;; skip only one \n | |
3184 (defun vip-skip-separators (forward) | |
3185 (if forward | |
3186 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3187 (vip-skip-all-separators-forward 'within-line) |
10789 | 3188 (if (looking-at "\n") |
3189 (progn | |
3190 (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
|
3191 (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
|
3192 (vip-skip-all-separators-backward 'within-line) |
10789 | 3193 (backward-char) |
3194 (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
|
3195 (vip-skip-all-separators-backward 'within-line) |
10789 | 3196 (forward-char)))) |
3197 | |
3198 (defun vip-forward-word-kernel (val) | |
3199 (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
|
3200 (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
|
3201 (vip-skip-alpha-forward "_") |
10789 | 3202 (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
|
3203 ((vip-looking-at-separator) |
10789 | 3204 (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
|
3205 ((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
|
3206 (vip-skip-nonalphasep-forward) |
10789 | 3207 (vip-skip-separators t))) |
3208 (setq val (1- val)))) | |
3209 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3210 ;; first search backward for pat. Then skip chars backwards using aux-pat |
10789 | 3211 (defun vip-fwd-skip (pat aux-pat lim) |
3212 (if (and (save-excursion | |
3213 (re-search-backward pat lim t)) | |
3214 (= (point) (match-end 0))) | |
3215 (goto-char (match-beginning 0))) | |
3216 (skip-chars-backward aux-pat lim) | |
3217 (if (= (point) lim) | |
3218 (vip-forward-char-carefully)) | |
3219 ) | |
3220 | |
3221 | |
3222 (defun vip-forward-word (arg) | |
3223 "Forward word." | |
3224 (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
|
3225 (vip-leave-region-active) |
10789 | 3226 (let ((val (vip-p-val arg)) |
3227 (com (vip-getcom arg))) | |
3228 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3229 (vip-forward-word-kernel val) | |
3230 (if com (progn | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3231 (cond ((memq com (list ?c (- ?c))) |
10789 | 3232 (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
|
3233 ;; 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
|
3234 ((memq com (list ?y (- ?y))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3235 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) |
10789 | 3236 ((vip-dotable-command-p com) |
3237 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | |
3238 (vip-execute-com 'vip-forward-word val com))))) | |
3239 | |
3240 | |
3241 (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
|
3242 "Forward word delimited by white characters." |
10789 | 3243 (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
|
3244 (vip-leave-region-active) |
10789 | 3245 (let ((val (vip-p-val arg)) |
3246 (com (vip-getcom arg))) | |
3247 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3248 (vip-loop val | |
3249 (progn | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3250 (vip-skip-nonseparators 'forward) |
10789 | 3251 (vip-skip-separators t))) |
3252 (if com (progn | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3253 (cond ((memq com (list ?c (- ?c))) |
10789 | 3254 (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
|
3255 ;; 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
|
3256 ((memq com (list ?y (- ?y))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3257 (vip-fwd-skip "\n[ \t]*" "" vip-com-point)) |
10789 | 3258 ((vip-dotable-command-p com) |
3259 (vip-fwd-skip "\n[ \t]*" "" vip-com-point))) | |
3260 (vip-execute-com 'vip-forward-Word val com))))) | |
3261 | |
3262 | |
3263 ;; this is a bit different from Vi, but Vi's end of word | |
3264 ;; makes no sense whatsoever | |
3265 (defun vip-end-of-word-kernel () | |
3266 (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
|
3267 (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
|
3268 (vip-skip-all-separators-forward)) |
10789 | 3269 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3270 (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
|
3271 ((not (vip-looking-at-alphasep)) (vip-skip-nonalphasep-forward))) |
10789 | 3272 (vip-backward-char-carefully)) |
3273 | |
3274 (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
|
3275 (or (eobp) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3276 (save-excursion |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3277 (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
|
3278 (forward-char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3279 (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
|
3280 ((not (vip-looking-at-alphasep)) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3281 (forward-char) |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3282 (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
|
3283 |
10789 | 3284 |
3285 (defun vip-end-of-word (arg &optional careful) | |
3286 "Move point to end of current word." | |
3287 (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
|
3288 (vip-leave-region-active) |
10789 | 3289 (let ((val (vip-p-val arg)) |
3290 (com (vip-getcom arg))) | |
3291 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3292 (vip-loop val (vip-end-of-word-kernel)) | |
3293 (if com | |
3294 (progn | |
3295 (forward-char) | |
3296 (vip-execute-com 'vip-end-of-word val com))))) | |
3297 | |
3298 (defun vip-end-of-Word (arg) | |
3299 "Forward to end of word delimited by white character." | |
3300 (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
|
3301 (vip-leave-region-active) |
10789 | 3302 (let ((val (vip-p-val arg)) |
3303 (com (vip-getcom arg))) | |
3304 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3305 (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
|
3306 (progn |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
3307 (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
|
3308 (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
|
3309 (backward-char))) |
10789 | 3310 (if com |
3311 (progn | |
3312 (forward-char) | |
3313 (vip-execute-com 'vip-end-of-Word val com))))) | |
3314 | |
3315 (defun vip-backward-word-kernel (val) | |
3316 (while (> val 0) | |
3317 (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
|
3318 (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
|
3319 (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
|
3320 ((vip-looking-at-separator) |
10789 | 3321 (forward-char) |
3322 (vip-skip-separators nil) | |
3323 (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
|
3324 (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
|
3325 (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
|
3326 ((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
|
3327 (vip-skip-nonalphasep-backward)) |
10789 | 3328 (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
|
3329 ((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
|
3330 (vip-skip-nonalphasep-backward))) |
10789 | 3331 (setq val (1- val)))) |
3332 | |
3333 (defun vip-backward-word (arg) | |
3334 "Backward word." | |
3335 (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
|
3336 (vip-leave-region-active) |
10789 | 3337 (let ((val (vip-p-val arg)) |
3338 (com (vip-getcom arg))) | |
3339 (if com | |
3340 (let (i) | |
3341 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
3342 (backward-char)) | |
3343 (vip-move-marker-locally 'vip-com-point (point)) | |
3344 (if i (forward-char)))) | |
3345 (vip-backward-word-kernel val) | |
3346 (if com (vip-execute-com 'vip-backward-word val com)))) | |
3347 | |
3348 (defun vip-backward-Word (arg) | |
3349 "Backward word delimited by white character." | |
3350 (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
|
3351 (vip-leave-region-active) |
10789 | 3352 (let ((val (vip-p-val arg)) |
3353 (com (vip-getcom arg))) | |
3354 (if com | |
3355 (let (i) | |
3356 (if (setq i (save-excursion (backward-char) (looking-at "\n"))) | |
3357 (backward-char)) | |
3358 (vip-move-marker-locally 'vip-com-point (point)) | |
3359 (if i (forward-char)))) | |
3360 (vip-loop val | |
3361 (progn | |
3362 (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
|
3363 (vip-skip-nonseparators 'backward))) |
10789 | 3364 (if com (vip-execute-com 'vip-backward-Word val com)))) |
3365 | |
3366 | |
3367 | |
3368 ;; line commands | |
3369 | |
3370 (defun vip-beginning-of-line (arg) | |
3371 "Go to beginning of line." | |
3372 (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
|
3373 (vip-leave-region-active) |
10789 | 3374 (let ((val (vip-p-val arg)) |
3375 (com (vip-getcom arg))) | |
3376 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3377 (beginning-of-line val) | |
3378 (if com (vip-execute-com 'vip-beginning-of-line val com)))) | |
3379 | |
3380 (defun vip-bol-and-skip-white (arg) | |
3381 "Beginning of line at first non-white character." | |
3382 (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
|
3383 (vip-leave-region-active) |
10789 | 3384 (let ((val (vip-p-val arg)) |
3385 (com (vip-getcom arg))) | |
3386 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3387 (forward-to-indentation (1- val)) | |
3388 (if com (vip-execute-com 'vip-bol-and-skip-white val com)))) | |
3389 | |
3390 (defun vip-goto-eol (arg) | |
3391 "Go to end of line." | |
3392 (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
|
3393 (vip-leave-region-active) |
10789 | 3394 (let ((val (vip-p-val arg)) |
3395 (com (vip-getcom arg))) | |
3396 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3397 (end-of-line val) | |
3398 (if com (vip-execute-com 'vip-goto-eol val com)) | |
3399 (if vip-ex-style-motion | |
3400 (if (and (eolp) (not (bolp)) | |
3401 ;; a fix for vip-change-to-eol | |
3402 (not (equal vip-current-state 'insert-state))) | |
3403 (backward-char 1) | |
3404 )))) | |
3405 | |
3406 | |
3407 (defun vip-goto-col (arg) | |
3408 "Go to ARG's column." | |
3409 (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
|
3410 (vip-leave-region-active) |
10789 | 3411 (let ((val (vip-p-val arg)) |
3412 (com (vip-getcom arg))) | |
3413 (save-excursion | |
3414 (end-of-line) | |
3415 (if (> val (1+ (current-column))) (error ""))) | |
3416 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3417 (beginning-of-line) | |
3418 (forward-char (1- val)) | |
3419 (if com (vip-execute-com 'vip-goto-col val com)))) | |
3420 | |
3421 | |
3422 (defun vip-next-line (arg) | |
3423 "Go to next line." | |
3424 (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
|
3425 (vip-leave-region-active) |
10789 | 3426 (let ((val (vip-p-val arg)) |
3427 (com (vip-getCom arg))) | |
3428 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3429 (next-line val) | |
3430 (if vip-ex-style-motion | |
3431 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
3432 (setq this-command 'next-line) | |
3433 (if com (vip-execute-com 'vip-next-line val com)))) | |
3434 | |
3435 (defun vip-next-line-at-bol (arg) | |
3436 "Next line at beginning of line." | |
3437 (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
|
3438 (vip-leave-region-active) |
10789 | 3439 (save-excursion |
3440 (end-of-line) | |
3441 (if (eobp) (error "Last line in buffer"))) | |
3442 (let ((val (vip-p-val arg)) | |
3443 (com (vip-getCom arg))) | |
3444 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3445 (forward-line val) | |
3446 (back-to-indentation) | |
3447 (if com (vip-execute-com 'vip-next-line-at-bol val com)))) | |
3448 | |
3449 (defun vip-previous-line (arg) | |
3450 "Go to previous line." | |
3451 (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
|
3452 (vip-leave-region-active) |
10789 | 3453 (let ((val (vip-p-val arg)) |
3454 (com (vip-getCom arg))) | |
3455 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3456 (previous-line val) | |
3457 (if vip-ex-style-motion | |
3458 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
3459 (setq this-command 'previous-line) | |
3460 (if com (vip-execute-com 'vip-previous-line val com)))) | |
3461 | |
3462 | |
3463 (defun vip-previous-line-at-bol (arg) | |
3464 "Previous line at beginning 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 (save-excursion |
3468 (beginning-of-line) | |
3469 (if (bobp) (error "First line in buffer"))) | |
3470 (let ((val (vip-p-val arg)) | |
3471 (com (vip-getCom arg))) | |
3472 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3473 (forward-line (- val)) | |
3474 (back-to-indentation) | |
3475 (if com (vip-execute-com 'vip-previous-line val com)))) | |
3476 | |
3477 (defun vip-change-to-eol (arg) | |
3478 "Change to end of line." | |
3479 (interactive "P") | |
3480 (vip-goto-eol (cons arg ?c))) | |
3481 | |
3482 (defun vip-kill-line (arg) | |
3483 "Delete line." | |
3484 (interactive "P") | |
3485 (vip-goto-eol (cons arg ?d))) | |
3486 | |
3487 (defun vip-erase-line (arg) | |
3488 "Erase line." | |
3489 (interactive "P") | |
3490 (vip-beginning-of-line (cons arg ?d))) | |
3491 | |
3492 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3493 ;;; Moving around |
10789 | 3494 |
3495 (defun vip-goto-line (arg) | |
3496 "Go to ARG's line. Without ARG go to end of buffer." | |
3497 (interactive "P") | |
3498 (let ((val (vip-P-val arg)) | |
3499 (com (vip-getCom arg))) | |
3500 (vip-move-marker-locally 'vip-com-point (point)) | |
3501 (vip-deactivate-mark) | |
3502 (push-mark nil t) | |
3503 (if (null val) | |
3504 (goto-char (point-max)) | |
3505 (goto-char (point-min)) | |
3506 (forward-line (1- val))) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3507 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3508 ;; positioning is done twice: before and after command execution |
10789 | 3509 (if (and (eobp) (bolp) (not (bobp))) (forward-line -1)) |
3510 (back-to-indentation) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3511 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3512 (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
|
3513 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3514 (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
|
3515 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3516 )) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3517 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3518 ;; 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
|
3519 ;; 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
|
3520 ;; adjust point after search. |
10789 | 3521 (defun vip-find-char (arg char forward offset) |
3522 (or (char-or-string-p char) (error "")) | |
3523 (let ((arg (if forward arg (- arg))) | |
3524 (cmd (if (eq vip-intermediate-command 'vip-repeat) | |
3525 (nth 5 vip-d-com) | |
3526 (vip-array-to-string (this-command-keys)))) | |
3527 point) | |
3528 (save-excursion | |
3529 (save-restriction | |
3530 (if (> arg 0) | |
3531 (narrow-to-region | |
3532 ;; forward search begins here | |
3533 (if (eolp) (error "Command `%s': At end of line" cmd) (point)) | |
3534 ;; forward search ends here | |
3535 (progn (end-of-line) (point))) | |
3536 (narrow-to-region | |
3537 ;; backward search begins from here | |
3538 (if (bolp) | |
3539 (error "Command `%s': At beginning of line" cmd) (point)) | |
3540 ;; backward search ends here | |
3541 (progn (beginning-of-line) (point)))) | |
3542 ;; if arg > 0, point is forwarded before search. | |
3543 (if (> arg 0) (goto-char (1+ (point-min))) | |
3544 (goto-char (point-max))) | |
3545 (if (let ((case-fold-search nil)) | |
3546 (search-forward (char-to-string char) nil 0 arg)) | |
3547 (setq point (point)) | |
3548 (error "Command `%s': `%c' not found" cmd char)))) | |
3549 (goto-char (+ point (if (> arg 0) (if offset -2 -1) (if offset 1 0)))))) | |
3550 | |
3551 (defun vip-find-char-forward (arg) | |
3552 "Find char on the line. | |
3553 If called interactively read the char to find from the terminal, and if | |
3554 called from vip-repeat, the char last used is used. This behaviour is | |
3555 controlled by the sign of prefix numeric value." | |
3556 (interactive "P") | |
3557 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3558 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3559 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3560 (if (> val 0) |
3561 ;; this means that the function was called interactively | |
3562 (setq vip-f-char (read-char) | |
3563 vip-f-forward t | |
3564 vip-f-offset nil) | |
3565 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3566 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3567 (vip-seq-last-elt cmd-representation) |
10789 | 3568 vip-F-char) |
3569 vip-f-char vip-F-char) | |
3570 (setq val (- val))) | |
3571 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3572 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t nil) | |
3573 (setq val (- val)) | |
3574 (if com | |
3575 (progn | |
3576 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3577 (forward-char) | |
3578 (vip-execute-com 'vip-find-char-forward val com))))) | |
3579 | |
3580 (defun vip-goto-char-forward (arg) | |
3581 "Go up to char ARG forward on line." | |
3582 (interactive "P") | |
3583 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3584 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3585 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3586 (if (> val 0) |
3587 ;; this means that the function was called interactively | |
3588 (setq vip-f-char (read-char) | |
3589 vip-f-forward t | |
3590 vip-f-offset t) | |
3591 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3592 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3593 (vip-seq-last-elt cmd-representation) |
10789 | 3594 vip-F-char) |
3595 vip-f-char vip-F-char) | |
3596 (setq val (- val))) | |
3597 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3598 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) t t) | |
3599 (setq val (- val)) | |
3600 (if com | |
3601 (progn | |
3602 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3603 (forward-char) | |
3604 (vip-execute-com 'vip-goto-char-forward val com))))) | |
3605 | |
3606 (defun vip-find-char-backward (arg) | |
3607 "Find char ARG on line backward." | |
3608 (interactive "P") | |
3609 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3610 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3611 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3612 (if (> val 0) |
3613 ;; this means that the function was called interactively | |
3614 (setq vip-f-char (read-char) | |
3615 vip-f-forward nil | |
3616 vip-f-offset nil) | |
3617 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3618 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3619 (vip-seq-last-elt cmd-representation) |
10789 | 3620 vip-F-char) |
3621 vip-f-char vip-F-char) | |
3622 (setq val (- val))) | |
3623 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3624 (vip-find-char | |
3625 val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil) | |
3626 (setq val (- val)) | |
3627 (if com | |
3628 (progn | |
3629 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3630 (vip-execute-com 'vip-find-char-backward val com))))) | |
3631 | |
3632 (defun vip-goto-char-backward (arg) | |
3633 "Go up to char ARG backward on line." | |
3634 (interactive "P") | |
3635 (let ((val (vip-p-val arg)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3636 (com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3637 (cmd-representation (nth 5 vip-d-com))) |
10789 | 3638 (if (> val 0) |
3639 ;; this means that the function was called interactively | |
3640 (setq vip-f-char (read-char) | |
3641 vip-f-forward nil | |
3642 vip-f-offset t) | |
3643 ;; vip-repeat --- set vip-F-char from command-keys | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3644 (setq vip-F-char (if (stringp cmd-representation) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3645 (vip-seq-last-elt cmd-representation) |
10789 | 3646 vip-F-char) |
3647 vip-f-char vip-F-char) | |
3648 (setq val (- val))) | |
3649 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3650 (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t) | |
3651 (setq val (- val)) | |
3652 (if com | |
3653 (progn | |
3654 (setq vip-F-char vip-f-char) ; set new vip-F-char | |
3655 (vip-execute-com 'vip-goto-char-backward val com))))) | |
3656 | |
3657 (defun vip-repeat-find (arg) | |
3658 "Repeat previous find command." | |
3659 (interactive "P") | |
3660 (let ((val (vip-p-val arg)) | |
3661 (com (vip-getcom arg))) | |
3662 (vip-deactivate-mark) | |
3663 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3664 (vip-find-char val vip-f-char vip-f-forward vip-f-offset) | |
3665 (if com | |
3666 (progn | |
3667 (if vip-f-forward (forward-char)) | |
3668 (vip-execute-com 'vip-repeat-find val com))))) | |
3669 | |
3670 (defun vip-repeat-find-opposite (arg) | |
3671 "Repeat previous find command in the opposite direction." | |
3672 (interactive "P") | |
3673 (let ((val (vip-p-val arg)) | |
3674 (com (vip-getcom arg))) | |
3675 (vip-deactivate-mark) | |
3676 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3677 (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset) | |
3678 (if com | |
3679 (progn | |
3680 (if vip-f-forward (forward-char)) | |
3681 (vip-execute-com 'vip-repeat-find-opposite val com))))) | |
3682 | |
3683 | |
3684 ;; window scrolling etc. | |
3685 | |
3686 (defun vip-other-window (arg) | |
3687 "Switch to other window." | |
3688 (interactive "p") | |
3689 (other-window arg) | |
3690 (or (not (eq vip-current-state 'emacs-state)) | |
3691 (string= (buffer-name (current-buffer)) " *Minibuf-1*") | |
3692 (vip-change-state-to-vi))) | |
3693 | |
3694 (defun vip-window-top (arg) | |
3695 "Go to home window line." | |
3696 (interactive "P") | |
3697 (let ((val (vip-p-val arg)) | |
3698 (com (vip-getCom arg))) | |
3699 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3700 (push-mark nil t) | |
3701 (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
|
3702 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3703 ;; 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
|
3704 (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
|
3705 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3706 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3707 (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
|
3708 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3709 (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
|
3710 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3711 )) |
10789 | 3712 |
3713 (defun vip-window-middle (arg) | |
3714 "Go to middle window line." | |
3715 (interactive "P") | |
3716 (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
|
3717 (com (vip-getCom arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3718 lines) |
10789 | 3719 (if com (vip-move-marker-locally 'vip-com-point (point))) |
3720 (push-mark nil t) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3721 (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
|
3722 (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
|
3723 (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
|
3724 (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
|
3725 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3726 ;; 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
|
3727 (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
|
3728 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3729 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3730 (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
|
3731 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3732 (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
|
3733 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3734 )) |
10789 | 3735 |
3736 (defun vip-window-bottom (arg) | |
3737 "Go to last window line." | |
3738 (interactive "P") | |
3739 (let ((val (vip-p-val arg)) | |
3740 (com (vip-getCom arg))) | |
3741 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3742 (push-mark nil t) | |
3743 (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
|
3744 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3745 ;; 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
|
3746 (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
|
3747 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3748 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3749 (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
|
3750 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3751 (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
|
3752 (back-to-indentation) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
3753 )) |
10789 | 3754 |
3755 (defun vip-line-to-top (arg) | |
3756 "Put current line on the home line." | |
3757 (interactive "p") | |
3758 (recenter (1- arg))) | |
3759 | |
3760 (defun vip-line-to-middle (arg) | |
3761 "Put current line on the middle line." | |
3762 (interactive "p") | |
3763 (recenter (+ (1- arg) (/ (1- (window-height)) 2)))) | |
3764 | |
3765 (defun vip-line-to-bottom (arg) | |
3766 "Put current line on the last line." | |
3767 (interactive "p") | |
3768 (recenter (- (window-height) (1+ arg)))) | |
3769 | |
3770 | |
3771 ;; paren match | |
3772 ;; must correct this to only match ( to ) etc. On the other hand | |
3773 ;; it is good that paren match gets confused, because that way you | |
3774 ;; catch _all_ imbalances. | |
3775 | |
3776 (defun vip-paren-match (arg) | |
3777 "Go to the matching parenthesis." | |
3778 (interactive "P") | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3779 (let ((com (vip-getcom arg)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3780 anchor-point) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3781 (if (integerp arg) |
10789 | 3782 (if (or (> arg 99) (< arg 1)) |
3783 (error "Prefix must be between 1 and 99") | |
3784 (goto-char | |
3785 (if (> (point-max) 80000) | |
3786 (* (/ (point-max) 100) arg) | |
3787 (/ (* (point-max) arg) 100))) | |
3788 (back-to-indentation)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3789 (let (beg-lim end-lim) |
10789 | 3790 (if (and (eolp) (not (bolp))) (forward-char -1)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3791 (if (not (looking-at "[][(){}]")) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3792 (setq anchor-point (point))) |
10789 | 3793 (save-excursion |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3794 (beginning-of-line) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3795 (setq beg-lim (point)) |
10789 | 3796 (end-of-line) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3797 (setq end-lim (point))) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3798 (cond ((re-search-forward "[][(){}]" end-lim t) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3799 (backward-char) ) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3800 ((re-search-backward "[][(){}]" beg-lim t)) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3801 (t |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3802 (error "No matching character on line")))) |
10789 | 3803 (cond ((looking-at "[\(\[{]") |
3804 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3805 (forward-sexp 1) | |
3806 (if com | |
3807 (vip-execute-com 'vip-paren-match nil com) | |
3808 (backward-char))) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3809 (anchor-point |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3810 (if com |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3811 (progn |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3812 (vip-move-marker-locally 'vip-com-point anchor-point) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3813 (forward-char 1) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3814 (vip-execute-com 'vip-paren-match nil com) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
3815 ))) |
10789 | 3816 ((looking-at "[])}]") |
3817 (forward-char) | |
3818 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3819 (backward-sexp 1) | |
3820 (if com (vip-execute-com 'vip-paren-match nil com))) | |
3821 (t (error "")))))) | |
3822 | |
3823 | |
3824 ;; sentence ,paragraph and heading | |
3825 | |
3826 (defun vip-forward-sentence (arg) | |
3827 "Forward sentence." | |
3828 (interactive "P") | |
3829 (push-mark nil t) | |
3830 (let ((val (vip-p-val arg)) | |
3831 (com (vip-getcom arg))) | |
3832 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3833 (forward-sentence val) | |
3834 (if com (vip-execute-com 'vip-forward-sentence nil com)))) | |
3835 | |
3836 (defun vip-backward-sentence (arg) | |
3837 "Backward sentence." | |
3838 (interactive "P") | |
3839 (push-mark nil t) | |
3840 (let ((val (vip-p-val arg)) | |
3841 (com (vip-getcom arg))) | |
3842 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3843 (backward-sentence val) | |
3844 (if com (vip-execute-com 'vip-backward-sentence nil com)))) | |
3845 | |
3846 (defun vip-forward-paragraph (arg) | |
3847 "Forward paragraph." | |
3848 (interactive "P") | |
3849 (push-mark nil t) | |
3850 (let ((val (vip-p-val arg)) | |
3851 (com (vip-getCom arg))) | |
3852 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3853 (forward-paragraph val) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3854 (if com |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3855 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3856 (backward-char 1) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3857 (vip-execute-com 'vip-forward-paragraph nil com))))) |
10789 | 3858 |
3859 (defun vip-backward-paragraph (arg) | |
3860 "Backward paragraph." | |
3861 (interactive "P") | |
3862 (push-mark nil t) | |
3863 (let ((val (vip-p-val arg)) | |
3864 (com (vip-getCom arg))) | |
3865 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3866 (backward-paragraph val) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3867 (if com |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3868 (progn |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3869 (forward-char 1) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3870 (vip-execute-com 'vip-backward-paragraph nil com) |
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
3871 (backward-char 1))))) |
10789 | 3872 |
3873 ;; should be mode-specific etc. | |
3874 | |
3875 (defun vip-prev-heading (arg) | |
3876 (interactive "P") | |
3877 (let ((val (vip-p-val arg)) | |
3878 (com (vip-getCom arg))) | |
3879 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3880 (re-search-backward vip-heading-start nil t val) | |
3881 (goto-char (match-beginning 0)) | |
3882 (if com (vip-execute-com 'vip-prev-heading nil com)))) | |
3883 | |
3884 (defun vip-heading-end (arg) | |
3885 (interactive "P") | |
3886 (let ((val (vip-p-val arg)) | |
3887 (com (vip-getCom arg))) | |
3888 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3889 (re-search-forward vip-heading-end nil t val) | |
3890 (goto-char (match-beginning 0)) | |
3891 (if com (vip-execute-com 'vip-heading-end nil com)))) | |
3892 | |
3893 (defun vip-next-heading (arg) | |
3894 (interactive "P") | |
3895 (let ((val (vip-p-val arg)) | |
3896 (com (vip-getCom arg))) | |
3897 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
3898 (end-of-line) | |
3899 (re-search-forward vip-heading-start nil t val) | |
3900 (goto-char (match-beginning 0)) | |
3901 (if com (vip-execute-com 'vip-next-heading nil com)))) | |
3902 | |
3903 | |
3904 ;; scrolling | |
3905 | |
3906 (setq scroll-step 1) | |
3907 | |
3908 (defun vip-scroll (arg) | |
3909 "Scroll to next screen." | |
3910 (interactive "p") | |
3911 (if (> arg 0) | |
3912 (while (> arg 0) | |
3913 (scroll-up) | |
3914 (setq arg (1- arg))) | |
3915 (while (> 0 arg) | |
3916 (scroll-down) | |
3917 (setq arg (1+ arg))))) | |
3918 | |
3919 (defun vip-scroll-back (arg) | |
3920 "Scroll to previous screen." | |
3921 (interactive "p") | |
3922 (vip-scroll (- arg))) | |
3923 | |
3924 (defun vip-scroll-down (arg) | |
3925 "Pull down half screen." | |
3926 (interactive "P") | |
3927 (condition-case nil | |
3928 (if (null arg) | |
3929 (scroll-down (/ (window-height) 2)) | |
3930 (scroll-down arg)) | |
3931 (error (beep 1) | |
3932 (message "Beginning of buffer") | |
3933 (goto-char (point-min))))) | |
3934 | |
3935 (defun vip-scroll-down-one (arg) | |
3936 "Scroll up one line." | |
3937 (interactive "p") | |
3938 (scroll-down arg)) | |
3939 | |
3940 (defun vip-scroll-up (arg) | |
3941 "Pull up half screen." | |
3942 (interactive "P") | |
3943 (condition-case nil | |
3944 (if (null arg) | |
3945 (scroll-up (/ (window-height) 2)) | |
3946 (scroll-up arg)) | |
3947 (error (beep 1) | |
3948 (message "End of buffer") | |
3949 (goto-char (point-max))))) | |
3950 | |
3951 (defun vip-scroll-up-one (arg) | |
3952 "Scroll down one line." | |
3953 (interactive "p") | |
3954 (scroll-up arg)) | |
3955 | |
3956 | |
3957 ;; searching | |
3958 | |
3959 (defun vip-if-string (prompt) | |
3960 (let ((s (vip-read-string-with-history | |
3961 prompt | |
3962 nil ; no initial | |
3963 'vip-search-history | |
3964 (car vip-search-history)))) | |
3965 (if (not (string= s "")) | |
3966 (setq vip-s-string s)))) | |
3967 | |
3968 | |
3969 (defun vip-toggle-search-style (arg) | |
3970 "Toggle the value of vip-case-fold-search/vip-re-search. | |
3971 Without prefix argument, will ask which search style to toggle. With prefix | |
3972 arg 1,toggles vip-case-fold-search; with arg 2 toggles vip-re-search. | |
3973 | |
3974 Although this function is bound to \\[vip-toggle-search-style], the most | |
3975 convenient way to use it is to bind `//' to the macro | |
3976 `1 M-x vip-toggle-search-style' and `///' to | |
3977 `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
|
3978 toggle case-fold-search and hitting `/' three times witth toggle regexp |
10789 | 3979 search. Macros are more convenient in this case because they don't affect |
3980 the Emacs binding of `/'." | |
3981 (interactive "P") | |
3982 (let (msg) | |
3983 (cond ((or (eq arg 1) | |
3984 (and (null arg) | |
3985 (y-or-n-p (format "Search style: '%s'. Want '%s'? " | |
3986 (if vip-case-fold-search | |
3987 "case-insensitive" "case-sensitive") | |
3988 (if vip-case-fold-search | |
3989 "case-sensitive" | |
3990 "case-insensitive"))))) | |
3991 (setq vip-case-fold-search (null vip-case-fold-search)) | |
3992 (if vip-case-fold-search | |
3993 (setq msg "Search becomes case-insensitive") | |
3994 (setq msg "Search becomes case-sensitive"))) | |
3995 ((or (eq arg 2) | |
3996 (and (null arg) | |
3997 (y-or-n-p (format "Search style: '%s'. Want '%s'? " | |
3998 (if vip-re-search | |
3999 "regexp-search" "vanilla-search") | |
4000 (if vip-re-search | |
4001 "vanilla-search" | |
4002 "regexp-search"))))) | |
4003 (setq vip-re-search (null vip-re-search)) | |
4004 (if vip-re-search | |
4005 (setq msg "Search becomes regexp-style") | |
4006 (setq msg "Search becomes vanilla-style"))) | |
4007 (t | |
4008 (setq msg "Search style remains unchanged"))) | |
4009 (prin1 msg t))) | |
4010 | |
4011 | |
4012 (defun vip-search-forward (arg) | |
4013 "Search a string forward. | |
4014 ARG is used to find the ARG's occurrence of the string. | |
4015 Null string will repeat previous search." | |
4016 (interactive "P") | |
4017 (let ((val (vip-P-val arg)) | |
4018 (com (vip-getcom arg)) | |
4019 (old-str vip-s-string)) | |
4020 (setq vip-s-forward t) | |
4021 (vip-if-string "/") | |
4022 ;; this is not used at present, but may be used later | |
4023 (if (or (not (equal old-str vip-s-string)) | |
4024 (not (markerp vip-local-search-start-marker)) | |
4025 (not (marker-buffer vip-local-search-start-marker))) | |
4026 (setq vip-local-search-start-marker (point-marker))) | |
4027 (vip-search vip-s-string t val) | |
4028 (if com | |
4029 (progn | |
4030 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4031 (vip-execute-com 'vip-search-next val com))))) | |
4032 | |
4033 (defun vip-search-backward (arg) | |
4034 "Search a string backward. | |
4035 ARG is used to find the ARG's occurrence of the string. | |
4036 Null string will repeat previous search." | |
4037 (interactive "P") | |
4038 (let ((val (vip-P-val arg)) | |
4039 (com (vip-getcom arg)) | |
4040 (old-str vip-s-string)) | |
4041 (setq vip-s-forward nil) | |
4042 (vip-if-string "?") | |
4043 ;; this is not used at present, but may be used later | |
4044 (if (or (not (equal old-str vip-s-string)) | |
4045 (not (markerp vip-local-search-start-marker)) | |
4046 (not (marker-buffer vip-local-search-start-marker))) | |
4047 (setq vip-local-search-start-marker (point-marker))) | |
4048 (vip-search vip-s-string nil val) | |
4049 (if com | |
4050 (progn | |
4051 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4052 (vip-execute-com 'vip-search-next val com))))) | |
4053 | |
4054 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4055 ;; 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
|
4056 ;; 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
|
4057 ;; 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
|
4058 ;; Arguments: |
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
4059 ;; (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
|
4060 (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
|
4061 &optional no-offset init-point fail-if-not-found) |
10789 | 4062 (if (not (equal string "")) |
4063 (let ((val (vip-p-val arg)) | |
4064 (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
|
4065 (offset (not no-offset)) |
10789 | 4066 (case-fold-search vip-case-fold-search) |
4067 (start-point (or init-point (point)))) | |
4068 (vip-deactivate-mark) | |
4069 (if forward | |
4070 (condition-case nil | |
4071 (progn | |
4072 (if offset (vip-forward-char-carefully)) | |
4073 (if vip-re-search | |
4074 (progn | |
4075 (re-search-forward string nil nil val) | |
4076 (re-search-backward string)) | |
4077 (search-forward string nil nil val) | |
4078 (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
|
4079 ;; 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
|
4080 (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
|
4081 (vip-flash-search-pattern)) |
10789 | 4082 (if (not (equal start-point (point))) |
4083 (push-mark start-point t))) | |
4084 (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
|
4085 (if (and (not fail-if-not-found) vip-search-wrap-around-t) |
10789 | 4086 (progn |
4087 (message "Search wrapped around end of buffer") | |
4088 (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
|
4089 (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
|
4090 ;; 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
|
4091 (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
|
4092 ;; 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
|
4093 (message "") |
10789 | 4094 ) |
4095 (goto-char start-point) | |
4096 (error "`%s': %s not found" | |
4097 string | |
4098 (if vip-re-search "Pattern" "String")) | |
4099 ))) | |
4100 ;; backward | |
4101 (condition-case nil | |
4102 (progn | |
4103 (if vip-re-search | |
4104 (re-search-backward string nil nil val) | |
4105 (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
|
4106 ;; 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
|
4107 (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
|
4108 (vip-flash-search-pattern)) |
10789 | 4109 (if (not (equal start-point (point))) |
4110 (push-mark start-point t))) | |
4111 (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
|
4112 (if (and (not fail-if-not-found) vip-search-wrap-around-t) |
10789 | 4113 (progn |
4114 (message "Search wrapped around beginning of buffer") | |
4115 (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
|
4116 (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
|
4117 ;; 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
|
4118 (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
|
4119 ;; 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
|
4120 (message "") |
10789 | 4121 ) |
4122 (goto-char start-point) | |
4123 (error "`%s': %s not found" | |
4124 string | |
4125 (if vip-re-search "Pattern" "String")) | |
4126 ))))))) | |
4127 | |
4128 (defun vip-search-next (arg) | |
4129 "Repeat previous search." | |
4130 (interactive "P") | |
4131 (let ((val (vip-p-val arg)) | |
4132 (com (vip-getcom arg))) | |
4133 (if (null vip-s-string) (error vip-NoPrevSearch)) | |
4134 (vip-search vip-s-string vip-s-forward arg) | |
4135 (if com | |
4136 (progn | |
4137 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4138 (vip-execute-com 'vip-search-next val com))))) | |
4139 | |
4140 (defun vip-search-Next (arg) | |
4141 "Repeat previous search in the reverse direction." | |
4142 (interactive "P") | |
4143 (let ((val (vip-p-val arg)) | |
4144 (com (vip-getcom arg))) | |
4145 (if (null vip-s-string) (error vip-NoPrevSearch)) | |
4146 (vip-search vip-s-string (not vip-s-forward) arg) | |
4147 (if com | |
4148 (progn | |
4149 (vip-move-marker-locally 'vip-com-point (mark t)) | |
4150 (vip-execute-com 'vip-search-Next val com))))) | |
4151 | |
4152 | |
4153 ;; Search contents of buffer defined by one of Viper's motion commands. | |
4154 ;; Repeatable via `n' and `N'. | |
4155 (defun vip-buffer-search-enable (&optional c) | |
4156 (cond (c (setq vip-buffer-search-char c)) | |
4157 ((null vip-buffer-search-char) | |
4158 (setq vip-buffer-search-char ?g))) | |
4159 (define-key vip-vi-basic-map | |
4160 (char-to-string vip-buffer-search-char) 'vip-command-argument) | |
4161 (aset vip-exec-array vip-buffer-search-char 'vip-exec-buffer-search) | |
4162 (setq vip-prefix-commands (cons vip-buffer-search-char vip-prefix-commands))) | |
4163 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4164 ;; This is a Viper wraper for isearch-forward. |
10789 | 4165 (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
|
4166 "Do incremental search forward." |
10789 | 4167 (interactive "P") |
4168 ;; emacs bug workaround | |
4169 (if (listp arg) (setq arg (car arg))) | |
4170 (vip-exec-form-in-emacs (list 'isearch-forward arg))) | |
4171 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4172 ;; This is a Viper wraper for isearch-backward." |
10789 | 4173 (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
|
4174 "Do incremental search backward." |
10789 | 4175 (interactive "P") |
4176 ;; emacs bug workaround | |
4177 (if (listp arg) (setq arg (car arg))) | |
4178 (vip-exec-form-in-emacs (list 'isearch-backward arg))) | |
4179 | |
4180 | |
4181 ;; visiting and killing files, buffers | |
4182 | |
4183 (defun vip-switch-to-buffer () | |
4184 "Switch to buffer in the current window." | |
4185 (interactive) | |
4186 (let (buffer) | |
4187 (setq buffer | |
4188 (read-buffer | |
4189 (format "Switch to buffer in this window \(%s\): " | |
4190 (buffer-name (other-buffer (current-buffer)))))) | |
4191 (switch-to-buffer buffer) | |
4192 )) | |
4193 | |
4194 (defun vip-switch-to-buffer-other-window () | |
4195 "Switch to buffer in another window." | |
4196 (interactive) | |
4197 (let (buffer) | |
4198 (setq buffer | |
4199 (read-buffer | |
4200 (format "Switch to buffer in another window \(%s\): " | |
4201 (buffer-name (other-buffer (current-buffer)))))) | |
4202 (switch-to-buffer-other-window buffer) | |
4203 )) | |
4204 | |
4205 (defun vip-kill-buffer () | |
4206 "Kill a buffer." | |
4207 (interactive) | |
4208 (let (buffer buffer-name) | |
4209 (setq buffer-name | |
4210 (read-buffer | |
4211 (format "Kill buffer \(%s\): " | |
4212 (buffer-name (current-buffer))))) | |
4213 (setq buffer | |
4214 (if (null buffer-name) | |
4215 (current-buffer) | |
4216 (get-buffer buffer-name))) | |
4217 (if (null buffer) (error "`%s': No such buffer" buffer-name)) | |
4218 (if (or (not (buffer-modified-p buffer)) | |
4219 (y-or-n-p | |
4220 (format | |
4221 "Buffer `%s' is modified, are you sure you want to kill it? " | |
4222 buffer-name))) | |
4223 (kill-buffer buffer) | |
4224 (error "Buffer not killed")))) | |
4225 | |
4226 | |
4227 (defvar vip-smart-suffix-list '("" "tex" "c" "cc" "el" "p") | |
4228 "*List of suffixes that Viper automatically tries to append to filenames ending with a `.'. | |
4229 This is useful when you the current directory contains files with the same | |
4230 prefix and many different suffixes. Usually, only one of the suffixes | |
4231 represents an editable file. However, file completion will stop at the `.' | |
4232 The smart suffix feature lets you hit RET in such a case, and Viper will | |
4233 select the appropriate suffix. | |
4234 | |
4235 Suffixes are tried in the order given and the first suffix for which a | |
4236 corresponding file exists is selected. If no file exists for any of the | |
4237 suffixes, the user is asked to confirm. | |
4238 | |
4239 To turn this feature off, set this variable to nil.") | |
4240 | |
4241 ;; Try to add suffix to files ending with a `.' | |
4242 ;; Useful when the user hits RET on a non-completed file name. | |
4243 (defun vip-file-add-suffix () | |
4244 (let ((count 0) | |
4245 (len (length vip-smart-suffix-list)) | |
4246 (file (buffer-string)) | |
4247 found key cmd suff) | |
4248 (goto-char (point-max)) | |
4249 (if (and vip-smart-suffix-list (string-match "\\.$" file)) | |
4250 (progn | |
4251 (while (and (not found) (< count len)) | |
4252 (setq suff (nth count vip-smart-suffix-list) | |
4253 count (1+ count)) | |
4254 (if (file-exists-p (format "%s%s" file suff)) | |
4255 (progn | |
4256 (setq found t) | |
4257 (insert suff)))) | |
4258 | |
4259 (if found | |
4260 () | |
4261 (vip-tmp-insert-at-eob " [Please complete file name]") | |
4262 (unwind-protect | |
4263 (while (not (memq cmd '(exit-minibuffer vip-exit-minibuffer))) | |
4264 (setq cmd | |
4265 (key-binding (setq key (read-key-sequence nil)))) | |
4266 (cond ((eq cmd 'self-insert-command) | |
4267 (if vip-xemacs-p | |
4268 (insert (events-to-keys key)) | |
4269 (insert key))) | |
4270 ((memq cmd '(exit-minibuffer vip-exit-minibuffer)) | |
4271 nil) | |
4272 (t (command-execute cmd))) | |
4273 ))) | |
4274 )) | |
4275 )) | |
4276 | |
4277 | |
4278 ;; Advice for use in find-file and read-file-name commands. | |
4279 (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
|
4280 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer." |
10789 | 4281 (run-hooks 'vip-minibuffer-exit-hook)) |
4282 | |
4283 (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
|
4284 "Use `read-file-name' for reading arguments." |
10789 | 4285 (interactive (list (read-file-name "Find file: " |
4286 nil default-directory)))) | |
4287 | |
4288 (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
|
4289 "Use `read-file-name' for reading arguments." |
10789 | 4290 (interactive (list (read-file-name "Find file in other window: " |
4291 nil default-directory)))) | |
4292 | |
4293 (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
|
4294 "Use `read-file-name' for reading arguments." |
10789 | 4295 (interactive (list (read-file-name "Find file in other frame: " |
4296 nil default-directory)))) | |
4297 | |
4298 (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
|
4299 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." |
10789 | 4300 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) |
4301 ad-do-it)) | |
4302 | |
4303 | |
4304 | |
4305 ;; yank and pop | |
4306 | |
4307 (defsubst vip-yank (text) | |
4308 "Yank TEXT silently. This works correctly with Emacs's yank-pop command." | |
4309 (insert text) | |
4310 (setq this-command 'yank)) | |
4311 | |
4312 (defun vip-put-back (arg) | |
4313 "Put back after point/below line." | |
4314 (interactive "P") | |
4315 (let ((val (vip-p-val arg)) | |
4316 (text (if vip-use-register | |
4317 (cond ((vip-valid-register vip-use-register '(digit)) | |
4318 (current-kill (- vip-use-register ?1) 'do-not-rotate)) | |
4319 ((vip-valid-register vip-use-register) | |
4320 (get-register (downcase vip-use-register))) | |
4321 (t (error vip-InvalidRegister vip-use-register))) | |
4322 (current-kill 0)))) | |
4323 (if (null text) | |
4324 (if vip-use-register | |
4325 (let ((reg vip-use-register)) | |
4326 (setq vip-use-register nil) | |
4327 (error vip-EmptyRegister reg)) | |
4328 (error ""))) | |
4329 (setq vip-use-register nil) | |
4330 (if (vip-end-with-a-newline-p text) | |
4331 (progn | |
4332 (if (eobp) | |
4333 (insert "\n") | |
4334 (forward-line 1)) | |
4335 (beginning-of-line)) | |
4336 (if (not (eolp)) (vip-forward-char-carefully))) | |
4337 (set-marker (vip-mark-marker) (point) (current-buffer)) | |
4338 (vip-set-destructive-command | |
4339 (list 'vip-put-back val nil vip-use-register nil nil)) | |
4340 (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
|
4341 ;; 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
|
4342 ;; 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
|
4343 ;; a newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4344 (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
|
4345 (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
|
4346 (exchange-point-and-mark) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4347 (if (bolp) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4348 (back-to-indentation))) |
10789 | 4349 (vip-deactivate-mark)) |
4350 | |
4351 (defun vip-Put-back (arg) | |
4352 "Put back at point/above line." | |
4353 (interactive "P") | |
4354 (let ((val (vip-p-val arg)) | |
4355 (text (if vip-use-register | |
4356 (cond ((vip-valid-register vip-use-register '(digit)) | |
4357 (current-kill (- vip-use-register ?1) 'do-not-rotate)) | |
4358 ((vip-valid-register vip-use-register) | |
4359 (get-register (downcase vip-use-register))) | |
4360 (t (error vip-InvalidRegister vip-use-register))) | |
4361 (current-kill 0)))) | |
4362 (if (null text) | |
4363 (if vip-use-register | |
4364 (let ((reg vip-use-register)) | |
4365 (setq vip-use-register nil) | |
4366 (error vip-EmptyRegister reg)) | |
4367 (error ""))) | |
4368 (setq vip-use-register nil) | |
4369 (if (vip-end-with-a-newline-p text) (beginning-of-line)) | |
4370 (vip-set-destructive-command | |
4371 (list 'vip-Put-back val nil vip-use-register nil nil)) | |
4372 (set-marker (vip-mark-marker) (point) (current-buffer)) | |
4373 (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
|
4374 ;; 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
|
4375 ;; 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
|
4376 ;; a newline |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4377 (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
|
4378 (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
|
4379 (exchange-point-and-mark) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4380 (if (bolp) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4381 (back-to-indentation))) |
10789 | 4382 (vip-deactivate-mark)) |
4383 | |
4384 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4385 ;; Copy region to kill-ring. |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4386 ;; If BEG and END do not belong to the same buffer, copy empty region. |
10789 | 4387 (defun vip-copy-region-as-kill (beg end) |
4388 (condition-case nil | |
4389 (copy-region-as-kill beg end) | |
4390 (error (copy-region-as-kill beg beg)))) | |
4391 | |
4392 | |
4393 (defun vip-delete-char (arg) | |
4394 "Delete character." | |
4395 (interactive "P") | |
4396 (let ((val (vip-p-val arg))) | |
4397 (vip-set-destructive-command (list 'vip-delete-char val nil nil nil nil)) | |
4398 (if (> val 1) | |
4399 (save-excursion | |
4400 (let ((here (point))) | |
4401 (end-of-line) | |
4402 (if (> val (- (point) here)) | |
4403 (setq val (- (point) here)))))) | |
4404 (if (and (eq val 0) (not vip-ex-style-motion)) (setq val 1)) | |
4405 (if (and vip-ex-style-motion (eolp)) | |
4406 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch | |
4407 (if vip-use-register | |
4408 (progn | |
4409 (cond ((vip-valid-register vip-use-register '((Letter))) | |
4410 (vip-append-to-register | |
4411 (downcase vip-use-register) (point) (- (point) val))) | |
4412 ((vip-valid-register vip-use-register) | |
4413 (copy-to-register | |
4414 vip-use-register (point) (- (point) val) nil)) | |
4415 (t (error vip-InvalidRegister vip-use-register))) | |
4416 (setq vip-use-register nil))) | |
4417 (if vip-ex-style-motion | |
4418 (progn | |
4419 (delete-char val t) | |
4420 (if (and (eolp) (not (bolp))) (backward-char 1))) | |
4421 (if (eolp) | |
4422 (delete-backward-char val t) | |
4423 (delete-char val t))))) | |
4424 | |
4425 (defun vip-delete-backward-char (arg) | |
4426 "Delete previous character. On reaching beginning of line, stop and beep." | |
4427 (interactive "P") | |
4428 (let ((val (vip-p-val arg))) | |
4429 (vip-set-destructive-command | |
4430 (list 'vip-delete-backward-char val nil nil nil nil)) | |
4431 (if (> val 1) | |
4432 (save-excursion | |
4433 (let ((here (point))) | |
4434 (beginning-of-line) | |
4435 (if (> val (- here (point))) | |
4436 (setq val (- here (point))))))) | |
4437 (if vip-use-register | |
4438 (progn | |
4439 (cond ((vip-valid-register vip-use-register '(Letter)) | |
4440 (vip-append-to-register | |
4441 (downcase vip-use-register) (point) (+ (point) val))) | |
4442 ((vip-valid-register vip-use-register) | |
4443 (copy-to-register | |
4444 vip-use-register (point) (+ (point) val) nil)) | |
4445 (t (error vip-InvalidRegister vip-use-register))) | |
4446 (setq vip-use-register nil))) | |
4447 (if (bolp) (ding) | |
4448 (delete-backward-char val t)))) | |
4449 | |
4450 (defun vip-del-backward-char-in-insert () | |
4451 "Delete 1 char backwards while in insert mode." | |
4452 (interactive) | |
4453 (if (and vip-ex-style-editing-in-insert (bolp)) | |
4454 (beep 1) | |
4455 (delete-backward-char 1 t))) | |
4456 | |
4457 (defun vip-del-backward-char-in-replace () | |
4458 "Delete one character in replace mode. | |
4459 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
|
4460 charecters. If it is nil, then the cursor just moves backwards, similarly |
10789 | 4461 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
|
4462 cursor move past the beginning of line." |
10789 | 4463 (interactive) |
4464 (cond (vip-delete-backwards-in-replace | |
4465 (cond ((not (bolp)) | |
4466 (delete-backward-char 1 t)) | |
4467 (vip-ex-style-editing-in-insert | |
4468 (beep 1)) | |
4469 ((bobp) | |
4470 (beep 1)) | |
4471 (t | |
4472 (delete-backward-char 1 t)))) | |
4473 (vip-ex-style-editing-in-insert | |
4474 (if (bolp) | |
4475 (beep 1) | |
4476 (backward-char 1))) | |
4477 (t | |
4478 (backward-char 1)))) | |
4479 | |
4480 | |
4481 | |
4482 ;; join lines. | |
4483 | |
4484 (defun vip-join-lines (arg) | |
4485 "Join this line to next, if ARG is nil. Otherwise, join ARG lines." | |
4486 (interactive "*P") | |
4487 (let ((val (vip-P-val arg))) | |
4488 (vip-set-destructive-command (list 'vip-join-lines val nil nil nil nil)) | |
4489 (vip-loop (if (null val) 1 (1- val)) | |
4490 (progn | |
4491 (end-of-line) | |
4492 (if (not (eobp)) | |
4493 (progn | |
4494 (forward-line 1) | |
4495 (delete-region (point) (1- (point))) | |
4496 (fixup-whitespace))))))) | |
4497 | |
4498 | |
4499 ;; Replace state | |
4500 | |
4501 (defun vip-change (beg end) | |
4502 (if (markerp beg) (setq beg (marker-position beg))) | |
4503 (if (markerp end) (setq end (marker-position end))) | |
4504 ;; beg is sometimes (mark t), which may be nil | |
4505 (or beg (setq beg end)) | |
4506 | |
4507 (vip-set-complex-command-for-undo) | |
4508 (if vip-use-register | |
4509 (progn | |
4510 (copy-to-register vip-use-register beg end nil) | |
4511 (setq vip-use-register nil))) | |
4512 (vip-set-replace-overlay beg end) | |
4513 (setq last-command nil) ; separate repl text from prev kills | |
4514 | |
4515 (if (= (vip-replace-start) (point-max)) | |
4516 (error "End of buffer")) | |
4517 | |
4518 (setq vip-last-replace-region | |
4519 (buffer-substring (vip-replace-start) | |
4520 (vip-replace-end))) | |
4521 | |
4522 ;; protect against error while inserting "@" and other disasters | |
4523 ;; (e.g., read-only buff) | |
4524 (condition-case conds | |
4525 (if (vip-same-line (vip-replace-start) | |
4526 (vip-replace-end)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4527 (progn |
10789 | 4528 ;; tabs cause problems in replace, so untabify |
4529 (goto-char (vip-replace-end)) | |
4530 (insert-before-markers "@") ; put placeholder after the TAB | |
4531 (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
|
4532 ;; 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
|
4533 (delete-backward-char 1) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4534 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4535 (vip-set-replace-overlay-glyphs |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4536 vip-replace-region-start-delimiter |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4537 vip-replace-region-end-delimiter) |
10789 | 4538 ;; this move takes care of the last posn in the overlay, which |
4539 ;; has to be shifted because of insert. We can't simply insert | |
4540 ;; "$" before-markers because then overlay-start will shift the | |
4541 ;; beginning of the overlay in case we are replacing a single | |
4542 ;; character. This fixes the bug with `s' and `cl' commands. | |
4543 (vip-move-replace-overlay (vip-replace-start) (point)) | |
4544 (goto-char (vip-replace-start)) | |
4545 (vip-change-state-to-replace t)) | |
4546 (kill-region (vip-replace-start) | |
4547 (vip-replace-end)) | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
4548 (vip-hide-replace-overlay) |
10789 | 4549 (vip-change-state-to-insert)) |
4550 (error ;; make sure that the overlay doesn't stay. | |
4551 ;; go back to the original point | |
4552 (goto-char (vip-replace-start)) | |
4553 (vip-hide-replace-overlay) | |
4554 (vip-message-conditions conds)))) | |
4555 | |
4556 | |
4557 (defun vip-change-subr (beg end) | |
4558 ;; beg is sometimes (mark t), which may be nil | |
4559 (or beg (setq beg end)) | |
4560 | |
4561 (if vip-use-register | |
4562 (progn | |
4563 (copy-to-register vip-use-register beg end nil) | |
4564 (setq vip-use-register nil))) | |
4565 (kill-region beg end) | |
4566 (setq this-command 'vip-change) | |
4567 (vip-yank-last-insertion)) | |
4568 | |
4569 (defun vip-toggle-case (arg) | |
4570 "Toggle character case." | |
4571 (interactive "P") | |
4572 (let ((val (vip-p-val arg)) (c)) | |
4573 (vip-set-destructive-command (list 'vip-toggle-case val nil nil nil nil)) | |
4574 (while (> val 0) | |
4575 (setq c (following-char)) | |
4576 (delete-char 1 nil) | |
4577 (if (eq c (upcase c)) | |
4578 (insert-char (downcase c) 1) | |
4579 (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
|
4580 (if (eolp) (backward-char 1)) |
10789 | 4581 (setq val (1- val))))) |
4582 | |
4583 | |
4584 ;; query replace | |
4585 | |
4586 (defun vip-query-replace () | |
4587 "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
|
4588 If a null string is suplied as the string to be replaced, |
10789 | 4589 the query replace mode will toggle between string replace |
4590 and regexp replace." | |
4591 (interactive) | |
4592 (let (str) | |
4593 (setq str (vip-read-string-with-history | |
4594 (if vip-re-query-replace "Query replace regexp: " | |
4595 "Query replace: ") | |
4596 nil ; no initial | |
4597 'vip-replace1-history | |
4598 (car vip-replace1-history) ; default | |
4599 )) | |
4600 (if (string= str "") | |
4601 (progn | |
4602 (setq vip-re-query-replace (not vip-re-query-replace)) | |
4603 (message "Query replace mode changed to %s" | |
4604 (if vip-re-query-replace "regexp replace" | |
4605 "string replace"))) | |
4606 (if vip-re-query-replace | |
4607 (query-replace-regexp | |
4608 str | |
4609 (vip-read-string-with-history | |
4610 (format "Query replace regexp `%s' with: " str) | |
4611 nil ; no initial | |
4612 'vip-replace1-history | |
4613 (car vip-replace1-history) ; default | |
4614 )) | |
4615 (query-replace | |
4616 str | |
4617 (vip-read-string-with-history | |
4618 (format "Query replace `%s' with: " str) | |
4619 nil ; no initial | |
4620 'vip-replace1-history | |
4621 (car vip-replace1-history) ; default | |
4622 )))))) | |
4623 | |
4624 | |
4625 ;; marking | |
4626 | |
4627 (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
|
4628 "Mark beginning of buffer." |
10789 | 4629 (interactive) |
4630 (push-mark (point)) | |
4631 (goto-char (point-min)) | |
4632 (exchange-point-and-mark) | |
4633 (message "Mark set at the beginning of buffer")) | |
4634 | |
4635 (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
|
4636 "Mark end of buffer." |
10789 | 4637 (interactive) |
4638 (push-mark (point)) | |
4639 (goto-char (point-max)) | |
4640 (exchange-point-and-mark) | |
4641 (message "Mark set at the end of buffer")) | |
4642 | |
4643 (defun vip-mark-point () | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4644 "Set mark at point of buffer." |
10789 | 4645 (interactive) |
4646 (let ((char (vip-read-char-exclusive))) | |
4647 (cond ((and (<= ?a char) (<= char ?z)) | |
4648 (point-to-register (1+ (- char ?a)))) | |
4649 ((= char ?<) (vip-mark-beginning-of-buffer)) | |
4650 ((= char ?>) (vip-mark-end-of-buffer)) | |
4651 ((= char ?.) (vip-set-mark-if-necessary)) | |
4652 ((= char ?,) (vip-cycle-through-mark-ring)) | |
4653 ((= char ?D) (mark-defun)) | |
4654 (t (error "")) | |
4655 ))) | |
4656 | |
4657 ;; Algorithm: If first invocation of this command save mark on ring, goto | |
4658 ;; mark, M0, and pop the most recent elt from the mark ring into mark, | |
4659 ;; making it into the new mark, M1. | |
4660 ;; Push this mark back and set mark to the original point position, p1. | |
4661 ;; So, if you hit '' or `` then you can return to p1. | |
4662 ;; | |
4663 ;; If repeated command, pop top elt from the ring into mark and | |
4664 ;; jump there. This forgets the position, p1, and puts M1 back into mark. | |
4665 ;; Then we save the current pos, which is M0, jump to M1 and pop M2 from | |
4666 ;; the ring into mark. Push M2 back on the ring and set mark to M0. | |
4667 ;; etc. | |
4668 (defun vip-cycle-through-mark-ring () | |
4669 "Visit previous locations on the mark ring. | |
4670 One can use `` and '' to temporarily jump 1 step back." | |
4671 (let* ((sv-pt (point))) | |
4672 ;; if repeated `m,' command, pop the previously saved mark. | |
4673 ;; Prev saved mark is actually prev saved point. It is used if the | |
4674 ;; user types `` or '' and is discarded | |
4675 ;; from the mark ring by the next `m,' command. | |
4676 ;; In any case, go to the previous or previously saved mark. | |
4677 ;; Then push the current mark (popped off the ring) and set current | |
4678 ;; point to be the mark. Current pt as mark is discarded by the next | |
4679 ;; m, command. | |
4680 (if (eq last-command 'vip-cycle-through-mark-ring) | |
4681 () | |
4682 ;; save current mark if the first iteration | |
4683 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
4684 (if (mark t) | |
4685 (push-mark (mark t) t)) ) | |
4686 (pop-mark) | |
4687 (set-mark-command 1) | |
4688 ;; don't duplicate mark on the ring | |
4689 (setq mark-ring (delete (vip-mark-marker) mark-ring)) | |
4690 (push-mark sv-pt t) | |
4691 (vip-deactivate-mark) | |
4692 (setq this-command 'vip-cycle-through-mark-ring) | |
4693 )) | |
4694 | |
4695 | |
4696 (defun vip-goto-mark (arg) | |
4697 "Go to mark." | |
4698 (interactive "P") | |
4699 (let ((char (read-char)) | |
4700 (com (vip-getcom arg))) | |
4701 (vip-goto-mark-subr char com nil))) | |
4702 | |
4703 (defun vip-goto-mark-and-skip-white (arg) | |
4704 "Go to mark and skip to first non-white character on line." | |
4705 (interactive "P") | |
4706 (let ((char (read-char)) | |
4707 (com (vip-getCom arg))) | |
4708 (vip-goto-mark-subr char com t))) | |
4709 | |
4710 (defun vip-goto-mark-subr (char com skip-white) | |
4711 (if (eobp) | |
4712 (if (bobp) | |
4713 (error "Empty buffer") | |
4714 (backward-char 1))) | |
4715 (cond ((vip-valid-register char '(letter)) | |
4716 (let* ((buff (current-buffer)) | |
4717 (reg (1+ (- char ?a))) | |
4718 (text-marker (get-register reg))) | |
4719 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4720 (if (not (vip-valid-marker text-marker)) | |
14581
4951b11970a1
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14580
diff
changeset
|
4721 (error vip-EmptyTextmarker char)) |
10789 | 4722 (if (and (vip-same-line (point) vip-last-jump) |
4723 (= (point) vip-last-jump-ignore)) | |
4724 (push-mark vip-last-jump t) | |
4725 (push-mark nil t)) ; no msg | |
4726 (vip-register-to-point reg) | |
4727 (setq vip-last-jump (point-marker)) | |
4728 (cond (skip-white | |
4729 (back-to-indentation) | |
4730 (setq vip-last-jump-ignore (point)))) | |
4731 (if com | |
4732 (if (equal buff (current-buffer)) | |
4733 (vip-execute-com (if skip-white | |
4734 'vip-goto-mark-and-skip-white | |
4735 'vip-goto-mark) | |
4736 nil com) | |
4737 (switch-to-buffer buff) | |
4738 (goto-char vip-com-point) | |
4739 (vip-change-state-to-vi) | |
4740 (error ""))))) | |
4741 ((and (not skip-white) (= char ?`)) | |
4742 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4743 (if (and (vip-same-line (point) vip-last-jump) | |
4744 (= (point) vip-last-jump-ignore)) | |
4745 (goto-char vip-last-jump)) | |
4746 (if (= (point) (mark t)) (pop-mark)) | |
4747 (exchange-point-and-mark) | |
4748 (setq vip-last-jump (point-marker) | |
4749 vip-last-jump-ignore 0) | |
4750 (if com (vip-execute-com 'vip-goto-mark nil com))) | |
4751 ((and skip-white (= char ?')) | |
4752 (if com (vip-move-marker-locally 'vip-com-point (point))) | |
4753 (if (and (vip-same-line (point) vip-last-jump) | |
4754 (= (point) vip-last-jump-ignore)) | |
4755 (goto-char vip-last-jump)) | |
4756 (if (= (point) (mark t)) (pop-mark)) | |
4757 (exchange-point-and-mark) | |
4758 (setq vip-last-jump (point)) | |
4759 (back-to-indentation) | |
4760 (setq vip-last-jump-ignore (point)) | |
4761 (if com (vip-execute-com 'vip-goto-mark-and-skip-white nil com))) | |
4762 (t (error vip-InvalidTextmarker char)))) | |
4763 | |
4764 (defun vip-insert-tab () | |
4765 (interactive) | |
4766 (insert-tab)) | |
4767 | |
4768 (defun vip-exchange-point-and-mark () | |
4769 (interactive) | |
4770 (exchange-point-and-mark) | |
4771 (back-to-indentation)) | |
4772 | |
4773 ;; Input Mode Indentation | |
4774 | |
14384
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4775 ;; 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
|
4776 (defsubst vip-looking-back (str) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4777 (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
|
4778 (= (point) (match-end 0)))) |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4779 |
854325337547
Moved code around to minimize compiler warnings.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14276
diff
changeset
|
4780 |
10789 | 4781 (defun vip-forward-indent () |
4782 "Indent forward -- `C-t' in Vi." | |
4783 (interactive) | |
4784 (setq vip-cted t) | |
4785 (indent-to (+ (current-column) vip-shift-width))) | |
4786 | |
4787 (defun vip-backward-indent () | |
4788 "Backtab, C-d in VI" | |
4789 (interactive) | |
4790 (if vip-cted | |
4791 (let ((p (point)) (c (current-column)) bol (indent t)) | |
4792 (if (vip-looking-back "[0^]") | |
4793 (progn | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4794 (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
|
4795 (setq vip-preserve-indent t)) |
10789 | 4796 (delete-backward-char 1) |
4797 (setq p (point)) | |
4798 (setq indent nil))) | |
4799 (save-excursion | |
4800 (beginning-of-line) | |
4801 (setq bol (point))) | |
4802 (if (re-search-backward "[^ \t]" bol 1) (forward-char)) | |
4803 (delete-region (point) p) | |
4804 (if indent | |
4805 (indent-to (- c vip-shift-width))) | |
4806 (if (or (bolp) (vip-looking-back "[^ \t]")) | |
4807 (setq vip-cted nil))))) | |
4808 | |
4809 (defun vip-autoindent () | |
4810 "Auto Indentation, Vi-style." | |
4811 (interactive) | |
4812 (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
|
4813 (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
|
4814 (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
|
4815 (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
|
4816 ;; don't leave whitespace lines around |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4817 (if (memq last-command |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4818 '(vip-autoindent |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4819 vip-open-line vip-Open-line |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
4820 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
|
4821 (indent-to-left-margin)) |
10789 | 4822 (newline 1) |
4823 (if vip-auto-indent | |
4824 (progn | |
4825 (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
|
4826 (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
|
4827 (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
|
4828 (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
|
4829 )) |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
4830 )) |
10789 | 4831 |
4832 | |
4833 ;; Viewing registers | |
4834 | |
4835 (defun vip-ket-function (arg) | |
4836 "Function called by \], the ket. View registers and call \]\]." | |
4837 (interactive "P") | |
4838 (let ((reg (read-char))) | |
4839 (cond ((vip-valid-register reg '(letter Letter)) | |
4840 (view-register (downcase reg))) | |
4841 ((vip-valid-register reg '(digit)) | |
4842 (let ((text (current-kill (- reg ?1) 'do-not-rotate))) | |
4843 (save-excursion | |
4844 (set-buffer (get-buffer-create "*Output*")) | |
4845 (delete-region (point-min) (point-max)) | |
4846 (insert (format "Register %c contains the string:\n" reg)) | |
4847 (insert text) | |
4848 (goto-char (point-min))) | |
4849 (display-buffer "*Output*"))) | |
4850 ((= ?\] reg) | |
4851 (vip-next-heading arg)) | |
4852 (t (error | |
4853 vip-InvalidRegister reg))))) | |
4854 | |
4855 (defun vip-brac-function (arg) | |
4856 "Function called by \[, the brac. View textmarkers and call \[\[" | |
4857 (interactive "P") | |
4858 (let ((reg (read-char))) | |
4859 (cond ((= ?\[ reg) | |
4860 (vip-prev-heading arg)) | |
4861 ((= ?\] reg) | |
4862 (vip-heading-end arg)) | |
4863 ((vip-valid-register reg '(letter)) | |
4864 (let* ((val (get-register (1+ (- reg ?a)))) | |
4865 (buf (if (not val) | |
14580
1883960762e0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14579
diff
changeset
|
4866 (error vip-EmptyTextmarker reg) |
10789 | 4867 (marker-buffer val))) |
4868 (pos (marker-position val)) | |
4869 line-no text (s pos) (e pos)) | |
4870 (save-excursion | |
4871 (set-buffer (get-buffer-create "*Output*")) | |
4872 (delete-region (point-min) (point-max)) | |
4873 (if (and buf pos) | |
4874 (progn | |
4875 (save-excursion | |
4876 (set-buffer buf) | |
4877 (setq line-no (1+ (count-lines (point-min) val))) | |
4878 (goto-char pos) | |
4879 (beginning-of-line) | |
4880 (if (re-search-backward "[^ \t]" nil t) | |
4881 (progn | |
4882 (beginning-of-line) | |
4883 (setq s (point)))) | |
4884 (goto-char pos) | |
4885 (forward-line 1) | |
4886 (if (re-search-forward "[^ \t]" nil t) | |
4887 (progn | |
4888 (end-of-line) | |
4889 (setq e (point)))) | |
4890 (setq text (buffer-substring s e)) | |
4891 (setq text (format "%s<%c>%s" | |
4892 (substring text 0 (- pos s)) | |
4893 reg (substring text (- pos s))))) | |
4894 (insert | |
4895 (format | |
4896 "Textmarker `%c' is in buffer `%s' at line %d.\n" | |
4897 reg (buffer-name buf) line-no)) | |
4898 (insert (format "Here is some text around %c:\n\n %s" | |
4899 reg text))) | |
4900 (insert (format vip-EmptyTextmarker reg))) | |
4901 (goto-char (point-min))) | |
4902 (display-buffer "*Output*"))) | |
4903 (t (error vip-InvalidTextmarker reg))))) | |
4904 | |
4905 | |
4906 | |
4907 ;; commands in insertion mode | |
4908 | |
4909 (defun vip-delete-backward-word (arg) | |
4910 "Delete previous word." | |
4911 (interactive "p") | |
4912 (save-excursion | |
4913 (push-mark nil t) | |
4914 (backward-word arg) | |
4915 (delete-region (point) (mark t)) | |
4916 (pop-mark))) | |
4917 | |
4918 | |
4919 (defun vip-set-expert-level (&optional dont-change-unless) | |
4920 "Sets the expert level for a Viper user. | |
4921 Can be called interactively to change (temporarily or permanently) the | |
4922 current expert level. | |
4923 | |
4924 The optional argument DONT-CHANGE-UNLESS if not nil, says that | |
4925 the level should not be changed, unless its current value is | |
4926 meaningless (i.e., not one of 1,2,3,4,5). | |
4927 | |
4928 User level determines the setting of Viper variables that are most | |
4929 sensitive for VI-style look-and-feel." | |
4930 | |
4931 (interactive) | |
4932 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
4933 (if (not (natnump vip-expert-level)) (setq vip-expert-level 0)) |
10789 | 4934 |
4935 (save-window-excursion | |
4936 (delete-other-windows) | |
4937 ;; if 0 < vip-expert-level < vip-max-expert-level | |
4938 ;; & dont-change-unless = t -- use it; else ask | |
4939 (vip-ask-level dont-change-unless)) | |
4940 | |
4941 (setq vip-always t | |
4942 vip-ex-style-motion t | |
4943 vip-ex-style-editing-in-insert t | |
4944 vip-want-ctl-h-help nil) | |
4945 | |
4946 (cond | |
4947 ;; a novice or a beginner | |
4948 ((eq vip-expert-level 1) | |
4949 (global-set-key vip-toggle-key ;; in emacs-state | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4950 (if (vip-window-display-p) |
10789 | 4951 'vip-iconify |
4952 'suspend-emacs)) | |
4953 (setq vip-no-multiple-ESC t | |
4954 vip-re-search t | |
4955 vip-vi-style-in-minibuffer t | |
4956 vip-search-wrap-around-t t | |
4957 vip-want-emacs-keys-in-vi nil | |
4958 vip-want-emacs-keys-in-insert nil)) | |
4959 | |
4960 ;; an intermediate to guru | |
4961 ((and (> vip-expert-level 1) (< vip-expert-level 5)) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
4962 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) |
10789 | 4963 vip-want-emacs-keys-in-vi t |
4964 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
|
4965 |
10789 | 4966 (if (eq vip-expert-level 4) ; respect user's ex-style motions |
4967 ; and vip-no-multiple-ESC | |
4968 (progn | |
4969 (setq-default vip-ex-style-editing-in-insert | |
4970 (cdr (assoc 'vip-ex-style-editing-in-insert | |
4971 vip-saved-user-settings)) | |
4972 vip-ex-style-motion | |
4973 (cdr (assoc 'vip-ex-style-motion | |
4974 vip-saved-user-settings))) | |
4975 (setq vip-ex-style-motion | |
4976 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings)) | |
4977 vip-ex-style-editing-in-insert | |
4978 (cdr (assoc 'vip-ex-style-editing-in-insert | |
4979 vip-saved-user-settings)) | |
4980 vip-re-search | |
4981 (cdr (assoc 'vip-re-search vip-saved-user-settings)) | |
4982 vip-no-multiple-ESC | |
4983 (cdr (assoc 'vip-no-multiple-ESC | |
4984 vip-saved-user-settings)))))) | |
4985 | |
4986 ;; A wizard | |
4987 ;; Ideally, if 5 is selected, a buffer should pop up to let the | |
4988 ;; user toggle variable values. | |
4989 (t (setq-default vip-ex-style-editing-in-insert | |
4990 (cdr (assoc 'vip-ex-style-editing-in-insert | |
4991 vip-saved-user-settings)) | |
4992 vip-ex-style-motion | |
4993 (cdr (assoc 'vip-ex-style-motion | |
4994 vip-saved-user-settings))) | |
4995 (setq vip-want-ctl-h-help | |
4996 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings)) | |
4997 vip-always | |
4998 (cdr (assoc 'vip-always vip-saved-user-settings)) | |
4999 vip-no-multiple-ESC | |
5000 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings)) | |
5001 vip-ex-style-motion | |
5002 (cdr (assoc 'vip-ex-style-motion vip-saved-user-settings)) | |
5003 vip-ex-style-editing-in-insert | |
5004 (cdr (assoc 'vip-ex-style-editing-in-insert | |
5005 vip-saved-user-settings)) | |
5006 vip-re-search | |
5007 (cdr (assoc 'vip-re-search vip-saved-user-settings)) | |
5008 vip-want-emacs-keys-in-vi | |
5009 (cdr (assoc 'vip-want-emacs-keys-in-vi | |
5010 vip-saved-user-settings)) | |
5011 vip-want-emacs-keys-in-insert | |
5012 (cdr (assoc 'vip-want-emacs-keys-in-insert | |
5013 vip-saved-user-settings))))) | |
5014 (vip-set-mode-vars-for vip-current-state) | |
5015 (if (or vip-always | |
5016 (and (> vip-expert-level 0) (> 5 vip-expert-level))) | |
5017 (vip-set-hooks))) | |
5018 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5019 ;; Ask user expert level. |
10789 | 5020 (defun vip-ask-level (dont-change-unless) |
5021 (let ((ask-buffer " *vip-ask-level*") | |
5022 level-changed repeated) | |
5023 (save-window-excursion | |
5024 (switch-to-buffer ask-buffer) | |
5025 | |
5026 (or (eq this-command 'vip-set-expert-level) | |
5027 (and | |
5028 (<= vip-expert-level vip-max-expert-level) | |
5029 (>= vip-expert-level 1)) | |
5030 (progn | |
5031 (insert " | |
5032 | |
5033 *** Important Notice for VIP users*** | |
5034 | |
5035 This is VIPER | |
5036 | |
5037 @joke | |
5038 Viper Is a Package for Emacs Rebels, | |
5039 a VI Plan for Emacs Rescue, | |
5040 and a venomous VI PERil. | |
5041 @end joke | |
5042 | |
5043 Technically speaking, Viper is a new Vi emulator that replaces | |
5044 the old VIP package. | |
5045 | |
5046 Viper emulates Vi much better than VIP. It also significantly | |
5047 extends and improves upon Vi in many useful ways. | |
5048 | |
5049 Although many VIP settings in your ~/.vip are compatible with Viper, | |
5050 you may have to change some of them. Please refer to the documentation, | |
5051 which can be obtained by executing | |
5052 | |
5053 :help | |
5054 | |
5055 when Viper is in Vi state. | |
5056 | |
5057 If you will be so lucky as to find a bug, report it via the command | |
5058 | |
5059 :submitReport | |
5060 | |
5061 Type any key to continue... ") | |
5062 | |
5063 (read-char) | |
5064 (erase-buffer))) | |
5065 | |
5066 (while (or (> vip-expert-level vip-max-expert-level) | |
5067 (< vip-expert-level 1) | |
5068 (null dont-change-unless)) | |
5069 (erase-buffer) | |
5070 (if repeated | |
5071 (progn | |
5072 (message "Invalid user level") | |
5073 (beep 1)) | |
5074 (setq repeated t)) | |
5075 (setq dont-change-unless t | |
5076 level-changed t) | |
5077 (insert " | |
5078 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
|
5079 (and the VI Plan for Emacs Rescue). |
10789 | 5080 You can change it at any time by typing `M-x vip-set-expert-level RET' |
5081 | |
5082 1 -- BEGINNER: Almost all Emacs features are suppressed. | |
5083 Feels almost like straight Vi. File name completion and | |
5084 command history in the minibuffer are thrown in as a bonus. | |
5085 To use Emacs productively, you must reach level 3 or higher. | |
5086 2 -- MASTER: C-c now has its standard Emacs meaning in Vi command state, | |
5087 so most Emacs commands can be used when Viper is in Vi state. | |
5088 Good progress---you are well on the way to level 3! | |
5089 3 -- GRAND MASTER: Like 3, but most Emacs commands are available also | |
5090 in Viper's insert state. | |
5091 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC, | |
5092 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert | |
5093 variables. Adjust these settings to your taste. | |
5094 5 -- WIZARD: Like 4, but user settings are also respected for vip-always, | |
5095 vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, and | |
5096 vip-want-emacs-keys-in-insert. Adjust these to your taste. | |
5097 | |
5098 Please, specify your level now: ") | |
5099 | |
5100 (setq vip-expert-level (- (vip-read-char-exclusive) ?0)) | |
5101 ) ; end while | |
5102 | |
5103 ;; tell the user if level was changed | |
5104 (and level-changed | |
5105 (progn | |
5106 (insert | |
5107 (format "\n\n\n\n\n\t\tYou have selected user level %d" | |
5108 vip-expert-level)) | |
5109 (if (y-or-n-p "Do you wish to make this change permanent? ") | |
5110 ;; save the setting for vip-expert-level | |
5111 (vip-save-setting | |
5112 'vip-expert-level | |
5113 (format "Saving user level %d ..." vip-expert-level) | |
5114 vip-custom-file-name)) | |
5115 )) | |
5116 (bury-buffer) ; remove ask-buffer from screen | |
5117 (message "") | |
5118 ))) | |
5119 | |
5120 | |
5121 (defun viper-version () | |
5122 (interactive) | |
5123 (message "Viper version is %s" viper-version)) | |
5124 | |
5125 (defalias 'vip-version 'viper-version) | |
5126 | |
5127 (defun vip-nil () | |
5128 (interactive) | |
5129 (beep 1)) | |
5130 | |
5131 | |
5132 ;; if ENFORCE-BUFFER is not nil, error if CHAR is a marker in another buffer | |
5133 (defun vip-register-to-point (char &optional enforce-buffer) | |
5134 "Like jump-to-register, but switches to another buffer in another window." | |
5135 (interactive "cViper register to point: ") | |
5136 (let ((val (get-register char))) | |
5137 (cond | |
5138 ((and (fboundp 'frame-configuration-p) | |
5139 (frame-configuration-p val)) | |
5140 (set-frame-configuration val)) | |
5141 ((window-configuration-p val) | |
5142 (set-window-configuration val)) | |
5143 ((vip-valid-marker val) | |
5144 (if (and enforce-buffer | |
5145 (not (equal (current-buffer) (marker-buffer val)))) | |
5146 (error (concat vip-EmptyTextmarker " in this buffer") | |
5147 (1- (+ char ?a)))) | |
5148 (pop-to-buffer (marker-buffer val)) | |
5149 (goto-char val)) | |
5150 ((and (consp val) (eq (car val) 'file)) | |
5151 (find-file (cdr val))) | |
5152 (t | |
5153 (error vip-EmptyTextmarker (1- (+ char ?a))))))) | |
5154 | |
5155 | |
5156 (defun vip-save-kill-buffer () | |
5157 "Save then kill current buffer. " | |
5158 (interactive) | |
5159 (if (< vip-expert-level 2) | |
5160 (save-buffers-kill-emacs) | |
5161 (save-buffer) | |
5162 (kill-buffer (current-buffer)))) | |
5163 | |
5164 | |
5165 | |
5166 ;;; Bug Report | |
5167 | |
5168 (defun vip-submit-report () | |
5169 "Submit bug report on Viper." | |
5170 (interactive) | |
5171 (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
|
5172 (vip-device-type (vip-device-type)) |
10789 | 5173 color-display-p frame-parameters |
5174 minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face | |
5175 varlist salutation window-config) | |
5176 | |
5177 ;; If mode info is needed, add variable to `let' and then set it below, | |
5178 ;; 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
|
5179 (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
|
5180 (vip-color-display-p) |
10789 | 5181 'non-x) |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5182 minibuffer-vi-face (if (vip-has-face-support-p) |
10789 | 5183 (vip-get-face vip-minibuffer-vi-face) |
5184 'non-x) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5185 minibuffer-insert-face (if (vip-has-face-support-p) |
10789 | 5186 (vip-get-face vip-minibuffer-insert-face) |
5187 'non-x) | |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5188 minibuffer-emacs-face (if (vip-has-face-support-p) |
10789 | 5189 (vip-get-face vip-minibuffer-emacs-face) |
5190 'non-x) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5191 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
|
5192 (frame-parameters (selected-frame)))) |
10789 | 5193 |
5194 (setq varlist (list 'vip-vi-minibuffer-minor-mode | |
5195 'vip-insert-minibuffer-minor-mode | |
5196 'vip-vi-intercept-minor-mode | |
5197 'vip-vi-local-user-minor-mode | |
5198 'vip-vi-kbd-minor-mode | |
5199 'vip-vi-global-user-minor-mode | |
5200 'vip-vi-state-modifier-minor-mode | |
5201 'vip-vi-diehard-minor-mode | |
5202 'vip-vi-basic-minor-mode | |
5203 'vip-replace-minor-mode | |
5204 'vip-insert-intercept-minor-mode | |
5205 'vip-insert-local-user-minor-mode | |
5206 'vip-insert-kbd-minor-mode | |
5207 'vip-insert-global-user-minor-mode | |
5208 'vip-insert-state-modifier-minor-mode | |
5209 'vip-insert-diehard-minor-mode | |
5210 'vip-insert-basic-minor-mode | |
5211 'vip-emacs-intercept-minor-mode | |
5212 'vip-emacs-local-user-minor-mode | |
5213 'vip-emacs-kbd-minor-mode | |
5214 'vip-emacs-global-user-minor-mode | |
5215 'vip-emacs-state-modifier-minor-mode | |
5216 'vip-automatic-iso-accents | |
5217 'vip-want-emacs-keys-in-insert | |
5218 'vip-want-emacs-keys-in-vi | |
5219 'vip-keep-point-on-undo | |
5220 'vip-no-multiple-ESC | |
5221 'vip-ESC-key | |
5222 'vip-want-ctl-h-help | |
5223 'vip-ex-style-editing-in-insert | |
5224 'vip-delete-backwards-in-replace | |
5225 '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
|
5226 '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
|
5227 '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
|
5228 '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
|
5229 'vip-emacs-state-hook |
10789 | 5230 'ex-cycle-other-window |
5231 'ex-cycle-through-non-files | |
5232 'vip-expert-level | |
5233 'major-mode | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5234 'vip-device-type |
10789 | 5235 'color-display-p |
5236 'frame-parameters | |
5237 'minibuffer-vi-face | |
5238 'minibuffer-insert-face | |
5239 'minibuffer-emacs-face | |
5240 )) | |
5241 (setq salutation " | |
5242 Congratulations! You may have unearthed a bug in Viper! | |
5243 Please mail a concise, accurate summary of the problem to the address above. | |
5244 | |
5245 -------------------------------------------------------------------") | |
5246 (setq window-config (current-window-configuration)) | |
5247 (with-output-to-temp-buffer " *vip-info*" | |
5248 (switch-to-buffer " *vip-info*") | |
5249 (delete-other-windows) | |
5250 (princ " | |
5251 PLEASE FOLLOW THESE PROCEDURES | |
5252 ------------------------------ | |
5253 | |
5254 Before reporting a bug, please verify that it is related to Viper, and is | |
5255 not cause by other packages you are using. | |
5256 | |
5257 Don't report compilation warnings, unless you are certain that there is a | |
5258 problem. These warnings are normal and unavoidable. | |
5259 | |
5260 Please note that users should not modify variables and keymaps other than | |
5261 those advertised in the manual. Such `customization' is likely to crash | |
5262 Viper, as it would any other improperly customized Emacs package. | |
5263 | |
5264 If you are reporting an error message received while executing one of the | |
5265 Viper commands, type: | |
5266 | |
5267 M-x set-variable <Return> debug-on-error <Return> t <Return> | |
5268 | |
5269 Then reproduce the error. The above command will cause Emacs to produce a | |
5270 back trace of the execution that leads to the error. Please include this | |
5271 trace in your bug report. | |
5272 | |
5273 If you believe that one of Viper's commands goes into an infinite loop | |
5274 \(e.g., Emacs freezes\), type: | |
5275 | |
5276 M-x set-variable <Return> debug-on-quit <Return> t <Return> | |
5277 | |
5278 Then reproduce the problem. Wait for a few seconds, then type C-g to abort | |
5279 the current command. Include the resulting back trace in the bug report. | |
5280 | |
5281 Mail anyway (y or n)? ") | |
5282 (if (y-or-n-p "Mail anyway? ") | |
5283 () | |
5284 (set-window-configuration window-config) | |
5285 (error "Bug report aborted"))) | |
5286 | |
5287 (require 'reporter) | |
5288 (set-window-configuration window-config) | |
5289 | |
5290 (reporter-submit-bug-report "kifer@cs.sunysb.edu" | |
5291 (vip-version) | |
5292 varlist | |
5293 nil 'delete-other-windows | |
5294 salutation) | |
5295 )) | |
5296 | |
5297 | |
5298 | |
5299 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5300 ;; Smoothes out the difference between Emacs' unread-command-events |
10789 | 5301 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of |
5302 ;; events or a sequence of keys. | |
5303 ;; | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5304 ;; 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
|
5305 ;; 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
|
5306 ;; 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
|
5307 ;; common symbol that might appear in this wrong context. |
10789 | 5308 (defun vip-set-unread-command-events (arg) |
5309 (if vip-emacs-p | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5310 (setq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5311 unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5312 (let ((new-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5313 (cond ((eventp arg) (list arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5314 ((listp arg) arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5315 ((sequencep arg) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5316 (listify-key-sequence arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5317 (t (error |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5318 "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
|
5319 arg))))) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5320 (if (not (eventp nil)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5321 (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
|
5322 (append new-events unread-command-events))) |
10789 | 5323 ;; XEmacs |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5324 (setq |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5325 unread-command-events |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5326 (append |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5327 (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
|
5328 ((eventp arg) (list arg)) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5329 ((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
|
5330 ((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
|
5331 ((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
|
5332 (t (error |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5333 "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
|
5334 unread-command-events)))) |
12691
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5335 |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5336 ;; 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
|
5337 (defun vip-eventify-list-xemacs (lis) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5338 (mapcar |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5339 (function (lambda (elt) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5340 (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
|
5341 ((eventp elt) elt) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5342 (t (error |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5343 "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
|
5344 elt))))) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5345 lis)) |
7bd050135516
(vip-info-file-name): variable removed.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12203
diff
changeset
|
5346 |
10789 | 5347 |
5348 | |
5349 ;;; Bring in the rest of the files | |
5350 (require 'viper-mous) | |
5351 (require 'viper-macs) | |
5352 (require 'viper-ex) | |
5353 | |
5354 | |
5355 | |
5356 ;; The following is provided for compatibility with older VIP's | |
5357 | |
5358 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) | |
5359 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) | |
5360 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) | |
5361 | |
5362 | |
5363 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5364 ;;; 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
|
5365 |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5366 ;; 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
|
5367 (defun vip-comint-mode-hook () |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5368 (setq require-final-newline nil) |
10789 | 5369 (setq vip-ex-style-editing-in-insert nil |
5370 vip-ex-style-motion nil) | |
5371 (vip-add-local-keys 'vi-state | |
5372 '(("\C-m" . comint-send-input) ; return | |
5373 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d | |
5374 (vip-add-local-keys 'insert-state | |
5375 '(("\C-m" . comint-send-input) ; return | |
5376 ("\C-d" . comint-delchar-or-maybe-eof))) ; \C-d | |
5377 ) | |
5378 | |
5379 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5380 ;; This sets major mode hooks to make them come up in vi-state. |
10789 | 5381 (defun vip-set-hooks () |
5382 | |
5383 ;; It is of course a misnomer to call viper-mode a `major mode'. | |
5384 ;; However, this has the effect that if the user didn't specify the | |
5385 ;; default mode, new buffers that fall back on the default will come up | |
5386 ;; in Fundamental Mode and Vi state. | |
5387 (setq default-major-mode 'viper-mode) | |
5388 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5389 ;; The following major modes should come up in vi-state |
10789 | 5390 (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
|
5391 "Run `vip-change-state-to-vi' on entry." |
10789 | 5392 (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
|
5393 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5394 (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
|
5395 (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
|
5396 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5397 (defvar help-mode-hook) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5398 (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
|
5399 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5400 (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
|
5401 (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
|
5402 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5403 (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
|
5404 (add-hook 'html-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5405 (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
|
5406 (add-hook 'html-helper-mode-hook 'viper-mode) |
10789 | 5407 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5408 (defvar emacs-lisp-mode-hook) |
10789 | 5409 (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
|
5410 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5411 (defvar lisp-mode-hook) |
10789 | 5412 (add-hook 'lisp-mode-hook 'viper-mode) |
5413 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5414 (defvar bibtex-mode-hook) |
10789 | 5415 (add-hook 'bibtex-mode-hook 'viper-mode) |
5416 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5417 (defvar cc-mode-hook) |
10789 | 5418 (add-hook 'cc-mode-hook 'viper-mode) |
5419 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5420 (defvar c-mode-hook) |
10789 | 5421 (add-hook 'c-mode-hook 'viper-mode) |
5422 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5423 (defvar c++-mode-hook) |
10789 | 5424 (add-hook 'c++-mode-hook 'viper-mode) |
5425 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5426 (defvar lisp-interaction-mode-hook) |
10789 | 5427 (add-hook 'lisp-interaction-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5428 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5429 (defvar fortran-mode-hook) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5430 (add-hook 'fortran-mode-hook 'vip-mode) |
10789 | 5431 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5432 (defvar text-mode-hook) |
10789 | 5433 (add-hook 'text-mode-hook 'viper-mode) |
5434 | |
5435 (add-hook 'completion-list-mode-hook 'viper-mode) | |
5436 (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
|
5437 |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5438 (add-hook 'perl-mode-hook 'viper-mode) |
14579
a81dd4e9603a
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14434
diff
changeset
|
5439 (add-hook 'tcl-mode-hook 'viper-mode) |
10789 | 5440 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5441 (defvar emerge-startup-hook) |
10789 | 5442 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) |
5443 ;; Run vip-change-state-to-vi after quitting emerge. | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5444 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5445 "emerge" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5446 '(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
|
5447 "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
|
5448 (vip-change-state-to-vi))) |
10789 | 5449 ;; In case Emerge was loaded before Viper. |
5450 (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
|
5451 "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
|
5452 (vip-change-state-to-vi)) |
10789 | 5453 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5454 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5455 "asm-mode" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5456 '(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
|
5457 "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
|
5458 (vip-change-state-to-vi))) |
10789 | 5459 |
5460 ;; 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
|
5461 ;; thus overriding the local map. We don't need Vi mode here. |
10789 | 5462 (vip-eval-after-load |
5463 "passwd" | |
5464 '(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
|
5465 "Switch to emacs state while reading password." |
10789 | 5466 (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
|
5467 |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5468 (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
|
5469 "prolog" |
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5470 '(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
|
5471 "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
|
5472 (vip-change-state-to-vi))) |
10789 | 5473 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5474 ;; Emacs shell, ange-ftp, and comint-based modes |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5475 (defvar comint-mode-hook) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5476 (add-hook 'comint-mode-hook 'vip-change-state-to-insert) |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5477 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) |
10789 | 5478 |
5479 ;; Shell scripts | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5480 (defvar sh-mode-hook) |
10789 | 5481 (add-hook 'sh-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5482 (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
|
5483 (add-hook 'ksh-mode-hook 'viper-mode) |
10789 | 5484 |
5485 ;; Dired | |
5486 ;; This is only necessary when the user uses vip-modify-major-mode | |
5487 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) | |
5488 | |
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 (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
|
5490 (progn |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5491 (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
|
5492 (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
|
5493 (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
|
5494 "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
|
5495 (vip-change-state-to-emacs)) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5496 (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
|
5497 (add-hook 'view-hook 'vip-change-state-to-emacs)) |
10789 | 5498 |
5499 ;; For VM users. | |
5500 ;; Put summary and other VM buffers in Emacs state. | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5501 (defvar vm-mode-hooks) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
5502 (defvar vm-summary-mode-hooks) |
10789 | 5503 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs) |
5504 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs) | |
5505 | |
5506 ;; For RMAIL users. | |
5507 ;; Put buf in Emacs state after edit. | |
5508 (vip-eval-after-load | |
5509 "rmailedit" | |
5510 '(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
|
5511 "Switch to emacs state when done editing message." |
10789 | 5512 (vip-change-state-to-emacs))) |
5513 ;; In case RMAIL was loaded before Viper. | |
5514 (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
|
5515 "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
|
5516 (vip-change-state-to-emacs)) |
10789 | 5517 ) ; vip-set-hooks |
5518 | |
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
|
5519 ;; 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
|
5520 ;; 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
|
5521 |
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
|
5522 ;; 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
|
5523 (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
|
5524 (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
|
5525 [(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
|
5526 ;; 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
|
5527 (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
|
5528 (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
|
5529 [(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
|
5530 |
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
|
5531 ;; 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
|
5532 (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
|
5533 "//" '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
|
5534 [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
|
5535 ;; 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
|
5536 (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
|
5537 "///" '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
|
5538 [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
|
5539 |
10789 | 5540 |
5541 ;; ~/.vip is loaded if it exists | |
5542 (if (and (file-exists-p vip-custom-file-name) | |
5543 (not noninteractive)) | |
5544 (load vip-custom-file-name)) | |
5545 | |
5546 ;; VIP compatibility: merge whatever the user has in vip-mode-map into | |
5547 ;; Viper's basic map. | |
5548 (vip-add-keymap vip-mode-map vip-vi-global-user-map) | |
5549 | |
5550 | |
5551 ;; Applying Viper customization -- runs after (load .vip) | |
5552 | |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
5553 ;; Save user settings or Viper defaults for vars controled by vip-expert-level |
10789 | 5554 (setq vip-saved-user-settings |
5555 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) | |
5556 (cons 'vip-always vip-always) | |
5557 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) | |
5558 (cons 'vip-ex-style-motion vip-ex-style-motion) | |
5559 (cons 'vip-ex-style-editing-in-insert | |
5560 vip-ex-style-editing-in-insert) | |
5561 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi) | |
5562 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) | |
5563 (cons 'vip-re-search vip-re-search))) | |
5564 | |
5565 | |
5566 (vip-set-minibuffer-style) | |
5567 (vip-set-minibuffer-faces) | |
5568 (vip-set-search-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
|
5569 (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
|
5570 (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
|
5571 (vip-update-alphanumeric-class) |
10789 | 5572 |
5573 ;;; Familiarize Viper with some minor modes that have their own keymaps | |
5574 (vip-harness-minor-mode "compile") | |
5575 (vip-harness-minor-mode "outline") | |
5576 (vip-harness-minor-mode "allout") | |
5577 (vip-harness-minor-mode "xref") | |
5578 (vip-harness-minor-mode "lmenu") | |
5579 (vip-harness-minor-mode "vc") | |
5580 (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
|
5581 (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
|
5582 (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
|
5583 (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
|
5584 (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
|
5585 (vip-harness-minor-mode "view") |
10789 | 5586 |
5587 | |
5588 ;; Intercept maps could go in viper-keym.el | |
5589 ;; We keep them here in case someone redefines them in ~/.vip | |
5590 | |
5591 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
5592 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
5593 | |
5594 ;; This is taken care of by vip-insert-global-user-map. | |
5595 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key) | |
5596 | |
5597 (define-key vip-insert-intercept-map vip-toggle-key 'vip-alternate-ESC) | |
5598 ;; The default vip-toggle-key is \C-z; for the novice, it suspends or | |
5599 ;; iconifies Emacs | |
5600 (define-key vip-vi-intercept-map vip-toggle-key | |
5601 '(lambda () (interactive) | |
5602 (if (and (< vip-expert-level 2) (equal vip-toggle-key "\C-z")) | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
5603 (if (vip-window-display-p) (vip-iconify) (suspend-emacs)) |
10789 | 5604 (vip-change-state-to-emacs)))) |
5605 | |
5606 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) | |
5607 | |
5608 | |
5609 (if (or vip-always | |
5610 (and (< vip-expert-level 5) (> vip-expert-level 0))) | |
5611 (vip-set-hooks)) | |
5612 | |
5613 ;; Let all minor modes take effect after loading | |
5614 ;; this may not be enough, so we also set default minor-mode-alist. | |
5615 ;; Without setting the default, new buffers that come up in emacs mode have | |
5616 ;; minor-mode-map-alist = nil, unless we call vip-change-state-* | |
5617 (if (eq vip-current-state 'emacs-state) | |
5618 (progn | |
5619 (vip-change-state-to-emacs) | |
5620 (setq-default minor-mode-map-alist minor-mode-map-alist) | |
5621 )) | |
5622 | |
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
|
5623 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
5624 (run-hooks 'vip-load-hook) ; the last chance to change something |
10789 | 5625 |
5626 (provide 'viper) | |
5627 (provide 'vip19) | |
5628 (provide 'vip) | |
5629 | |
5630 ;;; viper.el ends here |