comparison lisp/viper/viper.el @ 175:2d532a89d707 r20-3b14

Import from CVS: tag r20-3b14
author cvs
date Mon, 13 Aug 2007 09:50:14 +0200
parents 0132846995bd
children 6075d714658b
comparison
equal deleted inserted replaced
174:bb3568571b84 175:2d532a89d707
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.94 of June 12, 1997" 11 (defconst viper-version "2.95 of July 9, 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
148 ;; Bindings done to the keymap of the first mode overshadow those done to 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. 149 ;; the second, which, in turn, overshadows those done to the third, etc.
150 ;; 150 ;;
151 ;; The last vip-vi-basic-minor-mode contains most of the usual Vi bindings 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. 152 ;; in its edit mode. This mode provides access to all Emacs facilities.
153 ;; Novice users, however, may want to set their vip-expert-level to 1 153 ;; 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 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. 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 156 ;; For instance, C-c will not have its standard Emacs binding
157 ;; and so many of the goodies of Emacs are not available. 157 ;; and so many of the goodies of Emacs are not available.
158 ;; 158 ;;
159 ;; A skilled user should set vip-expert-level to at least 3. This will 159 ;; 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. 160 ;; enable `C-c' and many Emacs facilities will become available.
161 ;; In this case, vip-vi-diehard-minor-mode is inactive. 161 ;; In this case, vip-vi-diehard-minor-mode is inactive.
162 ;; 162 ;;
163 ;; Viper gurus should have at least 163 ;; Viper gurus should have at least
164 ;; (setq vip-expert-level 4) 164 ;; (setq viper-expert-level 4)
165 ;; in their ~/.vip files. This will unsuppress all Emacs keys that are not 165 ;; in their ~/.viper files. This will unsuppress all Emacs keys that are not
166 ;; essential for VI-style editing. 166 ;; essential for VI-style editing.
167 ;; Pick-and-choose users may want to put 167 ;; Pick-and-choose users may want to put
168 ;; (setq vip-expert-level 5) 168 ;; (setq viper-expert-level 5)
169 ;; in ~/.vip. Viper will then leave it up to the user to set the variables 169 ;; in ~/.viper. Viper will then leave it up to the user to set the variables
170 ;; vip-want-* See vip-set-expert-level for details. 170 ;; vip-want-* See viper-set-expert-level for details.
171 ;; 171 ;;
172 ;; The very first minor mode, vip-vi-intercept-minor-mode, is of no 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 173 ;; concern for the user. It is needed to bind Viper's vital keys, such as
174 ;; ESC and C-z. 174 ;; ESC and C-z.
175 ;; 175 ;;
300 (require 'cl) 300 (require 'cl)
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)
306 (defvar vip-expert-level)
305 307
306 ;; loading happens only in non-interactive compilation 308 ;; loading happens only in non-interactive compilation
307 ;; in order to spare non-viperized emacs from being viperized 309 ;; in order to spare non-viperized emacs from being viperized
308 (if noninteractive 310 (if noninteractive
309 (eval-when-compile 311 (eval-when-compile
311 (or (featurep 'viper-cmd) 313 (or (featurep 'viper-cmd)
312 (load "viper-cmd.el" nil nil 'nosuffix)) 314 (load "viper-cmd.el" nil nil 'nosuffix))
313 ))) 315 )))
314 ;; end pacifier 316 ;; end pacifier
315 317
318 ;; better be defined before Viper custom group.
319 (defvar vip-custom-file-name (vip-convert-standard-file-name "~/.viper")
320 "Viper customisation file.
321 If set by the user, this must be done _before_ Viper is loaded in `~/.emacs'.")
322
323 (defgroup viper nil
324 "Vi emulation within Emacs.
325 NOTE: Viper customization should be saved in `vip-custom-file-name', which
326 defaults to `~/.viper'."
327 :prefix "vip-"
328 :group 'emulations)
329
316 (require 'viper-cmd) 330 (require 'viper-cmd)
317 331
318 (defvar vip-always t 332 (defvar vip-always t
319 "See `viper-always'. This variable is for compatibility with older Vipers.") 333 "See `viper-always'. This variable is for compatibility with older Vipers.")
320 (defvar viper-always vip-always 334 (defcustom viper-always vip-always
321 "Non-nil means, arrange for vi-state to be a default when appropriate. 335 "Non-nil means, arrange for vi-state to be a default when appropriate.
322 This is different from `viper-mode' variable in that `viper-mode' determines 336 This is different from `viper-mode' variable in that `viper-mode' determines
323 whether to use Viper in the first place, while `viper-always', if nil, lets 337 whether to use Viper in the first place, while `viper-always', if nil, lets
324 user decide when to invoke Viper in a major mode.") 338 user decide when to invoke Viper in a major mode."
325 339 :type 'boolean
326 (defvar viper-mode (cond (noninteractive nil) 340 :tag "Always Invoke Viper"
327 (t 'ask)) 341 :group 'viper)
328 "Viperize or not Viperize. 342
343 ;; Non-viper variables that need to be saved in case the user decides to
344 ;; de-viperize emacs.
345 (defvar viper-saved-non-viper-variables nil)
346 ;; Contains user settings for vars affected by viper-set-expert-level function.
347 ;; Not a user option.
348 (defvar viper-saved-user-settings nil)
349
350 (defcustom viper-mode (cond (noninteractive nil)
351 (t 'ask))
352 "To Viperize or not to Viperize.
329 If t, viperize emacs. If nil -- don't. If `ask', ask the user. 353 If t, viperize emacs. If nil -- don't. If `ask', ask the user.
330 This variable is used primatily when Viper is being loaded. 354 This variable is used primatily when Viper is being loaded.
331 355
332 Must be set in `~/.emacs' before Viper is loaded. 356 Must be set in `~/.emacs' before Viper is loaded.
333 DO NOT set this variable interactively.") 357 DO NOT set this variable interactively."
358 :type '(choice (const nil) (const t) (const ask))
359 :tag "Set Viper Mode on Loading"
360 :group 'viper)
334 361
335 362
336 ;; The following are provided for compatibility with older VIP's 363 ;; The following are provided for compatibility with older VIP's
337 364
338 ;;;###autoload 365 ;;;###autoload
339 (defalias 'vip-mode 'viper-mode) 366 (defalias 'vip-mode 'viper-mode)
340 367
341 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) 368 (defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi)
342 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) 369 (defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert)
343 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs) 370 (defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs)
371
344 372
345 373
346 374
347 ;;;###autoload 375 ;;;###autoload
348 (defun viper-mode () 376 (defun viper-mode ()
365 (delete-other-windows) 393 (delete-other-windows)
366 (switch-to-buffer "Viper Startup Message") 394 (switch-to-buffer "Viper Startup Message")
367 (erase-buffer) 395 (erase-buffer)
368 (insert 396 (insert
369 (substitute-command-keys 397 (substitute-command-keys
370 "Viper Is a Package for Emacs Rebels. 398 "Viper Is a Package for Emacs Rebels,
371 It is also a VI Plan for Emacs Rescue and a venomous VI PERil. 399 a VI Plan for Emacs Rescue, and a venomous VI PERil.
372 400
373 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and 401 Incidentally, Viper emulates Vi under GNU Emacs 20 and XEmacs 20.
374 XEmacs 19. It supports virtually all of Vi and Ex functionality, extending 402 It supports all of what is good in Vi and Ex, while extending
375 and improving upon much of it. 403 and improving upon much of it.
376 404
377 1. Viper supports Vi at several levels. Level 1 is the closest to Vi, 405 1. Viper supports Vi at several levels. Level 1 is the closest to Vi,
378 level 5 provides the most flexibility to depart from many Vi conventions. 406 level 5 provides the most flexibility to depart from many Vi conventions.
379 407
381 409
382 If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave 410 If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave
383 as in VI, to smooth transition to Viper for the beginners. However, to 411 as in VI, to smooth transition to Viper for the beginners. However, to
384 use Emacs productively, you are advised to reach user level 3 or higher. 412 use Emacs productively, you are advised to reach user level 3 or higher.
385 413
386 If your user level is 2 or higher, ^X and ^C will invoke Emacs 414 At user level 2 or higher, ^X and ^C have Emacs, not Vi, bindings;
387 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and 415 ^Z toggles Vi/Emacs states; ^G is Emacs' keyboard-quit (like ^C in Vi).
388 ^G will be the usual Emacs's keyboard-quit (something like ^C in VI).
389 416
390 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they 417 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they
391 do not cause Emacs to quit, except at user level 1 (a novice). 418 do not cause Emacs to quit, except at user level 1 (for a novice).
392 3. ^X^C EXITS EMACS. 419 3. ^X^C EXITS EMACS.
393 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat 420 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
394 undo. Another `u' changes direction. 421 undo. Another `u' changes direction.
395 422
396 6. Emacs Meta functions are invoked by typing `C-\\' or `\\ ESC'. 423 6. Emacs Meta key is `C-\\' (in all modes) or `\\ ESC' (in Vi command mode).
397 On a window system, the best way is to use the Meta-key. 424 On a window system, the best way is to use the Meta-key on your keyboard.
398 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if 425 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
399 something funny happens. This would abort the current editing command. 426 something funny happens. This would abort the current editing command.
400 427
401 You can get more information on Viper by: 428 For more information on Viper:
402 429
403 a. Typing `:help' in Vi state 430 a. Type `:help' in Vi command mode
404 b. Printing Viper manual, found in ./etc/viper.dvi 431 b. Print Viper manual, found in ./etc/viper.dvi
405 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi 432 c. Print the Quick Reference, found in ./etc/viperCard.dvi
433
434 To submit a bug report or to contact the author, type :submitReport in Vi
435 command mode. To shoo Viper away and return to pure Emacs (horror!), type:
436
437 M-x viper-go-away
406 438
407 This startup message appears whenever you load Viper, unless you type `y' now." 439 This startup message appears whenever you load Viper, unless you type `y' now."
408 )) 440 ))
409 (goto-char (point-min)) 441 (goto-char (point-min))
410 (if (y-or-n-p "Inhibit Viper startup message? ") 442 (if (y-or-n-p "Inhibit Viper startup message? ")
415 ;;(kill-buffer (current-buffer)) 447 ;;(kill-buffer (current-buffer))
416 (message 448 (message
417 "The last message is in buffer `Viper Startup Message'") 449 "The last message is in buffer `Viper Startup Message'")
418 (sit-for 4) 450 (sit-for 4)
419 )) 451 ))
420 (vip-set-expert-level 'dont-change-unless))) 452 (viper-set-expert-level 'dont-change-unless)))
421 (vip-change-state-to-vi)))) 453 (vip-change-state-to-vi))))
422 454
423 455
424 ;; This hook designed to enable Vi-style editing in comint-based modes." 456 ;; This hook designed to enable Vi-style editing in comint-based modes."
425 (defun vip-comint-mode-hook () 457 (defun vip-comint-mode-hook ()
427 vip-ex-style-editing-in-insert nil 459 vip-ex-style-editing-in-insert nil
428 vip-ex-style-motion nil) 460 vip-ex-style-motion nil)
429 (vip-change-state-to-insert)) 461 (vip-change-state-to-insert))
430 462
431 463
464 ;; remove viper hooks from SYMBOL
465 (defun viper-remove-hooks (symbol)
466 (cond ((not (boundp symbol)) nil)
467 ((not (listp (eval symbol))) nil)
468 ((string-match "-hook" (symbol-name symbol))
469 (remove-hook symbol 'viper-mode)
470 (remove-hook symbol 'vip-change-state-to-emacs)
471 (remove-hook symbol 'vip-change-state-to-insert)
472 (remove-hook symbol 'vip-change-state-to-vi)
473 )))
474
475 ;; Remove local value in all existing buffers
476 ;; This doesn't delocalize vars (which would have been desirable)
477 (defun viper-delocalize-var (symbol)
478 (mapcar (function (lambda (buf)
479 (save-excursion
480 (set-buffer buf)
481 (kill-local-variable symbol))))
482 (buffer-list)))
483
484
485 (defun viper-go-away ()
486 "De-Viperize Emacs.
487 This function tries to do as good a job as possible. However, it may undo some
488 user customization, unrelated to Viper. For instance, if the user advised
489 `read-file-name', `describe-key', and some others, then this advice will be
490 undone.
491 It also doesn't undo some Viper settings. For instance, `minor-mode-map-alist'
492 remains buffer-local."
493 (interactive)
494
495 ;; restore non-viper vars
496 (setq-default
497 default-major-mode
498 (viper-standard-value 'default-major-mode viper-saved-non-viper-variables)
499 next-line-add-newlines
500 (viper-standard-value
501 'next-line-add-newlines viper-saved-non-viper-variables)
502 require-final-newline
503 (viper-standard-value
504 'require-final-newline viper-saved-non-viper-variables)
505 scroll-step
506 (viper-standard-value 'scroll-step viper-saved-non-viper-variables)
507 mode-line-buffer-identification
508 (viper-standard-value
509 'mode-line-buffer-identification viper-saved-non-viper-variables)
510 global-mode-string
511 (viper-standard-value 'global-mode-string viper-saved-non-viper-variables))
512
513 (if vip-emacs-p
514 (setq-default
515 mark-even-if-inactive
516 (viper-standard-value
517 'mark-even-if-inactive viper-saved-non-viper-variables)))
518
519 ;; Ideally, we would like to be able to de-localize local variables
520 (viper-delocalize-var 'minor-mode-map-alist)
521 (viper-delocalize-var 'require-final-newline)
522
523
524 ;; deactivate all advices done by Viper.
525 (ad-deactivate-regexp "vip-")
526
527 (setq viper-mode nil)
528
529 (viper-delocalize-var 'vip-vi-minibuffer-minor-mode)
530 (viper-delocalize-var 'vip-insert-minibuffer-minor-mode)
531 (viper-delocalize-var 'vip-vi-intercept-minor-mode)
532 (viper-delocalize-var 'vip-insert-intercept-minor-mode)
533
534 (viper-delocalize-var 'vip-vi-local-user-minor-mode)
535 (viper-delocalize-var 'vip-vi-kbd-minor-mode)
536 (viper-delocalize-var 'vip-vi-global-user-minor-mode)
537 (viper-delocalize-var 'vip-vi-state-modifier-minor-mode)
538 (viper-delocalize-var 'vip-vi-diehard-minor-mode)
539 (viper-delocalize-var 'vip-vi-basic-minor-mode)
540
541 (viper-delocalize-var 'vip-replace-minor-mode)
542
543 (viper-delocalize-var 'vip-insert-local-user-minor-mode)
544 (viper-delocalize-var 'vip-insert-kbd-minor-mode)
545 (viper-delocalize-var 'vip-insert-global-user-minor-mode)
546 (viper-delocalize-var 'vip-insert-state-modifier-minor-mode)
547 (viper-delocalize-var 'vip-insert-diehard-minor-mode)
548 (viper-delocalize-var 'vip-insert-basic-minor-mode)
549
550 (viper-delocalize-var 'vip-emacs-intercept-minor-mode)
551 (viper-delocalize-var 'vip-emacs-local-user-minor-mode)
552 (viper-delocalize-var 'vip-emacs-kbd-minor-mode)
553 (viper-delocalize-var 'vip-emacs-global-user-minor-mode)
554 (viper-delocalize-var 'vip-emacs-state-modifier-minor-mode)
555
556 (setq-default vip-vi-minibuffer-minor-mode nil
557 vip-insert-minibuffer-minor-mode nil
558 vip-vi-intercept-minor-mode nil
559 vip-insert-intercept-minor-mode nil
560
561 vip-vi-local-user-minor-mode nil
562 vip-vi-kbd-minor-mode nil
563 vip-vi-global-user-minor-mode nil
564 vip-vi-state-modifier-minor-mode nil
565 vip-vi-diehard-minor-mode nil
566 vip-vi-basic-minor-mode nil
567
568 vip-replace-minor-mode nil
569
570 vip-insert-local-user-minor-mode nil
571 vip-insert-kbd-minor-mode nil
572 vip-insert-global-user-minor-mode nil
573 vip-insert-state-modifier-minor-mode nil
574 vip-insert-diehard-minor-mode nil
575 vip-insert-basic-minor-mode nil
576
577 vip-emacs-intercept-minor-mode nil
578 vip-emacs-local-user-minor-mode nil
579 vip-emacs-kbd-minor-mode nil
580 vip-emacs-global-user-minor-mode nil
581 vip-emacs-state-modifier-minor-mode nil
582 )
583
584 ;; remove all hooks set by viper
585 (mapatoms 'viper-remove-hooks)
586 (remove-hook 'comint-mode-hook 'vip-comint-mode-hook)
587 (remove-hook 'minibuffer-setup-hook 'vip-minibuffer-setup-sentinel)
588 )
589
590
591
592
432 ;; This sets major mode hooks to make them come up in vi-state. 593 ;; This sets major mode hooks to make them come up in vi-state.
433 (defun vip-set-hooks () 594 (defun vip-set-hooks ()
434 595
435 ;; It is of course a misnomer to call viper-mode a `major mode'. 596 ;; It is of course a misnomer to call viper-mode a `major mode'.
436 ;; However, this has the effect that if the user didn't specify the 597 ;; However, this has the effect that if the user didn't specify the
458 (defvar html-helper-mode-hook) 619 (defvar html-helper-mode-hook)
459 (add-hook 'html-helper-mode-hook 'viper-mode) 620 (add-hook 'html-helper-mode-hook 'viper-mode)
460 621
461 (defvar java-mode-hook) 622 (defvar java-mode-hook)
462 (add-hook 'java-mode-hook 'viper-mode) 623 (add-hook 'java-mode-hook 'viper-mode)
624
625 (defvar javascript-mode-hook)
626 (add-hook 'javascript-mode-hook 'viper-mode)
463 627
464 (defvar emacs-lisp-mode-hook) 628 (defvar emacs-lisp-mode-hook)
465 (add-hook 'emacs-lisp-mode-hook 'viper-mode) 629 (add-hook 'emacs-lisp-mode-hook 'viper-mode)
466 (defvar lisp-mode-hook) 630 (defvar lisp-mode-hook)
467 (add-hook 'lisp-mode-hook 'viper-mode) 631 (add-hook 'lisp-mode-hook 'viper-mode)
500 (add-hook 'text-mode-hook 'viper-mode) 664 (add-hook 'text-mode-hook 'viper-mode)
501 665
502 (add-hook 'completion-list-mode-hook 'viper-mode) 666 (add-hook 'completion-list-mode-hook 'viper-mode)
503 (add-hook 'compilation-mode-hook 'viper-mode) 667 (add-hook 'compilation-mode-hook 'viper-mode)
504 668
505 (add-hook 'perl-mode-hook 'viper-mode) 669 (defvar perl-mode-hook)
506 (add-hook 'tcl-mode-hook 'viper-mode) 670 (add-hook 'perl-mode-hook 'viper-mode)
671
672 (defvar tcl-mode-hook)
673 (add-hook 'tcl-mode-hook 'viper-mode)
674
675 (defvar python-mode-hook)
676 (add-hook 'python-mode-hook 'viper-mode)
507 677
508 (defvar emerge-startup-hook) 678 (defvar emerge-startup-hook)
509 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs) 679 (add-hook 'emerge-startup-hook 'vip-change-state-to-emacs)
510 680
511 ;; Tell vc-diff to put *vc* in Vi mode 681 ;; Tell vc-diff to put *vc* in Vi mode
566 (defvar ksh-mode-hook) 736 (defvar ksh-mode-hook)
567 (add-hook 'ksh-mode-hook 'viper-mode) 737 (add-hook 'ksh-mode-hook 'viper-mode)
568 738
569 ;; Dired 739 ;; Dired
570 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map) 740 (vip-modify-major-mode 'dired-mode 'emacs-state vip-dired-modifier-map)
571 (vip-set-emacs-search-style-macros nil 'dired-mode) 741 (vip-set-emacs-state-searchstyle-macros nil 'dired-mode)
572 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs) 742 (add-hook 'dired-mode-hook 'vip-change-state-to-emacs)
573 743
574 ;; Tar 744 ;; Tar
575 (vip-modify-major-mode 'tar-mode 'emacs-state vip-slash-and-colon-map) 745 (vip-modify-major-mode 'tar-mode 'emacs-state vip-slash-and-colon-map)
576 (vip-set-emacs-search-style-macros nil 'tar-mode) 746 (vip-set-emacs-state-searchstyle-macros nil 'tar-mode)
577 747
578 ;; MH-E 748 ;; MH-E
579 (vip-modify-major-mode 'mh-folder-mode 'emacs-state vip-slash-and-colon-map) 749 (vip-modify-major-mode 'mh-folder-mode 'emacs-state vip-slash-and-colon-map)
580 (vip-set-emacs-search-style-macros nil 'mh-folder-mode) 750 (vip-set-emacs-state-searchstyle-macros nil 'mh-folder-mode)
581 ;; changing state to emacs is needed so the preceding will take hold 751 ;; changing state to emacs is needed so the preceding will take hold
582 (add-hook 'mh-folder-mode-hook 'vip-change-state-to-emacs) 752 (add-hook 'mh-folder-mode-hook 'vip-change-state-to-emacs)
583 (add-hook 'mh-show-mode-hook 'viper-mode) 753 (add-hook 'mh-show-mode-hook 'viper-mode)
584 754
585 ;; Gnus 755 ;; Gnus
586 (vip-modify-major-mode 'gnus-group-mode 'emacs-state vip-slash-and-colon-map) 756 (vip-modify-major-mode 'gnus-group-mode 'emacs-state vip-slash-and-colon-map)
587 (vip-set-emacs-search-style-macros nil 'gnus-group-mode) 757 (vip-set-emacs-state-searchstyle-macros nil 'gnus-group-mode)
588 (vip-modify-major-mode 758 (vip-modify-major-mode
589 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map) 759 'gnus-summary-mode 'emacs-state vip-slash-and-colon-map)
590 (vip-set-emacs-search-style-macros nil 'gnus-summary-mode) 760 (vip-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode)
591 ;; changing state to emacs is needed so the preceding will take hold 761 ;; changing state to emacs is needed so the preceding will take hold
592 (add-hook 'gnus-group-mode-hook 'vip-change-state-to-emacs) 762 (add-hook 'gnus-group-mode-hook 'vip-change-state-to-emacs)
593 (add-hook 'gnus-summary-mode-hook 'vip-change-state-to-emacs) 763 (add-hook 'gnus-summary-mode-hook 'vip-change-state-to-emacs)
594 (add-hook 'gnus-article-mode-hook 'viper-mode) 764 (add-hook 'gnus-article-mode-hook 'viper-mode)
595 765
596 ;; Info 766 ;; Info
597 (vip-modify-major-mode 'Info-mode 'emacs-state vip-slash-and-colon-map) 767 (vip-modify-major-mode 'Info-mode 'emacs-state vip-slash-and-colon-map)
598 (vip-set-emacs-search-style-macros nil 'Info-mode) 768 (vip-set-emacs-state-searchstyle-macros nil 'Info-mode)
599 ;; Switching to emacs is needed so the above will take hold 769 ;; Switching to emacs is needed so the above will take hold
600 (defadvice Info-mode (after vip-Info-ad activate) 770 (defadvice Info-mode (after vip-Info-ad activate)
601 "Switch to emacs mode." 771 "Switch to emacs mode."
602 (vip-change-state-to-emacs)) 772 (vip-change-state-to-emacs))
603 773
604 ;; Buffer menu 774 ;; Buffer menu
605 (vip-modify-major-mode 775 (vip-modify-major-mode
606 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map) 776 'Buffer-menu-mode 'emacs-state vip-slash-and-colon-map)
607 (vip-set-emacs-search-style-macros nil 'Buffer-menu-mode) 777 (vip-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode)
608 ;; Switching to emacs is needed so the above will take hold 778 ;; Switching to emacs is needed so the above will take hold
609 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate) 779 (defadvice Buffer-menu-mode (after vip-Buffer-menu-ad activate)
610 "Switch to emacs mode." 780 "Switch to emacs mode."
611 (vip-change-state-to-emacs)) 781 (vip-change-state-to-emacs))
612 782
657 require-final-newline t) 827 require-final-newline t)
658 828
659 (make-variable-buffer-local 'require-final-newline) 829 (make-variable-buffer-local 'require-final-newline)
660 830
661 ;; don't bark when mark is inactive 831 ;; don't bark when mark is inactive
662 (setq mark-even-if-inactive t) 832 (if vip-emacs-p
833 (setq mark-even-if-inactive t))
663 834
664 (setq scroll-step 1) 835 (setq scroll-step 1)
665 836
666 ;; Variable displaying the current Viper state in the mode line. 837 ;; Variable displaying the current Viper state in the mode line.
667 (vip-deflocalvar vip-mode-string vip-emacs-state-id) 838 (vip-deflocalvar vip-mode-string vip-emacs-state-id)
707 878
708 (defadvice find-file (before vip-add-suffix-advice activate) 879 (defadvice find-file (before vip-add-suffix-advice activate)
709 "Use `read-file-name' for reading arguments." 880 "Use `read-file-name' for reading arguments."
710 (interactive (cons (read-file-name "Find file: " nil default-directory) 881 (interactive (cons (read-file-name "Find file: " nil default-directory)
711 ;; if Mule and prefix argument, ask for coding system 882 ;; if Mule and prefix argument, ask for coding system
712 (if (or (boundp 'MULE) ; mule integrated Emacs 19 883 (cond ((and vip-emacs-p
713 (featurep 'mule)) ; mule integrated XEmacs 20 884 (boundp 'MULE)) ; Emacs 20 with MULE
714 (list 885 nil)
715 (and current-prefix-arg 886 ((and vip-xemacs-p
716 (read-coding-system "Coding-system: ")))) 887 (featurep 'mule)) ; XEmacs 20 with MULE
888 (list
889 (and current-prefix-arg
890 (read-coding-system
891 "Coding-system: "))))
892 )
717 ))) 893 )))
718 894
719 (defadvice find-file-other-window (before vip-add-suffix-advice activate) 895 (defadvice find-file-other-window (before vip-add-suffix-advice activate)
720 "Use `read-file-name' for reading arguments." 896 "Use `read-file-name' for reading arguments."
721 (interactive (cons (read-file-name "Find file in other window: " 897 (interactive (cons (read-file-name "Find file in other window: "
722 nil default-directory) 898 nil default-directory)
723 ;; if Mule and prefix argument, ask for coding system 899 ;; if Mule and prefix argument, ask for coding system
724 (if (or (boundp 'MULE) ; mule integrated Emacs 19 900 (cond ((and vip-emacs-p
725 (featurep 'mule)) ; mule integrated XEmacs 20 901 (boundp 'MULE)) ; Emacs 20 with MULE
726 (list 902 nil)
727 (and current-prefix-arg 903 ((and vip-xemacs-p
728 (read-coding-system "Coding-system: ")))) 904 (featurep 'mule)) ; XEmacs 20 with MULE
905 (list
906 (and current-prefix-arg
907 (read-coding-system
908 "Coding-system: "))))
909 )
729 ))) 910 )))
730 911
912
731 (defadvice find-file-other-frame (before vip-add-suffix-advice activate) 913 (defadvice find-file-other-frame (before vip-add-suffix-advice activate)
732 "Use `read-file-name' for reading arguments." 914 "Use `read-file-name' for reading arguments."
733 (interactive (cons (read-file-name "Find file in other frame: " 915 (interactive (cons (read-file-name "Find file in other frame: "
734 nil default-directory) 916 nil default-directory)
735 ;; if Mule and prefix argument, ask for coding system 917 ;; if Mule and prefix argument, ask for coding system
736 (if (or (boundp 'MULE) ; mule integrated Emacs 19 918 (cond ((and vip-emacs-p
737 (featurep 'mule)) ; mule integrated XEmacs 20 919 (boundp 'MULE)) ; Emacs 20 with MULE
738 (list 920 nil)
739 (and current-prefix-arg 921 ((and vip-xemacs-p
740 (read-coding-system "Coding-system: ")))) 922 (featurep 'mule)) ; XEmacs 20 with MULE
923 (list
924 (and current-prefix-arg
925 (read-coding-system
926 "Coding-system: "))))
927 )
741 ))) 928 )))
929
742 930
743 (defadvice read-file-name (around vip-suffix-advice activate) 931 (defadvice read-file-name (around vip-suffix-advice activate)
744 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook." 932 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook."
745 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix)) 933 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix))
746 ad-do-it)) 934 ad-do-it))
813 (require 'viper) 1001 (require 'viper)
814 1002
815 in your .emacs file (preferably, close to the top). 1003 in your .emacs file (preferably, close to the top).
816 These two lines must come in the order given. 1004 These two lines must come in the order given.
817 1005
818 Also, the startup file name has changed from .vip to .viper")) 1006 Also, the startup file name has been changed from .vip to .viper"))
819 (if (y-or-n-p "Viperize? ") 1007 (if (y-or-n-p "Viperize? ")
820 (setq viper-mode t) 1008 (setq viper-mode t)
821 (setq viper-mode nil)) 1009 (setq viper-mode nil))
822 (message "") 1010 (message "")
823 (kill-buffer " *vip-info*")))) 1011 (kill-buffer " *vip-info*"))))
824 1012
825 1013
826 1014
827 1015
1016 ;; Get viper standard value of SYMBOL. If symbol is customized, get its
1017 ;; standard value. Otherwise, get the value saved in the alist STORAGE. If
1018 ;; STORAGE is nil, use viper-saved-user-settings.
1019 (defun viper-standard-value (symbol &optional storage)
1020 (or (eval (car (get symbol 'customized-value)))
1021 (eval (car (get symbol 'saved-value)))
1022 (nth 1 (assoc symbol (or storage viper-saved-user-settings)))))
1023
1024
1025
1026 ;; save non-viper vars that Viper might change
1027 (if (null viper-saved-non-viper-variables)
1028 (setq viper-saved-non-viper-variables
1029 (list
1030 (cons 'default-major-mode (list default-major-mode))
1031 (cons 'next-line-add-newlines (list next-line-add-newlines))
1032 (cons 'require-final-newline (list require-final-newline))
1033 (cons 'scroll-step (list scroll-step))
1034 (cons 'mode-line-buffer-identification
1035 (list (default-value 'mode-line-buffer-identification)))
1036 (cons 'global-mode-string (list global-mode-string))
1037 (if vip-emacs-p
1038 (cons 'mark-even-if-inactive (list mark-even-if-inactive)))
1039 )))
1040
828 1041
829 ;; Set some useful macros, advices 1042 ;; Set some useful macros, advices
830 ;; These must be BEFORE we ~/.vip is loaded, 1043 ;; These must be BEFORE ~/.viper is loaded,
831 ;; so the user can unrecord them in ~/.vip. 1044 ;; so the user can unrecord them in ~/.viper.
832 (if viper-mode 1045 (if viper-mode
833 (progn 1046 (progn
834 ;; set advices and some variables that give emacs Vi look. 1047 ;; set advices and some variables that give emacs Vi look.
835 (vip-non-hook-settings) 1048 (vip-non-hook-settings)
836 1049
841 ;; repeat the 3d previous command without rotating the command history 1054 ;; repeat the 3d previous command without rotating the command history
842 (vip-record-kbd-macro 1055 (vip-record-kbd-macro
843 (vector vip-repeat-from-history-key '\2) 'vi-state 1056 (vector vip-repeat-from-history-key '\2) 'vi-state
844 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) 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)
845 1058
846 ;; set the toggle case sensitivity and regexp search macros 1059 ;; set macros for toggling case sensitivity and regexp search
847 (vip-set-vi-search-style-macros nil) 1060 (vip-set-searchstyle-toggling-macros nil)
848
849 ;; Make %%% toggle parsing comments for matching parentheses 1061 ;; Make %%% toggle parsing comments for matching parentheses
850 (vip-record-kbd-macro 1062 (vip-set-parsing-style-toggling-macro nil)
851 "%%%" 'vi-state
852 [(meta x) v i p - t o g g l e - p a r s e - s e x p - i g n o r e - c o m m e n t s return]
853 't)
854 )) 1063 ))
855 1064
856 1065
857 ;; ~/.vip is loaded if it exists 1066 ;; ~/.viper is loaded if it exists
858 (if (and (file-exists-p vip-custom-file-name) 1067 (if (and (file-exists-p vip-custom-file-name)
859 viper-mode 1068 viper-mode
860 (not noninteractive)) 1069 (not noninteractive))
861 (load vip-custom-file-name)) 1070 (load vip-custom-file-name))
862 1071
863 ;; VIP compatibility: merge whatever the user has in vip-mode-map into 1072 ;; VIP compatibility: merge whatever the user has in vip-mode-map into
864 ;; Viper's basic map. 1073 ;; Viper's basic map.
865 (vip-add-keymap vip-mode-map vip-vi-global-user-map) 1074 (vip-add-keymap vip-mode-map vip-vi-global-user-map)
866 1075
1076 (if (boundp 'vip-expert-level)
1077 (setq viper-expert-level vip-expert-level))
1078
1079
867 1080
868 ;; Applying Viper customization -- runs after (load .vip) 1081 ;; Applying Viper customization -- runs after (load .vip)
869 1082
870 ;; Save user settings or Viper defaults for vars controled by vip-expert-level 1083 ;; Save user settings or Viper defaults for vars controled by
871 (setq vip-saved-user-settings 1084 ;; viper-expert-level
872 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) 1085 (if (null viper-saved-user-settings)
873 (cons 'viper-always viper-always) 1086 (setq viper-saved-user-settings
874 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) 1087 (list (cons 'vip-want-ctl-h-help (list vip-want-ctl-h-help))
875 (cons 'vip-ex-style-motion vip-ex-style-motion) 1088 (cons 'viper-always (list viper-always))
876 (cons 'vip-ex-style-editing-in-insert 1089 (cons 'vip-no-multiple-ESC (list vip-no-multiple-ESC))
877 vip-ex-style-editing-in-insert) 1090 (cons 'vip-ex-style-motion (list vip-ex-style-motion))
878 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi) 1091 (cons 'vip-ex-style-editing-in-insert
879 (cons 'vip-electric-mode vip-electric-mode) 1092 (list vip-ex-style-editing-in-insert))
880 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) 1093 (cons 'vip-want-emacs-keys-in-vi
881 (cons 'vip-re-search vip-re-search))) 1094 (list vip-want-emacs-keys-in-vi))
1095 (cons 'vip-electric-mode (list vip-electric-mode))
1096 (cons 'vip-want-emacs-keys-in-insert
1097 (list vip-want-emacs-keys-in-insert))
1098 (cons 'vip-re-search (list vip-re-search)))))
882 1099
883 1100
884 (if viper-mode 1101 (if viper-mode
885 (progn 1102 (progn
886 (vip-set-minibuffer-style) 1103 (vip-set-minibuffer-style)
907 (vip-harness-minor-mode "view") 1124 (vip-harness-minor-mode "view")
908 )) 1125 ))
909 1126
910 1127
911 ;; Intercept maps could go in viper-keym.el 1128 ;; Intercept maps could go in viper-keym.el
912 ;; We keep them here in case someone redefines them in ~/.vip 1129 ;; We keep them here in case someone redefines them in ~/.viper
913 1130
914 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key) 1131 (define-key vip-vi-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
915 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key) 1132 (define-key vip-insert-intercept-map vip-ESC-key 'vip-intercept-ESC-key)
916 1133
917 ;; This is taken care of by vip-insert-global-user-map. 1134 ;; This is taken care of by vip-insert-global-user-map.
924 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) 1141 (define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi)
925 1142
926 1143
927 (if (and viper-mode 1144 (if (and viper-mode
928 (or viper-always 1145 (or viper-always
929 (and (< vip-expert-level 5) (> vip-expert-level 0)))) 1146 (and (< viper-expert-level 5) (> viper-expert-level 0))))
930 (vip-set-hooks)) 1147 (vip-set-hooks))
931 1148
932 ;; Let all minor modes take effect after loading 1149 ;; Let all minor modes take effect after loading
933 ;; this may not be enough, so we also set default minor-mode-alist. 1150 ;; this may not be enough, so we also set default minor-mode-alist.
934 ;; Without setting the default, new buffers that come up in emacs mode have 1151 ;; Without setting the default, new buffers that come up in emacs mode have
944 (run-hooks 'vip-load-hook) ; the last chance to change something 1161 (run-hooks 'vip-load-hook) ; the last chance to change something
945 1162
946 (provide 'vip) 1163 (provide 'vip)
947 (provide 'viper) 1164 (provide 'viper)
948 1165
1166
1167 ;;; Local Variables:
1168 ;;; eval: (put 'vip-deflocalvar 'lisp-indent-hook 'defun)
1169 ;;; End:
1170
949 ;;; viper.el ends here 1171 ;;; viper.el ends here