aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kifer1997-06-18 01:26:55 +0000
committerMichael Kifer1997-06-18 01:26:55 +0000
commite36a387ddd540c1b3427577db2ed1b1577014c9a (patch)
tree3fb3a02b4ff75ef8c1a64b9b309de49df5728296
parentdd824ce4e975de9542f17afabbbac07cccf77799 (diff)
downloademacs-e36a387ddd540c1b3427577db2ed1b1577014c9a.tar.gz
emacs-e36a387ddd540c1b3427577db2ed1b1577014c9a.zip
new version
-rw-r--r--lisp/emulation/viper-cmd.el104
-rw-r--r--lisp/emulation/viper-ex.el87
-rw-r--r--lisp/emulation/viper-init.el5
-rw-r--r--lisp/emulation/viper-keym.el4
-rw-r--r--lisp/emulation/viper.el555
5 files changed, 430 insertions, 325 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el
index 2e25a44a7e5..d8ff9bdaa67 100644
--- a/lisp/emulation/viper-cmd.el
+++ b/lisp/emulation/viper-cmd.el
@@ -12,6 +12,7 @@
12(defvar vip-minibuffer-insert-face) 12(defvar vip-minibuffer-insert-face)
13(defvar vip-minibuffer-vi-face) 13(defvar vip-minibuffer-vi-face)
14(defvar vip-minibuffer-emacs-face) 14(defvar vip-minibuffer-emacs-face)
15(defvar viper-always)
15(defvar vip-mode-string ) 16(defvar vip-mode-string )
16(defvar iso-accents-mode) 17(defvar iso-accents-mode)
17(defvar zmacs-region-stays) 18(defvar zmacs-region-stays)
@@ -412,80 +413,7 @@
412 413
413 ;; Sets Viper mode string in global-mode-string 414 ;; Sets Viper mode string in global-mode-string
414 (force-mode-line-update)) 415 (force-mode-line-update))
415
416;;;###autoload
417(defun viper-mode ()
418 "Turn on Viper emulation of Vi."
419 (interactive)
420 (if (not noninteractive)
421 (progn
422 (if vip-first-time ; This check is important. Without it, startup and
423 (progn ; expert-level msgs mix up when viper-mode recurses
424 (setq vip-first-time nil)
425 (if (not vip-inhibit-startup-message)
426 (save-window-excursion
427 (setq vip-inhibit-startup-message t)
428 (delete-other-windows)
429 (switch-to-buffer "Viper Startup Message")
430 (erase-buffer)
431 (insert
432 (substitute-command-keys
433 "Viper Is a Package for Emacs Rebels.
434It is also a VI Plan for Emacs Rescue and a venomous VI PERil.
435
436Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and
437XEmacs 19. It supports virtually all of Vi and Ex functionality, extending
438and improving upon much of it.
439
440 1. Viper supports Vi at several levels. Level 1 is the closest to Vi,
441 level 5 provides the most flexibility to depart from many Vi conventions.
442
443 You will be asked to specify your user level in a following screen.
444
445 If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave
446 as in VI, to smooth transition to Viper for the beginners. However, to
447 use Emacs productively, you are advised to reach user level 3 or higher.
448
449 If your user level is 2 or higher, ^X and ^C will invoke Emacs
450 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and
451 ^G will be the usual Emacs's keyboard-quit (something like ^C in VI).
452
453 2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they
454 do not cause Emacs to quit, except at user level 1 (a novice).
455 3. ^X^C EXITS EMACS.
456 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
457 undo. Another `u' changes direction.
458
459 6. Emacs Meta functions are invoked by typing `C-\\' or `\\ ESC'.
460 On a window system, the best way is to use the Meta-key.
461 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
462 something funny happens. This would abort the current editing command.
463
464You can get more information on Viper by:
465
466 a. Typing `:help' in Vi state
467 b. Printing Viper manual, found in ./etc/viper.dvi
468 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi
469
470This startup message appears whenever you load Viper, unless you type `y' now."
471 ))
472 (goto-char (point-min))
473 (if (y-or-n-p "Inhibit Viper startup message? ")
474 (vip-save-setting
475 'vip-inhibit-startup-message
476 "Viper startup message inhibited"
477 vip-custom-file-name t))
478 ;;(kill-buffer (current-buffer))
479 (message
480 "The last message is in buffer `Viper Startup Message'")
481 (sit-for 4)
482 ))
483 (vip-set-expert-level 'dont-change-unless)))
484 (vip-change-state-to-vi))))
485 416
486;;;###autoload
487(defalias 'vip-mode 'viper-mode)
488
489 417
490;; Switch from Insert state to Vi state. 418;; Switch from Insert state to Vi state.
491(defun vip-exit-insert-state () 419(defun vip-exit-insert-state ()
@@ -4109,7 +4037,8 @@ One can use `` and '' to temporarily jump 1 step back."
4109 (if vip-auto-indent 4037 (if vip-auto-indent
4110 (progn 4038 (progn
4111 (setq vip-cted t) 4039 (setq vip-cted t)
4112 (if vip-electric-mode 4040 (if (and vip-electric-mode
4041 (not (eq major-mode 'fundamental-mode)))
4113 (indent-according-to-mode) 4042 (indent-according-to-mode)
4114 (indent-to vip-current-indent)) 4043 (indent-to vip-current-indent))
4115 )) 4044 ))
@@ -4207,7 +4136,7 @@ One can use `` and '' to temporarily jump 1 step back."
4207Can be called interactively to change (temporarily or permanently) the 4136Can be called interactively to change (temporarily or permanently) the
4208current expert level. 4137current expert level.
4209 4138
4210The optional argument DONT-CHANGE-UNLESS if not nil, says that 4139The optional argument DONT-CHANGE-UNLESS, if not nil, says that
4211the level should not be changed, unless its current value is 4140the level should not be changed, unless its current value is
4212meaningless (i.e., not one of 1,2,3,4,5). 4141meaningless (i.e., not one of 1,2,3,4,5).
4213 4142
@@ -4224,7 +4153,7 @@ sensitive for VI-style look-and-feel."
4224 ;; & dont-change-unless = t -- use it; else ask 4153 ;; & dont-change-unless = t -- use it; else ask
4225 (vip-ask-level dont-change-unless)) 4154 (vip-ask-level dont-change-unless))
4226 4155
4227 (setq vip-always t 4156 (setq viper-always t
4228 vip-ex-style-motion t 4157 vip-ex-style-motion t
4229 vip-ex-style-editing-in-insert t 4158 vip-ex-style-editing-in-insert t
4230 vip-want-ctl-h-help nil) 4159 vip-want-ctl-h-help nil)
@@ -4237,16 +4166,19 @@ sensitive for VI-style look-and-feel."
4237 vip-re-search t 4166 vip-re-search t
4238 vip-vi-style-in-minibuffer t 4167 vip-vi-style-in-minibuffer t
4239 vip-search-wrap-around-t t 4168 vip-search-wrap-around-t t
4169 vip-electric-mode nil
4240 vip-want-emacs-keys-in-vi nil 4170 vip-want-emacs-keys-in-vi nil
4241 vip-want-emacs-keys-in-insert nil)) 4171 vip-want-emacs-keys-in-insert nil))
4242 4172
4243 ((and (> vip-expert-level 1) (< vip-expert-level 5)) 4173 ((and (> vip-expert-level 1) (< vip-expert-level 5))
4244 ;; intermediate to guru 4174 ;; intermediate to guru
4245 (setq vip-no-multiple-ESC (if (vip-window-display-p) t 'twice) 4175 (setq vip-no-multiple-ESC (if (vip-window-display-p)
4176 t 'twice)
4177 vip-electric-mode t
4246 vip-want-emacs-keys-in-vi t 4178 vip-want-emacs-keys-in-vi t
4247 vip-want-emacs-keys-in-insert (> vip-expert-level 2)) 4179 vip-want-emacs-keys-in-insert (> vip-expert-level 2))
4248 4180
4249 (if (eq vip-expert-level 4) ; respect user's ex-style motions 4181 (if (eq vip-expert-level 4) ; respect user's ex-style motion
4250 ; and vip-no-multiple-ESC 4182 ; and vip-no-multiple-ESC
4251 (progn 4183 (progn
4252 (setq-default vip-ex-style-editing-in-insert 4184 (setq-default vip-ex-style-editing-in-insert
@@ -4277,8 +4209,8 @@ sensitive for VI-style look-and-feel."
4277 vip-saved-user-settings))) 4209 vip-saved-user-settings)))
4278 (setq vip-want-ctl-h-help 4210 (setq vip-want-ctl-h-help
4279 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings)) 4211 (cdr (assoc 'vip-want-ctl-h-help vip-saved-user-settings))
4280 vip-always 4212 viper-always
4281 (cdr (assoc 'vip-always vip-saved-user-settings)) 4213 (cdr (assoc 'viper-always vip-saved-user-settings))
4282 vip-no-multiple-ESC 4214 vip-no-multiple-ESC
4283 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings)) 4215 (cdr (assoc 'vip-no-multiple-ESC vip-saved-user-settings))
4284 vip-ex-style-motion 4216 vip-ex-style-motion
@@ -4288,6 +4220,9 @@ sensitive for VI-style look-and-feel."
4288 vip-saved-user-settings)) 4220 vip-saved-user-settings))
4289 vip-re-search 4221 vip-re-search
4290 (cdr (assoc 'vip-re-search vip-saved-user-settings)) 4222 (cdr (assoc 'vip-re-search vip-saved-user-settings))
4223 vip-electric-mode
4224 (cdr (assoc 'vip-electric-mode
4225 vip-saved-user-settings))
4291 vip-want-emacs-keys-in-vi 4226 vip-want-emacs-keys-in-vi
4292 (cdr (assoc 'vip-want-emacs-keys-in-vi 4227 (cdr (assoc 'vip-want-emacs-keys-in-vi
4293 vip-saved-user-settings)) 4228 vip-saved-user-settings))
@@ -4295,7 +4230,7 @@ sensitive for VI-style look-and-feel."
4295 (cdr (assoc 'vip-want-emacs-keys-in-insert 4230 (cdr (assoc 'vip-want-emacs-keys-in-insert
4296 vip-saved-user-settings))))) 4231 vip-saved-user-settings)))))
4297 (vip-set-mode-vars-for vip-current-state) 4232 (vip-set-mode-vars-for vip-current-state)
4298 (if (or vip-always 4233 (if (or viper-always
4299 (and (> vip-expert-level 0) (> 5 vip-expert-level))) 4234 (and (> vip-expert-level 0) (> 5 vip-expert-level)))
4300 (vip-set-hooks))) 4235 (vip-set-hooks)))
4301 4236
@@ -4374,9 +4309,9 @@ You can change it at any time by typing `M-x vip-set-expert-level RET'
4374 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC, 4309 4 -- GURU: Like 3, but user settings are respected for vip-no-multiple-ESC,
4375 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert 4310 vip-re-search, vip-ex-style-motion, & vip-ex-style-editing-in-insert
4376 variables. Adjust these settings to your taste. 4311 variables. Adjust these settings to your taste.
4377 5 -- WIZARD: Like 4, but user settings are also respected for vip-always, 4312 5 -- WIZARD: Like 4, but user settings are also respected for viper-always,
4378 vip-want-ctl-h-help, vip-want-emacs-keys-in-vi, and 4313 vip-electric-mode, vip-want-ctl-h-help, vip-want-emacs-keys-in-vi,
4379 vip-want-emacs-keys-in-insert. Adjust these to your taste. 4314 and vip-want-emacs-keys-in-insert. Adjust these to your taste.
4380 4315
4381Please, specify your level now: ") 4316Please, specify your level now: ")
4382 4317
@@ -4495,6 +4430,7 @@ Please, specify your level now: ")
4495 'vip-want-emacs-keys-in-vi 4430 'vip-want-emacs-keys-in-vi
4496 'vip-keep-point-on-undo 4431 'vip-keep-point-on-undo
4497 'vip-no-multiple-ESC 4432 'vip-no-multiple-ESC
4433 'vip-electric-mode
4498 'vip-ESC-key 4434 'vip-ESC-key
4499 'vip-want-ctl-h-help 4435 'vip-want-ctl-h-help
4500 'vip-ex-style-editing-in-insert 4436 'vip-ex-style-editing-in-insert
diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el
index 4a81df559e0..8ef9eccec4a 100644
--- a/lisp/emulation/viper-ex.el
+++ b/lisp/emulation/viper-ex.el
@@ -34,6 +34,7 @@
34(defvar vip-expert-level) 34(defvar vip-expert-level)
35(defvar vip-custom-file-name) 35(defvar vip-custom-file-name)
36(defvar vip-case-fold-search) 36(defvar vip-case-fold-search)
37(defvar explicit-shell-file-name)
37 38
38;; loading happens only in non-interactive compilation 39;; loading happens only in non-interactive compilation
39;; in order to spare non-viperized emacs from being viperized 40;; in order to spare non-viperized emacs from being viperized
@@ -76,15 +77,16 @@
76;; A-list of Ex variables that can be set using the :set command. 77;; A-list of Ex variables that can be set using the :set command.
77(defconst ex-variable-alist 78(defconst ex-variable-alist
78 '(("wrapscan") ("ws") ("wrapmargin") ("wm") 79 '(("wrapscan") ("ws") ("wrapmargin") ("wm")
79 ("global-tabstop") ("gts") ("tabstop") ("ts") 80 ("tabstop-global") ("ts-g") ("tabstop") ("ts")
80 ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh") 81 ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh")
81 ("readonly") ("ro") 82 ("readonly") ("ro")
82 ("nowrapscan") ("nows") ("noshowmatch") ("nosm") 83 ("nowrapscan") ("nows") ("noshowmatch") ("nosm")
83 ("noreadonly") ("noro") ("nomagic") ("noma") 84 ("noreadonly") ("noro") ("nomagic") ("noma")
84 ("noignorecase") ("noic") 85 ("noignorecase") ("noic")
85 ("global-noautoindent") ("gnoai") ("noautoindent") ("noai") 86 ("noautoindent-global") ("noai-g") ("noautoindent") ("noai")
86 ("magic") ("ma") ("ignorecase") ("ic") 87 ("magic") ("ma") ("ignorecase") ("ic")
87 ("global-autoindent") ("gai") ("autoindent") ("ai") 88 ("autoindent-global") ("ai-g") ("autoindent") ("ai")
89 ("all")
88 )) 90 ))
89 91
90 92
@@ -1564,7 +1566,7 @@ reversed.")
1564 (while (string-match "^[ \\t\\n]*$" 1566 (while (string-match "^[ \\t\\n]*$"
1565 (setq str 1567 (setq str
1566 (completing-read ":set " ex-variable-alist))) 1568 (completing-read ":set " ex-variable-alist)))
1567 (message ":set <Variable> ") 1569 (message ":set <Variable> [= <Value>]")
1568 ;; if there are unread events, don't wait 1570 ;; if there are unread events, don't wait
1569 (or (vip-set-unread-command-events "") (sit-for 2)) 1571 (or (vip-set-unread-command-events "") (sit-for 2))
1570 ) ; while 1572 ) ; while
@@ -1582,12 +1584,15 @@ reversed.")
1582 actual-lisp-cmd lisp-cmd-del-pattern 1584 actual-lisp-cmd lisp-cmd-del-pattern
1583 val2 orig-var) 1585 val2 orig-var)
1584 (setq orig-var var) 1586 (setq orig-var var)
1585 (cond ((member var '("ai" "autoindent")) 1587 (cond ((string= var "all")
1588 (setq ask-if-save nil
1589 set-cmd nil))
1590 ((member var '("ai" "autoindent"))
1586 (setq var "vip-auto-indent" 1591 (setq var "vip-auto-indent"
1587 set-cmd "setq" 1592 set-cmd "setq"
1588 ask-if-save nil 1593 ask-if-save nil
1589 val "t")) 1594 val "t"))
1590 ((member var '("gai" "global-autoindent")) 1595 ((member var '("ai-g" "autoindent-global"))
1591 (kill-local-variable 'vip-auto-indent) 1596 (kill-local-variable 'vip-auto-indent)
1592 (setq var "vip-auto-indent" 1597 (setq var "vip-auto-indent"
1593 set-cmd "setq-default" 1598 set-cmd "setq-default"
@@ -1596,7 +1601,7 @@ reversed.")
1596 (setq var "vip-auto-indent" 1601 (setq var "vip-auto-indent"
1597 ask-if-save nil 1602 ask-if-save nil
1598 val "nil")) 1603 val "nil"))
1599 ((member var '("gnoai" "global-noautoindent")) 1604 ((member var '("noai-g" "noautoindent-global"))
1600 (kill-local-variable 'vip-auto-indent) 1605 (kill-local-variable 'vip-auto-indent)
1601 (setq var "vip-auto-indent" 1606 (setq var "vip-auto-indent"
1602 set-cmd "setq-default" 1607 set-cmd "setq-default"
@@ -1610,7 +1615,7 @@ reversed.")
1610 ((member var '("ma" "magic")) 1615 ((member var '("ma" "magic"))
1611 (setq var "vip-re-search" 1616 (setq var "vip-re-search"
1612 val "t")) 1617 val "t"))
1613 ((member var '("noma" "nomagic")) 1618 ((member var '("noma" "nomagic"))
1614 (setq var "vip-re-search" 1619 (setq var "vip-re-search"
1615 val "nil")) 1620 val "nil"))
1616 ((member var '("ro" "readonly")) 1621 ((member var '("ro" "readonly"))
@@ -1631,7 +1636,7 @@ reversed.")
1631 ((member var '("nows" "nowrapscan")) 1636 ((member var '("nows" "nowrapscan"))
1632 (setq var "vip-search-wrap-around-t" 1637 (setq var "vip-search-wrap-around-t"
1633 val "nil"))) 1638 val "nil")))
1634 (if (eq val 0) ; value must be set by the user 1639 (if (and set-cmd (eq val 0)) ; value must be set by the user
1635 (let ((cursor-in-echo-area t)) 1640 (let ((cursor-in-echo-area t))
1636 (message ":set %s = <Value>" var) 1641 (message ":set %s = <Value>" var)
1637 ;; if there are unread events, don't wait 1642 ;; if there are unread events, don't wait
@@ -1643,7 +1648,7 @@ reversed.")
1643 (if (member var 1648 (if (member var
1644 '("sw" "shiftwidth" 1649 '("sw" "shiftwidth"
1645 "ts" "tabstop" 1650 "ts" "tabstop"
1646 "gts" "global-tabstop" 1651 "ts-g" "tabstop-global"
1647 "wm" "wrapmargin")) 1652 "wm" "wrapmargin"))
1648 (condition-case nil 1653 (condition-case nil
1649 (or (numberp (setq val2 (car (read-from-string val)))) 1654 (or (numberp (setq val2 (car (read-from-string val))))
@@ -1659,7 +1664,7 @@ reversed.")
1659 (setq var "tab-width" 1664 (setq var "tab-width"
1660 set-cmd "setq" 1665 set-cmd "setq"
1661 ask-if-save nil)) 1666 ask-if-save nil))
1662 ((member var '("gts" "global-tabstop")) 1667 ((member var '("ts-g" "tabstop-global"))
1663 (kill-local-variable 'tab-width) 1668 (kill-local-variable 'tab-width)
1664 (setq var "tab-width" 1669 (setq var "tab-width"
1665 set-cmd "setq-default")) 1670 set-cmd "setq-default"))
@@ -1674,11 +1679,12 @@ reversed.")
1674 val (format "\"%s\"" val))))) 1679 val (format "\"%s\"" val)))))
1675 (ex-fixup-history "set" orig-var)) 1680 (ex-fixup-history "set" orig-var))
1676 1681
1677 (setq actual-lisp-cmd (format "\n(%s %s %s) %s" 1682 (if set-cmd
1678 set-cmd var val auto-cmd-label)) 1683 (setq actual-lisp-cmd
1679 (setq lisp-cmd-del-pattern 1684 (format "\n(%s %s %s) %s" set-cmd var val auto-cmd-label)
1680 (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s" 1685 lisp-cmd-del-pattern
1681 set-cmd var auto-cmd-label)) 1686 (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s"
1687 set-cmd var auto-cmd-label)))
1682 1688
1683 (if (and ask-if-save 1689 (if (and ask-if-save
1684 (y-or-n-p (format "Do you want to save this setting in %s " 1690 (y-or-n-p (format "Do you want to save this setting in %s "
@@ -1705,15 +1711,19 @@ reversed.")
1705 )) 1711 ))
1706 )) 1712 ))
1707 1713
1708 (message "%s %s %s" set-cmd var (if (string-match "^[ \t]*$" val) 1714 (if set-cmd
1709 (format "%S" val) 1715 (message "%s %s %s"
1710 val)) 1716 set-cmd var
1711 (eval (car (read-from-string actual-lisp-cmd))) 1717 (if (string-match "^[ \t]*$" val)
1712 (if (string= var "fill-column") 1718 (format "%S" val)
1713 (if (> val2 0) 1719 val)))
1714 (auto-fill-mode 1) 1720 (if actual-lisp-cmd
1715 (auto-fill-mode -1))) 1721 (eval (car (read-from-string actual-lisp-cmd))))
1716 1722 (if (string= var "fill-column")
1723 (if (> val2 0)
1724 (auto-fill-mode 1)
1725 (auto-fill-mode -1)))
1726 (if (string= var "all") (ex-show-vars))
1717 )) 1727 ))
1718 1728
1719;; In inline args, skip regex-forw and (optionally) chars-back. 1729;; In inline args, skip regex-forw and (optionally) chars-back.
@@ -2077,5 +2087,32 @@ Please contact your system administrator. "
2077 (kill-buffer " *vip-info*"))) 2087 (kill-buffer " *vip-info*")))
2078 )) 2088 ))
2079 2089
2090;; display all variables set through :set
2091(defun ex-show-vars ()
2092 (with-output-to-temp-buffer " *vip-info*"
2093 (princ (if vip-auto-indent
2094 "autoindent (local)\n" "noautoindent (local)\n"))
2095 (princ (if (default-value 'vip-auto-indent)
2096 "autoindent (global) \n" "noautoindent (global) \n"))
2097 (princ (if vip-case-fold-search "ignorecase\n" "noignorecase\n"))
2098 (princ (if vip-re-search "magic\n" "nomagic\n"))
2099 (princ (if buffer-read-only "readonly\n" "noreadonly\n"))
2100 (princ (if blink-matching-paren "showmatch\n" "noshowmatch\n"))
2101 (princ (if vip-search-wrap-around-t "wrapscan\n" "nowrapscan\n"))
2102 (princ (format "shiftwidth \t\t= %S\n" vip-shift-width))
2103 (princ (format "tabstop (local) \t= %S\n" tab-width))
2104 (princ (format "tabstop (global) \t= %S\n" (default-value 'tab-width)))
2105 (princ (format "wrapmargin (local) \t= %S\n"
2106 (- (window-width) fill-column)))
2107 (princ (format "wrapmargin (global) \t= %S\n"
2108 (- (window-width) (default-value 'fill-column))))
2109 (princ (format "shell \t\t\t= %S\n" (if (boundp 'explicit-shell-file-name)
2110 explicit-shell-file-name
2111 'none)))
2112 ))
2113
2114
2115
2116
2080 2117
2081;;; viper-ex.el ends here 2118;;; viper-ex.el ends here
diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el
index 84a40193cb5..91aa1e98b4b 100644
--- a/lisp/emulation/viper-init.el
+++ b/lisp/emulation/viper-init.el
@@ -599,10 +599,7 @@ These buffers can be cycled through via :R and :P commands.")
599(defvar vip-inhibit-startup-message nil 599(defvar vip-inhibit-startup-message nil
600 "Whether Viper startup message should be inhibited.") 600 "Whether Viper startup message should be inhibited.")
601 601
602(defvar vip-always t 602(defvar vip-custom-file-name (vip-convert-standard-file-name "~/.viper")
603 "t means, arrange that vi-state will be a default.")
604
605(defvar vip-custom-file-name (vip-convert-standard-file-name "~/.vip")
606 "Viper customisation file. 603 "Viper customisation file.
607This variable must be set _before_ loading Viper.") 604This variable must be set _before_ loading Viper.")
608 605
diff --git a/lisp/emulation/viper-keym.el b/lisp/emulation/viper-keym.el
index 370ae3de291..9c1f50158b9 100644
--- a/lisp/emulation/viper-keym.el
+++ b/lisp/emulation/viper-keym.el
@@ -24,7 +24,7 @@
24(provide 'viper-keym) 24(provide 'viper-keym)
25 25
26;; compiler pacifier 26;; compiler pacifier
27(defvar vip-always) 27(defvar viper-always)
28(defvar vip-current-state) 28(defvar vip-current-state)
29(defvar vip-mode-string) 29(defvar vip-mode-string)
30(defvar vip-expert-level) 30(defvar vip-expert-level)
@@ -586,7 +586,7 @@ Arguments: (major-mode vip-state keymap)"
586 586
587 (princ (format "\nvip-expert-level %S\n" vip-expert-level)) 587 (princ (format "\nvip-expert-level %S\n" vip-expert-level))
588 (princ (format "vip-no-multiple-ESC %S\n" vip-no-multiple-ESC)) 588 (princ (format "vip-no-multiple-ESC %S\n" vip-no-multiple-ESC))
589 (princ (format "vip-always %S\n" vip-always)) 589 (princ (format "viper-always %S\n" viper-always))
590 (princ (format "vip-ex-style-motion %S\n" 590 (princ (format "vip-ex-style-motion %S\n"
591 vip-ex-style-motion)) 591 vip-ex-style-motion))
592 (princ (format "vip-ex-style-editing-in-insert %S\n" 592 (princ (format "vip-ex-style-editing-in-insert %S\n"
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index 2e33a428ad8..ab36617e0f6 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -8,7 +8,7 @@
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 9, 1997" 11(defconst viper-version "2.94 of June 12, 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.
@@ -315,53 +315,112 @@
315 315
316(require 'viper-cmd) 316(require 'viper-cmd)
317 317
318(defvar vip-always t
319 "See `viper-always'. This variable is for compatibility with older Vipers.")
320(defvar viper-always vip-always
321 "Non-nil means, arrange for vi-state to be a default when appropriate.
322This is different from `viper-mode' variable in that `viper-mode' determines
323whether to use Viper in the first place, while `viper-always', if nil, lets
324user decide when to invoke Viper in a major mode.")
318 325
319;; The following is provided for compatibility with older VIP's 326(defvar viper-mode (cond (noninteractive nil)
327 (t 'ask))
328 "Viperize or not Viperize.
329If t, viperize emacs. If nil -- don't. If `ask', ask the user.
330This variable is used primatily when Viper is being loaded.
320 331
321(defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi) 332Must be set in `~/.emacs' before Viper is loaded.
322(defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert) 333DO NOT set this variable interactively.")
323(defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs)
324
325
326;;; Here we put things that may affect global emacs behavior.
327;;; This file is not loaded during compilation, so this makes
328;;; interactive compilation of Viper safe for non-viper users.
329
330
331;; This is not local in Emacs, so we make it local.
332;; This must be local because although the stack of minor modes can be the same
333;; for all buffers, the associated *keymaps* can be different. In Viper,
334;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have
335;; different keymaps for different buffers.
336;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode
337;; can be different.
338(make-variable-buffer-local 'minor-mode-map-alist)
339
340;; Viper changes the default mode-line-buffer-identification
341(setq-default mode-line-buffer-identification '(" %b"))
342
343;; setup emacs-supported vi-style feel
344(setq next-line-add-newlines nil
345 require-final-newline t)
346
347(make-variable-buffer-local 'require-final-newline)
348 334
349;; don't bark when mark is inactive 335
350(setq mark-even-if-inactive t) 336;; The following are provided for compatibility with older VIP's
351 337
352(setq scroll-step 1) 338;;;###autoload
339(defalias 'vip-mode 'viper-mode)
353 340
354;; Variable displaying the current Viper state in the mode line. 341(defalias 'vip-change-mode-to-vi 'vip-change-state-to-vi)
355(vip-deflocalvar vip-mode-string vip-emacs-state-id) 342(defalias 'vip-change-mode-to-insert 'vip-change-state-to-insert)
356(or (memq 'vip-mode-string global-mode-string) 343(defalias 'vip-change-mode-to-emacs 'vip-change-state-to-emacs)
357 (setq global-mode-string
358 (append '("" vip-mode-string) (cdr global-mode-string))))
359 344
345
360 346
347;;;###autoload
348(defun viper-mode ()
349 "Turn on Viper emulation of Vi."
350 (interactive)
351 (if (not noninteractive)
352 (progn
353 ;; if the user requested viper-mode explicitly
354 (if viper-mode
355 ()
356 (setq viper-mode 1)
357 (load-library "viper"))
358
359 (if vip-first-time ; This check is important. Without it, startup and
360 (progn ; expert-level msgs mix up when viper-mode recurses
361 (setq vip-first-time nil)
362 (if (not vip-inhibit-startup-message)
363 (save-window-excursion
364 (setq vip-inhibit-startup-message t)
365 (delete-other-windows)
366 (switch-to-buffer "Viper Startup Message")
367 (erase-buffer)
368 (insert
369 (substitute-command-keys
370 "Viper Is a Package for Emacs Rebels.
371It is also a VI Plan for Emacs Rescue and a venomous VI PERil.
372
373Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and
374XEmacs 19. It supports virtually all of Vi and Ex functionality, extending
375and improving upon much of it.
376
377 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.
379
380 You will be asked to specify your user level in a following screen.
381
382 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
384 use Emacs productively, you are advised to reach user level 3 or higher.
385
386 If your user level is 2 or higher, ^X and ^C will invoke Emacs
387 functions,as usual in Emacs; ^Z will toggle vi/emacs modes, and
388 ^G will be the usual Emacs's keyboard-quit (something like ^C in VI).
389
390 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).
392 3. ^X^C EXITS EMACS.
393 4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
394 undo. Another `u' changes direction.
395
396 6. Emacs Meta functions are invoked by typing `C-\\' or `\\ ESC'.
397 On a window system, the best way is to use the Meta-key.
398 7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
399 something funny happens. This would abort the current editing command.
400
401You can get more information on Viper by:
361 402
403 a. Typing `:help' in Vi state
404 b. Printing Viper manual, found in ./etc/viper.dvi
405 c. Printing ViperCard, the Quick Reference, found in ./etc/viperCard.dvi
406
407This startup message appears whenever you load Viper, unless you type `y' now."
408 ))
409 (goto-char (point-min))
410 (if (y-or-n-p "Inhibit Viper startup message? ")
411 (vip-save-setting
412 'vip-inhibit-startup-message
413 "Viper startup message inhibited"
414 vip-custom-file-name t))
415 ;;(kill-buffer (current-buffer))
416 (message
417 "The last message is in buffer `Viper Startup Message'")
418 (sit-for 4)
419 ))
420 (vip-set-expert-level 'dont-change-unless)))
421 (vip-change-state-to-vi))))
422
362 423
363;;; Load set up hooks then load .vip
364
365;; This hook designed to enable Vi-style editing in comint-based modes." 424;; This hook designed to enable Vi-style editing in comint-based modes."
366(defun vip-comint-mode-hook () 425(defun vip-comint-mode-hook ()
367 (setq require-final-newline nil 426 (setq require-final-newline nil
@@ -398,14 +457,16 @@
398 (add-hook 'html-mode-hook 'viper-mode) 457 (add-hook 'html-mode-hook 'viper-mode)
399 (defvar html-helper-mode-hook) 458 (defvar html-helper-mode-hook)
400 (add-hook 'html-helper-mode-hook 'viper-mode) 459 (add-hook 'html-helper-mode-hook 'viper-mode)
460
401 (defvar java-mode-hook) 461 (defvar java-mode-hook)
402 (add-hook 'java-mode-hook 'viper-mode) 462 (add-hook 'java-mode-hook 'viper-mode)
403 463
404 (defvar emacs-lisp-mode-hook) 464 (defvar emacs-lisp-mode-hook)
405 (add-hook 'emacs-lisp-mode-hook 'viper-mode) 465 (add-hook 'emacs-lisp-mode-hook 'viper-mode)
406
407 (defvar lisp-mode-hook) 466 (defvar lisp-mode-hook)
408 (add-hook 'lisp-mode-hook 'viper-mode) 467 (add-hook 'lisp-mode-hook 'viper-mode)
468 (defvar lisp-interaction-mode-hook)
469 (add-hook 'lisp-interaction-mode-hook 'viper-mode)
409 470
410 (defvar bibtex-mode-hook) 471 (defvar bibtex-mode-hook)
411 (add-hook 'bibtex-mode-hook 'viper-mode) 472 (add-hook 'bibtex-mode-hook 'viper-mode)
@@ -418,17 +479,16 @@
418 479
419 (defvar c++-mode-hook) 480 (defvar c++-mode-hook)
420 (add-hook 'c++-mode-hook 'viper-mode) 481 (add-hook 'c++-mode-hook 'viper-mode)
421
422 (defvar lisp-interaction-mode-hook)
423 (add-hook 'lisp-interaction-mode-hook 'viper-mode)
424 482
425 (defvar fortran-mode-hook) 483 (defvar fortran-mode-hook)
426 (add-hook 'fortran-mode-hook 'vip-mode) 484 (add-hook 'fortran-mode-hook 'viper-mode)
485 (defvar f90-mode-hook)
486 (add-hook 'f90-mode-hook 'viper-mode)
427 487
428 (defvar basic-mode-hook) 488 (defvar basic-mode-hook)
429 (add-hook 'basic-mode-hook 'vip-mode) 489 (add-hook 'basic-mode-hook 'viper-mode)
430 (defvar bat-mode-hook) 490 (defvar bat-mode-hook)
431 (add-hook 'bat-mode-hook 'vip-mode) 491 (add-hook 'bat-mode-hook 'viper-mode)
432 492
433 (defvar text-mode-hook) 493 (defvar text-mode-hook)
434 (add-hook 'text-mode-hook 'viper-mode) 494 (add-hook 'text-mode-hook 'viper-mode)
@@ -587,160 +647,227 @@
587 (vip-change-state-to-emacs)) 647 (vip-change-state-to-emacs))
588 ) ; vip-set-hooks 648 ) ; vip-set-hooks
589 649
650
651;; these are primarily advices and Vi-ish variable settings
652(defun vip-non-hook-settings ()
653
654 ;; This var is not local in Emacs, so we make it local.
655 ;; It must be local because although the stack of minor modes can be the same
656 ;; for all buffers, the associated *keymaps* can be different. In Viper,
657 ;; vip-vi-local-user-map, vip-insert-local-user-map, and others can have
658 ;; different keymaps for different buffers.
659 ;; Also, the keymaps associated with vip-vi/insert-state-modifier-minor-mode
660 ;; can be different.
661 (make-variable-buffer-local 'minor-mode-map-alist)
662
663 ;; Viper changes the default mode-line-buffer-identification
664 (setq-default mode-line-buffer-identification '(" %b"))
665
666 ;; setup emacs-supported vi-style feel
667 (setq next-line-add-newlines nil
668 require-final-newline t)
669
670 (make-variable-buffer-local 'require-final-newline)
671
672 ;; don't bark when mark is inactive
673 (setq mark-even-if-inactive t)
674
675 (setq scroll-step 1)
676
677 ;; Variable displaying the current Viper state in the mode line.
678 (vip-deflocalvar vip-mode-string vip-emacs-state-id)
679 (or (memq 'vip-mode-string global-mode-string)
680 (setq global-mode-string
681 (append '("" vip-mode-string) (cdr global-mode-string))))
682
683 (defadvice read-key-sequence (around vip-read-keyseq-ad activate)
684 "Harness to work for Viper. This advice is harmless---don't worry!"
685 (let (inhibit-quit event keyseq)
686 (setq keyseq ad-do-it)
687 (setq event (if vip-xemacs-p
688 (elt keyseq 0) ; XEmacs returns vector of events
689 (elt (listify-key-sequence keyseq) 0)))
690 (if (vip-ESC-event-p event)
691 (let (unread-command-events)
692 (vip-set-unread-command-events keyseq)
693 (if (vip-fast-keysequence-p)
694 (let ((vip-vi-global-user-minor-mode nil)
695 (vip-vi-local-user-minor-mode nil)
696 (vip-replace-minor-mode nil) ; actually unnecessary
697 (vip-insert-global-user-minor-mode nil)
698 (vip-insert-local-user-minor-mode nil))
699 (setq keyseq ad-do-it))
700 (setq keyseq ad-do-it))))
701 keyseq))
702
703 (defadvice describe-key (before vip-read-keyseq-ad protect activate)
704 "Force to read key via `read-key-sequence'."
705 (interactive (list (vip-events-to-keys
706 (read-key-sequence "Describe key: ")))))
707
708 (defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate)
709 "Force to read key via `read-key-sequence'."
710 (interactive (list (vip-events-to-keys
711 (read-key-sequence "Describe key briefly: ")))))
712
713
714 ;; Advice for use in find-file and read-file-name commands.
715 (defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate)
716 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer."
717 (run-hooks 'vip-minibuffer-exit-hook))
718
719 (defadvice find-file (before vip-add-suffix-advice activate)
720 "Use `read-file-name' for reading arguments."
721 (interactive (cons (read-file-name "Find file: " nil default-directory)
722 ;; if Mule and prefix argument, ask for coding system
723 (if (or (boundp 'MULE) ; mule integrated Emacs 19
724 (featurep 'mule)) ; mule integrated XEmacs 20
725 (list
726 (and current-prefix-arg
727 (read-coding-system "Coding-system: "))))
728 )))
729
730 (defadvice find-file-other-window (before vip-add-suffix-advice activate)
731 "Use `read-file-name' for reading arguments."
732 (interactive (cons (read-file-name "Find file in other window: "
733 nil default-directory)
734 ;; if Mule and prefix argument, ask for coding system
735 (if (or (boundp 'MULE) ; mule integrated Emacs 19
736 (featurep 'mule)) ; mule integrated XEmacs 20
737 (list
738 (and current-prefix-arg
739 (read-coding-system "Coding-system: "))))
740 )))
741
742 (defadvice find-file-other-frame (before vip-add-suffix-advice activate)
743 "Use `read-file-name' for reading arguments."
744 (interactive (cons (read-file-name "Find file in other frame: "
745 nil default-directory)
746 ;; if Mule and prefix argument, ask for coding system
747 (if (or (boundp 'MULE) ; mule integrated Emacs 19
748 (featurep 'mule)) ; mule integrated XEmacs 20
749 (list
750 (and current-prefix-arg
751 (read-coding-system "Coding-system: "))))
752 )))
753
754 (defadvice read-file-name (around vip-suffix-advice activate)
755 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook."
756 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix))
757 ad-do-it))
758
759 (defadvice start-kbd-macro (after vip-kbd-advice activate)
760 "Remove Viper's intercepting bindings for C-x ).
761 This may be needed if the previous `:map' command terminated abnormally."
762 (define-key vip-vi-intercept-map "\C-x)" nil)
763 (define-key vip-insert-intercept-map "\C-x)" nil)
764 (define-key vip-emacs-intercept-map "\C-x)" nil))
765
766 (cond ((vip-window-display-p)
767 (let* ((search-key (if vip-xemacs-p
768 [(meta shift button1up)] [M-S-mouse-1]))
769 (search-key-catch
770 (if vip-xemacs-p [(meta shift button1)] [M-S-down-mouse-1]))
771 (insert-key (if vip-xemacs-p
772 [(meta shift button2up)] [M-S-mouse-2]))
773 (insert-key-catch
774 (if vip-xemacs-p [(meta shift button2)] [M-S-down-mouse-2]))
775 (search-key-unbound (and (not (key-binding search-key))
776 (not (key-binding search-key-catch))))
777 (insert-key-unbound (and (not (key-binding insert-key))
778 (not (key-binding insert-key-catch))))
779 )
780
781 (if search-key-unbound
782 (global-set-key search-key 'vip-mouse-click-search-word))
783 (if insert-key-unbound
784 (global-set-key insert-key 'vip-mouse-click-insert-word))
785
786 ;; The following would be needed if you want to use the above two
787 ;; while clicking in another frame. If you only want to use them
788 ;; by clicking in another window, not frame, the bindings below
789 ;; aren't necessary.
790
791 ;; These must be bound to mouse-down event for the same mouse
792 ;; buttons as 'vip-mouse-click-search-word and
793 ;; 'vip-mouse-click-insert-word
794 (if search-key-unbound
795 (global-set-key search-key-catch 'vip-mouse-catch-frame-switch))
796 (if insert-key-unbound
797 (global-set-key insert-key-catch 'vip-mouse-catch-frame-switch))
798
799 (if vip-xemacs-p
800 (add-hook 'mouse-leave-frame-hook
801 'vip-remember-current-frame)
802 (defadvice handle-switch-frame (before vip-frame-advice activate)
803 "Remember the selected frame before the switch-frame event."
804 (vip-remember-current-frame (selected-frame))))
805 )))
806 ) ; end vip-non-hook-settings
807
590 808
591;; Defadvices 809(if (eq viper-mode 'ask)
592 810 (progn
593(defadvice read-key-sequence (around vip-read-keyseq-ad activate) 811 (save-window-excursion
594 "Harness to work for Viper. This advice is harmless---don't worry!" 812 (with-output-to-temp-buffer " *vip-info*"
595 (let (inhibit-quit event keyseq) 813 (princ "
596 (setq keyseq ad-do-it) 814You have loaded Viper, and are about to Viperize your emacs!
597 (setq event (if vip-xemacs-p 815
598 (elt keyseq 0) ; XEmacs returns vector of events 816Viper is a Package for Emacs Rebels
599 (elt (listify-key-sequence keyseq) 0))) 817and a venomous VI PERil,
600 (if (vip-ESC-event-p event) 818
601 (let (unread-command-events) 819It's time to decide: to Viperize or not to Viperize...
602 (vip-set-unread-command-events keyseq) 820
603 (if (vip-fast-keysequence-p) 821If you wish to Viperize AND make this your way of life, please put
604 (let ((vip-vi-global-user-minor-mode nil) 822
605 (vip-vi-local-user-minor-mode nil) 823 (setq viper-mode t)
606 (vip-replace-minor-mode nil) ; actually unnecessary 824 (require 'viper)
607 (vip-insert-global-user-minor-mode nil) 825
608 (vip-insert-local-user-minor-mode nil)) 826in your .emacs file (preferably, close to the top).
609 (setq keyseq ad-do-it)) 827These two lines must come in the order given.
610 (setq keyseq ad-do-it)))) 828
611 keyseq)) 829Also, the startup file name has changed from .vip to .viper"))
612 830 (if (y-or-n-p "Viperize? ")
613(defadvice describe-key (before vip-read-keyseq-ad protect activate) 831 (setq viper-mode t)
614 "Force to read key via `read-key-sequence'." 832 (setq viper-mode nil))
615 (interactive (list (vip-events-to-keys 833 (message "")
616 (read-key-sequence "Describe key: "))))) 834 (kill-buffer " *vip-info*"))))
617 835
618(defadvice describe-key-briefly (before vip-read-keyseq-ad protect activate)
619 "Force to read key via `read-key-sequence'."
620 (interactive (list (vip-events-to-keys
621 (read-key-sequence "Describe key briefly: ")))))
622
623
624;; Advice for use in find-file and read-file-name commands.
625(defadvice exit-minibuffer (before vip-exit-minibuffer-advice activate)
626 "Run `vip-minibuffer-exit-hook' just before exiting the minibuffer."
627 (run-hooks 'vip-minibuffer-exit-hook))
628
629(defadvice find-file (before vip-add-suffix-advice activate)
630 "Use `read-file-name' for reading arguments."
631 (interactive (cons (read-file-name "Find file: " nil default-directory)
632 ;; if Mule and prefix argument, ask for coding system
633 (if (or (boundp 'MULE) ; mule integrated Emacs 19
634 (featurep 'mule)) ; mule integrated XEmacs 20
635 (list
636 (and current-prefix-arg
637 (read-coding-system "Coding-system: "))))
638 )))
639
640(defadvice find-file-other-window (before vip-add-suffix-advice activate)
641 "Use `read-file-name' for reading arguments."
642 (interactive (cons (read-file-name "Find file in other window: "
643 nil default-directory)
644 ;; if Mule and prefix argument, ask for coding system
645 (if (or (boundp 'MULE) ; mule integrated Emacs 19
646 (featurep 'mule)) ; mule integrated XEmacs 20
647 (list
648 (and current-prefix-arg
649 (read-coding-system "Coding-system: "))))
650 )))
651
652(defadvice find-file-other-frame (before vip-add-suffix-advice activate)
653 "Use `read-file-name' for reading arguments."
654 (interactive (cons (read-file-name "Find file in other frame: "
655 nil default-directory)
656 ;; if Mule and prefix argument, ask for coding system
657 (if (or (boundp 'MULE) ; mule integrated Emacs 19
658 (featurep 'mule)) ; mule integrated XEmacs 20
659 (list
660 (and current-prefix-arg
661 (read-coding-system "Coding-system: "))))
662 )))
663
664(defadvice read-file-name (around vip-suffix-advice activate)
665 "Tell `exit-minibuffer' to run `vip-file-add-suffix' as a hook."
666 (let ((vip-minibuffer-exit-hook 'vip-file-add-suffix))
667 ad-do-it))
668
669(defadvice start-kbd-macro (after vip-kbd-advice activate)
670 "Remove Viper's intercepting bindings for C-x ).
671This may be needed if the previous `:map' command terminated abnormally."
672 (define-key vip-vi-intercept-map "\C-x)" nil)
673 (define-key vip-insert-intercept-map "\C-x)" nil)
674 (define-key vip-emacs-intercept-map "\C-x)" nil))
675
676(cond ((vip-window-display-p)
677 (let* ((search-key (if vip-xemacs-p
678 [(meta shift button1up)] [M-S-mouse-1]))
679 (search-key-catch (if vip-xemacs-p
680 [(meta shift button1)] [M-S-down-mouse-1]))
681 (insert-key (if vip-xemacs-p
682 [(meta shift button2up)] [M-S-mouse-2]))
683 (insert-key-catch (if vip-xemacs-p
684 [(meta shift button2)] [M-S-down-mouse-2]))
685 (search-key-unbound (and (not (key-binding search-key))
686 (not (key-binding search-key-catch))))
687 (insert-key-unbound (and (not (key-binding insert-key))
688 (not (key-binding insert-key-catch))))
689 )
690
691 (if search-key-unbound
692 (global-set-key search-key 'vip-mouse-click-search-word))
693 (if insert-key-unbound
694 (global-set-key insert-key 'vip-mouse-click-insert-word))
695
696 ;; The following would be needed if you want to use the above two
697 ;; while clicking in another frame. If you only want to use them
698 ;; by clicking in another window, not frame, the bindings below
699 ;; aren't necessary.
700
701 ;; These must be bound to mouse-down event for the same mouse
702 ;; buttons as 'vip-mouse-click-search-word and
703 ;; 'vip-mouse-click-insert-word
704 (if search-key-unbound
705 (global-set-key search-key-catch 'vip-mouse-catch-frame-switch))
706 (if insert-key-unbound
707 (global-set-key insert-key-catch 'vip-mouse-catch-frame-switch))
708
709 (if vip-xemacs-p
710 (add-hook 'mouse-leave-frame-hook
711 'vip-remember-current-frame)
712 (defadvice handle-switch-frame (before vip-frame-advice activate)
713 "Remember the selected frame before the switch-frame event."
714 (vip-remember-current-frame (selected-frame))))
715 )))
716 836
717 837
718 838
719 839
720;; Set some useful macros 840;; Set some useful macros, advices
721;; These must be before we load .vip, so the user could unrecord them. 841;; These must be BEFORE we ~/.vip is loaded,
722 842;; so the user can unrecord them in ~/.vip.
723;; repeat the 2nd previous command without rotating the command history 843(if viper-mode
724(vip-record-kbd-macro 844 (progn
725 (vector vip-repeat-from-history-key '\1) 'vi-state 845 ;; set advices and some variables that give emacs Vi look.
726 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) 846 (vip-non-hook-settings)
727;; repeat the 3d previous command without rotating the command history 847
728(vip-record-kbd-macro 848 ;; repeat the 2nd previous command without rotating the command history
729 (vector vip-repeat-from-history-key '\2) 'vi-state 849 (vip-record-kbd-macro
730 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't) 850 (vector vip-repeat-from-history-key '\1) 'vi-state
731 851 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
732;; set the toggle case sensitivity and regexp search macros 852 ;; repeat the 3d previous command without rotating the command history
733(vip-set-vi-search-style-macros nil) 853 (vip-record-kbd-macro
734 854 (vector vip-repeat-from-history-key '\2) 'vi-state
735;; Make %%% toggle parsing comments for matching parentheses 855 [(meta x) v i p - r e p e a t - f r o m - h i s t o r y return] 't)
736(vip-record-kbd-macro 856
737 "%%%" 'vi-state 857 ;; set the toggle case sensitivity and regexp search macros
738 [(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] 858 (vip-set-vi-search-style-macros nil)
739 't) 859
860 ;; Make %%% toggle parsing comments for matching parentheses
861 (vip-record-kbd-macro
862 "%%%" 'vi-state
863 [(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]
864 't)
865 ))
740 866
741 867
742;; ~/.vip is loaded if it exists 868;; ~/.vip is loaded if it exists
743(if (and (file-exists-p vip-custom-file-name) 869(if (and (file-exists-p vip-custom-file-name)
870 viper-mode
744 (not noninteractive)) 871 (not noninteractive))
745 (load vip-custom-file-name)) 872 (load vip-custom-file-name))
746 873
@@ -754,35 +881,42 @@ This may be needed if the previous `:map' command terminated abnormally."
754;; Save user settings or Viper defaults for vars controled by vip-expert-level 881;; Save user settings or Viper defaults for vars controled by vip-expert-level
755(setq vip-saved-user-settings 882(setq vip-saved-user-settings
756 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help) 883 (list (cons 'vip-want-ctl-h-help vip-want-ctl-h-help)
757 (cons 'vip-always vip-always) 884 (cons 'viper-always viper-always)
758 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC) 885 (cons 'vip-no-multiple-ESC vip-no-multiple-ESC)
759 (cons 'vip-ex-style-motion vip-ex-style-motion) 886 (cons 'vip-ex-style-motion vip-ex-style-motion)
760 (cons 'vip-ex-style-editing-in-insert 887 (cons 'vip-ex-style-editing-in-insert
761 vip-ex-style-editing-in-insert) 888 vip-ex-style-editing-in-insert)
762 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi) 889 (cons 'vip-want-emacs-keys-in-vi vip-want-emacs-keys-in-vi)
890 (cons 'vip-electric-mode vip-electric-mode)
763 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert) 891 (cons 'vip-want-emacs-keys-in-insert vip-want-emacs-keys-in-insert)
764 (cons 'vip-re-search vip-re-search))) 892 (cons 'vip-re-search vip-re-search)))
765 893
766 894
767(vip-set-minibuffer-style) 895(if viper-mode
768(if vip-buffer-search-char 896 (progn
769 (vip-buffer-search-enable)) 897 (vip-set-minibuffer-style)
770(vip-update-alphanumeric-class) 898 (if vip-buffer-search-char
899 (vip-buffer-search-enable))
900 (vip-update-alphanumeric-class)
901 ))
771 902
772 903
773;;; Familiarize Viper with some minor modes that have their own keymaps 904;;; Familiarize Viper with some minor modes that have their own keymaps
774(vip-harness-minor-mode "compile") 905(if viper-mode
775(vip-harness-minor-mode "outline") 906 (progn
776(vip-harness-minor-mode "allout") 907 (vip-harness-minor-mode "compile")
777(vip-harness-minor-mode "xref") 908 (vip-harness-minor-mode "outline")
778(vip-harness-minor-mode "lmenu") 909 (vip-harness-minor-mode "allout")
779(vip-harness-minor-mode "vc") 910 (vip-harness-minor-mode "xref")
780(vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX 911 (vip-harness-minor-mode "lmenu")
781(vip-harness-minor-mode "latex") ; which is in one of these two files 912 (vip-harness-minor-mode "vc")
782(vip-harness-minor-mode "cyrillic") 913 (vip-harness-minor-mode "ltx-math") ; LaTeX-math-mode in AUC-TeX
783(vip-harness-minor-mode "russian") 914 (vip-harness-minor-mode "latex") ; which is in one of these two files
784(vip-harness-minor-mode "view-less") 915 (vip-harness-minor-mode "cyrillic")
785(vip-harness-minor-mode "view") 916 (vip-harness-minor-mode "russian")
917 (vip-harness-minor-mode "view-less")
918 (vip-harness-minor-mode "view")
919 ))
786 920
787 921
788;; Intercept maps could go in viper-keym.el 922;; Intercept maps could go in viper-keym.el
@@ -801,8 +935,9 @@ This may be needed if the previous `:map' command terminated abnormally."
801(define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi) 935(define-key vip-emacs-intercept-map vip-toggle-key 'vip-change-state-to-vi)
802 936
803 937
804(if (or vip-always 938(if (and viper-mode
805 (and (< vip-expert-level 5) (> vip-expert-level 0))) 939 (or viper-always
940 (and (< vip-expert-level 5) (> vip-expert-level 0))))
806 (vip-set-hooks)) 941 (vip-set-hooks))
807 942
808;; Let all minor modes take effect after loading 943;; Let all minor modes take effect after loading