comparison lisp/viper/viper.el @ 181:bfd6434d15b3 r20-3b17

Import from CVS: tag r20-3b17
author cvs
date Mon, 13 Aug 2007 09:53:19 +0200
parents 6075d714658b
children 3d6bfa290dbd
comparison
equal deleted inserted replaced
180:add28d59e586 181:bfd6434d15b3
1 ;;; viper.el --- A full-featured Vi emulator for GNU Emacs 19 and XEmacs 19, 1 ;;; viper.el --- A full-featured Vi emulator for GNU Emacs and XEmacs,
2 ;; a VI Plan for Emacs Rescue, 2 ;; a VI Plan for Emacs Rescue,
3 ;; and a venomous VI PERil. 3 ;; and a venomous VI PERil.
4 ;; Viper Is also a Package for Emacs Rebels. 4 ;; Viper Is also a Package for Emacs Rebels.
5 ;; 5 ;;
6 ;; Keywords: emulations 6 ;; Keywords: emulations
7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> 7 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
8 8
9 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. 9 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
10 10
11 (defconst viper-version "2.95 of July 9, 1997" 11 (defconst viper-version "2.96 of August 7, 1997"
12 "The current version of Viper") 12 "The current version of Viper")
13 13
14 ;; This file is part of GNU Emacs. 14 ;; This file is part of GNU Emacs.
15 15
16 ;; GNU Emacs is free software; you can redistribute it and/or modify 16 ;; GNU Emacs is free software; you can redistribute it and/or modify
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA. 29 ;; Boston, MA 02111-1307, USA.
30 30
31 ;;; Commentary: 31 ;;; Commentary:
32 32
33 ;; Viper is a full-featured Vi emulator for Emacs 19. It emulates and 33 ;; Viper is a full-featured Vi emulator for Emacs and XEmacs. It emulates and
34 ;; improves upon the standard features of Vi and, at the same time, allows 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, 35 ;; full access to all Emacs facilities. Viper supports multiple undo,
36 ;; file name completion, command, file, and search history and it extends 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 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 38 ;; hooks, user variables, and keymaps. It is implemented as a collection
122 ;; As an immediate solution, you can hit C-z to bring about the right mode. 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: 123 ;; An interim solution is to add an appropriate hook to the mode like this:
124 ;; 124 ;;
125 ;; (add-hook 'your-favorite-mode 'viper-mode) 125 ;; (add-hook 'your-favorite-mode 'viper-mode)
126 ;; or 126 ;; or
127 ;; (add-hook 'your-favorite-mode 'vip-change-state-to-emacs) 127 ;; (add-hook 'your-favorite-mode 'viper-change-state-to-emacs)
128 ;; 128 ;;
129 ;; whichever applies. The right thing to do, however, is to complain to the 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 130 ;; author of the respective package. (Sometimes they also neglect to equip
131 ;; their modes with hooks, which is one more reason for complaining.) 131 ;; their modes with hooks, which is one more reason for complaining.)
132 ;; 132 ;;
133 ;; 2. Keymap handling 133 ;; 2. Keymap handling
134 ;; Because Emacs 19 has an elegant mechanism for turning minor mode keymaps 134 ;; Each Viper state (insert, vi, replace) is implemented as a collection of
135 ;; on and off, implementation of Viper has been greatly simplified. Viper 135 ;; several minor modes, each with its own keymap.
136 ;; has several minor modes.
137 ;; 136 ;;
138 ;; Viper's Vi state consists of seven minor modes: 137 ;; Viper's Vi state consists of seven minor modes:
139 ;; 138 ;;
140 ;; vip-vi-intercept-minor-mode 139 ;; viper-vi-intercept-minor-mode
141 ;; vip-vi-local-user-minor-mode 140 ;; viper-vi-local-user-minor-mode
142 ;; vip-vi-global-user-minor-mode 141 ;; viper-vi-global-user-minor-mode
143 ;; vip-vi-kbd-minor-mode 142 ;; viper-vi-kbd-minor-mode
144 ;; vip-vi-state-modifier-minor-mode 143 ;; viper-vi-state-modifier-minor-mode
145 ;; vip-vi-diehard-minor-mode 144 ;; viper-vi-diehard-minor-mode
146 ;; vip-vi-basic-minor-mode 145 ;; viper-vi-basic-minor-mode
147 ;; 146 ;;
148 ;; Bindings done to the keymap of the first mode overshadow those done to 147 ;; 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. 148 ;; the second, which, in turn, overshadows those done to the third, etc.
150 ;; 149 ;;
151 ;; The last vip-vi-basic-minor-mode contains most of the usual Vi bindings 150 ;; The last viper-vi-basic-minor-mode contains most of the usual Vi bindings
152 ;; in its edit mode. This mode provides access to all Emacs facilities. 151 ;; in its edit mode. This mode provides access to all Emacs facilities.
153 ;; Novice users, however, may want to set their viper-expert-level to 1 152 ;; Novice users, however, may want to set their viper-expert-level to 1
154 ;; in their .vip file. This will enable vip-vi-diehard-minor-mode. This 153 ;; in their .viper file. This will enable viper-vi-diehard-minor-mode. This
155 ;; minor mode's bindings make Viper simulate the usual Vi very closely. 154 ;; minor mode's bindings make Viper simulate the usual Vi very closely.
156 ;; For instance, C-c will not have its standard Emacs binding 155 ;; For instance, C-c will not have its standard Emacs binding
157 ;; and so many of the goodies of Emacs are not available. 156 ;; and so many of the goodies of Emacs are not available.
158 ;; 157 ;;
159 ;; A skilled user should set viper-expert-level to at least 3. This will 158 ;; A skilled user should set viper-expert-level to at least 3. This will
160 ;; enable `C-c' and many Emacs facilities will become available. 159 ;; enable `C-c' and many Emacs facilities will become available.
161 ;; In this case, vip-vi-diehard-minor-mode is inactive. 160 ;; In this case, viper-vi-diehard-minor-mode is inactive.
162 ;; 161 ;;
163 ;; Viper gurus should have at least 162 ;; Viper gurus should have at least
164 ;; (setq viper-expert-level 4) 163 ;; (setq viper-expert-level 4)
165 ;; in their ~/.viper files. This will unsuppress all Emacs keys that are not 164 ;; in their ~/.viper files. This will unsuppress all Emacs keys that are not
166 ;; essential for VI-style editing. 165 ;; essential for VI-style editing.
167 ;; Pick-and-choose users may want to put 166 ;; Pick-and-choose users may want to put
168 ;; (setq viper-expert-level 5) 167 ;; (setq viper-expert-level 5)
169 ;; in ~/.viper. Viper will then leave it up to the user to set the variables 168 ;; 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. 169 ;; viper-want-* See viper-set-expert-level for details.
171 ;; 170 ;;
172 ;; The very first minor mode, vip-vi-intercept-minor-mode, is of no 171 ;; The very first minor mode, viper-vi-intercept-minor-mode, is of no
173 ;; concern for the user. It is needed to bind Viper's vital keys, such as 172 ;; concern for the user. It is needed to bind Viper's vital keys, such as
174 ;; ESC and C-z. 173 ;; ESC and C-z.
175 ;; 174 ;;
176 ;; The second mode, vip-vi-local-user-minor-mode, usually has an 175 ;; The second mode, viper-vi-local-user-minor-mode, usually has an
177 ;; empty keymap. However, the user can set bindings in this keymap, which 176 ;; empty keymap. However, the user can set bindings in this keymap, which
178 ;; will overshadow the corresponding bindings in the other two minor 177 ;; will overshadow the corresponding bindings in the other two minor
179 ;; modes. This is useful, for example, for setting up ZZ in gnus, 178 ;; 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. 179 ;; 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 180 ;; 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. 181 ;; 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 182 ;; Setting local keys is tricky, so don't do it directly. Instead, use
184 ;; vip-add-local-keys function (see its doc). 183 ;; viper-add-local-keys function (see its doc).
185 ;; 184 ;;
186 ;; The third minor mode, vip-vi-global-user-minor-mode, is also intended 185 ;; The third minor mode, viper-vi-global-user-minor-mode, is also intended
187 ;; for the users but, unlike vip-vi-local-user-minor-mode, its key 186 ;; for the users but, unlike viper-vi-local-user-minor-mode, its key
188 ;; bindings are seen in all Viper buffers. This mode keys can be done 187 ;; bindings are seen in all Viper buffers. This mode keys can be done
189 ;; with define-key command. 188 ;; with define-key command.
190 ;; 189 ;;
191 ;; The fourth minor mode, vip-vi-kbd-minor-mode, is used by keyboard 190 ;; The fourth minor mode, viper-vi-kbd-minor-mode, is used by keyboard
192 ;; macros. Users are NOT supposed to modify this keymap directly. 191 ;; macros. Users are NOT supposed to modify this keymap directly.
193 ;; 192 ;;
194 ;; The fifth mode, vip-vi-state-modifier-minor-mode, can be used to set 193 ;; The fifth mode, viper-vi-state-modifier-minor-mode, can be used to set
195 ;; key bindings that are visible in some major modes but not in others. 194 ;; key bindings that are visible in some major modes but not in others.
196 ;; 195 ;;
197 ;; Users are allowed to modify keymaps that belong to 196 ;; Users are allowed to modify keymaps that belong to
198 ;; vip-vi-local-user-minor-mode, vip-vi-global-user-minor-mode, 197 ;; viper-vi-local-user-minor-mode, viper-vi-global-user-minor-mode,
199 ;; and vip-vi-state-modifier-minor-mode only. 198 ;; and viper-vi-state-modifier-minor-mode only.
200 ;; 199 ;;
201 ;; Viper's Insert state also has seven minor modes: 200 ;; Viper's Insert state also has seven minor modes:
202 ;; 201 ;;
203 ;; vip-insert-intercept-minor-mode 202 ;; viper-insert-intercept-minor-mode
204 ;; vip-insert-local-user-minor-mode 203 ;; viper-insert-local-user-minor-mode
205 ;; vip-insert-global-user-minor-mode 204 ;; viper-insert-global-user-minor-mode
206 ;; vip-insert-kbd-minor-mode 205 ;; viper-insert-kbd-minor-mode
207 ;; vip-insert-state-modifier-minor-mode 206 ;; viper-insert-state-modifier-minor-mode
208 ;; vip-insert-diehard-minor-mode 207 ;; viper-insert-diehard-minor-mode
209 ;; vip-insert-basic-minor-mode 208 ;; viper-insert-basic-minor-mode
210 ;; 209 ;;
211 ;; As with VI's editing modes, the first mode, vip-insert-intercept-minor-mode 210 ;; As with VI's editing modes, the first mode,
212 ;; is used to bind vital keys that are not to be changed by the user. 211 ;; viper-insert-intercept-minor-mode is used to bind vital keys that are not
213 ;; 212 ;; to be changed by the user.
214 ;; The next mode, vip-insert-local-user-minor-mode, is used to customize 213 ;;
214 ;; The next mode, viper-insert-local-user-minor-mode, is used to customize
215 ;; bindings in the insert state of Viper. The third mode, 215 ;; bindings in the insert state of Viper. The third mode,
216 ;; vip-insert-global-user-minor-mode is like 216 ;; viper-insert-global-user-minor-mode is like
217 ;; vip-insert-local-user-minor-mode, except that its bindings are seen in 217 ;; viper-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 218 ;; all Viper buffers. As with viper-vi-local-user-minor-mode, its bindings
219 ;; should be done via the function vip-add-local-keys. Bindings for 219 ;; should be done via the function viper-add-local-keys. Bindings for
220 ;; vip-insert-global-user-minor-mode can be set with the define-key command. 220 ;; viper-insert-global-user-minor-mode can be set with the define-key command.
221 ;; 221 ;;
222 ;; The next minor mode, vip-insert-kbd-minor-mode, 222 ;; The next minor mode, viper-insert-kbd-minor-mode,
223 ;; is used for keyboard VI-style macros defined with :map!. 223 ;; is used for keyboard VI-style macros defined with :map!.
224 ;; 224 ;;
225 ;; The fifth minor mode, vip-insert-state-modifier-minor-mode, is like 225 ;; The fifth minor mode, viper-insert-state-modifier-minor-mode, is like
226 ;; vip-vi-state-modifier-minor-mode, except that it is used in the Insert 226 ;; viper-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. 227 ;; state; it can be used to modify keys in a mode-specific fashion.
228 ;; 228 ;;
229 ;; The minor mode vip-insert-diehard-minor-mode is in effect when 229 ;; The minor mode viper-insert-diehard-minor-mode is in effect when
230 ;; the user wants a high degree of Vi compatibility (a bad idea, really!). 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 231 ;; The last minor mode, viper-insert-basic-minor-mode, is always in effect
232 ;; when Viper is in insert state. It binds a small number of keys needed for 232 ;; when Viper is in insert state. It binds a small number of keys needed for
233 ;; Viper's operation. 233 ;; Viper's operation.
234 ;; 234 ;;
235 ;; Finally, Viper provides minor modes for overriding bindings set by Emacs 235 ;; Finally, Viper provides minor modes for overriding bindings set by Emacs
236 ;; modes when Viper is in Emacs state: 236 ;; modes when Viper is in Emacs state:
237 ;; 237 ;;
238 ;; vip-emacs-local-user-minor-mode 238 ;; viper-emacs-local-user-minor-mode
239 ;; vip-emacs-global-user-minor-mode 239 ;; viper-emacs-global-user-minor-mode
240 ;; vip-emacs-kbd-minor-mode 240 ;; viper-emacs-kbd-minor-mode
241 ;; vip-emacs-state-modifier-minor-mode 241 ;; viper-emacs-state-modifier-minor-mode
242 ;; 242 ;;
243 ;; These minor modes are in effect when Viper is in Emacs state. The keymap 243 ;; These minor modes are in effect when Viper is in Emacs state. The keymap
244 ;; associated with vip-emacs-global-user-minor-mode, 244 ;; associated with viper-emacs-global-user-minor-mode,
245 ;; vip-emacs-global-user-map, overrides the global and local keymaps as 245 ;; viper-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 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 247 ;; viper-emacs-local-user-minor-mode, viper-emacs-local-user-map, overrides
248 ;; everything, but it is used on a per buffer basis. 248 ;; everything, but it is used on a per buffer basis.
249 ;; The keymap associated with vip-emacs-state-modifier-minor-mode 249 ;; The keymap associated with viper-emacs-state-modifier-minor-mode
250 ;; overrides keys on a per-major-mode basis. The 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 251 ;; viper-emacs-kbd-minor-mode is used to define Vi-style macros in Emacs
252 ;; state. 252 ;; state.
253 ;; 253 ;;
254 ;; 3. There is also one minor mode that is used when Viper is in its 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 255 ;; replace-state (used for commands like cw, C, etc.). This mode is
256 ;; called 256 ;; called
257 ;; 257 ;;
258 ;; vip-replace-minor-mode 258 ;; viper-replace-minor-mode
259 ;; 259 ;;
260 ;; and its keymap is vip-replace-map. Replace minor mode is always 260 ;; and its keymap is viper-replace-map. Replace minor mode is always
261 ;; used in conjunction with the minor modes for insert-state, and its 261 ;; used in conjunction with the minor modes for insert-state, and its
262 ;; keymap overshadows the keymaps for insert minor modes. 262 ;; keymap overshadows the keymaps for insert minor modes.
263 ;; 263 ;;
264 ;; 4. Defining buffer-local bindings in Vi and Insert modes. 264 ;; 4. Defining buffer-local bindings in Vi and Insert modes.
265 ;; As mentioned before, sometimes, it is convenient to have 265 ;; As mentioned before, sometimes, it is convenient to have
266 ;; buffer-specific of mode-specific key bindings in Vi and insert modes. 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 267 ;; Viper provides a special function, viper-add-local-keys, to do precisely
268 ;; this. For instance, is you need to add couple of mode-specific bindings 268 ;; this. For instance, is you need to add couple of mode-specific bindings
269 ;; to Insert mode, you can put 269 ;; to Insert mode, you can put
270 ;; 270 ;;
271 ;; (vip-add-local-keys 'insert-state '((key1 . func1) (key2 .func2))) 271 ;; (viper-add-local-keys 'insert-state '((key1 . func1) (key2 .func2)))
272 ;; 272 ;;
273 ;; somewhere in a hook of this major mode. If you put something like this 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 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. 275 ;; buffer that was current at the time of the call to viper-add-local-keys.
276 ;; The only thing to make sure here is that the major mode of this buffer 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 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. 278 ;; (kill-all-local-variables). See viper-add-local-keys for more details.
279 ;; 279 ;;
280 ;; 280 ;;
281 ;; TO DO (volunteers?): 281 ;; TO DO (volunteers?):
282 ;; 282 ;;
283 ;; 1. Some of the code that is inherited from VIP-3.5 is rather 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 284 ;; convoluted. Instead of viper-command-argument, keymaps should bind the
285 ;; actual commands. E.g., "dw" should be bound to a generic command 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 286 ;; viper-delete that will delete things based on the value of
287 ;; last-command-char. This would greatly simplify the logic and the code. 287 ;; last-command-char. This would greatly simplify the logic and the code.
288 ;; 288 ;;
289 ;; 2. Somebody should venture to write a customization package a la 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 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 291 ;; that meet certain specs (e.g., match a regexp) and whose doc string
301 (require 'ring) 301 (require 'ring)
302 302
303 ;; compiler pacifier 303 ;; compiler pacifier
304 (defvar mark-even-if-inactive) 304 (defvar mark-even-if-inactive)
305 (defvar viper-expert-level) 305 (defvar viper-expert-level)
306 (defvar vip-expert-level) 306 (defvar viper-expert-level)
307 307
308 ;; loading happens only in non-interactive compilation 308 ;; loading happens only in non-interactive compilation
309 ;; in order to spare non-viperized emacs from being viperized 309 ;; in order to spare non-viperized emacs from being viperized
310 (if noninteractive 310 (if noninteractive
311 (eval-when-compile 311 (eval-when-compile
318 ;; end pacifier 318 ;; end pacifier
319 319
320 (require 'viper-init) 320 (require 'viper-init)
321 321
322 ;; better be defined before Viper custom group. 322 ;; better be defined before Viper custom group.
323 (defvar vip-custom-file-name (vip-convert-standard-file-name "~/.viper") 323 (defvar viper-custom-file-name (convert-standard-filename "~/.viper")
324 "Viper customisation file. 324 "Viper customisation file.
325 If set by the user, this must be done _before_ Viper is loaded in `~/.emacs'.") 325 If set by the user, this must be done _before_ Viper is loaded in `~/.emacs'.")
326 326
327 (defgroup viper nil 327 (defgroup viper nil
328 "Vi emulation within Emacs. 328 "Vi emulation within Emacs.
329 NOTE: Viper customization should be saved in `vip-custom-file-name', which 329 NOTE: Viper customization should be saved in `viper-custom-file-name', which
330 defaults to `~/.viper'." 330 defaults to `~/.viper'."
331 :prefix "vip-" 331 :prefix "viper-"
332 :group 'emulations) 332 :group 'emulations)
333 333
334 (require 'viper-cmd) 334 (require 'viper-cmd)
335 335
336 (defvar vip-always t 336 (defcustom viper-always t
337 "See `viper-always'. This variable is for compatibility with older Vipers.")
338 (defcustom viper-always vip-always
339 "Non-nil means, arrange for vi-state to be a default when appropriate. 337 "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 338 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 339 whether to use Viper in the first place, while `viper-always', if nil, lets
342 user decide when to invoke Viper in a major mode." 340 user decide when to invoke Viper in a major mode."
343 :type 'boolean 341 :type 'boolean
361 DO NOT set this variable interactively." 359 DO NOT set this variable interactively."
362 :type '(choice (const nil) (const t) (const ask)) 360 :type '(choice (const nil) (const t) (const ask))
363 :tag "Set Viper Mode on Loading" 361 :tag "Set Viper Mode on Loading"
364 :group 'viper) 362 :group 'viper)
365 363
364 (defcustom viper-non-vi-major-modes
365 '(custom-mode dired-mode efs-mode internal-ange-ftp-mode tar-mode
366 mh-folder-mode gnus-group-mode gnus-summary-mode Info-mode
367 Buffer-menu-mode view-mode vm-mode vm-summary-mode)
368 "*A list of major modes that should never come up in Vi command mode.
369 Viper automatically augments this list with some obvious modes, such as
370 `dired-mode', `tar-mode', etc. So, don't put modes on this list, unless
371 it comes up in a wrong Viper state."
372 :type 'list
373 :group 'viper)
374
375
366 376
367 ;; The following are provided for compatibility with older VIP's
368 377
369 ;;;###autoload 378 ;;;###autoload
370 (defalias 'vip-mode 'viper-mode) 379 (defun toggle-viper-mode ()
371 380 (interactive)
372 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) 381 (if (eq viper-mode t)
373 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) 382 (viper-go-away)
374 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) 383 (setq viper-mode nil)
375 384 (viper-mode)))
376
377
378 385
379 ;;;###autoload 386 ;;;###autoload
380 (defun viper-mode () 387 (defun viper-mode ()
381 "Turn on Viper emulation of Vi." 388 "Turn on Viper emulation of Vi."
382 (interactive) 389 (interactive)
383 (if (not noninteractive) 390 (if (not noninteractive)
384 (progn 391 (progn
385 ;; if the user requested viper-mode explicitly 392 ;; if the user requested viper-mode explicitly
386 (if viper-mode 393 (if viper-mode
387 () 394 ()
388 (setq viper-mode 1) 395 (setq viper-mode t)
389 (load-library "viper")) 396 (load-library "viper"))
390 397
391 (if vip-first-time ; This check is important. Without it, startup and 398 (if viper-first-time ; Important check. Prevents mix-up of startup and
392 (progn ; expert-level msgs mix up when viper-mode recurses 399 (progn ; expert-level msgs when viper-mode recurses
393 (setq vip-first-time nil) 400 (setq viper-first-time nil)
394 (if (not vip-inhibit-startup-message) 401 (if (not viper-inhibit-startup-message)
395 (save-window-excursion 402 (save-window-excursion
396 (setq vip-inhibit-startup-message t) 403 (setq viper-inhibit-startup-message t)
397 (delete-other-windows) 404 (delete-other-windows)
398 (switch-to-buffer "Viper Startup Message") 405 (switch-to-buffer "Viper Startup Message")
399 (erase-buffer) 406 (erase-buffer)
400 (insert 407 (insert
401 (substitute-command-keys 408 (substitute-command-keys
442 449
443 This startup message appears whenever you load Viper, unless you type `y' now." 450 This startup message appears whenever you load Viper, unless you type `y' now."
444 )) 451 ))
445 (goto-char (point-min)) 452 (goto-char (point-min))
446 (if (y-or-n-p "Inhibit Viper startup message? ") 453 (if (y-or-n-p "Inhibit Viper startup message? ")
447 (vip-save-setting 454 (viper-save-setting
448 'vip-inhibit-startup-message 455 'viper-inhibit-startup-message
449 "Viper startup message inhibited" 456 "Viper startup message inhibited"
450 vip-custom-file-name t)) 457 viper-custom-file-name t))
451 ;;(kill-buffer (current-buffer)) 458 ;;(kill-buffer (current-buffer))
452 (message 459 (message
453 "The last message is in buffer `Viper Startup Message'") 460 "The last message is in buffer `Viper Startup Message'")
454 (sit-for 4) 461 (sit-for 4)
455 )) 462 ))
456 (viper-set-expert-level 'dont-change-unless))) 463 (viper-set-expert-level 'dont-change-unless)))
457 (vip-change-state-to-vi)))) 464
465 (or (memq major-mode viper-non-vi-major-modes) ; don't switch to Vi
466 (viper-change-state-to-vi)))))
458 467
459 468
460 ;; This hook designed to enable Vi-style editing in comint-based modes." 469 ;; This hook designed to enable Vi-style editing in comint-based modes."
461 (defun vip-comint-mode-hook () 470 (defun viper-comint-mode-hook ()
462 (setq require-final-newline nil 471 (setq require-final-newline nil
463 vip-ex-style-editing-in-insert nil 472 viper-ex-style-editing-in-insert nil
464 vip-ex-style-motion nil) 473 viper-ex-style-motion nil)
465 (vip-change-state-to-insert)) 474 (viper-change-state-to-insert))
466 475
467 476
468 ;; remove viper hooks from SYMBOL 477 ;; remove viper hooks from SYMBOL
469 (defun viper-remove-hooks (symbol) 478 (defun viper-remove-hooks (symbol)
470 (cond ((not (boundp symbol)) nil) 479 (cond ((not (boundp symbol)) nil)
471 ((not (listp (eval symbol))) nil) 480 ((not (listp (eval symbol))) nil)
472 ((string-match "-hook" (symbol-name symbol)) 481 ((string-match "-hook" (symbol-name symbol))
473 (remove-hook symbol 'viper-mode) 482 (remove-hook symbol 'viper-mode)
474 (remove-hook symbol 'vip-change-state-to-emacs) 483 (remove-hook symbol 'viper-change-state-to-emacs)
475 (remove-hook symbol 'vip-change-state-to-insert) 484 (remove-hook symbol 'viper-change-state-to-insert)
476 (remove-hook symbol 'vip-change-state-to-vi) 485 (remove-hook symbol 'viper-change-state-to-vi)
477 ))) 486 )))
478 487
479 ;; Remove local value in all existing buffers 488 ;; Remove local value in all existing buffers
480 ;; This doesn't delocalize vars (which would have been desirable) 489 ;; This doesn't delocalize vars (which would have been desirable)
481 (defun viper-delocalize-var (symbol) 490 (defun viper-delocalize-var (symbol)
512 (viper-standard-value 521 (viper-standard-value
513 'mode-line-buffer-identification viper-saved-non-viper-variables) 522 'mode-line-buffer-identification viper-saved-non-viper-variables)
514 global-mode-string 523 global-mode-string
515 (viper-standard-value 'global-mode-string viper-saved-non-viper-variables)) 524 (viper-standard-value 'global-mode-string viper-saved-non-viper-variables))
516 525
517 (if vip-emacs-p 526 (if viper-emacs-p
518 (setq-default 527 (setq-default
519 mark-even-if-inactive 528 mark-even-if-inactive
520 (viper-standard-value 529 (viper-standard-value
521 'mark-even-if-inactive viper-saved-non-viper-variables))) 530 'mark-even-if-inactive viper-saved-non-viper-variables)))
522 531
524 (viper-delocalize-var 'minor-mode-map-alist) 533 (viper-delocalize-var 'minor-mode-map-alist)
525 (viper-delocalize-var 'require-final-newline) 534 (viper-delocalize-var 'require-final-newline)
526 535
527 536
528 ;; deactivate all advices done by Viper. 537 ;; deactivate all advices done by Viper.
529 (ad-deactivate-regexp "vip-") 538 (ad-deactivate-regexp "viper-")
530 539
531 (setq viper-mode nil) 540 (setq viper-mode nil)
532 541
533 (viper-delocalize-var 'vip-vi-minibuffer-minor-mode) 542 (viper-delocalize-var 'viper-vi-minibuffer-minor-mode)
534 (viper-delocalize-var 'vip-insert-minibuffer-minor-mode) 543 (viper-delocalize-var 'viper-insert-minibuffer-minor-mode)
535 (viper-delocalize-var 'vip-vi-intercept-minor-mode) 544 (viper-delocalize-var 'viper-vi-intercept-minor-mode)
536 (viper-delocalize-var 'vip-insert-intercept-minor-mode) 545 (viper-delocalize-var 'viper-insert-intercept-minor-mode)
537 546
538 (viper-delocalize-var 'vip-vi-local-user-minor-mode) 547 (viper-delocalize-var 'viper-vi-local-user-minor-mode)
539 (viper-delocalize-var 'vip-vi-kbd-minor-mode) 548 (viper-delocalize-var 'viper-vi-kbd-minor-mode)
540 (viper-delocalize-var 'vip-vi-global-user-minor-mode) 549 (viper-delocalize-var 'viper-vi-global-user-minor-mode)
541 (viper-delocalize-var 'vip-vi-state-modifier-minor-mode) 550 (viper-delocalize-var 'viper-vi-state-modifier-minor-mode)
542 (viper-delocalize-var 'vip-vi-diehard-minor-mode) 551 (viper-delocalize-var 'viper-vi-diehard-minor-mode)
543 (viper-delocalize-var 'vip-vi-basic-minor-mode) 552 (viper-delocalize-var 'viper-vi-basic-minor-mode)
544 553
545 (viper-delocalize-var 'vip-replace-minor-mode) 554 (viper-delocalize-var 'viper-replace-minor-mode)
546 555
547 (viper-delocalize-var 'vip-insert-local-user-minor-mode) 556 (viper-delocalize-var 'viper-insert-local-user-minor-mode)
548 (viper-delocalize-var 'vip-insert-kbd-minor-mode) 557 (viper-delocalize-var 'viper-insert-kbd-minor-mode)
549 (viper-delocalize-var 'vip-insert-global-user-minor-mode) 558 (viper-delocalize-var 'viper-insert-global-user-minor-mode)
550 (viper-delocalize-var 'vip-insert-state-modifier-minor-mode) 559 (viper-delocalize-var 'viper-insert-state-modifier-minor-mode)
551 (viper-delocalize-var 'vip-insert-diehard-minor-mode) 560 (viper-delocalize-var 'viper-insert-diehard-minor-mode)
552 (viper-delocalize-var 'vip-insert-basic-minor-mode) 561 (viper-delocalize-var 'viper-insert-basic-minor-mode)
553 562
554 (viper-delocalize-var 'vip-emacs-intercept-minor-mode) 563 (viper-delocalize-var 'viper-emacs-intercept-minor-mode)
555 (viper-delocalize-var 'vip-emacs-local-user-minor-mode) 564 (viper-delocalize-var 'viper-emacs-local-user-minor-mode)
556 (viper-delocalize-var 'vip-emacs-kbd-minor-mode) 565 (viper-delocalize-var 'viper-emacs-kbd-minor-mode)
557 (viper-delocalize-var 'vip-emacs-global-user-minor-mode) 566 (viper-delocalize-var 'viper-emacs-global-user-minor-mode)
558 (viper-delocalize-var 'vip-emacs-state-modifier-minor-mode) 567 (viper-delocalize-var 'viper-emacs-state-modifier-minor-mode)
559 568
560 (setq-default vip-vi-minibuffer-minor-mode nil 569 (setq-default viper-vi-minibuffer-minor-mode nil
561 vip-insert-minibuffer-minor-mode nil 570 viper-insert-minibuffer-minor-mode nil
562 vip-vi-intercept-minor-mode nil 571 viper-vi-intercept-minor-mode nil
563 vip-insert-intercept-minor-mode nil 572 viper-insert-intercept-minor-mode nil
564 573
565 vip-vi-local-user-minor-mode nil 574 viper-vi-local-user-minor-mode nil
566 vip-vi-kbd-minor-mode nil 575 viper-vi-kbd-minor-mode nil
567 vip-vi-global-user-minor-mode nil 576 viper-vi-global-user-minor-mode nil
568 vip-vi-state-modifier-minor-mode nil 577 viper-vi-state-modifier-minor-mode nil
569 vip-vi-diehard-minor-mode nil 578 viper-vi-diehard-minor-mode nil
570 vip-vi-basic-minor-mode nil 579 viper-vi-basic-minor-mode nil
571 580
572 vip-replace-minor-mode nil 581 viper-replace-minor-mode nil
573 582
574 vip-insert-local-user-minor-mode nil 583 viper-insert-local-user-minor-mode nil
575 vip-insert-kbd-minor-mode nil 584 viper-insert-kbd-minor-mode nil
576 vip-insert-global-user-minor-mode nil 585 viper-insert-global-user-minor-mode nil
577 vip-insert-state-modifier-minor-mode nil 586 viper-insert-state-modifier-minor-mode nil
578 vip-insert-diehard-minor-mode nil 587 viper-insert-diehard-minor-mode nil
579 vip-insert-basic-minor-mode nil 588 viper-insert-basic-minor-mode nil
580 589
581 vip-emacs-intercept-minor-mode nil 590 viper-emacs-intercept-minor-mode nil
582 vip-emacs-local-user-minor-mode nil 591 viper-emacs-local-user-minor-mode nil
583 vip-emacs-kbd-minor-mode nil 592 viper-emacs-kbd-minor-mode nil
584 vip-emacs-global-user-minor-mode nil 593 viper-emacs-global-user-minor-mode nil
585 vip-emacs-state-modifier-minor-mode nil 594 viper-emacs-state-modifier-minor-mode nil
586 ) 595 )
587 596
588 ;; remove all hooks set by viper 597 ;; remove all hooks set by viper
589 (mapatoms 'viper-remove-hooks) 598 (mapatoms 'viper-remove-hooks)
590 (remove-hook 'comint-mode-hook 'vip-comint-mode-hook) 599 (remove-hook 'comint-mode-hook 'viper-comint-mode-hook)
591 (remove-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel) 600 (remove-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel)
592 ) 601
602 ;; unbind Viper mouse bindings
603 (viper-unbind-mouse-search-key)
604 (viper-unbind-mouse-insert-key)
605 ;; In emacs, we have to advice handle-switch-frame
606 ;; This advice is undone earlier, when all advices matchine "viper-" are
607 ;; deactivated.
608 (if viper-xemacs-p
609 (remove-hook 'mouse-leave-frame-hook 'viper-remember-current-frame))
610 ) ; end viper-go-away
593 611
594 612
595 613
596 614
597 ;; This sets major mode hooks to make them come up in vi-state. 615 ;; This sets major mode hooks to make them come up in vi-state.
598 (defun vip-set-hooks () 616 (defun viper-set-hooks ()
599 617
600 ;; It is of course a misnomer to call viper-mode a `major mode'. 618 ;; It is of course a misnomer to call viper-mode a `major mode'.
601 ;; However, this has the effect that if the user didn't specify the 619 ;; However, this has the effect that if the user didn't specify the
602 ;; default mode, new buffers that fall back on the default will come up 620 ;; default mode, new buffers that fall back on the default will come up
603 ;; in Fundamental Mode and Vi state. 621 ;; in Fundamental Mode and Vi state.
604 (setq default-major-mode 'viper-mode) 622 (setq default-major-mode 'viper-mode)
605 623
606 ;; The following major modes should come up in vi-state 624 ;; The following major modes should come up in vi-state
607 (defadvice fundamental-mode (after vip-fundamental-mode-ad activate) 625 (defadvice fundamental-mode (after viper-fundamental-mode-ad activate)
608 "Run `vip-change-state-to-vi' on entry." 626 "Run `viper-change-state-to-vi' on entry."
609 (vip-change-state-to-vi)) 627 (viper-change-state-to-vi))
610 628
611 (defvar makefile-mode-hook) 629 (defvar makefile-mode-hook)
612 (add-hook 'makefile-mode-hook 'viper-mode) 630 (add-hook 'makefile-mode-hook 'viper-mode)
613 631
614 (defvar help-mode-hook) 632 (defvar help-mode-hook)
615 (add-hook 'help-mode-hook 'viper-mode) 633 (add-hook 'help-mode-hook 'viper-mode)
616 (vip-modify-major-mode 'help-mode 'vi-state vip-help-modifier-map) 634 (viper-modify-major-mode 'help-mode 'vi-state viper-help-modifier-map)
617 635
618 (defvar awk-mode-hook) 636 (defvar awk-mode-hook)
619 (add-hook 'awk-mode-hook 'viper-mode) 637 (add-hook 'awk-mode-hook 'viper-mode)
620 638
621 (defvar html-mode-hook) 639 (defvar html-mode-hook)
678 696
679 (defvar python-mode-hook) 697 (defvar python-mode-hook)
680 (add-hook 'python-mode-hook 'viper-mode) 698 (add-hook 'python-mode-hook 'viper-mode)
681 699
682 (defvar emerge-startup-hook) 700 (defvar emerge-startup-hook)
683 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) 701 (add-hook 'emerge-startup-hook 'viper-change-state-to-emacs)
684 702
685 ;; Tell vc-diff to put *vc* in Vi mode 703 ;; Tell vc-diff to put *vc* in Vi mode
686 (if (featurep 'vc) 704 (if (featurep 'vc)
687 (defadvice vc-diff (after vip-vc-ad activate) 705 (defadvice vc-diff (after viper-vc-ad activate)
688 "Force Vi state in VC diff buffer." 706 "Force Vi state in VC diff buffer."
689 (vip-change-state-to-vi)) 707 (viper-change-state-to-vi))
690 (vip-eval-after-load 708 (eval-after-load
691 "vc" 709 "vc"
692 '(defadvice vc-diff (after vip-vc-ad activate) 710 '(defadvice vc-diff (after viper-vc-ad activate)
693 "Force Vi state in VC diff buffer." 711 "Force Vi state in VC diff buffer."
694 (vip-change-state-to-vi)))) 712 (viper-change-state-to-vi))))
695 713
696 (vip-eval-after-load 714 (eval-after-load
697 "emerge" 715 "emerge"
698 '(defadvice emerge-quit (after vip-emerge-advice activate) 716 '(defadvice emerge-quit (after viper-emerge-advice activate)
699 "Run `vip-change-state-to-vi' after quitting emerge." 717 "Run `viper-change-state-to-vi' after quitting emerge."
700 (vip-change-state-to-vi))) 718 (viper-change-state-to-vi)))
701 ;; In case Emerge was loaded before Viper. 719 ;; In case Emerge was loaded before Viper.
702 (defadvice emerge-quit (after vip-emerge-advice activate) 720 (defadvice emerge-quit (after viper-emerge-advice activate)
703 "Run `vip-change-state-to-vi' after quitting emerge." 721 "Run `viper-change-state-to-vi' after quitting emerge."
704 (vip-change-state-to-vi)) 722 (viper-change-state-to-vi))
705 723
706 ;; passwd.el sets up its own buffer, which turns up in Vi mode, 724 ;; passwd.el sets up its own buffer, which turns up in Vi mode,
707 ;; thus overriding the local map. We don't need Vi mode here. 725 ;; thus overriding the local map. We don't need Vi mode here.
708 (vip-eval-after-load 726 (eval-after-load
709 "passwd" 727 "passwd"
710 '(defadvice read-passwd-1 (before vip-passwd-ad activate) 728 '(defadvice read-passwd-1 (before viper-passwd-ad activate)
711 "Switch to emacs state while reading password." 729 "Switch to emacs state while reading password."
712 (vip-change-state-to-emacs))) 730 (viper-change-state-to-emacs)))
713 731
714 ;; Emacs shell, ange-ftp, and comint-based modes 732 ;; Emacs shell, ange-ftp, and comint-based modes
715 (defvar comint-mode-hook) 733 (defvar comint-mode-hook)
716 (vip-modify-major-mode 734 (viper-modify-major-mode
717 'comint-mode 'insert-state vip-comint-mode-modifier-map) 735 'comint-mode 'insert-state viper-comint-mode-modifier-map)
718 (vip-modify-major-mode 736 (viper-modify-major-mode
719 'comint-mode 'vi-state vip-comint-mode-modifier-map) 737 'comint-mode 'vi-state viper-comint-mode-modifier-map)
720 (vip-modify-major-mode 738 (viper-modify-major-mode
721 'shell-mode 'insert-state vip-comint-mode-modifier-map) 739 'shell-mode 'insert-state viper-comint-mode-modifier-map)
722 (vip-modify-major-mode 740 (viper-modify-major-mode
723 'shell-mode 'vi-state vip-comint-mode-modifier-map) 741 'shell-mode 'vi-state viper-comint-mode-modifier-map)
724 ;; ange-ftp in XEmacs 742 ;; ange-ftp in XEmacs
725 (vip-modify-major-mode 743 (viper-modify-major-mode
726 'ange-ftp-shell-mode 'insert-state vip-comint-mode-modifier-map) 744 'ange-ftp-shell-mode 'insert-state viper-comint-mode-modifier-map)
727 (vip-modify-major-mode 745 (viper-modify-major-mode
728 'ange-ftp-shell-mode 'vi-state vip-comint-mode-modifier-map) 746 'ange-ftp-shell-mode 'vi-state viper-comint-mode-modifier-map)
729 ;; ange-ftp in Emacs 747 ;; ange-ftp in Emacs
730 (vip-modify-major-mode 748 (viper-modify-major-mode
731 'internal-ange-ftp-mode 'insert-state vip-comint-mode-modifier-map) 749 'internal-ange-ftp-mode 'insert-state viper-comint-mode-modifier-map)
732 (vip-modify-major-mode 750 (viper-modify-major-mode
733 'internal-ange-ftp-mode 'vi-state vip-comint-mode-modifier-map) 751 'internal-ange-ftp-mode 'vi-state viper-comint-mode-modifier-map)
734 ;; set hook 752 ;; set hook
735 (add-hook 'comint-mode-hook 'vip-comint-mode-hook) 753 (add-hook 'comint-mode-hook 'viper-comint-mode-hook)
736 754
737 ;; Shell scripts 755 ;; Shell scripts
738 (defvar sh-mode-hook) 756 (defvar sh-mode-hook)
739 (add-hook 'sh-mode-hook 'viper-mode) 757 (add-hook 'sh-mode-hook 'viper-mode)
740 (defvar ksh-mode-hook) 758 (defvar ksh-mode-hook)
741 (add-hook 'ksh-mode-hook 'viper-mode) 759 (add-hook 'ksh-mode-hook 'viper-mode)
742 760
743 ;; Dired 761 ;; Dired
744 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map) 762 (viper-modify-major-mode 'dired-mode 'emacs-state viper-dired-modifier-map)
745 (vip-set-emacs-state-searchstyle-macros nil 'dired-mode) 763 (viper-set-emacs-state-searchstyle-macros nil 'dired-mode)
746 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) 764 (add-hook 'dired-mode-hook 'viper-change-state-to-emacs)
747 765
748 ;; Tar 766 ;; Tar
749 (vip-modify-major-mode 'tar-mode 'emacs-state vip-slash-and-colon-map) 767 (viper-modify-major-mode 'tar-mode 'emacs-state viper-slash-and-colon-map)
750 (vip-set-emacs-state-searchstyle-macros nil 'tar-mode) 768 (viper-set-emacs-state-searchstyle-macros nil 'tar-mode)
751 769
752 ;; MH-E 770 ;; MH-E
753 (vip-modify-major-mode 'mh-folder-mode 'emacs-state vip-slash-and-colon-map) 771 (viper-modify-major-mode
754 (vip-set-emacs-state-searchstyle-macros nil 'mh-folder-mode) 772 'mh-folder-mode 'emacs-state viper-slash-and-colon-map)
773 (viper-set-emacs-state-searchstyle-macros nil 'mh-folder-mode)
755 ;; changing state to emacs is needed so the preceding will take hold 774 ;; changing state to emacs is needed so the preceding will take hold
756 (add-hook 'mh-folder-mode-hook 'vip-change-state-to-emacs) 775 (add-hook 'mh-folder-mode-hook 'viper-change-state-to-emacs)
757 (add-hook 'mh-show-mode-hook 'viper-mode) 776 (add-hook 'mh-show-mode-hook 'viper-mode)
758 777
759 ;; Gnus 778 ;; Gnus
760 (vip-modify-major-mode 'gnus-group-mode 'emacs-state vip-slash-and-colon-map) 779 (viper-modify-major-mode
761 (vip-set-emacs-state-searchstyle-macros nil 'gnus-group-mode) 780 'gnus-group-mode 'emacs-state viper-slash-and-colon-map)
762 (vip-modify-major-mode 781 (viper-set-emacs-state-searchstyle-macros nil 'gnus-group-mode)
763 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map) 782 (viper-modify-major-mode
764 (vip-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode) 783 'gnus-summary-mode 'emacs-state viper-slash-and-colon-map)
784 (viper-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode)
765 ;; changing state to emacs is needed so the preceding will take hold 785 ;; changing state to emacs is needed so the preceding will take hold
766 (add-hook 'gnus-group-mode-hook 'vip-change-state-to-emacs) 786 (add-hook 'gnus-group-mode-hook 'viper-change-state-to-emacs)
767 (add-hook 'gnus-summary-mode-hook 'vip-change-state-to-emacs) 787 (add-hook 'gnus-summary-mode-hook 'viper-change-state-to-emacs)
768 (add-hook 'gnus-article-mode-hook 'viper-mode) 788 (add-hook 'gnus-article-mode-hook 'viper-mode)
769 789
770 ;; Info 790 ;; Info
771 (vip-modify-major-mode 'Info-mode 'emacs-state vip-slash-and-colon-map) 791 (viper-modify-major-mode 'Info-mode 'emacs-state viper-slash-and-colon-map)
772 (vip-set-emacs-state-searchstyle-macros nil 'Info-mode) 792 (viper-set-emacs-state-searchstyle-macros nil 'Info-mode)
773 ;; Switching to emacs is needed so the above will take hold 793 ;; Switching to emacs is needed so the above will take hold
774 (defadvice Info-mode (after vip-Info-ad activate) 794 (defadvice Info-mode (after viper-Info-ad activate)
775 "Switch to emacs mode." 795 "Switch to emacs mode."
776 (vip-change-state-to-emacs)) 796 (viper-change-state-to-emacs))
777 797
778 ;; Buffer menu 798 ;; Buffer menu
779 (vip-modify-major-mode 799 (viper-modify-major-mode
780 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map) 800 'Buffer-menu-mode 'emacs-state viper-slash-and-colon-map)
781 (vip-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode) 801 (viper-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode)
782 ;; Switching to emacs is needed so the above will take hold 802 ;; Switching to emacs is needed so the above will take hold
783 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate) 803 (defadvice Buffer-menu-mode (after viper-Buffer-menu-ad activate)
784 "Switch to emacs mode." 804 "Switch to emacs mode."
785 (vip-change-state-to-emacs)) 805 (viper-change-state-to-emacs))
786 806
787 ;; View mode 807 ;; View mode
788 (defvar view-mode-hook) 808 (defvar view-mode-hook)
789 (defvar view-hook) 809 (defvar view-hook)
790 (add-hook 'view-hook 'vip-change-state-to-emacs) 810 (add-hook 'view-hook 'viper-change-state-to-emacs)
791 (add-hook 'view-mode-hook 'vip-change-state-to-emacs) 811 (add-hook 'view-mode-hook 'viper-change-state-to-emacs)
792 812
793 ;; For VM users. 813 ;; For VM users.
794 ;; Put summary and other VM buffers in Emacs state. 814 ;; Put summary and other VM buffers in Emacs state.
795 (defvar vm-mode-hooks) 815 (defvar vm-mode-hooks)
796 (defvar vm-summary-mode-hooks) 816 (defvar vm-summary-mode-hooks)
797 (add-hook 'vm-mode-hooks 'vip-change-state-to-emacs) 817 (add-hook 'vm-mode-hooks 'viper-change-state-to-emacs)
798 (add-hook 'vm-summary-mode-hooks 'vip-change-state-to-emacs) 818 (add-hook 'vm-summary-mode-hooks 'viper-change-state-to-emacs)
799 819
800 ;; For RMAIL users. 820 ;; For RMAIL users.
801 ;; Put buf in Emacs state after edit. 821 ;; Put buf in Emacs state after edit.
802 (vip-eval-after-load 822 (eval-after-load
803 "rmailedit" 823 "rmailedit"
804 '(defadvice rmail-cease-edit (after vip-rmail-advice activate) 824 '(defadvice rmail-cease-edit (after viper-rmail-advice activate)
805 "Switch to emacs state when done editing message." 825 "Switch to emacs state when done editing message."
806 (vip-change-state-to-emacs))) 826 (viper-change-state-to-emacs)))
807 ;; In case RMAIL was loaded before Viper. 827 ;; In case RMAIL was loaded before Viper.
808 (defadvice rmail-cease-edit (after vip-rmail-advice activate) 828 (defadvice rmail-cease-edit (after viper-rmail-advice activate)
809 "Switch to emacs state when done editing message." 829 "Switch to emacs state when done editing message."
810 (vip-change-state-to-emacs)) 830 (viper-change-state-to-emacs))
811 ) ; vip-set-hooks 831 ) ; viper-set-hooks
812 832
813 833
814 ;; these are primarily advices and Vi-ish variable settings 834 ;; these are primarily advices and Vi-ish variable settings
815 (defun vip-non-hook-settings () 835 (defun viper-non-hook-settings ()
816 836
817 ;; This var is not local in Emacs, so we make it local. 837 ;; This var is not local in Emacs, so we make it local. It must be local
818 ;; It must be local because although the stack of minor modes can be the same 838 ;; because although the stack of minor modes can be the same for all buffers,
819 ;; for all buffers, the associated *keymaps* can be different. In Viper, 839 ;; the associated *keymaps* can be different. In Viper,
820 ;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have 840 ;; viper-vi-local-user-map, viper-insert-local-user-map, and others can have
821 ;; different keymaps for different buffers. 841 ;; different keymaps for different buffers. Also, the keymaps associated
822 ;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode 842 ;; with viper-vi/insert-state-modifier-minor-mode can be different.
823 ;; can be different.
824 (make-variable-buffer-local 'minor-mode-map-alist) 843 (make-variable-buffer-local 'minor-mode-map-alist)
825 844
826 ;; Viper changes the default mode-line-buffer-identification 845 ;; Viper changes the default mode-line-buffer-identification
827 (setq-default mode-line-buffer-identification '(" %b")) 846 (setq-default mode-line-buffer-identification '(" %b"))
828 847
831 require-final-newline t) 850 require-final-newline t)
832 851
833 (make-variable-buffer-local 'require-final-newline) 852 (make-variable-buffer-local 'require-final-newline)
834 853
835 ;; don't bark when mark is inactive 854 ;; don't bark when mark is inactive
836 (if vip-emacs-p 855 (if viper-emacs-p
837 (setq mark-even-if-inactive t)) 856 (setq mark-even-if-inactive t))
838 857
839 (setq scroll-step 1) 858 (setq scroll-step 1)
840 859
841 ;; Variable displaying the current Viper state in the mode line. 860 ;; Variable displaying the current Viper state in the mode line.
842 (vip-deflocalvar vip-mode-string vip-emacs-state-id) 861 (viper-deflocalvar viper-mode-string viper-emacs-state-id)
843 (or (memq 'vip-mode-string global-mode-string) 862 (or (memq 'viper-mode-string global-mode-string)
844 (setq global-mode-string 863 (setq global-mode-string
845 (append '("" vip-mode-string) (cdr global-mode-string)))) 864 (append '("" viper-mode-string) (cdr global-mode-string))))
846 865
847 (defadvice read-key-sequence (around vip-read-keyseq-ad activate) 866 (defadvice read-key-sequence (around viper-read-keyseq-ad activate)
848 "Harness to work for Viper. This advice is harmless---don't worry!" 867 "Harness to work for Viper. This advice is harmless---don't worry!"
849 (let (inhibit-quit event keyseq) 868 (let (inhibit-quit event keyseq)
850 (setq keyseq ad-do-it) 869 (setq keyseq ad-do-it)
851 (setq event (if vip-xemacs-p 870 (setq event (if viper-xemacs-p
852 (elt keyseq 0) ; XEmacs returns vector of events 871 (elt keyseq 0) ; XEmacs returns vector of events
853 (elt (listify-key-sequence keyseq) 0))) 872 (elt (listify-key-sequence keyseq) 0)))
854 (if (vip-ESC-event-p event) 873 (if (viper-ESC-event-p event)
855 (let (unread-command-events) 874 (let (unread-command-events)
856 (vip-set-unread-command-events keyseq) 875 (viper-set-unread-command-events keyseq)
857 (if (vip-fast-keysequence-p) 876 (if (viper-fast-keysequence-p)
858 (let ((vip-vi-global-user-minor-mode nil) 877 (let ((viper-vi-global-user-minor-mode nil)
859 (vip-vi-local-user-minor-mode nil) 878 (viper-vi-local-user-minor-mode nil)
860 (vip-replace-minor-mode nil) ; actually unnecessary 879 (viper-replace-minor-mode nil) ; actually unnecessary
861 (vip-insert-global-user-minor-mode nil) 880 (viper-insert-global-user-minor-mode nil)
862 (vip-insert-local-user-minor-mode nil)) 881 (viper-insert-local-user-minor-mode nil))
863 (setq keyseq ad-do-it)) 882 (setq keyseq ad-do-it))
864 (setq keyseq ad-do-it)))) 883 (setq keyseq ad-do-it))))
865 keyseq)) 884 keyseq))
866 885
867 (defadvice describe-key (before vip-read-keyseq-ad protect activate) 886 (defadvice describe-key (before viper-read-keyseq-ad protect activate)
868 "Force to read key via `read-key-sequence'." 887 "Force to read key via `read-key-sequence'."
869 (interactive (list (vip-events-to-keys 888 (interactive (list (viper-events-to-keys
870 (read-key-sequence "Describe key: "))))) 889 (read-key-sequence "Describe key: ")))))
871 890
872 (defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate) 891 (defadvice describe-key-briefly
892 (before viper-read-keyseq-ad protect activate)
873 "Force to read key via `read-key-sequence'." 893 "Force to read key via `read-key-sequence'."
874 (interactive (list (vip-events-to-keys 894 (interactive (list (viper-events-to-keys
875 (read-key-sequence "Describe key briefly: "))))) 895 (read-key-sequence "Describe key briefly: ")))))
876 896
877 897
878 ;; Advice for use in find-file and read-file-name commands. 898 ;; Advice for use in find-file and read-file-name commands.
879 (defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate) 899 (defadvice exit-minibuffer (before viper-exit-minibuffer-advice activate)
880 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer." 900 "Run `viper-minibuffer-exit-hook' just before exiting the minibuffer."
881 (run-hooks 'vip-minibuffer-exit-hook)) 901 (run-hooks 'viper-minibuffer-exit-hook))
882 902
883 (defadvice find-file (before vip-add-suffix-advice activate) 903 (defadvice find-file (before viper-add-suffix-advice activate)
884 "Use `read-file-name' for reading arguments." 904 "Use `read-file-name' for reading arguments."
885 (interactive (cons (read-file-name "Find file: " nil default-directory) 905 (interactive (cons (read-file-name "Find file: " nil default-directory)
886 ;; if Mule and prefix argument, ask for coding system 906 ;; if Mule and prefix argument, ask for coding system
887 (cond ((and vip-emacs-p 907 (cond ((and viper-emacs-p
888 (boundp 'MULE)) ; Emacs 20 with MULE 908 (boundp 'MULE)) ; Emacs 20 with MULE
889 nil) 909 nil)
890 ((and vip-xemacs-p 910 ((and viper-xemacs-p
891 (featurep 'mule)) ; XEmacs 20 with MULE 911 (featurep 'mule)) ; XEmacs 20 with MULE
892 (list 912 (list
893 (and current-prefix-arg 913 (and current-prefix-arg
894 (read-coding-system 914 (read-coding-system
895 "Coding-system: ")))) 915 "Coding-system: "))))
896 ) 916 )
897 ))) 917 )))
898 918
899 (defadvice find-file-other-window (before vip-add-suffix-advice activate) 919 (defadvice find-file-other-window (before viper-add-suffix-advice activate)
900 "Use `read-file-name' for reading arguments." 920 "Use `read-file-name' for reading arguments."
901 (interactive (cons (read-file-name "Find file in other window: " 921 (interactive (cons (read-file-name "Find file in other window: "
902 nil default-directory) 922 nil default-directory)
903 ;; if Mule and prefix argument, ask for coding system 923 ;; if Mule and prefix argument, ask for coding system
904 (cond ((and vip-emacs-p 924 (cond ((and viper-emacs-p
905 (boundp 'MULE)) ; Emacs 20 with MULE 925 (boundp 'MULE)) ; Emacs 20 with MULE
906 nil) 926 nil)
907 ((and vip-xemacs-p 927 ((and viper-xemacs-p
908 (featurep 'mule)) ; XEmacs 20 with MULE 928 (featurep 'mule)) ; XEmacs 20 with MULE
909 (list 929 (list
910 (and current-prefix-arg 930 (and current-prefix-arg
911 (read-coding-system 931 (read-coding-system
912 "Coding-system: ")))) 932 "Coding-system: "))))
913 ) 933 )
914 ))) 934 )))
915 935
916 936
917 (defadvice find-file-other-frame (before vip-add-suffix-advice activate) 937 (defadvice find-file-other-frame (before viper-add-suffix-advice activate)
918 "Use `read-file-name' for reading arguments." 938 "Use `read-file-name' for reading arguments."
919 (interactive (cons (read-file-name "Find file in other frame: " 939 (interactive (cons (read-file-name "Find file in other frame: "
920 nil default-directory) 940 nil default-directory)
921 ;; if Mule and prefix argument, ask for coding system 941 ;; if Mule and prefix argument, ask for coding system
922 (cond ((and vip-emacs-p 942 (cond ((and viper-emacs-p
923 (boundp 'MULE)) ; Emacs 20 with MULE 943 (boundp 'MULE)) ; Emacs 20 with MULE
924 nil) 944 nil)
925 ((and vip-xemacs-p 945 ((and viper-xemacs-p
926 (featurep 'mule)) ; XEmacs 20 with MULE 946 (featurep 'mule)) ; XEmacs 20 with MULE
927 (list 947 (list
928 (and current-prefix-arg 948 (and current-prefix-arg
929 (read-coding-system 949 (read-coding-system
930 "Coding-system: ")))) 950 "Coding-system: "))))
931 ) 951 )
932 ))) 952 )))
933 953
934 954
935 (defadvice read-file-name (around vip-suffix-advice activate) 955 (defadvice read-file-name (around viper-suffix-advice activate)
936 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." 956 "Tell `exit-minibuffer' to run `viper-file-add-suffix' as a hook."
937 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) 957 (let ((viper-minibuffer-exit-hook 'viper-file-add-suffix))
938 ad-do-it)) 958 ad-do-it))
939 959
940 (defadvice start-kbd-macro (after vip-kbd-advice activate) 960 (defadvice start-kbd-macro (after viper-kbd-advice activate)
941 "Remove Viper's intercepting bindings for C-x ). 961 "Remove Viper's intercepting bindings for C-x ).
942 This may be needed if the previous `:map' command terminated abnormally." 962 This may be needed if the previous `:map' command terminated abnormally."
943 (define-key vip-vi-intercept-map "\C-x)" nil) 963 (define-key viper-vi-intercept-map "\C-x)" nil)
944 (define-key vip-insert-intercept-map "\C-x)" nil) 964 (define-key viper-insert-intercept-map "\C-x)" nil)
945 (define-key vip-emacs-intercept-map "\C-x)" nil)) 965 (define-key viper-emacs-intercept-map "\C-x)" nil))
946 966
947 (cond ((vip-window-display-p) 967 ;; catch frame switching event
948 (let* ((search-key (if vip-xemacs-p 968 (if (viper-window-display-p)
949 [(meta shift button1up)] [M-S-mouse-1])) 969 (if viper-xemacs-p
950 (search-key-catch 970 (add-hook 'mouse-leave-frame-hook
951 (if vip-xemacs-p [(meta shift button1)] [M-S-down-mouse-1])) 971 'viper-remember-current-frame)
952 (insert-key (if vip-xemacs-p 972 (defadvice handle-switch-frame (before viper-frame-advice activate)
953 [(meta shift button2up)] [M-S-mouse-2])) 973 "Remember the selected frame before the switch-frame event."
954 (insert-key-catch 974 (viper-remember-current-frame (selected-frame)))) )
955 (if vip-xemacs-p [(meta shift button2)] [M-S-down-mouse-2])) 975
956 (search-key-unbound (and (not (key-binding search-key)) 976 ) ; end viper-non-hook-settings
957 (not (key-binding search-key-catch))))
958 (insert-key-unbound (and (not (key-binding insert-key))
959 (not (key-binding insert-key-catch))))
960 )
961
962 (if search-key-unbound
963 (global-set-key search-key 'vip-mouse-click-search-word))
964 (if insert-key-unbound
965 (global-set-key insert-key 'vip-mouse-click-insert-word))
966
967 ;; The following would be needed if you want to use the above two
968 ;; while clicking in another frame. If you only want to use them
969 ;; by clicking in another window, not frame, the bindings below
970 ;; aren't necessary.
971
972 ;; These must be bound to mouse-down event for the same mouse
973 ;; buttons as 'vip-mouse-click-search-word and
974 ;; 'vip-mouse-click-insert-word
975 (if search-key-unbound
976 (global-set-key search-key-catch 'vip-mouse-catch-frame-switch))
977 (if insert-key-unbound
978 (global-set-key insert-key-catch 'vip-mouse-catch-frame-switch))
979
980 (if vip-xemacs-p
981 (add-hook 'mouse-leave-frame-hook
982 'vip-remember-current-frame)
983 (defadvice handle-switch-frame (before vip-frame-advice activate)
984 "Remember the selected frame before the switch-frame event."
985 (vip-remember-current-frame (selected-frame))))
986 )))
987 ) ; end vip-non-hook-settings
988 977
989 978
990 (if (eq viper-mode 'ask) 979 ;; Ask only if this-command/last-command are nil, i.e., when loading
991 (progn 980 (cond ((and (eq viper-mode 'ask) (null this-command) (null last-command))
992 (save-window-excursion 981 (save-window-excursion
993 (with-output-to-temp-buffer " *vip-info*" 982 (with-output-to-temp-buffer " *viper-info*"
994 (princ " 983 (princ "
995 You have loaded Viper, and are about to Viperize your emacs! 984 You have loaded Viper, and are about to Viperize your emacs!
996 985
997 Viper is a Package for Emacs Rebels 986 Viper is a Package for Emacs Rebels and a venomous VI PERil,
998 and a venomous VI PERil,
999 987
1000 It's time to decide: to Viperize or not to Viperize... 988 It's time to decide: to Viperize or not to Viperize...
1001 989
1002 If you wish to Viperize AND make this your way of life, please put 990 If you wish to Viperize AND make this your way of life, please put
1003 991
1005 (require 'viper) 993 (require 'viper)
1006 994
1007 in your .emacs file (preferably, close to the top). 995 in your .emacs file (preferably, close to the top).
1008 These two lines must come in the order given. 996 These two lines must come in the order given.
1009 997
1010 Also, the startup file name has been changed from .vip to .viper")) 998 ** Viper users:
1011 (if (y-or-n-p "Viperize? ") 999 **** The startup file name has been changed from .vip to .viper
1012 (setq viper-mode t) 1000 **** All vip-* style names have been converted to viper-* style."))
1013 (setq viper-mode nil)) 1001 (if (y-or-n-p "Viperize? ")
1014 (message "") 1002 (setq viper-mode t)
1015 (kill-buffer " *vip-info*")))) 1003 (setq viper-mode nil))
1004 (message "")
1005 (kill-buffer " *viper-info*")))
1006
1007 ;; If viper-mode is t, then just continue. Viper will kick in.
1008 ((eq viper-mode t))
1009 ;; Otherwise, it was asking mode and Viper was not loaded through .emacs
1010 ;; In this case, it was either through M-x viper-mode or via something
1011 ;; else, like the custom widget. If Viper was loaded through
1012 ;; M-x viper-mode, then viper will kick in anyway.
1013 (t (setq viper-mode nil)))
1014
1015 (defun viper-load-custom-file ()
1016 (if (and (file-exists-p viper-custom-file-name)
1017 (not noninteractive))
1018 (load viper-custom-file-name)))
1016 1019
1017 1020
1018 1021
1019 1022
1020 ;; Get viper standard value of SYMBOL. If symbol is customized, get its 1023 ;; Get viper standard value of SYMBOL. If symbol is customized, get its
1036 (cons 'require-final-newline (list require-final-newline)) 1039 (cons 'require-final-newline (list require-final-newline))
1037 (cons 'scroll-step (list scroll-step)) 1040 (cons 'scroll-step (list scroll-step))
1038 (cons 'mode-line-buffer-identification 1041 (cons 'mode-line-buffer-identification
1039 (list (default-value 'mode-line-buffer-identification))) 1042 (list (default-value 'mode-line-buffer-identification)))
1040 (cons 'global-mode-string (list global-mode-string)) 1043 (cons 'global-mode-string (list global-mode-string))
1041 (if vip-emacs-p 1044 (if viper-emacs-p
1042 (cons 'mark-even-if-inactive (list mark-even-if-inactive))) 1045 (cons 'mark-even-if-inactive (list mark-even-if-inactive)))
1043 ))) 1046 )))
1044 1047
1045 1048
1046 ;; Set some useful macros, advices 1049 ;; Set some useful macros, advices
1047 ;; These must be BEFORE ~/.viper is loaded, 1050 ;; These must be BEFORE ~/.viper is loaded,
1048 ;; so the user can unrecord them in ~/.viper. 1051 ;; so the user can unrecord them in ~/.viper.
1049 (if viper-mode 1052 (if viper-mode
1050 (progn 1053 (progn
1051 ;; set advices and some variables that give emacs Vi look. 1054 ;; set advices and some variables that give emacs Vi look.
1052 (vip-non-hook-settings) 1055 (viper-non-hook-settings)
1053 1056
1054 ;; repeat the 2nd previous command without rotating the command history 1057 ;; repeat the 2nd previous command without rotating the command history
1055 (vip-record-kbd-macro 1058 (viper-record-kbd-macro
1056 (vector vip-repeat-from-history-key '\1) 'vi-state 1059 (vector viper-repeat-from-history-key '\1) 'vi-state
1057 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) 1060 [(meta x) v i p e r - r e p e a t - f r o m - h i s t o r y return] 't)
1058 ;; repeat the 3d previous command without rotating the command history 1061 ;; repeat the 3d previous command without rotating the command history
1059 (vip-record-kbd-macro 1062 (viper-record-kbd-macro
1060 (vector vip-repeat-from-history-key '\2) 'vi-state 1063 (vector viper-repeat-from-history-key '\2) 'vi-state
1061 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) 1064 [(meta x) v i p e r - r e p e a t - f r o m - h i s t o r y return] 't)
1062 1065
1063 ;; set macros for toggling case sensitivity and regexp search 1066 ;; set macros for toggling case sensitivity and regexp search
1064 (vip-set-searchstyle-toggling-macros nil) 1067 (viper-set-searchstyle-toggling-macros nil)
1065 ;; Make %%% toggle parsing comments for matching parentheses 1068 ;; Make %%% toggle parsing comments for matching parentheses
1066 (vip-set-parsing-style-toggling-macro nil) 1069 (viper-set-parsing-style-toggling-macro nil)
1070
1071 ;; ~/.viper is loaded if exists
1072 (viper-load-custom-file)
1073
1074 ;; should be after loading custom file to avoid the pesky msg that
1075 ;; mouse-search/insert keys are already bound
1076 (viper-bind-mouse-search-key)
1077 (viper-bind-mouse-insert-key)
1067 )) 1078 ))
1068 1079
1069 1080
1070 ;; ~/.viper is loaded if it exists
1071 (if (and (file-exists-p vip-custom-file-name)
1072 viper-mode
1073 (not noninteractive))
1074 (load vip-custom-file-name))
1075
1076 ;; VIP compatibility: merge whatever the user has in vip-mode-map into
1077 ;; Viper's basic map.
1078 (vip-add-keymap vip-mode-map vip-vi-global-user-map)
1079
1080 (if (boundp 'vip-expert-level)
1081 (setq viper-expert-level vip-expert-level))
1082
1083
1084 1081
1085 ;; Applying Viper customization -- runs after (load .vip) 1082 ;; Applying Viper customization -- runs after (load .viper)
1086 1083
1087 ;; Save user settings or Viper defaults for vars controled by 1084 ;; Save user settings or Viper defaults for vars controled by
1088 ;; viper-expert-level 1085 ;; viper-expert-level
1089 (if (null viper-saved-user-settings) 1086 (if (null viper-saved-user-settings)
1090 (setq viper-saved-user-settings 1087 (setq viper-saved-user-settings
1091 (list (cons 'vip-want-ctl-h-help (list vip-want-ctl-h-help)) 1088 (list (cons 'viper-want-ctl-h-help (list viper-want-ctl-h-help))
1092 (cons 'viper-always (list viper-always)) 1089 (cons 'viper-always (list viper-always))
1093 (cons 'vip-no-multiple-ESC (list vip-no-multiple-ESC)) 1090 (cons 'viper-no-multiple-ESC (list viper-no-multiple-ESC))
1094 (cons 'vip-ex-style-motion (list vip-ex-style-motion)) 1091 (cons 'viper-ex-style-motion (list viper-ex-style-motion))
1095 (cons 'vip-ex-style-editing-in-insert 1092 (cons 'viper-ex-style-editing-in-insert
1096 (list vip-ex-style-editing-in-insert)) 1093 (list viper-ex-style-editing-in-insert))
1097 (cons 'vip-want-emacs-keys-in-vi 1094 (cons 'viper-want-emacs-keys-in-vi
1098 (list vip-want-emacs-keys-in-vi)) 1095 (list viper-want-emacs-keys-in-vi))
1099 (cons 'vip-electric-mode (list vip-electric-mode)) 1096 (cons 'viper-electric-mode (list viper-electric-mode))
1100 (cons 'vip-want-emacs-keys-in-insert 1097 (cons 'viper-want-emacs-keys-in-insert
1101 (list vip-want-emacs-keys-in-insert)) 1098 (list viper-want-emacs-keys-in-insert))
1102 (cons 'vip-re-search (list vip-re-search))))) 1099 (cons 'viper-re-search (list viper-re-search)))))
1103 1100
1104 1101
1105 (if viper-mode 1102 (if viper-mode
1106 (progn 1103 (progn
1107 (vip-set-minibuffer-style) 1104 (viper-set-minibuffer-style)
1108 (if vip-buffer-search-char 1105 (if viper-buffer-search-char
1109 (vip-buffer-search-enable)) 1106 (viper-buffer-search-enable))
1110 (vip-update-alphanumeric-class) 1107 (viper-update-alphanumeric-class)
1111 )) 1108 ))
1112 1109
1113 1110
1114 ;;; Familiarize Viper with some minor modes that have their own keymaps 1111 ;;; Familiarize Viper with some minor modes that have their own keymaps
1115 (if viper-mode 1112 (if viper-mode
1116 (progn 1113 (progn
1117 (vip-harness-minor-mode "compile") 1114 (viper-harness-minor-mode "compile")
1118 (vip-harness-minor-mode "outline") 1115 (viper-harness-minor-mode "outline")
1119 (vip-harness-minor-mode "allout") 1116 (viper-harness-minor-mode "allout")
1120 (vip-harness-minor-mode "xref") 1117 (viper-harness-minor-mode "xref")
1121 (vip-harness-minor-mode "lmenu") 1118 (viper-harness-minor-mode "lmenu")
1122 (vip-harness-minor-mode "vc") 1119 (viper-harness-minor-mode "vc")
1123 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX 1120 (viper-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX, which
1124 (vip-harness-minor-mode "latex") ; which is in one of these two files 1121 (viper-harness-minor-mode "latex") ; sits in one of these two files
1125 (vip-harness-minor-mode "cyrillic") 1122 (viper-harness-minor-mode "cyrillic")
1126 (vip-harness-minor-mode "russian") 1123 (viper-harness-minor-mode "russian")
1127 (vip-harness-minor-mode "view-less") 1124 (viper-harness-minor-mode "view-less")
1128 (vip-harness-minor-mode "view") 1125 (viper-harness-minor-mode "view")
1129 )) 1126 ))
1130 1127
1131 1128
1132 ;; Intercept maps could go in viper-keym.el 1129 ;; Intercept maps could go in viper-keym.el
1133 ;; We keep them here in case someone redefines them in ~/.viper 1130 ;; We keep them here in case someone redefines them in ~/.viper
1134 1131
1135 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key) 1132 (define-key viper-vi-intercept-map viper-ESC-key 'viper-intercept-ESC-key)
1136 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key) 1133 (define-key viper-insert-intercept-map viper-ESC-key 'viper-intercept-ESC-key)
1137 1134
1138 ;; This is taken care of by vip-insert-global-user-map. 1135 ;; This is taken care of by viper-insert-global-user-map.
1139 ;;(define-key vip-replace-map vip-ESC-key 'vip-intercept-ESC-key) 1136 ;;(define-key viper-replace-map viper-ESC-key 'viper-intercept-ESC-key)
1140 1137
1141 1138
1142 ;; The default vip-toggle-key is \C-z; for the novice, it suspends or 1139 ;; The default viper-toggle-key is \C-z; for the novice, it suspends or
1143 ;; iconifies Emacs 1140 ;; iconifies Emacs
1144 (define-key vip-vi-intercept-map vip-toggle-key 'vip-toggle-key-action) 1141 (define-key viper-vi-intercept-map viper-toggle-key 'viper-toggle-key-action)
1145 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) 1142 (define-key
1143 viper-emacs-intercept-map viper-toggle-key 'viper-change-state-to-vi)
1146 1144
1147 1145
1148 (if (and viper-mode 1146 (if (and viper-mode
1149 (or viper-always 1147 (or viper-always
1150 (and (< viper-expert-level 5) (> viper-expert-level 0)))) 1148 (and (< viper-expert-level 5) (> viper-expert-level 0))))
1151 (vip-set-hooks)) 1149 (viper-set-hooks))
1152 1150
1153 ;; Let all minor modes take effect after loading 1151 ;; Let all minor modes take effect after loading
1154 ;; this may not be enough, so we also set default minor-mode-alist. 1152 ;; this may not be enough, so we also set default minor-mode-alist.
1155 ;; Without setting the default, new buffers that come up in emacs mode have 1153 ;; Without setting the default, new buffers that come up in emacs mode have
1156 ;; minor-mode-map-alist = nil, unless we call vip-change-state-* 1154 ;; minor-mode-map-alist = nil, unless we call viper-change-state-*
1157 (if (eq vip-current-state 'emacs-state) 1155 (if (eq viper-current-state 'emacs-state)
1158 (progn 1156 (progn
1159 (vip-change-state-to-emacs) 1157 (viper-change-state-to-emacs)
1160 (setq-default minor-mode-map-alist minor-mode-map-alist) 1158 (setq-default minor-mode-map-alist minor-mode-map-alist)
1161 )) 1159 ))
1162 1160
1163 1161
1164 1162
1165 (run-hooks 'vip-load-hook) ; the last chance to change something 1163 (run-hooks 'viper-load-hook) ; the last chance to change something
1166 1164
1167 (provide 'vip)
1168 (provide 'viper) 1165 (provide 'viper)
1169 1166
1170 1167
1171 ;;; Local Variables: 1168 ;;; Local Variables:
1172 ;;; eval: (put 'vip-deflocalvar 'lisp-indent-hook 'defun) 1169 ;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
1173 ;;; End: 1170 ;;; End:
1174 1171
1175 ;;; viper.el ends here 1172 ;;; viper.el ends here