Mercurial > emacs
annotate lisp/emulation/viper.el @ 18999:4d5237dec736 libc-970727 libc-970728
Recognize SunOS 3.x.
author | Per Bothner <bothner@cygnus.com> |
---|---|
date | Sat, 26 Jul 1997 19:01:01 +0000 |
parents | 506ec0258d63 |
children | dfbef8117c6a |
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 |
18047 | 9 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
10 | |
18958 | 11 (defconst viper-version "2.95 of July 23, 1997" |
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. | |
18839 | 153 ;; Novice users, however, may want to set their viper-expert-level to 1 |
10789 | 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 ;; | |
18839 | 159 ;; A skilled user should set viper-expert-level to at least 3. This will |
15739 | 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 | |
18839 | 164 ;; (setq viper-expert-level 4) |
165 ;; in their ~/.viper files. This will unsuppress all Emacs keys that are not | |
10789 | 166 ;; essential for VI-style editing. |
167 ;; Pick-and-choose users may want to put | |
18839 | 168 ;; (setq viper-expert-level 5) |
169 ;; in ~/.viper. Viper will then leave it up to the user to set the variables | |
170 ;; vip-want-* See viper-set-expert-level for details. | |
10789 | 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 | |
18172 | 303 ;; compiler pacifier |
304 (defvar mark-even-if-inactive) | |
18839 | 305 (defvar viper-expert-level) |
306 (defvar vip-expert-level) | |
18172 | 307 |
308 ;; loading happens only in non-interactive compilation | |
309 ;; in order to spare non-viperized emacs from being viperized | |
310 (if noninteractive | |
311 (eval-when-compile | |
312 (let ((load-path (cons (expand-file-name ".") load-path))) | |
18907 | 313 (or (featurep 'viper-init) |
314 (load "viper-init.el" nil nil 'nosuffix)) | |
18172 | 315 (or (featurep 'viper-cmd) |
316 (load "viper-cmd.el" nil nil 'nosuffix)) | |
317 ))) | |
318 ;; end pacifier | |
10789 | 319 |
18896 | 320 (require 'viper-init) |
321 | |
18839 | 322 ;; better be defined before Viper custom group. |
323 (defvar vip-custom-file-name (vip-convert-standard-file-name "~/.viper") | |
324 "Viper customisation file. | |
325 If set by the user, this must be done _before_ Viper is loaded in `~/.emacs'.") | |
326 | |
327 (defgroup viper nil | |
328 "Vi emulation within Emacs. | |
329 NOTE: Viper customization should be saved in `vip-custom-file-name', which | |
330 defaults to `~/.viper'." | |
331 :prefix "vip-" | |
332 :group 'emulations) | |
333 | |
18129 | 334 (require 'viper-cmd) |
10789 | 335 |
18289 | 336 (defvar vip-always t |
337 "See `viper-always'. This variable is for compatibility with older Vipers.") | |
18839 | 338 (defcustom viper-always vip-always |
18289 | 339 "Non-nil means, arrange for vi-state to be a default when appropriate. |
340 This is different from `viper-mode' variable in that `viper-mode' determines | |
341 whether to use Viper in the first place, while `viper-always', if nil, lets | |
18839 | 342 user decide when to invoke Viper in a major mode." |
343 :type 'boolean | |
344 :tag "Always Invoke Viper" | |
345 :group 'viper) | |
10789 | 346 |
18839 | 347 ;; Non-viper variables that need to be saved in case the user decides to |
348 ;; de-viperize emacs. | |
349 (defvar viper-saved-non-viper-variables nil) | |
350 ;; Contains user settings for vars affected by viper-set-expert-level function. | |
351 ;; Not a user option. | |
352 (defvar viper-saved-user-settings nil) | |
353 | |
354 (defcustom viper-mode (cond (noninteractive nil) | |
355 (t 'ask)) | |
356 "To Viperize or not to Viperize. | |
18289 | 357 If t, viperize emacs. If nil -- don't. If `ask', ask the user. |
358 This variable is used primatily when Viper is being loaded. | |
359 | |
360 Must be set in `~/.emacs' before Viper is loaded. | |
18839 | 361 DO NOT set this variable interactively." |
362 :type '(choice (const nil) (const t) (const ask)) | |
363 :tag "Set Viper Mode on Loading" | |
364 :group 'viper) | |
18289 | 365 |
18958 | 366 (defcustom viper-non-vi-major-modes nil |
367 "*A list of major modes that should never come up in vi command mode. | |
368 Viper automatically augments this list with some obvious modes, such as | |
369 `dired-mode', `tar-mode', etc. So, don't put modes on this list, unless | |
370 it comes up in a wrong Viper state." | |
371 :type 'list | |
372 :group 'viper) | |
373 | |
374 | |
18289 | 375 |
376 ;; The following are provided for compatibility with older VIP's | |
377 | |
378 ;;;###autoload | |
379 (defalias 'vip-mode 'viper-mode) | |
10789 | 380 |
381 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) | |
382 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) | |
383 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) | |
18289 | 384 |
18839 | 385 |
18289 | 386 |
387 | |
388 ;;;###autoload | |
389 (defun viper-mode () | |
390 "Turn on Viper emulation of Vi." | |
391 (interactive) | |
392 (if (not noninteractive) | |
393 (progn | |
394 ;; if the user requested viper-mode explicitly | |
395 (if viper-mode | |
396 () | |
397 (setq viper-mode 1) | |
398 (load-library "viper")) | |
399 | |
400 (if vip-first-time ; This check is important. Without it, startup and | |
401 (progn ; expert-level msgs mix up when viper-mode recurses | |
402 (setq vip-first-time nil) | |
403 (if (not vip-inhibit-startup-message) | |
404 (save-window-excursion | |
405 (setq vip-inhibit-startup-message t) | |
406 (delete-other-windows) | |
407 (switch-to-buffer "Viper Startup Message") | |
408 (erase-buffer) | |
409 (insert | |
410 (substitute-command-keys | |
18839 | 411 "Viper Is a Package for Emacs Rebels, |
412 a VI Plan for Emacs Rescue, and a venomous VI PERil. | |
18289 | 413 |
18839 | 414 Incidentally, Viper emulates Vi under GNU Emacs 20 and XEmacs 20. |
415 It supports all of what is good in Vi and Ex, while extending | |
18289 | 416 and improving upon much of it. |
417 | |
418 1. Viper supports Vi at several levels. Level 1 is the closest to Vi, | |
419 level 5 provides the most flexibility to depart from many Vi conventions. | |
420 | |
421 You will be asked to specify your user level in a following screen. | |
422 | |
423 If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave | |
424 as in VI, to smooth transition to Viper for the beginners. However, to | |
425 use Emacs productively, you are advised to reach user level 3 or higher. | |
426 | |
18839 | 427 At user level 2 or higher, ^X and ^C have Emacs, not Vi, bindings; |
428 ^Z toggles Vi/Emacs states; ^G is Emacs' keyboard-quit (like ^C in Vi). | |
18289 | 429 |
430 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they | |
18839 | 431 do not cause Emacs to quit, except at user level 1 (for a novice). |
18289 | 432 3. ^X^C EXITS EMACS. |
433 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat | |
434 undo. Another `u' changes direction. | |
435 | |
18839 | 436 6. Emacs Meta key is `C-\\' (in all modes) or `\\ ESC' (in Vi command mode). |
437 On a window system, the best way is to use the Meta-key on your keyboard. | |
18289 | 438 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if |
439 something funny happens. This would abort the current editing command. | |
440 | |
18839 | 441 For more information on Viper: |
18289 | 442 |
18839 | 443 a. Type `:help' in Vi command mode |
444 b. Print Viper manual, found in ./etc/viper.dvi | |
445 c. Print the Quick Reference, found in ./etc/viperCard.dvi | |
446 | |
447 To submit a bug report or to contact the author, type :submitReport in Vi | |
448 command mode. To shoo Viper away and return to pure Emacs (horror!), type: | |
449 | |
450 M-x viper-go-away | |
18289 | 451 |
452 This startup message appears whenever you load Viper, unless you type `y' now." | |
453 )) | |
454 (goto-char (point-min)) | |
455 (if (y-or-n-p "Inhibit Viper startup message? ") | |
456 (vip-save-setting | |
457 'vip-inhibit-startup-message | |
458 "Viper startup message inhibited" | |
459 vip-custom-file-name t)) | |
460 ;;(kill-buffer (current-buffer)) | |
461 (message | |
462 "The last message is in buffer `Viper Startup Message'") | |
463 (sit-for 4) | |
464 )) | |
18839 | 465 (viper-set-expert-level 'dont-change-unless))) |
18958 | 466 |
467 (or (memq major-mode viper-non-vi-major-modes) ; don't switch to Vi | |
468 (vip-change-state-to-vi))))) | |
10789 | 469 |
18129 | 470 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
471 ;; 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
|
472 (defun vip-comint-mode-hook () |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
473 (setq require-final-newline nil |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
474 vip-ex-style-editing-in-insert nil |
10789 | 475 vip-ex-style-motion nil) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
476 (vip-change-state-to-insert)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
477 |
10789 | 478 |
18839 | 479 ;; remove viper hooks from SYMBOL |
480 (defun viper-remove-hooks (symbol) | |
481 (cond ((not (boundp symbol)) nil) | |
482 ((not (listp (eval symbol))) nil) | |
483 ((string-match "-hook" (symbol-name symbol)) | |
484 (remove-hook symbol 'viper-mode) | |
485 (remove-hook symbol 'vip-change-state-to-emacs) | |
486 (remove-hook symbol 'vip-change-state-to-insert) | |
487 (remove-hook symbol 'vip-change-state-to-vi) | |
488 ))) | |
489 | |
490 ;; Remove local value in all existing buffers | |
491 ;; This doesn't delocalize vars (which would have been desirable) | |
492 (defun viper-delocalize-var (symbol) | |
493 (mapcar (function (lambda (buf) | |
494 (save-excursion | |
495 (set-buffer buf) | |
496 (kill-local-variable symbol)))) | |
497 (buffer-list))) | |
498 | |
499 | |
500 (defun viper-go-away () | |
501 "De-Viperize Emacs. | |
502 This function tries to do as good a job as possible. However, it may undo some | |
503 user customization, unrelated to Viper. For instance, if the user advised | |
504 `read-file-name', `describe-key', and some others, then this advice will be | |
505 undone. | |
506 It also doesn't undo some Viper settings. For instance, `minor-mode-map-alist' | |
507 remains buffer-local." | |
508 (interactive) | |
509 | |
510 ;; restore non-viper vars | |
511 (setq-default | |
512 default-major-mode | |
513 (viper-standard-value 'default-major-mode viper-saved-non-viper-variables) | |
514 next-line-add-newlines | |
515 (viper-standard-value | |
516 'next-line-add-newlines viper-saved-non-viper-variables) | |
517 require-final-newline | |
518 (viper-standard-value | |
519 'require-final-newline viper-saved-non-viper-variables) | |
520 scroll-step | |
521 (viper-standard-value 'scroll-step viper-saved-non-viper-variables) | |
522 mode-line-buffer-identification | |
523 (viper-standard-value | |
18855 | 524 'mode-line-buffer-identification viper-saved-non-viper-variables) |
525 global-mode-string | |
526 (viper-standard-value 'global-mode-string viper-saved-non-viper-variables)) | |
527 | |
528 (if vip-emacs-p | |
529 (setq-default | |
530 mark-even-if-inactive | |
531 (viper-standard-value | |
532 'mark-even-if-inactive viper-saved-non-viper-variables))) | |
18839 | 533 |
534 ;; Ideally, we would like to be able to de-localize local variables | |
535 (viper-delocalize-var 'minor-mode-map-alist) | |
536 (viper-delocalize-var 'require-final-newline) | |
537 | |
538 | |
539 ;; deactivate all advices done by Viper. | |
540 (ad-deactivate-regexp "vip-") | |
541 | |
542 (setq viper-mode nil) | |
543 | |
544 (viper-delocalize-var 'vip-vi-minibuffer-minor-mode) | |
545 (viper-delocalize-var 'vip-insert-minibuffer-minor-mode) | |
546 (viper-delocalize-var 'vip-vi-intercept-minor-mode) | |
547 (viper-delocalize-var 'vip-insert-intercept-minor-mode) | |
548 | |
549 (viper-delocalize-var 'vip-vi-local-user-minor-mode) | |
550 (viper-delocalize-var 'vip-vi-kbd-minor-mode) | |
551 (viper-delocalize-var 'vip-vi-global-user-minor-mode) | |
552 (viper-delocalize-var 'vip-vi-state-modifier-minor-mode) | |
553 (viper-delocalize-var 'vip-vi-diehard-minor-mode) | |
554 (viper-delocalize-var 'vip-vi-basic-minor-mode) | |
555 | |
556 (viper-delocalize-var 'vip-replace-minor-mode) | |
557 | |
558 (viper-delocalize-var 'vip-insert-local-user-minor-mode) | |
559 (viper-delocalize-var 'vip-insert-kbd-minor-mode) | |
560 (viper-delocalize-var 'vip-insert-global-user-minor-mode) | |
561 (viper-delocalize-var 'vip-insert-state-modifier-minor-mode) | |
562 (viper-delocalize-var 'vip-insert-diehard-minor-mode) | |
563 (viper-delocalize-var 'vip-insert-basic-minor-mode) | |
564 | |
565 (viper-delocalize-var 'vip-emacs-intercept-minor-mode) | |
566 (viper-delocalize-var 'vip-emacs-local-user-minor-mode) | |
567 (viper-delocalize-var 'vip-emacs-kbd-minor-mode) | |
568 (viper-delocalize-var 'vip-emacs-global-user-minor-mode) | |
569 (viper-delocalize-var 'vip-emacs-state-modifier-minor-mode) | |
570 | |
571 (setq-default vip-vi-minibuffer-minor-mode nil | |
572 vip-insert-minibuffer-minor-mode nil | |
573 vip-vi-intercept-minor-mode nil | |
574 vip-insert-intercept-minor-mode nil | |
575 | |
576 vip-vi-local-user-minor-mode nil | |
577 vip-vi-kbd-minor-mode nil | |
578 vip-vi-global-user-minor-mode nil | |
579 vip-vi-state-modifier-minor-mode nil | |
580 vip-vi-diehard-minor-mode nil | |
581 vip-vi-basic-minor-mode nil | |
582 | |
583 vip-replace-minor-mode nil | |
584 | |
585 vip-insert-local-user-minor-mode nil | |
586 vip-insert-kbd-minor-mode nil | |
587 vip-insert-global-user-minor-mode nil | |
588 vip-insert-state-modifier-minor-mode nil | |
589 vip-insert-diehard-minor-mode nil | |
590 vip-insert-basic-minor-mode nil | |
591 | |
592 vip-emacs-intercept-minor-mode nil | |
593 vip-emacs-local-user-minor-mode nil | |
594 vip-emacs-kbd-minor-mode nil | |
595 vip-emacs-global-user-minor-mode nil | |
596 vip-emacs-state-modifier-minor-mode nil | |
597 ) | |
598 | |
599 ;; remove all hooks set by viper | |
600 (mapatoms 'viper-remove-hooks) | |
601 (remove-hook 'comint-mode-hook 'vip-comint-mode-hook) | |
602 (remove-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel) | |
603 ) | |
604 | |
605 | |
606 | |
607 | |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
608 ;; This sets major mode hooks to make them come up in vi-state. |
10789 | 609 (defun vip-set-hooks () |
610 | |
611 ;; It is of course a misnomer to call viper-mode a `major mode'. | |
612 ;; However, this has the effect that if the user didn't specify the | |
613 ;; default mode, new buffers that fall back on the default will come up | |
614 ;; in Fundamental Mode and Vi state. | |
615 (setq default-major-mode 'viper-mode) | |
616 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
617 ;; The following major modes should come up in vi-state |
10789 | 618 (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
|
619 "Run `vip-change-state-to-vi' on entry." |
10789 | 620 (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
|
621 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
622 (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
|
623 (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
|
624 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
625 (defvar help-mode-hook) |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
626 (add-hook 'help-mode-hook 'viper-mode) |
18047 | 627 (vip-modify-major-mode 'help-mode 'vi-state vip-help-modifier-map) |
14232
aa84e18af631
Sat Jan 20 01:41:56 1996 Michael Kifer <kifer@sbkifer>
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14169
diff
changeset
|
628 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
629 (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
|
630 (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
|
631 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
632 (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
|
633 (add-hook 'html-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
634 (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
|
635 (add-hook 'html-helper-mode-hook 'viper-mode) |
18289 | 636 |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
637 (defvar java-mode-hook) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
638 (add-hook 'java-mode-hook 'viper-mode) |
10789 | 639 |
18839 | 640 (defvar javascript-mode-hook) |
641 (add-hook 'javascript-mode-hook 'viper-mode) | |
642 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
643 (defvar emacs-lisp-mode-hook) |
10789 | 644 (add-hook 'emacs-lisp-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
645 (defvar lisp-mode-hook) |
10789 | 646 (add-hook 'lisp-mode-hook 'viper-mode) |
18289 | 647 (defvar lisp-interaction-mode-hook) |
648 (add-hook 'lisp-interaction-mode-hook 'viper-mode) | |
10789 | 649 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
650 (defvar bibtex-mode-hook) |
10789 | 651 (add-hook 'bibtex-mode-hook 'viper-mode) |
652 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
653 (defvar cc-mode-hook) |
10789 | 654 (add-hook 'cc-mode-hook 'viper-mode) |
655 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
656 (defvar c-mode-hook) |
10789 | 657 (add-hook 'c-mode-hook 'viper-mode) |
658 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
659 (defvar c++-mode-hook) |
10789 | 660 (add-hook 'c++-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
661 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
662 (defvar fortran-mode-hook) |
18289 | 663 (add-hook 'fortran-mode-hook 'viper-mode) |
664 (defvar f90-mode-hook) | |
665 (add-hook 'f90-mode-hook 'viper-mode) | |
16766
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
666 |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
667 (defvar basic-mode-hook) |
18289 | 668 (add-hook 'basic-mode-hook 'viper-mode) |
16766
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
669 (defvar bat-mode-hook) |
18289 | 670 (add-hook 'bat-mode-hook 'viper-mode) |
18343 | 671 |
672 (defvar asm-mode-hook) | |
673 (add-hook 'asm-mode-hook 'viper-mode) | |
674 | |
675 (defvar prolog-mode-hook) | |
676 (add-hook 'prolog-mode-hook 'viper-mode) | |
10789 | 677 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
678 (defvar text-mode-hook) |
10789 | 679 (add-hook 'text-mode-hook 'viper-mode) |
680 | |
681 (add-hook 'completion-list-mode-hook 'viper-mode) | |
682 (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
|
683 |
18839 | 684 (defvar perl-mode-hook) |
685 (add-hook 'perl-mode-hook 'viper-mode) | |
686 | |
687 (defvar tcl-mode-hook) | |
688 (add-hook 'tcl-mode-hook 'viper-mode) | |
689 | |
690 (defvar python-mode-hook) | |
691 (add-hook 'python-mode-hook 'viper-mode) | |
10789 | 692 |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
693 (defvar emerge-startup-hook) |
10789 | 694 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
695 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
696 ;; Tell vc-diff to put *vc* in Vi mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
697 (if (featurep 'vc) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
698 (defadvice vc-diff (after vip-vc-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
699 "Force Vi state in VC diff buffer." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
700 (vip-change-state-to-vi)) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
701 (vip-eval-after-load |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
702 "vc" |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
703 '(defadvice vc-diff (after vip-vc-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
704 "Force Vi state in VC diff buffer." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
705 (vip-change-state-to-vi)))) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
706 |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
707 (vip-eval-after-load |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
708 "emerge" |
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
709 '(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
|
710 "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
|
711 (vip-change-state-to-vi))) |
10789 | 712 ;; In case Emerge was loaded before Viper. |
713 (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
|
714 "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
|
715 (vip-change-state-to-vi)) |
10789 | 716 |
717 ;; 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
|
718 ;; thus overriding the local map. We don't need Vi mode here. |
10789 | 719 (vip-eval-after-load |
720 "passwd" | |
721 '(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
|
722 "Switch to emacs state while reading password." |
10789 | 723 (vip-change-state-to-emacs))) |
724 | |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
725 ;; Emacs shell, ange-ftp, and comint-based modes |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
726 (defvar comint-mode-hook) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
727 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
728 'comint-mode 'insert-state vip-comint-mode-modifier-map) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
729 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
730 'comint-mode 'vi-state vip-comint-mode-modifier-map) |
16766
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
731 (vip-modify-major-mode |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
732 'shell-mode 'insert-state vip-comint-mode-modifier-map) |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
733 (vip-modify-major-mode |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
734 'shell-mode 'vi-state vip-comint-mode-modifier-map) |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
735 ;; ange-ftp in XEmacs |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
736 (vip-modify-major-mode |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
737 'ange-ftp-shell-mode 'insert-state vip-comint-mode-modifier-map) |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
738 (vip-modify-major-mode |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
739 'ange-ftp-shell-mode 'vi-state vip-comint-mode-modifier-map) |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
740 ;; ange-ftp in Emacs |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
741 (vip-modify-major-mode |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
742 'internal-ange-ftp-mode 'insert-state vip-comint-mode-modifier-map) |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
743 (vip-modify-major-mode |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
744 'internal-ange-ftp-mode 'vi-state vip-comint-mode-modifier-map) |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
745 ;; set hook |
12137
e6af973190dc
(vip-envelop-ESC-key): if an ESC-sequence translates
Karl Heuer <kwzh@gnu.org>
parents:
11255
diff
changeset
|
746 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) |
10789 | 747 |
748 ;; Shell scripts | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
749 (defvar sh-mode-hook) |
10789 | 750 (add-hook 'sh-mode-hook 'viper-mode) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
751 (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
|
752 (add-hook 'ksh-mode-hook 'viper-mode) |
10789 | 753 |
754 ;; Dired | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
755 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map) |
18855 | 756 (vip-set-emacs-state-searchstyle-macros nil 'dired-mode) |
10789 | 757 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) |
18958 | 758 (setq viper-non-vi-major-modes |
759 (append '(dired-mode efs-mode internal-ange-ftp-mode) | |
760 viper-non-vi-major-modes)) | |
10789 | 761 |
16766
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
762 ;; Tar |
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
763 (vip-modify-major-mode 'tar-mode 'emacs-state vip-slash-and-colon-map) |
18855 | 764 (vip-set-emacs-state-searchstyle-macros nil 'tar-mode) |
18958 | 765 (setq viper-non-vi-major-modes (cons 'tar-mode viper-non-vi-major-modes)) |
16766
beb94a5271e2
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16248
diff
changeset
|
766 |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
767 ;; MH-E |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
768 (vip-modify-major-mode 'mh-folder-mode 'emacs-state vip-slash-and-colon-map) |
18855 | 769 (vip-set-emacs-state-searchstyle-macros nil 'mh-folder-mode) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
770 ;; changing state to emacs is needed so the preceding will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
771 (add-hook 'mh-folder-mode-hook 'vip-change-state-to-emacs) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
772 (add-hook 'mh-show-mode-hook 'viper-mode) |
18958 | 773 (setq viper-non-vi-major-modes |
774 (cons 'mh-folder-mode viper-non-vi-major-modes)) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
775 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
776 ;; Gnus |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
777 (vip-modify-major-mode 'gnus-group-mode 'emacs-state vip-slash-and-colon-map) |
18855 | 778 (vip-set-emacs-state-searchstyle-macros nil 'gnus-group-mode) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
779 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
780 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map) |
18855 | 781 (vip-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
782 ;; changing state to emacs is needed so the preceding will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
783 (add-hook 'gnus-group-mode-hook 'vip-change-state-to-emacs) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
784 (add-hook 'gnus-summary-mode-hook 'vip-change-state-to-emacs) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
785 (add-hook 'gnus-article-mode-hook 'viper-mode) |
18958 | 786 (setq viper-non-vi-major-modes |
787 (append '(gnus-group-mode gnus-summary-mode) | |
788 viper-non-vi-major-modes)) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
789 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
790 ;; Info |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
791 (vip-modify-major-mode 'Info-mode 'emacs-state vip-slash-and-colon-map) |
18855 | 792 (vip-set-emacs-state-searchstyle-macros nil 'Info-mode) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
793 ;; Switching to emacs is needed so the above will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
794 (defadvice Info-mode (after vip-Info-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
795 "Switch to emacs mode." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
796 (vip-change-state-to-emacs)) |
18958 | 797 (setq viper-non-vi-major-modes (cons 'Info-mode viper-non-vi-major-modes)) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
798 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
799 ;; Buffer menu |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
800 (vip-modify-major-mode |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
801 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map) |
18855 | 802 (vip-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode) |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
803 ;; Switching to emacs is needed so the above will take hold |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
804 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate) |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
805 "Switch to emacs mode." |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
806 (vip-change-state-to-emacs)) |
18958 | 807 (setq viper-non-vi-major-modes |
808 (cons 'Buffer-menu-mode viper-non-vi-major-modes)) | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
809 |
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
810 ;; View mode |
18343 | 811 (defvar view-mode-hook) |
812 (defvar view-hook) | |
813 (add-hook 'view-hook 'vip-change-state-to-emacs) | |
814 (add-hook 'view-mode-hook 'vip-change-state-to-emacs) | |
18958 | 815 (setq viper-non-vi-major-modes (cons 'view-mode viper-non-vi-major-modes)) |
10789 | 816 |
817 ;; For VM users. | |
818 ;; Put summary and other VM buffers in Emacs state. | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
819 (defvar vm-mode-hooks) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14909
diff
changeset
|
820 (defvar vm-summary-mode-hooks) |
10789 | 821 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs) |
822 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs) | |
18958 | 823 (setq viper-non-vi-major-modes |
824 (append '(vm-mode vm-summary-mode) viper-non-vi-major-modes)) | |
10789 | 825 |
826 ;; For RMAIL users. | |
827 ;; Put buf in Emacs state after edit. | |
828 (vip-eval-after-load | |
829 "rmailedit" | |
830 '(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
|
831 "Switch to emacs state when done editing message." |
10789 | 832 (vip-change-state-to-emacs))) |
833 ;; In case RMAIL was loaded before Viper. | |
834 (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
|
835 "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
|
836 (vip-change-state-to-emacs)) |
10789 | 837 ) ; vip-set-hooks |
18172 | 838 |
18289 | 839 |
840 ;; these are primarily advices and Vi-ish variable settings | |
841 (defun vip-non-hook-settings () | |
18172 | 842 |
18289 | 843 ;; This var is not local in Emacs, so we make it local. |
844 ;; It must be local because although the stack of minor modes can be the same | |
845 ;; for all buffers, the associated *keymaps* can be different. In Viper, | |
846 ;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have | |
847 ;; different keymaps for different buffers. | |
848 ;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode | |
849 ;; can be different. | |
850 (make-variable-buffer-local 'minor-mode-map-alist) | |
851 | |
852 ;; Viper changes the default mode-line-buffer-identification | |
853 (setq-default mode-line-buffer-identification '(" %b")) | |
854 | |
855 ;; setup emacs-supported vi-style feel | |
856 (setq next-line-add-newlines nil | |
857 require-final-newline t) | |
858 | |
859 (make-variable-buffer-local 'require-final-newline) | |
860 | |
861 ;; don't bark when mark is inactive | |
18855 | 862 (if vip-emacs-p |
863 (setq mark-even-if-inactive t)) | |
18289 | 864 |
865 (setq scroll-step 1) | |
866 | |
867 ;; Variable displaying the current Viper state in the mode line. | |
868 (vip-deflocalvar vip-mode-string vip-emacs-state-id) | |
869 (or (memq 'vip-mode-string global-mode-string) | |
870 (setq global-mode-string | |
871 (append '("" vip-mode-string) (cdr global-mode-string)))) | |
18172 | 872 |
18289 | 873 (defadvice read-key-sequence (around vip-read-keyseq-ad activate) |
874 "Harness to work for Viper. This advice is harmless---don't worry!" | |
875 (let (inhibit-quit event keyseq) | |
876 (setq keyseq ad-do-it) | |
877 (setq event (if vip-xemacs-p | |
878 (elt keyseq 0) ; XEmacs returns vector of events | |
879 (elt (listify-key-sequence keyseq) 0))) | |
880 (if (vip-ESC-event-p event) | |
881 (let (unread-command-events) | |
882 (vip-set-unread-command-events keyseq) | |
883 (if (vip-fast-keysequence-p) | |
884 (let ((vip-vi-global-user-minor-mode nil) | |
885 (vip-vi-local-user-minor-mode nil) | |
886 (vip-replace-minor-mode nil) ; actually unnecessary | |
887 (vip-insert-global-user-minor-mode nil) | |
888 (vip-insert-local-user-minor-mode nil)) | |
889 (setq keyseq ad-do-it)) | |
890 (setq keyseq ad-do-it)))) | |
891 keyseq)) | |
892 | |
893 (defadvice describe-key (before vip-read-keyseq-ad protect activate) | |
894 "Force to read key via `read-key-sequence'." | |
895 (interactive (list (vip-events-to-keys | |
896 (read-key-sequence "Describe key: "))))) | |
897 | |
898 (defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate) | |
899 "Force to read key via `read-key-sequence'." | |
900 (interactive (list (vip-events-to-keys | |
901 (read-key-sequence "Describe key briefly: "))))) | |
902 | |
903 | |
904 ;; Advice for use in find-file and read-file-name commands. | |
905 (defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate) | |
906 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer." | |
907 (run-hooks 'vip-minibuffer-exit-hook)) | |
908 | |
909 (defadvice find-file (before vip-add-suffix-advice activate) | |
910 "Use `read-file-name' for reading arguments." | |
911 (interactive (cons (read-file-name "Find file: " nil default-directory) | |
912 ;; if Mule and prefix argument, ask for coding system | |
18839 | 913 (cond ((and vip-emacs-p |
914 (boundp 'MULE)) ; Emacs 20 with MULE | |
915 nil) | |
916 ((and vip-xemacs-p | |
917 (featurep 'mule)) ; XEmacs 20 with MULE | |
918 (list | |
919 (and current-prefix-arg | |
920 (read-coding-system | |
921 "Coding-system: ")))) | |
922 ) | |
18289 | 923 ))) |
924 | |
925 (defadvice find-file-other-window (before vip-add-suffix-advice activate) | |
926 "Use `read-file-name' for reading arguments." | |
927 (interactive (cons (read-file-name "Find file in other window: " | |
928 nil default-directory) | |
929 ;; if Mule and prefix argument, ask for coding system | |
18839 | 930 (cond ((and vip-emacs-p |
931 (boundp 'MULE)) ; Emacs 20 with MULE | |
932 nil) | |
933 ((and vip-xemacs-p | |
934 (featurep 'mule)) ; XEmacs 20 with MULE | |
935 (list | |
936 (and current-prefix-arg | |
937 (read-coding-system | |
938 "Coding-system: ")))) | |
939 ) | |
18289 | 940 ))) |
941 | |
18839 | 942 |
18289 | 943 (defadvice find-file-other-frame (before vip-add-suffix-advice activate) |
944 "Use `read-file-name' for reading arguments." | |
945 (interactive (cons (read-file-name "Find file in other frame: " | |
946 nil default-directory) | |
947 ;; if Mule and prefix argument, ask for coding system | |
18839 | 948 (cond ((and vip-emacs-p |
949 (boundp 'MULE)) ; Emacs 20 with MULE | |
950 nil) | |
951 ((and vip-xemacs-p | |
952 (featurep 'mule)) ; XEmacs 20 with MULE | |
953 (list | |
954 (and current-prefix-arg | |
955 (read-coding-system | |
956 "Coding-system: ")))) | |
957 ) | |
18289 | 958 ))) |
18839 | 959 |
18289 | 960 |
961 (defadvice read-file-name (around vip-suffix-advice activate) | |
962 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." | |
963 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) | |
964 ad-do-it)) | |
965 | |
966 (defadvice start-kbd-macro (after vip-kbd-advice activate) | |
967 "Remove Viper's intercepting bindings for C-x ). | |
968 This may be needed if the previous `:map' command terminated abnormally." | |
969 (define-key vip-vi-intercept-map "\C-x)" nil) | |
970 (define-key vip-insert-intercept-map "\C-x)" nil) | |
971 (define-key vip-emacs-intercept-map "\C-x)" nil)) | |
972 | |
973 (cond ((vip-window-display-p) | |
974 (let* ((search-key (if vip-xemacs-p | |
975 [(meta shift button1up)] [M-S-mouse-1])) | |
976 (search-key-catch | |
977 (if vip-xemacs-p [(meta shift button1)] [M-S-down-mouse-1])) | |
978 (insert-key (if vip-xemacs-p | |
979 [(meta shift button2up)] [M-S-mouse-2])) | |
980 (insert-key-catch | |
981 (if vip-xemacs-p [(meta shift button2)] [M-S-down-mouse-2])) | |
982 (search-key-unbound (and (not (key-binding search-key)) | |
983 (not (key-binding search-key-catch)))) | |
984 (insert-key-unbound (and (not (key-binding insert-key)) | |
985 (not (key-binding insert-key-catch)))) | |
986 ) | |
987 | |
988 (if search-key-unbound | |
989 (global-set-key search-key 'vip-mouse-click-search-word)) | |
990 (if insert-key-unbound | |
991 (global-set-key insert-key 'vip-mouse-click-insert-word)) | |
992 | |
993 ;; The following would be needed if you want to use the above two | |
994 ;; while clicking in another frame. If you only want to use them | |
995 ;; by clicking in another window, not frame, the bindings below | |
996 ;; aren't necessary. | |
997 | |
998 ;; These must be bound to mouse-down event for the same mouse | |
999 ;; buttons as 'vip-mouse-click-search-word and | |
1000 ;; 'vip-mouse-click-insert-word | |
1001 (if search-key-unbound | |
1002 (global-set-key search-key-catch 'vip-mouse-catch-frame-switch)) | |
1003 (if insert-key-unbound | |
1004 (global-set-key insert-key-catch 'vip-mouse-catch-frame-switch)) | |
1005 | |
1006 (if vip-xemacs-p | |
1007 (add-hook 'mouse-leave-frame-hook | |
1008 'vip-remember-current-frame) | |
1009 (defadvice handle-switch-frame (before vip-frame-advice activate) | |
1010 "Remember the selected frame before the switch-frame event." | |
1011 (vip-remember-current-frame (selected-frame)))) | |
1012 ))) | |
1013 ) ; end vip-non-hook-settings | |
18172 | 1014 |
18289 | 1015 |
1016 (if (eq viper-mode 'ask) | |
1017 (progn | |
1018 (save-window-excursion | |
1019 (with-output-to-temp-buffer " *vip-info*" | |
1020 (princ " | |
1021 You have loaded Viper, and are about to Viperize your emacs! | |
1022 | |
1023 Viper is a Package for Emacs Rebels | |
1024 and a venomous VI PERil, | |
1025 | |
1026 It's time to decide: to Viperize or not to Viperize... | |
18172 | 1027 |
18289 | 1028 If you wish to Viperize AND make this your way of life, please put |
1029 | |
1030 (setq viper-mode t) | |
1031 (require 'viper) | |
1032 | |
1033 in your .emacs file (preferably, close to the top). | |
1034 These two lines must come in the order given. | |
1035 | |
18839 | 1036 Also, the startup file name has been changed from .vip to .viper")) |
18289 | 1037 (if (y-or-n-p "Viperize? ") |
1038 (setq viper-mode t) | |
1039 (setq viper-mode nil)) | |
1040 (message "") | |
1041 (kill-buffer " *vip-info*")))) | |
1042 | |
18172 | 1043 |
1044 | |
1045 | |
18839 | 1046 ;; Get viper standard value of SYMBOL. If symbol is customized, get its |
1047 ;; standard value. Otherwise, get the value saved in the alist STORAGE. If | |
1048 ;; STORAGE is nil, use viper-saved-user-settings. | |
1049 (defun viper-standard-value (symbol &optional storage) | |
1050 (or (eval (car (get symbol 'customized-value))) | |
1051 (eval (car (get symbol 'saved-value))) | |
1052 (nth 1 (assoc symbol (or storage viper-saved-user-settings))))) | |
1053 | |
1054 | |
1055 | |
1056 ;; save non-viper vars that Viper might change | |
1057 (if (null viper-saved-non-viper-variables) | |
1058 (setq viper-saved-non-viper-variables | |
1059 (list | |
1060 (cons 'default-major-mode (list default-major-mode)) | |
1061 (cons 'next-line-add-newlines (list next-line-add-newlines)) | |
1062 (cons 'require-final-newline (list require-final-newline)) | |
1063 (cons 'scroll-step (list scroll-step)) | |
1064 (cons 'mode-line-buffer-identification | |
1065 (list (default-value 'mode-line-buffer-identification))) | |
1066 (cons 'global-mode-string (list global-mode-string)) | |
18855 | 1067 (if vip-emacs-p |
1068 (cons 'mark-even-if-inactive (list mark-even-if-inactive))) | |
18839 | 1069 ))) |
1070 | |
10789 | 1071 |
18289 | 1072 ;; Set some useful macros, advices |
18839 | 1073 ;; These must be BEFORE ~/.viper is loaded, |
1074 ;; so the user can unrecord them in ~/.viper. | |
18289 | 1075 (if viper-mode |
1076 (progn | |
1077 ;; set advices and some variables that give emacs Vi look. | |
1078 (vip-non-hook-settings) | |
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
|
1079 |
18289 | 1080 ;; repeat the 2nd previous command without rotating the command history |
1081 (vip-record-kbd-macro | |
1082 (vector vip-repeat-from-history-key '\1) 'vi-state | |
1083 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) | |
1084 ;; repeat the 3d previous command without rotating the command history | |
1085 (vip-record-kbd-macro | |
1086 (vector vip-repeat-from-history-key '\2) 'vi-state | |
1087 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) | |
1088 | |
18839 | 1089 ;; set macros for toggling case sensitivity and regexp search |
18855 | 1090 (vip-set-searchstyle-toggling-macros nil) |
18289 | 1091 ;; Make %%% toggle parsing comments for matching parentheses |
18839 | 1092 (vip-set-parsing-style-toggling-macro nil) |
18289 | 1093 )) |
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
|
1094 |
10789 | 1095 |
18839 | 1096 ;; ~/.viper is loaded if it exists |
10789 | 1097 (if (and (file-exists-p vip-custom-file-name) |
18289 | 1098 viper-mode |
10789 | 1099 (not noninteractive)) |
1100 (load vip-custom-file-name)) | |
1101 | |
1102 ;; VIP compatibility: merge whatever the user has in vip-mode-map into | |
1103 ;; Viper's basic map. | |
1104 (vip-add-keymap vip-mode-map vip-vi-global-user-map) | |
1105 | |
18839 | 1106 (if (boundp 'vip-expert-level) |
1107 (setq viper-expert-level vip-expert-level)) | |
1108 | |
1109 | |
10789 | 1110 |
1111 ;; Applying Viper customization -- runs after (load .vip) | |
1112 | |
18839 | 1113 ;; Save user settings or Viper defaults for vars controled by |
1114 ;; viper-expert-level | |
1115 (if (null viper-saved-user-settings) | |
1116 (setq viper-saved-user-settings | |
1117 (list (cons 'vip-want-ctl-h-help (list vip-want-ctl-h-help)) | |
1118 (cons 'viper-always (list viper-always)) | |
1119 (cons 'vip-no-multiple-ESC (list vip-no-multiple-ESC)) | |
1120 (cons 'vip-ex-style-motion (list vip-ex-style-motion)) | |
1121 (cons 'vip-ex-style-editing-in-insert | |
1122 (list vip-ex-style-editing-in-insert)) | |
1123 (cons 'vip-want-emacs-keys-in-vi | |
1124 (list vip-want-emacs-keys-in-vi)) | |
1125 (cons 'vip-electric-mode (list vip-electric-mode)) | |
1126 (cons 'vip-want-emacs-keys-in-insert | |
1127 (list vip-want-emacs-keys-in-insert)) | |
1128 (cons 'vip-re-search (list vip-re-search))))) | |
10789 | 1129 |
1130 | |
18289 | 1131 (if viper-mode |
1132 (progn | |
1133 (vip-set-minibuffer-style) | |
1134 (if vip-buffer-search-char | |
1135 (vip-buffer-search-enable)) | |
1136 (vip-update-alphanumeric-class) | |
1137 )) | |
10789 | 1138 |
18129 | 1139 |
10789 | 1140 ;;; Familiarize Viper with some minor modes that have their own keymaps |
18289 | 1141 (if viper-mode |
1142 (progn | |
1143 (vip-harness-minor-mode "compile") | |
1144 (vip-harness-minor-mode "outline") | |
1145 (vip-harness-minor-mode "allout") | |
1146 (vip-harness-minor-mode "xref") | |
1147 (vip-harness-minor-mode "lmenu") | |
1148 (vip-harness-minor-mode "vc") | |
1149 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX | |
1150 (vip-harness-minor-mode "latex") ; which is in one of these two files | |
1151 (vip-harness-minor-mode "cyrillic") | |
1152 (vip-harness-minor-mode "russian") | |
1153 (vip-harness-minor-mode "view-less") | |
1154 (vip-harness-minor-mode "view") | |
1155 )) | |
10789 | 1156 |
1157 | |
1158 ;; Intercept maps could go in viper-keym.el | |
18839 | 1159 ;; We keep them here in case someone redefines them in ~/.viper |
10789 | 1160 |
1161 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
1162 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key) | |
1163 | |
1164 ;; This is taken care of by vip-insert-global-user-map. | |
1165 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key) | |
1166 | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1167 |
10789 | 1168 ;; The default vip-toggle-key is \C-z; for the novice, it suspends or |
1169 ;; iconifies Emacs | |
16135
102e7d27c135
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
16038
diff
changeset
|
1170 (define-key vip-vi-intercept-map vip-toggle-key 'vip-toggle-key-action) |
10789 | 1171 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) |
1172 | |
1173 | |
18289 | 1174 (if (and viper-mode |
1175 (or viper-always | |
18839 | 1176 (and (< viper-expert-level 5) (> viper-expert-level 0)))) |
10789 | 1177 (vip-set-hooks)) |
1178 | |
1179 ;; Let all minor modes take effect after loading | |
1180 ;; this may not be enough, so we also set default minor-mode-alist. | |
1181 ;; Without setting the default, new buffers that come up in emacs mode have | |
1182 ;; minor-mode-map-alist = nil, unless we call vip-change-state-* | |
1183 (if (eq vip-current-state 'emacs-state) | |
1184 (progn | |
1185 (vip-change-state-to-emacs) | |
1186 (setq-default minor-mode-map-alist minor-mode-map-alist) | |
1187 )) | |
1188 | |
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
|
1189 |
18129 | 1190 |
13214
bc4eeb585ff1
(vip-set-hooks): Use view-mode-hook in emacs and view
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
12900
diff
changeset
|
1191 (run-hooks 'vip-load-hook) ; the last chance to change something |
10789 | 1192 |
1193 (provide 'vip) | |
18129 | 1194 (provide 'viper) |
10789 | 1195 |
18839 | 1196 |
1197 ;;; Local Variables: | |
1198 ;;; eval: (put 'vip-deflocalvar 'lisp-indent-hook 'defun) | |
1199 ;;; End: | |
1200 | |
10789 | 1201 ;;; viper.el ends here |