summaryrefslogtreecommitdiff
path: root/lisp/emulation
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emulation')
-rw-r--r--lisp/emulation/viper-cmd.el171
-rw-r--r--lisp/emulation/viper-ex.el4
-rw-r--r--lisp/emulation/viper-init.el11
-rw-r--r--lisp/emulation/viper-macs.el2
-rw-r--r--lisp/emulation/viper.el471
5 files changed, 300 insertions, 359 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el
index a65931deb58..86364282dcf 100644
--- a/lisp/emulation/viper-cmd.el
+++ b/lisp/emulation/viper-cmd.el
@@ -1,4 +1,4 @@
-;;; viper-cmd.el --- Vi command support for Viper
+;;; viper-cmd.el --- Vi command support for Viper -*- lexical-binding:t -*-
;; Copyright (C) 1997-2017 Free Software Foundation, Inc.
@@ -40,13 +40,13 @@
(defvar quail-mode)
(defvar quail-current-str)
(defvar mark-even-if-inactive)
-(defvar init-message)
+(defvar viper--init-message)
(defvar viper-initial)
(defvar undo-beg-posn)
(defvar undo-end-posn)
(eval-and-compile
- (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
+ (unless (fboundp 'declare-function) (defmacro declare-function (&rest _))))
;; end pacifier
@@ -608,7 +608,7 @@
;; This also takes care of the annoying incomplete lines in files.
;; Also, this fixes `undo' to work vi-style for complex commands.
-(defun viper-change-state-to-vi ()
+(defun viper-change-state-to-vi (&rest _)
"Change Viper state to Vi."
(interactive)
(if (and viper-first-time (not (viper-is-in-minibuffer)))
@@ -694,7 +694,7 @@
)
-(defun viper-change-state-to-emacs ()
+(defun viper-change-state-to-emacs (&rest _)
"Change Viper state to Emacs."
(interactive)
(or (viper-overlay-p viper-replace-overlay)
@@ -1294,7 +1294,7 @@ as a Meta key and any number of multiple escapes are allowed."
;; define functions to be executed
;; invoked by the `C' command
-(defun viper-exec-change (m-com com)
+(defun viper-exec-change (m-com _com)
(or (and (markerp viper-com-point) (marker-position viper-com-point))
(set-marker viper-com-point (point) (current-buffer)))
;; handle C cmd at the eol and at eob.
@@ -1316,7 +1316,7 @@ as a Meta key and any number of multiple escapes are allowed."
(viper-change (mark t) (point))))
;; this is invoked by viper-substitute-line
-(defun viper-exec-Change (m-com com)
+(defun viper-exec-Change (_m-com _com)
(save-excursion
(set-mark viper-com-point)
(viper-enlarge-region (mark t) (point))
@@ -1338,7 +1338,7 @@ as a Meta key and any number of multiple escapes are allowed."
(viper-change-state-to-insert)
))
-(defun viper-exec-delete (m-com com)
+(defun viper-exec-delete (_m-com _com)
(or (and (markerp viper-com-point) (marker-position viper-com-point))
(set-marker viper-com-point (point) (current-buffer)))
(let (chars-deleted)
@@ -1364,7 +1364,7 @@ as a Meta key and any number of multiple escapes are allowed."
(if viper-ex-style-motion
(if (and (eolp) (not (bolp))) (backward-char 1)))))
-(defun viper-exec-Delete (m-com com)
+(defun viper-exec-Delete (m-com _com)
(save-excursion
(set-mark viper-com-point)
(viper-enlarge-region (mark t) (point))
@@ -1391,7 +1391,7 @@ as a Meta key and any number of multiple escapes are allowed."
(back-to-indentation)))
;; save region
-(defun viper-exec-yank (m-com com)
+(defun viper-exec-yank (_m-com _com)
(or (and (markerp viper-com-point) (marker-position viper-com-point))
(set-marker viper-com-point (point) (current-buffer)))
(let (chars-saved)
@@ -1415,7 +1415,7 @@ as a Meta key and any number of multiple escapes are allowed."
(goto-char viper-com-point)))
;; save lines
-(defun viper-exec-Yank (m-com com)
+(defun viper-exec-Yank (_m-com _com)
(save-excursion
(set-mark viper-com-point)
(viper-enlarge-region (mark t) (point))
@@ -1440,7 +1440,7 @@ as a Meta key and any number of multiple escapes are allowed."
(viper-deactivate-mark)
(goto-char viper-com-point))
-(defun viper-exec-bang (m-com com)
+(defun viper-exec-bang (_m-com com)
(save-excursion
(set-mark viper-com-point)
(viper-enlarge-region (mark t) (point))
@@ -1458,14 +1458,14 @@ as a Meta key and any number of multiple escapes are allowed."
viper-last-shell-com)
t t)))
-(defun viper-exec-equals (m-com com)
+(defun viper-exec-equals (_m-com _com)
(save-excursion
(set-mark viper-com-point)
(viper-enlarge-region (mark t) (point))
(if (> (mark t) (point)) (exchange-point-and-mark))
(indent-region (mark t) (point) nil)))
-(defun viper-exec-shift (m-com com)
+(defun viper-exec-shift (_m-com com)
(save-excursion
(set-mark viper-com-point)
(viper-enlarge-region (mark t) (point))
@@ -1479,10 +1479,10 @@ as a Meta key and any number of multiple escapes are allowed."
;; this is needed because some commands fake com by setting it to ?r, which
;; denotes repeated insert command.
-(defsubst viper-exec-dummy (m-com com)
+(defsubst viper-exec-dummy (_m-com _com)
nil)
-(defun viper-exec-buffer-search (m-com com)
+(defun viper-exec-buffer-search (_m-com _com)
(setq viper-s-string
(regexp-quote (buffer-substring (point) viper-com-point)))
(setq viper-s-forward t)
@@ -1648,7 +1648,7 @@ invokes the command before that, etc."
(add-hook 'after-change-functions 'viper-undo-sentinel)
;; Hook used in viper-undo
-(defun viper-after-change-undo-hook (beg end len)
+(defun viper-after-change-undo-hook (beg end _len)
(if (and (boundp 'undo-in-progress) undo-in-progress)
(setq undo-beg-posn beg
undo-end-posn (or end beg))
@@ -1662,8 +1662,7 @@ invokes the command before that, etc."
"Undo previous change."
(interactive)
(message "undo!")
- (let ((modified (buffer-modified-p))
- (before-undo-pt (point-marker))
+ (let ((before-undo-pt (point-marker))
undo-beg-posn undo-end-posn)
;; the viper-after-change-undo-hook removes itself after the 1st invocation
@@ -1710,40 +1709,20 @@ invokes the command before that, etc."
;; The following two functions are used to set up undo properly.
;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
;; they are undone all at once.
-(defun viper-adjust-undo ()
- (if viper-undo-needs-adjustment
- (let ((inhibit-quit t)
- tmp tmp2)
- (setq viper-undo-needs-adjustment nil)
- (when (listp buffer-undo-list)
- (let ((had-boundary (null (car buffer-undo-list))))
- (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list))
- (progn
- (setq tmp2 (cdr tmp)) ; the part after mark
-
- ;; cut tail from buffer-undo-list temporarily by direct
- ;; manipulation with pointers in buffer-undo-list
- (setcdr tmp nil)
-
- (setq buffer-undo-list (delq nil buffer-undo-list))
- (setq buffer-undo-list
- (delq viper-buffer-undo-list-mark buffer-undo-list))
- ;; restore tail of buffer-undo-list
- (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
- (setq buffer-undo-list (delq nil buffer-undo-list)))
- ;; The top-level loop only adds boundaries if there has been
- ;; modifications in the buffer, so make sure we don't accidentally
- ;; drop the "final" boundary (bug#22295).
- (if had-boundary (undo-boundary)))))))
+(viper-deflocalvar viper--undo-change-group-handle nil)
+(put 'viper--undo-change-group-handle 'permanent-local t)
+(defun viper-adjust-undo ()
+ (when viper--undo-change-group-handle
+ (undo-amalgamate-change-group
+ (prog1 viper--undo-change-group-handle
+ (setq viper--undo-change-group-handle nil)))))
(defun viper-set-complex-command-for-undo ()
- (if (listp buffer-undo-list)
- (if (not viper-undo-needs-adjustment)
- (let ((inhibit-quit t))
- (setq buffer-undo-list
- (cons viper-buffer-undo-list-mark buffer-undo-list))
- (setq viper-undo-needs-adjustment t)))))
+ (and (listp buffer-undo-list)
+ (not viper--undo-change-group-handle)
+ (setq viper--undo-change-group-handle
+ (prepare-change-group))))
;;; Viper's destructive Command ring utilities
@@ -1907,6 +1886,7 @@ Undo previous insertion and inserts new."
"Quote string: "
nil
'viper-quote-region-history
+ ;; FIXME: Use comment-region.
(cond ((string-match "tex.*-mode" (symbol-name major-mode)) "%%")
((string-match "java.*-mode" (symbol-name major-mode)) "//")
((string-match "perl.*-mode" (symbol-name major-mode)) "#")
@@ -1988,13 +1968,13 @@ Undo previous insertion and inserts new."
(funcall hook)
))
-;; This is a temp hook that uses free variables init-message and viper-initial.
+;; This is a temp hook that uses free variables viper--init-message and viper-initial.
;; A dirty feature, but it is the simplest way to have it do the right thing.
-;; The INIT-MESSAGE and VIPER-INITIAL vars come from the scope set by
+;; The VIPER--INIT-MESSAGE and VIPER-INITIAL vars come from the scope set by
;; viper-read-string-with-history
(defun viper-minibuffer-standard-hook ()
- (if (stringp init-message)
- (viper-tmp-insert-at-eob init-message))
+ (if (stringp viper--init-message)
+ (viper-tmp-insert-at-eob viper--init-message))
(when (stringp viper-initial)
;; don't wait if we have unread events or in kbd macro
(or unread-command-events
@@ -2058,7 +2038,7 @@ To turn this feature off, set this variable to nil."
(viper-minibuffer-real-start) (point-max)))
found key cmd suff)
(goto-char (point-max))
- (if (and viper-smart-suffix-list (string-match "\\.$" file))
+ (if (and viper-smart-suffix-list (string-match "\\.\\'" file))
(progn
(while (and (not found) (< count len))
(setq suff (nth count viper-smart-suffix-list)
@@ -2102,10 +2082,10 @@ problems."
;;; Reading string with history
-(defun viper-read-string-with-history (prompt &optional viper-initial
+(defun viper-read-string-with-history (prompt &optional initial
history-var default keymap
init-message)
- ;; Read string, prompting with PROMPT and inserting the VIPER-INITIAL
+ ;; Read string, prompting with PROMPT and inserting the INITIAL
;; value. Uses HISTORY-VAR. DEFAULT is the default value to accept if the
;; input is an empty string.
;; Default value is displayed until the user types something in the
@@ -2113,14 +2093,16 @@ problems."
;; KEYMAP is used, if given, instead of minibuffer-local-map.
;; INIT-MESSAGE is the message temporarily displayed after entering the
;; minibuffer.
- (let ((minibuffer-setup-hook
+ (let ((viper-initial initial)
+ (viper--init-message init-message)
+ (minibuffer-setup-hook
;; stolen from add-hook
(let ((old
(if (boundp 'minibuffer-setup-hook)
minibuffer-setup-hook
nil)))
(cons
- 'viper-minibuffer-standard-hook
+ #'viper-minibuffer-standard-hook
(if (or (not (listp old)) (eq (car old) 'lambda))
(list old) old))))
(val "")
@@ -2128,14 +2110,15 @@ problems."
temp-msg)
(setq keymap (or keymap minibuffer-local-map)
- viper-initial (or viper-initial "")
+ initial (or initial "")
+ viper-initial initial
temp-msg (if default
(format "(default %s) " default)
""))
(setq viper-incomplete-ex-cmd nil)
(setq val (read-from-minibuffer prompt
- (concat temp-msg viper-initial val padding)
+ (concat temp-msg initial val padding)
keymap nil history-var))
(setq minibuffer-setup-hook nil
padding (viper-array-to-string (this-command-keys))
@@ -2836,7 +2819,7 @@ On reaching beginning of line, stop and signal error."
(viper-looking-at-alphasep))))))
-(defun viper-end-of-word (arg &optional careful)
+(defun viper-end-of-word (arg &optional _careful)
"Move point to end of current word."
(interactive "P")
(viper-leave-region-active)
@@ -3672,17 +3655,14 @@ the Emacs binding of `/'."
(setq msg "Search style remains unchanged")))
(princ msg t)))
-(defun viper-set-searchstyle-toggling-macros (unset &optional major-mode)
+(defun viper-set-searchstyle-toggling-macros (unset &optional mode)
"Set the macros for toggling the search style in Viper's vi-state.
The macro that toggles case sensitivity is bound to `//', and the one that
toggles regexp search is bound to `///'.
With a prefix argument, this function unsets the macros.
-If MAJOR-MODE is set, set the macros only in that major mode."
+If MODE is set, set the macros only in that major mode."
(interactive "P")
- (let (scope)
- (if (and major-mode (symbolp major-mode))
- (setq scope major-mode)
- (setq scope 't))
+ (let ((scope (if (and mode (symbolp mode)) mode t)))
(or noninteractive
(if (not unset)
(progn
@@ -4875,33 +4855,36 @@ Please, specify your level now: "))
;;; Bug Report
+(defvar reporter-prompt-for-summary-p)
+
(defun viper-submit-report ()
"Submit bug report on Viper."
(interactive)
+ (defvar viper-device-type)
+ (defvar viper-color-display-p)
+ (defvar viper-frame-parameters)
+ (defvar viper-minibuffer-emacs-face)
+ (defvar viper-minibuffer-vi-face)
+ (defvar viper-minibuffer-insert-face)
(let ((reporter-prompt-for-summary-p t)
(viper-device-type (viper-device-type))
- color-display-p frame-parameters
- minibuffer-emacs-face minibuffer-vi-face minibuffer-insert-face
- varlist salutation window-config)
-
- ;; If mode info is needed, add variable to `let' and then set it below,
- ;; like we did with color-display-p.
- (setq color-display-p (if (viper-window-display-p)
+ (viper-color-display-p (if (viper-window-display-p)
(viper-color-display-p)
- 'non-x)
- minibuffer-vi-face (if (viper-has-face-support-p)
- (viper-get-face viper-minibuffer-vi-face)
- 'non-x)
- minibuffer-insert-face (if (viper-has-face-support-p)
- (viper-get-face
- viper-minibuffer-insert-face)
- 'non-x)
- minibuffer-emacs-face (if (viper-has-face-support-p)
- (viper-get-face
- viper-minibuffer-emacs-face)
- 'non-x)
- frame-parameters (if (fboundp 'frame-parameters)
- (frame-parameters (selected-frame))))
+ 'non-x))
+ (viper-frame-parameters (if (fboundp 'frame-parameters)
+ (frame-parameters (selected-frame))))
+ (viper-minibuffer-emacs-face (if (viper-has-face-support-p)
+ (viper-get-face
+ viper-minibuffer-emacs-face)
+ 'non-x))
+ (viper-minibuffer-vi-face (if (viper-has-face-support-p)
+ (viper-get-face viper-minibuffer-vi-face)
+ 'non-x))
+ (viper-minibuffer-insert-face (if (viper-has-face-support-p)
+ (viper-get-face
+ viper-minibuffer-insert-face)
+ 'non-x))
+ varlist salutation window-config)
(setq varlist (list 'viper-vi-minibuffer-minor-mode
'viper-insert-minibuffer-minor-mode
@@ -4946,11 +4929,11 @@ Please, specify your level now: "))
'viper-expert-level
'major-mode
'viper-device-type
- 'color-display-p
- 'frame-parameters
- 'minibuffer-vi-face
- 'minibuffer-insert-face
- 'minibuffer-emacs-face
+ 'viper-color-display-p
+ 'viper-frame-parameters
+ 'viper-minibuffer-vi-face
+ 'viper-minibuffer-insert-face
+ 'viper-minibuffer-emacs-face
))
(setq salutation "
Congratulations! You may have unearthed a bug in Viper!
diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el
index 84bff257af9..edc71ea859b 100644
--- a/lisp/emulation/viper-ex.el
+++ b/lisp/emulation/viper-ex.el
@@ -1250,7 +1250,7 @@ reversed."
(kill-region (point) (mark t))))))
-(declare-function viper-change-state-to-vi "viper-cmd" ())
+(declare-function viper-change-state-to-vi "viper-cmd" (&rest _))
;; Ex edit command
;; In Viper, `e' and `e!' behave identically. In both cases, the user is
@@ -1998,7 +1998,7 @@ Please contact your system administrator. "
(beginning-of-line)
(if opt-c (message "done"))))
-(declare-function viper-change-state-to-emacs "viper-cmd" ())
+(declare-function viper-change-state-to-emacs "viper-cmd" (&rest _))
;; Ex tag command
(defun ex-tag ()
diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el
index fae00023151..0d478011238 100644
--- a/lisp/emulation/viper-init.el
+++ b/lisp/emulation/viper-init.el
@@ -369,15 +369,6 @@ Use `\\[viper-set-expert-level]' to change this.")
;; VI-style Undo
-;; Used to 'undo' complex commands, such as replace and insert commands.
-(viper-deflocalvar viper-undo-needs-adjustment nil)
-(put 'viper-undo-needs-adjustment 'permanent-local t)
-
-;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a
-;; complex command that must be undone atomically. If inserted, it is
-;; erased by viper-change-state-to-vi and viper-repeat.
-(defconst viper-buffer-undo-list-mark 'viper)
-
(defcustom viper-keep-point-on-undo nil
"Non-nil means not to move point while undoing commands.
This style is different from Emacs and Vi. Try it to see if
@@ -786,7 +777,7 @@ Related buffers can be cycled through via :R and :P commands."
"^@end \\|" ; texinfo
")\n\n[ \t\n]*\\|" ; lisp
"\\.\\s-*$") ; prolog
- "*Regexps to end Headings/Sections. Used by [].")
+ "Regexps to end Headings/Sections. Used by [].")
;; These two vars control the interaction of jumps performed by ' and `.
diff --git a/lisp/emulation/viper-macs.el b/lisp/emulation/viper-macs.el
index 6f731e22037..1353f7e1772 100644
--- a/lisp/emulation/viper-macs.el
+++ b/lisp/emulation/viper-macs.el
@@ -274,7 +274,7 @@ a key is a symbol, e.g., `a', `\\1', `f2', etc., or a list, e.g.,
))
-(declare-function viper-change-state-to-vi "viper-cmd" ())
+(declare-function viper-change-state-to-vi "viper-cmd" (&rest _))
;; Terminate a Vi kbd macro.
;; optional argument IGNORE, if t, indicates that we are dealing with an
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index d45b2df74bd..b03af9b0839 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -1,4 +1,4 @@
-;;; viper.el --- A full-featured Vi emulator for Emacs and XEmacs,
+;;; viper.el --- A full-featured Vi emulator for Emacs and XEmacs, -*-lexical-binding:t -*-
;; a VI Plan for Emacs Rescue,
;; and a venomous VI PERil.
;; Viper Is also a Package for Emacs Rebels.
@@ -126,9 +126,9 @@
;; As an immediate solution, you can hit C-z to bring about the right mode.
;; An interim solution is to add an appropriate hook to the mode like this:
;;
-;; (add-hook 'your-favorite-mode 'viper-mode)
+;; (add-hook 'your-favorite-mode #'viper-mode)
;; or
-;; (add-hook 'your-favorite-mode 'viper-change-state-to-emacs)
+;; (add-hook 'your-favorite-mode #'viper-change-state-to-emacs)
;;
;; whichever applies. The right thing to do, however, is to complain to the
;; author of the respective package. (Sometimes they also neglect to equip
@@ -308,7 +308,6 @@
(defvar viper-major-mode-modifier-list)
;; end pacifier
-(require 'advice)
(require 'viper-init)
(require 'viper-keym)
@@ -337,8 +336,7 @@ 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)
+ :tag "Always Invoke Viper")
;; Non-viper variables that need to be saved in case the user decides to
;; de-viperize emacs.
@@ -354,8 +352,7 @@ Must be set in your init file 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)
+ :tag "Set Viper Mode on Loading")
(defcustom viper-vi-state-mode-list
'(fundamental-mode
@@ -401,8 +398,7 @@ widget."
mh-show-mode
)
"Major modes that require Vi command state."
- :type '(repeat symbol)
- :group 'viper-misc)
+ :type '(repeat symbol))
(defcustom viper-emacs-state-mode-list
'(Custom-mode
@@ -440,8 +436,7 @@ 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)
+ :type '(repeat symbol))
(defcustom viper-insert-state-mode-list
'(internal-ange-ftp-mode
@@ -452,18 +447,17 @@ unless it is coming up in a wrong Viper state."
eshell-mode
shell-mode)
"A list of major modes that should come up in Vi Insert state."
- :type '(repeat symbol)
- :group 'viper-misc)
+ :type '(repeat symbol))
;; used to set viper-major-mode-modifier-list in defcustom
(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))
+ (mapc (lambda (triple)
+ (viper-modify-major-mode
+ (nth 0 triple) (nth 1 triple) (symbol-value (nth 2 triple))))
+ viper-major-mode-modifier-list))
;; We change standard bindings in some major modes, making them slightly
;; different than in "normal" vi/insert/emacs states
@@ -504,10 +498,7 @@ existing triple."
(const vi-state)
(const insert-state))
symbol))
- :set 'viper-apply-major-mode-modifiers
- :group 'viper-misc)
-
-
+ :set #'viper-apply-major-mode-modifiers)
@@ -632,17 +623,17 @@ This startup message appears whenever you load Viper, unless you type `y' now."
;; remove viper hooks from SYMBOL
(defun viper-remove-hooks (symbol)
(cond ((not (boundp symbol)) nil)
- ((not (listp (eval symbol))) nil)
+ ((not (listp (symbol-value 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)
- (remove-hook symbol 'viper-minibuffer-post-command-hook)
- (remove-hook symbol 'viper-minibuffer-setup-sentinel)
- (remove-hook symbol 'viper-major-mode-change-sentinel)
- (remove-hook symbol 'set-viper-state-in-major-mode)
- (remove-hook symbol 'viper-post-command-sentinel)
+ (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)
+ (remove-hook symbol #'viper-minibuffer-post-command-hook)
+ (remove-hook symbol #'viper-minibuffer-setup-sentinel)
+ (remove-hook symbol #'viper-major-mode-change-sentinel)
+ (remove-hook symbol #'set-viper-state-in-major-mode)
+ (remove-hook symbol #'viper-post-command-sentinel)
)))
;; Remove local value in all existing buffers
@@ -652,6 +643,19 @@ This startup message appears whenever you load Viper, unless you type `y' now."
(with-current-buffer buf
(kill-local-variable symbol))))
+(defvar viper--advice-list nil)
+
+(defun viper--advice-add (function where advice)
+ (advice-add function where advice)
+ (push (cons function advice) viper--advice-list))
+
+(defun viper--deactivate-advice-list ()
+ (mapc (lambda (n)
+ (advice-remove
+ (car n)
+ (cdr n)))
+ viper--advice-list)
+ (setq viper--advice-list nil))
(defun viper-go-away ()
"De-Viperize Emacs.
@@ -679,7 +683,7 @@ It also can't undo some Viper settings."
(delq 'viper-mode-string global-mode-string))
(setq-default major-mode
- (viper-standard-value 'default-major-mode
+ (viper-standard-value 'major-mode
viper-saved-non-viper-variables))
(if (featurep 'emacs)
@@ -697,7 +701,7 @@ It also can't undo some Viper settings."
;; deactivate all advices done by Viper.
- (ad-deactivate-regexp "viper-")
+ (viper--deactivate-advice-list)
(setq viper-mode nil)
@@ -769,10 +773,10 @@ It also can't undo some Viper settings."
)
;; remove all hooks set by viper
- (mapatoms 'viper-remove-hooks)
- (remove-hook 'comint-mode-hook 'viper-comint-mode-hook)
- (remove-hook 'erc-mode-hook 'viper-comint-mode-hook)
- (remove-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
+ (mapatoms #'viper-remove-hooks)
+ (remove-hook 'comint-mode-hook #'viper-comint-mode-hook)
+ (remove-hook 'erc-mode-hook #'viper-comint-mode-hook)
+ (remove-hook 'change-major-mode-hook #'viper-major-mode-change-sentinel)
;; unbind Viper mouse bindings
(viper-unbind-mouse-search-key)
@@ -781,7 +785,7 @@ It also can't undo some Viper settings."
;; This advice is undone earlier, when all advices matching "viper-" are
;; deactivated.
(if (featurep 'xemacs)
- (remove-hook 'mouse-leave-frame-hook 'viper-remember-current-frame))
+ (remove-hook 'mouse-leave-frame-hook #'viper-remember-current-frame))
) ; end viper-go-away
@@ -813,7 +817,7 @@ It also can't undo some Viper settings."
;; clear the list of bufs that changed major mode
(setq viper-new-major-mode-buffer-list nil)
;; change the global value of hook
- (remove-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode))
+ (remove-hook 'viper-post-command-hooks #'set-viper-state-in-major-mode))
;; sets up post-command-hook to turn viper-mode, if the current mode is
;; fundamental
@@ -823,7 +827,7 @@ It also can't undo some Viper settings."
(setq viper-new-major-mode-buffer-list
(cons (current-buffer) viper-new-major-mode-buffer-list))))
;; change the global value of hook
- (add-hook 'viper-post-command-hooks 'set-viper-state-in-major-mode t))
+ (add-hook 'viper-post-command-hooks #'set-viper-state-in-major-mode t))
;;; Handling of tty's ESC event
@@ -869,8 +873,8 @@ Two differences:
(defun viper-setup-ESC-to-escape (enable)
(if enable
- (add-hook 'tty-setup-hook 'viper-catch-tty-ESC)
- (remove-hook 'tty-setup-hook 'viper-catch-tty-ESC))
+ (add-hook 'tty-setup-hook #'viper-catch-tty-ESC)
+ (remove-hook 'tty-setup-hook #'viper-catch-tty-ESC))
(let ((seen ()))
(dolist (frame (frame-list))
(let ((terminal (frame-terminal frame)))
@@ -887,21 +891,21 @@ Two differences:
;; in Fundamental Mode and Vi state.
;; When viper-mode is executed in such a case, it will set the major mode
;; back to fundamental-mode.
- (if (eq (default-value 'major-mode) 'fundamental-mode)
+ (if (eq (default-value 'major-mode) #'fundamental-mode)
;; FIXME: We should use after-change-major-mode-hook instead!
- (setq-default major-mode 'viper-mode))
+ (setq-default major-mode #'viper-mode))
(viper-setup-ESC-to-escape t)
- (add-hook 'change-major-mode-hook 'viper-major-mode-change-sentinel)
- (add-hook 'find-file-hooks 'set-viper-state-in-major-mode)
+ (add-hook 'change-major-mode-hook #'viper-major-mode-change-sentinel)
+ (add-hook 'find-file-hooks #'set-viper-state-in-major-mode)
;; keep this because many modes we don't know about use this hook
(defvar text-mode-hook)
- (add-hook 'text-mode-hook 'viper-mode)
+ (add-hook 'text-mode-hook #'viper-mode)
(defvar emerge-startup-hook)
- (add-hook 'emerge-startup-hook 'viper-change-state-to-emacs)
+ (add-hook 'emerge-startup-hook #'viper-change-state-to-emacs)
;; if viper is started from .emacs, it might be impossible to get certain
;; info about the display and windows until emacs initialization is complete
@@ -916,28 +920,15 @@ Two differences:
))
;; Tell vc-diff to put *vc* in Vi mode
- (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)))
+ (viper--advice-add 'vc-diff :after #'viper-change-state-to-vi)
+ (viper--advice-add 'emerge-quit :after #'viper-change-state-to-vi)
;; passwd.el sets up its own buffer, which turns up in Vi mode,
;; thus overriding the local map. We don't need Vi mode here.
- (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."
+ (viper--advice-add 'read-passwd-1 :before #'viper-change-state-to-emacs)
+
+ (viper--advice-add 'self-insert-command :around
+ (lambda (orig-fun &rest args)
;; FIXME: Use remapping?
(if (and (eq viper-current-state 'vi-state)
;; Do not use called-interactively-p here. XEmacs does not have it
@@ -945,16 +936,16 @@ Two differences:
;; (called-interactively-p 'interactive))
(interactive-p))
(beep 1)
- ad-do-it
- ))
+ (apply orig-fun args))))
- (defadvice set-cursor-color (after viper-set-cursor-color-ad activate)
+ (viper--advice-add 'set-cursor-color :after
+ (lambda (color-name)
"Change cursor color in VI state."
(modify-frame-parameters
- (selected-frame)
- (list (cons 'viper-vi-state-cursor-color (ad-get-arg 0))))
- (setq viper-vi-state-cursor-color (ad-get-arg 0))
- )
+ (selected-frame)
+ (list (cons 'viper-vi-state-cursor-color color-name)))
+ (setq viper-vi-state-cursor-color color-name)))
+
(when (and (fboundp 'add-to-ordered-list) (boundp 'emulation-mode-map-alists))
;; needs to be as early as possible
@@ -965,8 +956,8 @@ Two differences:
)
;; Emacs shell, ange-ftp, and comint-based modes
- (add-hook 'comint-mode-hook 'viper-comint-mode-hook) ; comint
- (add-hook 'erc-mode-hook 'viper-comint-mode-hook) ; ERC
+ (add-hook 'comint-mode-hook #'viper-comint-mode-hook) ; comint
+ (add-hook 'erc-mode-hook #'viper-comint-mode-hook) ; ERC
(add-hook 'eshell-mode-hook
(lambda () (setq viper-auto-indent nil)))
@@ -984,22 +975,14 @@ Two differences:
;; For RMAIL users.
;; Put buf in Emacs state after edit.
- (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)))
-
- ;; ISO accents
- ;; Need to do it after loading iso-acc, or else this loading will wipe out
- ;; the advice.
- (eval-after-load
- "iso-acc"
- '(defadvice iso-accents-mode (around viper-iso-accents-advice activate)
+ (viper--advice-add 'rmail-cease-edit :after #'viper-change-state-to-emacs)
+
+ ;; ISO accents.
+ (viper--advice-add 'iso-accents-mode :after
+ (lambda (arg &rest _)
"Set viper-automatic-iso-accents to iso-accents-mode."
- (let ((arg (ad-get-arg 0)))
- ad-do-it
- (setq viper-automatic-iso-accents
+ (defvar iso-accents-mode)
+ (setq viper-automatic-iso-accents
(if (eq viper-current-state 'vi-state)
(if arg
;; if iso-accents-mode was called with positive arg, turn
@@ -1015,35 +998,31 @@ Two differences:
(if (memq viper-current-state '(vi-state insert-state replace-state))
(message "Viper ISO accents mode: %s"
(if viper-automatic-iso-accents "on" "off")))
- )))
+ ))
;; International input methods
- (if (featurep 'emacs)
- (eval-after-load "mule-cmds"
- '(progn
- (defadvice deactivate-input-method (after viper-mule-advice activate)
- "Set viper-special-input-method to disable intl. input methods."
- (viper-deactivate-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))
- ))
+ (if nil ;; (featurep 'emacs) ;;The hooks should now work!
+ (progn
+ (viper--advice-add 'deactivate-input-method :after
+ #'viper-deactivate-input-method-action)
+ (viper--advice-add 'activate-input-method :after
+ #'viper-activate-input-method-action))
;; XEmacs Although these hooks exist in Emacs, they don't seem to be always
;; called on input-method activation/deactivation, so we the above advise
;; functions instead.
(eval-after-load "mule-cmds"
'(progn
(add-hook 'input-method-activate-hook
- 'viper-activate-input-method-action t)
+ #'viper-activate-input-method-action t)
(add-hook 'input-method-deactivate-hook
- 'viper-deactivate-input-method-action t)))
+ #'viper-deactivate-input-method-action t)))
)
- (eval-after-load "mule-cmds"
- '(defadvice toggle-input-method (around viper-mule-advice activate)
+ (viper--advice-add 'toggle-input-method :around
+ (lambda (orig-fun &rest args)
"Adjust input-method toggling in vi-state."
(if (and viper-special-input-method (eq viper-current-state 'vi-state))
- (viper-deactivate-input-method)
- ad-do-it)))
+ (viper-deactivate-input-method)
+ (apply orig-fun args))))
) ; viper-set-hooks
@@ -1075,11 +1054,11 @@ Two differences:
"Force to read key via `viper-read-key-sequence'."
(interactive (list (viper-read-key-sequence "Describe key: "))))
;; Emacs
- (defadvice describe-key (before viper-describe-key-ad protect activate)
+ (viper--advice-add 'describe-key :before
+ (lambda (&rest _)
"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): "))
+ (interactive (let ((key (viper-read-key-sequence
+ "Describe key (or click or menu item): ")))
(list key
(prefix-numeric-value current-prefix-arg)
;; If KEY is a down-event, read also the
@@ -1098,7 +1077,9 @@ Two differences:
(and (> (length key) 1)
(eventp (aref key 1))
(memq 'down (event-modifiers (aref key 1)))))
- (read-event))))))
+ (read-event)))))
+ nil))
+
) ; (if (featurep 'xemacs)
(if (featurep 'xemacs)
@@ -1108,12 +1089,11 @@ Two differences:
"Force to read key via `viper-read-key-sequence'."
(interactive (list (viper-read-key-sequence "Describe key briefly: "))))
;; Emacs
- (defadvice describe-key-briefly
- (before viper-describe-key-briefly-ad protect activate)
+ (viper--advice-add 'describe-key-briefly :before
+ (lambda (&rest _)
"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): "))
+ (interactive (let ((key (viper-read-key-sequence
+ "Describe key (or click or menu item): ")))
;; If KEY is a down-event, read and discard the
;; corresponding up-event.
(and (vectorp key)
@@ -1124,84 +1104,85 @@ Two differences:
(list key
(if current-prefix-arg
(prefix-numeric-value current-prefix-arg))
- 1))))
+ 1)))
+ nil))
) ; (if (featurep 'xemacs)
- (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)
- ;; XEmacs: if Mule & prefix arg, ask for coding system
- (cond ((and (featurep 'xemacs) (featurep 'mule))
- (list
- (and current-prefix-arg
- (read-coding-system "Coding-system: "))))
- ;; Emacs: do wildcards
- ((and (featurep 'emacs) (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)
- ;; XEmacs: if Mule & prefix arg, ask for coding system
- (cond ((and (featurep 'xemacs) (featurep 'mule))
- (list
- (and current-prefix-arg
- (read-coding-system "Coding-system: "))))
- ;; Emacs: do wildcards
- ((and (featurep 'emacs) (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)
- ;; XEmacs: if Mule & prefix arg, ask for coding system
- (cond ((and (featurep 'xemacs) (featurep 'mule))
- (list
- (and current-prefix-arg
- (read-coding-system "Coding-system: "))))
- ;; Emacs: do wildcards
- ((and (featurep 'emacs) (boundp 'find-file-wildcards))
- (list find-file-wildcards))))
- ))
-
-
- (defadvice read-file-name (around viper-suffix-advice activate)
+ ;; FIXME: The default already uses read-file-name, so it looks like this
+ ;; advice is not needed any more.
+ ;; (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)
+ ;; ;; XEmacs: if Mule & prefix arg, ask for coding system
+ ;; (cond ((and (featurep 'xemacs) (featurep 'mule))
+ ;; (list
+ ;; (and current-prefix-arg
+ ;; (read-coding-system "Coding-system: "))))
+ ;; ;; Emacs: do wildcards
+ ;; ((and (featurep 'emacs) (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)
+ ;; ;; XEmacs: if Mule & prefix arg, ask for coding system
+ ;; (cond ((and (featurep 'xemacs) (featurep 'mule))
+ ;; (list
+ ;; (and current-prefix-arg
+ ;; (read-coding-system "Coding-system: "))))
+ ;; ;; Emacs: do wildcards
+ ;; ((and (featurep 'emacs) (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)
+ ;; ;; XEmacs: if Mule & prefix arg, ask for coding system
+ ;; (cond ((and (featurep 'xemacs) (featurep 'mule))
+ ;; (list
+ ;; (and current-prefix-arg
+ ;; (read-coding-system "Coding-system: "))))
+ ;; ;; Emacs: do wildcards
+ ;; ((and (featurep 'emacs) (boundp 'find-file-wildcards))
+ ;; (list find-file-wildcards))))
+ ;; ))
+
+
+ (viper--advice-add 'read-file-name :around
+ (lambda (orig-fun &rest args)
"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))
+ (apply orig-fun args))))
- (defadvice start-kbd-macro (after viper-kbd-advice activate)
+ (viper--advice-add 'start-kbd-macro :after
+ (lambda (&rest _)
"Remove Viper's intercepting bindings for C-x ).
- This may be needed if the previous `:map' command terminated abnormally."
+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))
+ (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)
+ (viper--advice-add 'add-minor-mode :after
+ (lambda (&rest _)
"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)))
+ (setq-default minor-mode-map-alist minor-mode-map-alist))))
;; catch frame switching event
(if (viper-window-display-p)
(if (featurep 'xemacs)
- (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)))) )
+ (add-hook 'mouse-leave-frame-hook
+ #'viper-remember-current-frame)
+ (viper--advice-add 'handle-switch-frame :before
+ (lambda (&rest _)
+ "Remember the selected frame before the switch-frame event."
+ (viper-remember-current-frame (selected-frame))))))
) ; end viper-non-hook-settings
@@ -1253,7 +1234,7 @@ These two lines must come in the order given."))
(if (null viper-saved-non-viper-variables)
(setq viper-saved-non-viper-variables
(list
- (cons 'default-major-mode (list (default-value 'major-mode)))
+ (cons 'major-mode (list (default-value 'major-mode)))
(cons 'next-line-add-newlines (list next-line-add-newlines))
(cons 'require-final-newline (list require-final-newline))
(cons 'scroll-step (list scroll-step))
@@ -1318,97 +1299,83 @@ These two lines must come in the order given."))
(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)
- ))
-
-;;; Familiarize Viper with some minor modes that have their own keymaps
-(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") ; LaTeX-math-mode in AUC-TeX, which
- (viper-harness-minor-mode "latex") ; sits in one of these two files
- (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")
- ))
-
-
;; Intercept maps could go in viper-keym.el
;; We keep them here in case someone redefines them in viper-custom-file-name
-(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-ESC-key #'viper-intercept-ESC-key)
+(define-key viper-insert-intercept-map viper-ESC-key #'viper-intercept-ESC-key)
;; This is taken care of by viper-insert-global-user-map.
-;;(define-key viper-replace-map viper-ESC-key 'viper-intercept-ESC-key)
+;;(define-key viper-replace-map viper-ESC-key #'viper-intercept-ESC-key)
;; The default viper-toggle-key is \C-z; for the novice, it suspends or
;; iconifies Emacs
(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)
+ viper-emacs-intercept-map viper-toggle-key #'viper-change-state-to-vi)
-;;; Removed to avoid bad interaction with cua-mode.
-;;; Escape from Emacs and Insert modes to Vi for one command
+;; Removed to avoid bad interaction with cua-mode.
+;; Escape from Emacs and Insert modes to Vi for one command
;;(define-key viper-emacs-intercept-map "\C-c\\" 'viper-escape-to-vi)
;;(define-key viper-insert-intercept-map "\C-c\\" 'viper-escape-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))
-
-;; Let all minor modes take effect after loading.
-;; This may not be enough, so we also set default minor-mode-alist.
-;; Without setting the default, new buffers that come up in emacs mode have
-;; minor-mode-map-alist = nil, unless we call viper-change-state-*
-(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))
- ))
+(when viper-mode
+ (viper-set-minibuffer-style)
+ (if viper-buffer-search-char
+ (viper-buffer-search-enable))
+ (viper-update-syntax-classes 'set-default)
+
+ ;; Familiarize Viper with some minor modes that have their own keymaps
+ (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") ; LaTeX-math-mode in AUC-TeX, which
+ (viper-harness-minor-mode "latex") ; sits in one of these two files
+ (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")
+
+ (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 (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 (or viper-always
+ (and (< viper-expert-level 5) (> viper-expert-level 0)))
+ (viper-set-hooks))
+
+ ;; Let all minor modes take effect after loading.
+ ;; This may not be enough, so we also set default minor-mode-alist.
+ ;; Without setting the default, new buffers that come up in emacs mode have
+ ;; minor-mode-map-alist = nil, unless we call viper-change-state-*
+ (when (eq viper-current-state 'emacs-state)
+ (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 (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))
- ))
+ (add-function :after initial-major-mode #'set-viper-state-in-major-mode))