(defconst viper-version "3.13.1 of October 23, 2006"
"The current version of Viper")
(require 'advice)
(require 'cl)
(require 'ring)
(defvar mark-even-if-inactive)
(defvar quail-mode)
(defvar viper-expert-level)
(defvar viper-mode-string)
(defvar viper-major-mode-modifier-list)
(if noninteractive
(eval-when-compile
(let ((load-path (cons (expand-file-name ".") load-path)))
(or (featurep 'viper-init)
(load "viper-init.el" nil nil 'nosuffix))
(or (featurep 'viper-cmd)
(load "viper-cmd.el" nil nil 'nosuffix))
)))
(require 'viper-init)
(require 'viper-keym)
(defvar viper-custom-file-name (convert-standard-filename "~/.viper")
"Viper customization file.
If set by the user, this must be done _before_ Viper is loaded in `~/.emacs'.")
(defgroup viper nil
"Vi emulation within Emacs.
NOTE: Viper customization should be saved in `viper-custom-file-name', which
defaults to `~/.viper'."
:prefix "viper-"
:group 'emulations)
(require 'viper-cmd)
(defgroup viper-misc nil
"Miscellaneous Viper customization."
:prefix "viper-"
:group 'viper)
(defcustom viper-always t
"Non-nil means, arrange for vi-state to be a default when appropriate.
This is different from `viper-mode' variable in that `viper-mode' determines
whether to use Viper in the first place, while `viper-always', if nil, lets
user decide when to invoke Viper in a major mode."
:type 'boolean
:tag "Always Invoke Viper"
:group 'viper-misc)
(defvar viper-saved-non-viper-variables nil)
(defcustom viper-mode (cond (noninteractive nil)
(t 'ask))
"To Viperize or not to Viperize.
If t, viperize Emacs. If nil -- don't. If `ask', ask the user.
This variable is used primarily when Viper is being loaded.
Must be set in `~/.emacs' before Viper is loaded.
DO NOT set this variable interactively, unless you are using the customization
widget."
:type '(choice (const nil) (const t) (const ask))
:tag "Set Viper Mode on Loading"
:group 'viper-misc)
(defcustom viper-vi-state-mode-list
'(fundamental-mode
makefile-mode
awk-mode
m4-mode
xrdb-mode
winmgr-mode
autoconf-mode
cvs-edit-mode
html-mode html-helper-mode
emacs-lisp-mode lisp-mode lisp-interaction-mode
jde-mode java-mode
cc-mode c-mode c++-mode objc-mode
fortran-mode f90-mode
basic-mode
bat-mode
asm-mode
prolog-mode
flora-mode
sql-mode
text-mode indented-text-mode
tex-mode latex-mode bibtex-mode
ps-mode
diff-mode
idl-mode
perl-mode
cperl-mode
javascript-mode
tcl-mode
python-mode
sh-mode ksh-mode csh-mode
gnus-article-mode
mh-show-mode
)
"Major modes that require Vi command state."
:type '(repeat symbol)
:group 'viper-misc)
(defcustom viper-emacs-state-mode-list
'(custom-mode
dired-mode
efs-mode
tar-mode
browse-kill-ring-mode
recentf-mode
recentf-dialog-mode
occur-mode
mh-folder-mode
gnus-group-mode
gnus-summary-mode
completion-list-mode
help-mode
Info-mode
Buffer-menu-mode
compilation-mode
rcirc-mode
jde-javadoc-checker-report-mode
view-mode
vm-mode
vm-summary-mode)
"*A list of major modes that should come up in Emacs state.
Normally, Viper would bring buffers up in Emacs state, unless the corresponding
major mode has been placed on `viper-vi-state-mode-list' or
`viper-insert-state-mode-list'. So, don't place a new mode on this list,
unless it is coming up in a wrong Viper state."
:type '(repeat symbol)
:group 'viper-misc)
(defcustom viper-insert-state-mode-list
'(internal-ange-ftp-mode
comint-mode
inferior-emacs-lisp-mode
erc-mode
eshell-mode
shell-mode)
"*A list of major modes that should come up in Vi Insert state."
:type '(repeat symbol)
:group 'viper-misc)
(defun viper-apply-major-mode-modifiers (&optional symbol value)
(if symbol
(set symbol value))
(mapcar (lambda (triple)
(viper-modify-major-mode
(nth 0 triple) (nth 1 triple) (eval (nth 2 triple))))
viper-major-mode-modifier-list))
(defcustom viper-major-mode-modifier-list
'((help-mode emacs-state viper-slash-and-colon-map)
(comint-mode insert-state viper-comint-mode-modifier-map)
(comint-mode vi-state viper-comint-mode-modifier-map)
(shell-mode insert-state viper-comint-mode-modifier-map)
(inferior-emacs-lisp-mode insert-state viper-comint-mode-modifier-map)
(shell-mode vi-state viper-comint-mode-modifier-map)
(ange-ftp-shell-mode insert-state viper-comint-mode-modifier-map)
(ange-ftp-shell-mode vi-state viper-comint-mode-modifier-map)
(internal-ange-ftp-mode insert-state viper-comint-mode-modifier-map)
(internal-ange-ftp-mode vi-state viper-comint-mode-modifier-map)
(dired-mode emacs-state viper-dired-modifier-map)
(tar-mode emacs-state viper-slash-and-colon-map)
(mh-folder-mode emacs-state viper-slash-and-colon-map)
(gnus-group-mode emacs-state viper-gnus-modifier-map)
(gnus-summary-mode emacs-state viper-gnus-modifier-map)
(Info-mode emacs-state viper-slash-and-colon-map)
(Buffer-menu-mode emacs-state viper-slash-and-colon-map)
(erc-mode insert-state viper-comint-mode-modifier-map)
(erc-mode vi-state viper-comint-mode-modifier-map)
)
"List specifying how to modify the various major modes to enable some Viperisms.
The list has the structure: ((mode viper-state keymap) (mode viper-state
keymap) ...). If `mode' is on the list, the `kemap' will be made active (on
the minor-mode-map-alist) in the specified viper state.
If you change this list, have to restart Emacs for the change to take effect.
However, if you did the change through the customization widget, then Emacs
needs to be restarted only if you deleted a triple mode-state-keymap from the
list. No need to restart Emacs in case of insertion or modification of an
existing triple."
:type '(repeat
(list symbol
(choice (const emacs-state)
(const vi-state)
(const insert-state))
symbol))
:set 'viper-apply-major-mode-modifiers
:group 'viper-misc)
(defun toggle-viper-mode ()
"Toggle Viper on/off.
If Viper is enabled, turn it off. Otherwise, turn it on."
(interactive)
(if (eq viper-mode t)
(viper-go-away)
(setq viper-mode nil)
(viper-mode)))
(defun viper-mode ()
"Turn on Viper emulation of Vi in Emacs. See Info node `(viper)Top'."
(interactive)
(if (not noninteractive)
(progn
(if viper-mode
()
(setq viper-mode t)
(load-library "viper"))
(if viper-first-time (progn (setq viper-first-time nil)
(if (not viper-inhibit-startup-message)
(save-window-excursion
(setq viper-inhibit-startup-message t)
(delete-other-windows)
(switch-to-buffer "Viper Startup Message")
(erase-buffer)
(insert
(substitute-command-keys
"Viper Is a Package for Emacs Rebels,
a VI Plan for Emacs Rescue, and a venomous VI PERil.
Incidentally, Viper emulates Vi under GNU Emacs 20 and XEmacs 20.
It supports all of what is good in Vi and Ex, while extending
and improving upon much of it.
1. Viper supports Vi at several levels. Level 1 is the closest to Vi,
level 5 provides the most flexibility to depart from many Vi conventions.
You will be asked to specify your user level in a following screen.
If you select user level 1 then the keys ^X, ^C, ^Z, and ^G will behave
as in VI, to smooth transition to Viper for the beginners. However, to
use Emacs productively, you are advised to reach user level 3 or higher.
At user level 2 or higher, ^X and ^C have Emacs, not Vi, bindings;
^Z toggles Vi/Emacs states; ^G is Emacs' keyboard-quit (like ^C in Vi).
2. Vi exit functions (e.g., :wq, ZZ) work on INDIVIDUAL files -- they
do not cause Emacs to quit, except at user level 1 (for a novice).
3. ^X^C EXITS EMACS.
4. Viper supports multiple undo: `u' will undo. Typing `.' will repeat
undo. Another `u' changes direction.
6. Emacs Meta key is `C-\\' (in all modes) or `\\ ESC' (in Vi command mode).
On a window system, the best way is to use the Meta-key on your keyboard.
7. Try \\[keyboard-quit] and \\[abort-recursive-edit] repeatedly,if
something funny happens. This would abort the current editing command.
For more information on Viper:
a. Type `:help' in Vi command mode
b. Print Viper manual, found in ./etc/viper.dvi
c. Print the Quick Reference, found in ./etc/viperCard.dvi
To submit a bug report or to contact the author, type :submitReport in Vi
command mode. To shoo Viper away and return to pure Emacs (horror!), type:
M-x viper-go-away
This startup message appears whenever you load Viper, unless you type `y' now."
))
(goto-char (point-min))
(if (y-or-n-p "Inhibit Viper startup message? ")
(viper-save-setting
'viper-inhibit-startup-message
"Viper startup message inhibited"
viper-custom-file-name t))
(message
"The last message is in buffer `Viper Startup Message'")
(sit-for 4)
))
(viper-set-expert-level 'dont-change-unless)))
(if (eq major-mode 'viper-mode)
(setq major-mode 'fundamental-mode))
(or (memq major-mode viper-emacs-state-mode-list) (memq major-mode viper-insert-state-mode-list) (viper-change-state-to-vi))
)))
(defun this-major-mode-requires-vi-state (mode)
(cond ((memq mode viper-vi-state-mode-list) t)
((memq mode viper-emacs-state-mode-list) nil)
((memq mode viper-insert-state-mode-list) nil)
(t (and (eq (key-binding "a") 'self-insert-command)
(eq (key-binding " ") 'self-insert-command)))))
(defun viper-comint-mode-hook ()
(set (make-local-variable 'require-final-newline) nil)
(setq viper-ex-style-editing nil
viper-ex-style-motion nil)
(viper-change-state-to-insert))
(defun viper-remove-hooks (symbol)
(cond ((not (boundp symbol)) nil)
((not (listp (eval symbol))) nil)
((string-match "-hook" (symbol-name symbol))
(remove-hook symbol 'viper-mode)
(remove-hook symbol 'viper-change-state-to-emacs)
(remove-hook symbol 'viper-change-state-to-insert)
(remove-hook symbol 'viper-change-state-to-vi)
)))
(defun viper-delocalize-var (symbol)
(mapcar (lambda (buf) (save-excursion
(set-buffer buf)
(kill-local-variable symbol)))
(buffer-list)))
(defun viper-go-away ()
"De-Viperize Emacs.
This function tries to do as good a job as possible. However, it may undo some
user customization, unrelated to Viper. For instance, if the user advised
`read-file-name', `describe-key', and some others, then this advice will be
undone.
It also can't undo some Viper settings."
(interactive)
(setq-default
next-line-add-newlines
(viper-standard-value
'next-line-add-newlines viper-saved-non-viper-variables)
require-final-newline
(viper-standard-value
'require-final-newline viper-saved-non-viper-variables)
scroll-step
(viper-standard-value 'scroll-step viper-saved-non-viper-variables)
mode-line-buffer-identification
(viper-standard-value
'mode-line-buffer-identification viper-saved-non-viper-variables)
global-mode-string
(delq 'viper-mode-string global-mode-string))
(if viper-emacs-p
(setq-default
mark-even-if-inactive
(viper-standard-value
'mark-even-if-inactive viper-saved-non-viper-variables)))
(unless
(and (fboundp 'add-to-ordered-list) (boundp 'emulation-mode-map-alists))
(viper-delocalize-var 'minor-mode-map-alist))
(viper-delocalize-var 'require-final-newline)
(if viper-xemacs-p (viper-delocalize-var 'bar-cursor))
(ad-deactivate-regexp "viper-")
(setq viper-mode nil)
(when (and (fboundp 'add-to-ordered-list) (boundp 'emulation-mode-map-alists))
(setq emulation-mode-map-alists
(delq 'viper--intercept-key-maps
(delq 'viper--key-maps emulation-mode-map-alists))
))
(viper-delocalize-var 'viper-vi-minibuffer-minor-mode)
(viper-delocalize-var 'viper-insert-minibuffer-minor-mode)
(viper-delocalize-var 'viper-vi-intercept-minor-mode)
(viper-delocalize-var 'viper-insert-intercept-minor-mode)
(viper-delocalize-var 'viper-vi-local-user-minor-mode)
(viper-delocalize-var 'viper-vi-kbd-minor-mode)
(viper-delocalize-var 'viper-vi-global-user-minor-mode)
(viper-delocalize-var 'viper-vi-state-modifier-minor-mode)
(viper-delocalize-var 'viper-vi-diehard-minor-mode)
(viper-delocalize-var 'viper-vi-basic-minor-mode)
(viper-delocalize-var 'viper-replace-minor-mode)
(viper-delocalize-var 'viper-insert-local-user-minor-mode)
(viper-delocalize-var 'viper-insert-kbd-minor-mode)
(viper-delocalize-var 'viper-insert-global-user-minor-mode)
(viper-delocalize-var 'viper-insert-state-modifier-minor-mode)
(viper-delocalize-var 'viper-insert-diehard-minor-mode)
(viper-delocalize-var 'viper-insert-basic-minor-mode)
(viper-delocalize-var 'viper-emacs-intercept-minor-mode)
(viper-delocalize-var 'viper-emacs-local-user-minor-mode)
(viper-delocalize-var 'viper-emacs-kbd-minor-mode)
(viper-delocalize-var 'viper-emacs-global-user-minor-mode)
(viper-delocalize-var 'viper-emacs-state-modifier-minor-mode)
(viper-delocalize-var 'viper-current-state)
(viper-delocalize-var 'viper-mode-string)
(setq-default viper-vi-minibuffer-minor-mode nil
viper-insert-minibuffer-minor-mode nil
viper-vi-intercept-minor-mode nil
viper-insert-intercept-minor-mode nil
viper-vi-local-user-minor-mode nil
viper-vi-kbd-minor-mode nil
viper-vi-global-user-minor-mode nil
viper-vi-state-modifier-minor-mode nil
viper-vi-diehard-minor-mode nil
viper-vi-basic-minor-mode nil
viper-replace-minor-mode nil
viper-insert-local-user-minor-mode nil
viper-insert-kbd-minor-mode nil
viper-insert-global-user-minor-mode nil
viper-insert-state-modifier-minor-mode nil
viper-insert-diehard-minor-mode nil
viper-insert-basic-minor-mode nil
viper-emacs-intercept-minor-mode nil
viper-emacs-local-user-minor-mode nil
viper-emacs-kbd-minor-mode nil
viper-emacs-global-user-minor-mode nil
viper-emacs-state-modifier-minor-mode nil
viper-current-state 'emacs-state
viper-mode-string viper-emacs-state-id
)
(mapatoms 'viper-remove-hooks)
(remove-hook 'comint-mode-hook 'viper-comint-mode-hook)
(remove-hook 'erc-mode-hook 'viper-comint-mode-hook)
(remove-hook 'minibuffer-setup-hook 'viper-minibuffer-setup-sentinel)
(remove-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
(remove-hook 'post-command-hook 'viper-minibuffer-post-command-hook)
(viper-unbind-mouse-search-key)
(viper-unbind-mouse-insert-key)
(if viper-xemacs-p
(remove-hook 'mouse-leave-frame-hook 'viper-remember-current-frame))
)
(defvar viper-new-major-mode-buffer-list nil)
(defun set-viper-state-in-major-mode ()
(mapcar
(lambda (buf)
(if (viper-buffer-live-p buf)
(with-current-buffer buf
(cond ((and (this-major-mode-requires-vi-state major-mode)
(eq viper-current-state 'emacs-state))
(viper-mode))
((memq major-mode viper-emacs-state-mode-list)
(viper-change-state-to-emacs))
((and (memq major-mode viper-insert-state-mode-list)
(not (eq viper-current-state 'insert-state)))
(viper-change-state-to-insert))
)) )) viper-new-major-mode-buffer-list)
(setq viper-new-major-mode-buffer-list nil)
(remove-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode))
(defun viper-major-mode-change-sentinel ()
(save-match-data
(or (string-match "\*Minibuf-" (buffer-name))
(setq viper-new-major-mode-buffer-list
(cons (current-buffer) viper-new-major-mode-buffer-list))))
(add-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode t))
(defun viper-set-hooks ()
(if (eq default-major-mode 'fundamental-mode)
(setq default-major-mode 'viper-mode))
(add-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
(add-hook 'find-file-hooks 'set-viper-state-in-major-mode)
(defvar text-mode-hook)
(add-hook 'text-mode-hook 'viper-mode)
(defvar emerge-startup-hook)
(add-hook 'emerge-startup-hook 'viper-change-state-to-emacs)
(defvar flyspell-mode-hook)
(add-hook 'flyspell-mode-hook
'(lambda ()
(define-key flyspell-mouse-map viper-ESC-key nil)))
(add-hook 'window-setup-hook
'(lambda ()
(modify-frame-parameters
(selected-frame)
(list (cons 'viper-vi-state-cursor-color
(viper-get-cursor-color))))))
(if (featurep 'vc)
(defadvice vc-diff (after viper-vc-ad activate)
"Force Vi state in VC diff buffer."
(viper-change-state-to-vi))
(eval-after-load
"vc"
'(defadvice vc-diff (after viper-vc-ad activate)
"Force Vi state in VC diff buffer."
(viper-change-state-to-vi))))
(eval-after-load
"emerge"
'(defadvice emerge-quit (after viper-emerge-advice activate)
"Run `viper-change-state-to-vi' after quitting emerge."
(viper-change-state-to-vi)))
(defadvice emerge-quit (after viper-emerge-advice activate)
"Run `viper-change-state-to-vi' after quitting emerge."
(viper-change-state-to-vi))
(eval-after-load
"passwd"
'(defadvice read-passwd-1 (before viper-passwd-ad activate)
"Switch to Emacs state while reading password."
(viper-change-state-to-emacs)))
(defadvice self-insert-command (around viper-self-insert-ad activate)
"Ignore all self-inserting keys in the vi-state."
(if (and (eq viper-current-state 'vi-state) (interactive-p))
(beep 1)
ad-do-it
))
(defadvice set-cursor-color (after viper-set-cursor-color-ad activate)
"Change cursor color in VI state."
(modify-frame-parameters
(selected-frame)
(list (cons 'viper-vi-state-cursor-color (ad-get-arg 0))))
)
(when (and (fboundp 'add-to-ordered-list) (boundp 'emulation-mode-map-alists))
(add-to-ordered-list
'emulation-mode-map-alists 'viper--intercept-key-maps 100)
(add-to-ordered-list 'emulation-mode-map-alists 'viper--key-maps 500)
)
(add-hook 'comint-mode-hook 'viper-comint-mode-hook) (add-hook 'erc-mode-hook 'viper-comint-mode-hook)
(add-hook 'eshell-mode-hook
(lambda () (setq viper-auto-indent nil)))
(viper-set-emacs-state-searchstyle-macros nil 'dired-mode) (viper-set-emacs-state-searchstyle-macros nil 'tar-mode) (viper-set-emacs-state-searchstyle-macros nil 'mh-folder-mode) (viper-set-emacs-state-searchstyle-macros nil 'gnus-group-mode) (viper-set-emacs-state-searchstyle-macros nil 'gnus-summary-mode)
(viper-set-emacs-state-searchstyle-macros nil 'Info-mode) (viper-set-emacs-state-searchstyle-macros nil 'Buffer-menu-mode)
(viper-apply-major-mode-modifiers)
(eval-after-load
"rmailedit"
'(defadvice rmail-cease-edit (after viper-rmail-advice activate)
"Switch to Emacs state when done editing message."
(viper-change-state-to-emacs)))
(defadvice rmail-cease-edit (after viper-rmail-advice activate)
"Switch to emacs state when done editing message."
(viper-change-state-to-emacs))
(eval-after-load
"iso-acc"
'(defadvice iso-accents-mode (around viper-iso-accents-advice activate)
"Set viper-automatic-iso-accents to iso-accents-mode."
(let ((arg (ad-get-arg 0)))
ad-do-it
(setq viper-automatic-iso-accents
(if (eq viper-current-state 'vi-state)
(if arg
(> (prefix-numeric-value arg) 0)
(not viper-automatic-iso-accents))
iso-accents-mode))
(if (eq viper-current-state 'vi-state)
(viper-set-iso-accents-mode nil))
(if (memq viper-current-state '(vi-state insert-state replace-state))
(message "Viper ISO accents mode: %s"
(if viper-automatic-iso-accents "on" "off")))
)))
(if viper-emacs-p
(eval-after-load "mule-cmds"
'(progn
(defadvice inactivate-input-method (after viper-mule-advice activate)
"Set viper-special-input-method to disable intl. input methods."
(viper-inactivate-input-method-action))
(defadvice activate-input-method (after viper-mule-advice activate)
"Set viper-special-input-method to enable intl. input methods."
(viper-activate-input-method-action))
))
(eval-after-load "mule-cmds"
'(progn
(add-hook 'input-method-activate-hook
'viper-activate-input-method-action t)
(add-hook 'input-method-inactivate-hook
'viper-inactivate-input-method-action t)))
)
(eval-after-load "mule-cmds"
'(defadvice toggle-input-method (around viper-mule-advice activate)
"Adjust input-method toggling in vi-state."
(if (and viper-special-input-method (eq viper-current-state 'vi-state))
(viper-inactivate-input-method)
ad-do-it)))
)
(defun viper-non-hook-settings ()
(setq next-line-add-newlines nil
require-final-newline t)
(if viper-emacs-p
(setq mark-even-if-inactive t))
(setq scroll-step 1)
(or (memq 'viper-mode-string global-mode-string)
(setq global-mode-string
(append '("" viper-mode-string) (cdr global-mode-string))))
(defadvice describe-key (before viper-describe-key-ad protect activate)
"Force to read key via `viper-read-key-sequence'."
(interactive (let (key)
(setq key (viper-read-key-sequence
"Describe key (or click or menu item): "))
(list key
(prefix-numeric-value current-prefix-arg)
(and (vectorp key)
(let ((last-idx (1- (length key))))
(and (eventp (aref key last-idx))
(memq 'down (event-modifiers
(aref key last-idx)))))
(or (and (eventp (aref key 0))
(memq 'down (event-modifiers
(aref key 0)))
(= (length key) 1))
(and (> (length key) 1)
(eventp (aref key 1))
(memq 'down (event-modifiers (aref key 1)))))
(read-event))))))
(defadvice describe-key-briefly
(before viper-describe-key-briefly-ad protect activate)
"Force to read key via `viper-read-key-sequence'."
(interactive (let (key)
(setq key (viper-read-key-sequence
"Describe key (or click or menu item): "))
(and (vectorp key)
(let ((last-idx (1- (length key))))
(and (eventp (aref key last-idx))
(memq 'down (event-modifiers (aref key last-idx)))))
(read-event))
(list key
(if current-prefix-arg
(prefix-numeric-value current-prefix-arg))
1))))
(defadvice find-file (before viper-add-suffix-advice activate)
"Use `read-file-name' for reading arguments."
(interactive (cons (read-file-name "Find file: " nil default-directory)
(cond ((and viper-xemacs-p (featurep 'mule))
(list
(and current-prefix-arg
(read-coding-system "Coding-system: "))))
((and viper-emacs-p (boundp 'find-file-wildcards))
(list find-file-wildcards))))
))
(defadvice find-file-other-window (before viper-add-suffix-advice activate)
"Use `read-file-name' for reading arguments."
(interactive (cons (read-file-name "Find file in other window: "
nil default-directory)
(cond ((and viper-xemacs-p (featurep 'mule))
(list
(and current-prefix-arg
(read-coding-system "Coding-system: "))))
((and viper-emacs-p (boundp 'find-file-wildcards))
(list find-file-wildcards))))
))
(defadvice find-file-other-frame (before viper-add-suffix-advice activate)
"Use `read-file-name' for reading arguments."
(interactive (cons (read-file-name "Find file in other frame: "
nil default-directory)
(cond ((and viper-xemacs-p (featurep 'mule))
(list
(and current-prefix-arg
(read-coding-system "Coding-system: "))))
((and viper-emacs-p (boundp 'find-file-wildcards))
(list find-file-wildcards))))
))
(defadvice read-file-name (around viper-suffix-advice activate)
"Tell `exit-minibuffer' to run `viper-file-add-suffix' as a hook."
(let ((viper-minibuffer-exit-hook
(append viper-minibuffer-exit-hook
'(viper-minibuffer-trim-tail viper-file-add-suffix))))
ad-do-it))
(defadvice start-kbd-macro (after viper-kbd-advice activate)
"Remove Viper's intercepting bindings for C-x ).
This may be needed if the previous `:map' command terminated abnormally."
(define-key viper-vi-intercept-map "\C-x)" nil)
(define-key viper-insert-intercept-map "\C-x)" nil)
(define-key viper-emacs-intercept-map "\C-x)" nil))
(defadvice add-minor-mode (after
viper-advice-add-minor-mode
(toggle name &optional keymap after toggle-fun)
activate)
"Run viper-normalize-minor-mode-map-alist after adding a minor mode."
(viper-normalize-minor-mode-map-alist)
(unless
(and (fboundp 'add-to-ordered-list) (boundp 'emulation-mode-map-alists))
(setq-default minor-mode-map-alist minor-mode-map-alist)))
(if (viper-window-display-p)
(if viper-xemacs-p
(add-hook 'mouse-leave-frame-hook
'viper-remember-current-frame)
(defadvice handle-switch-frame (before viper-frame-advice activate)
"Remember the selected frame before the switch-frame event."
(viper-remember-current-frame (selected-frame)))) )
)
(cond ((and (eq viper-mode 'ask) (null this-command) (null last-command))
(save-window-excursion
(with-output-to-temp-buffer " *viper-info*"
(princ "
You have loaded Viper, and are about to Viperize your Emacs!
Viper is a Package for Emacs Rebels and a venomous VI PERil,
It's time to decide: to Viperize or not to Viperize...
If you wish to Viperize AND make this your way of life, please put
(setq viper-mode t)
(require 'viper)
in your .emacs file (preferably, close to the top).
These two lines must come in the order given.
** Viper users:
**** The startup file name has been changed from .vip to .viper
**** All vip-* style names have been converted to viper-* style."))
(if (y-or-n-p "Viperize? ")
(setq viper-mode t)
(setq viper-mode nil))
(message "")
(kill-buffer " *viper-info*")))
((eq viper-mode t))
(t (setq viper-mode nil)))
(defun viper-load-custom-file ()
(if (and (file-exists-p viper-custom-file-name)
(not noninteractive))
(load viper-custom-file-name)))
(if (null viper-saved-non-viper-variables)
(setq viper-saved-non-viper-variables
(list
(cons 'next-line-add-newlines (list next-line-add-newlines))
(cons 'require-final-newline (list require-final-newline))
(cons 'scroll-step (list scroll-step))
(cons 'mode-line-buffer-identification
(list (default-value 'mode-line-buffer-identification)))
(cons 'global-mode-string (list global-mode-string))
(if viper-emacs-p
(cons 'mark-even-if-inactive (list mark-even-if-inactive)))
)))
(if viper-mode
(progn
(viper-non-hook-settings)
(viper-record-kbd-macro
(vector viper-repeat-from-history-key '\1) 'vi-state
[(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)
(viper-record-kbd-macro
(vector viper-repeat-from-history-key '\2) 'vi-state
[(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)
(viper-set-searchstyle-toggling-macros nil)
(viper-set-parsing-style-toggling-macro nil)
(viper-load-custom-file)
(viper-bind-mouse-search-key)
(viper-bind-mouse-insert-key)
))
(if (null viper-saved-user-settings)
(setq viper-saved-user-settings
(list (cons 'viper-want-ctl-h-help (list viper-want-ctl-h-help))
(cons 'viper-always (list viper-always))
(cons 'viper-no-multiple-ESC (list viper-no-multiple-ESC))
(cons 'viper-ex-style-motion (list viper-ex-style-motion))
(cons 'viper-ex-style-editing
(list viper-ex-style-editing))
(cons 'viper-want-emacs-keys-in-vi
(list viper-want-emacs-keys-in-vi))
(cons 'viper-electric-mode (list viper-electric-mode))
(cons 'viper-want-emacs-keys-in-insert
(list viper-want-emacs-keys-in-insert))
(cons 'viper-re-search (list viper-re-search)))))
(if viper-mode
(progn
(viper-set-minibuffer-style)
(if viper-buffer-search-char
(viper-buffer-search-enable))
(viper-update-syntax-classes 'set-default)
))
(if viper-mode
(progn
(viper-harness-minor-mode "compile")
(viper-harness-minor-mode "outline")
(viper-harness-minor-mode "allout")
(viper-harness-minor-mode "xref")
(viper-harness-minor-mode "lmenu")
(viper-harness-minor-mode "vc")
(viper-harness-minor-mode "ltx-math") (viper-harness-minor-mode "latex") (viper-harness-minor-mode "cyrillic")
(viper-harness-minor-mode "russian")
(viper-harness-minor-mode "view-less")
(viper-harness-minor-mode "view")
(viper-harness-minor-mode "reftex")
(viper-harness-minor-mode "flyspell")
))
(define-key viper-vi-intercept-map viper-ESC-key 'viper-intercept-ESC-key)
(define-key viper-insert-intercept-map viper-ESC-key 'viper-intercept-ESC-key)
(define-key viper-vi-intercept-map viper-toggle-key 'viper-toggle-key-action)
(define-key
viper-emacs-intercept-map viper-toggle-key 'viper-change-state-to-vi)
(if viper-mode
(setq-default viper-emacs-intercept-minor-mode t
viper-emacs-local-user-minor-mode t
viper-emacs-global-user-minor-mode t
viper-emacs-kbd-minor-mode t
viper-emacs-state-modifier-minor-mode t))
(if (and viper-mode (eq viper-current-state 'emacs-state))
(setq viper-emacs-intercept-minor-mode t
viper-emacs-local-user-minor-mode t
viper-emacs-global-user-minor-mode t
viper-emacs-kbd-minor-mode t
viper-emacs-state-modifier-minor-mode t))
(if (and viper-mode
(or viper-always
(and (< viper-expert-level 5) (> viper-expert-level 0))))
(viper-set-hooks))
(if (and viper-mode (eq viper-current-state 'emacs-state))
(progn
(viper-change-state-to-emacs)
(unless
(and (fboundp 'add-to-ordered-list)
(boundp 'emulation-mode-map-alists))
(setq-default minor-mode-map-alist minor-mode-map-alist))
))
(if (and viper-mode (this-major-mode-requires-vi-state major-mode))
(viper-mode))
(if viper-mode
(setq initial-major-mode
`(lambda ()
(funcall (quote ,initial-major-mode))
(set-viper-state-in-major-mode))
))
(run-hooks 'viper-load-hook)
(provide 'viper)