-;;; viper-cmd.el --- Vi command support for Viper
+;;; viper-cmd.el --- Vi command support for Viper -*- lexical-binding:t -*-
-;; Copyright (C) 1997-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1997-2016 Free Software Foundation, Inc.
;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
;; Package: viper
(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
;; 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)))
)
-(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)
(defun viper-ESC (arg)
"Emulate ESC key in Emacs.
Prevents multiple escape keystrokes if viper-no-multiple-ESC is true.
-If viper-no-multiple-ESC is 'twice double ESC would ding in vi-state.
+If `viper-no-multiple-ESC' is `twice' double ESC would ding in vi-state.
Other ESC sequences are emulated via the current Emacs's major mode
keymap. This is more convenient on TTYs, since this won't block
function keys such as up, down, etc. ESC will also will also work as
-a Meta key in this case. When viper-no-multiple-ESC is nil, ESC works
+a Meta key in this case. When `viper-no-multiple-ESC' is nil, ESC works
as a Meta key and any number of multiple escapes are allowed."
(interactive "P")
(let (char)
;; 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.
(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))
(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)
(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))
(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)
(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))
(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))
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))
;; 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)
(defun viper-repeat (arg)
"Re-execute last destructive command.
Use the info in viper-d-com, which has the form
-\(com val ch reg inserted-text command-keys\),
+\(com val ch reg inserted-text command-keys),
where `com' is the command to be re-executed, `val' is the
argument to `com', `ch' is a flag for repeat, and `reg' is optional;
if it exists, it is the name of the register for `com'.
(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))
"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
(let ((inhibit-quit t)
tmp tmp2)
(setq viper-undo-needs-adjustment nil)
- (if (listp buffer-undo-list)
- (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list))
+ (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
(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)))))
- ))
+ (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)))))))
(defun viper-set-complex-command-for-undo ()
(setq this-command 'viper-display-current-destructive-command)
- (message " `.' runs %s%s"
- (concat "`" (viper-array-to-string keys) "'")
+ (message " `.' runs `%s'%s"
+ (viper-array-to-string keys)
(viper-abbreviate-string
(if (featurep 'xemacs)
(replace-in-string ; xemacs
text ; emacs
)
max-text-len
- " inserting `" "'" " ......."))
+ (format-message " inserting `") (format-message "'")
+ " ......."))
))
"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)) "#")
(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
(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)
\f
;;; 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
;; 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 "")
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))
(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)
((re-search-backward "[][(){}]" beg-lim t))
(t
(error "No matching character on line"))))
- (cond ((looking-at "[\(\[{]")
+ (cond ((looking-at "[([{]")
(if com (viper-move-marker-locally 'viper-com-point (point)))
(forward-sexp 1)
(if com
(interactive)
(setq viper-parse-sexp-ignore-comments
(not viper-parse-sexp-ignore-comments))
- (princ (format
+ (princ (format-message
"From now on, `%%' will %signore parentheses inside comment fields"
(if viper-parse-sexp-ignore-comments "" "NOT "))))
(let (msg)
(cond ((or (eq arg 1)
(and (null arg)
- (y-or-n-p (format "Search style: '%s'. Want '%s'? "
- (if viper-case-fold-search
- "case-insensitive" "case-sensitive")
- (if viper-case-fold-search
- "case-sensitive"
- "case-insensitive")))))
+ (y-or-n-p (format-message
+ "Search style: `%s'. Want `%s'? "
+ (if viper-case-fold-search
+ "case-insensitive" "case-sensitive")
+ (if viper-case-fold-search
+ "case-sensitive"
+ "case-insensitive")))))
(setq viper-case-fold-search (null viper-case-fold-search))
(if viper-case-fold-search
(setq msg "Search becomes case-insensitive")
(setq msg "Search becomes case-sensitive")))
((or (eq arg 2)
(and (null arg)
- (y-or-n-p (format "Search style: '%s'. Want '%s'? "
- (if viper-re-search
- "regexp-search" "vanilla-search")
- (if viper-re-search
- "vanilla-search"
- "regexp-search")))))
+ (y-or-n-p (format-message
+ "Search style: `%s'. Want `%s'? "
+ (if viper-re-search
+ "regexp-search" "vanilla-search")
+ (if viper-re-search
+ "vanilla-search"
+ "regexp-search")))))
(setq viper-re-search (null viper-re-search))
(if viper-re-search
(setq msg "Search becomes regexp-style")
(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
If the optional prefix argument is non-nil and specifies a valid major mode,
this sets the macros only in the macros in that major mode. Otherwise,
the macros are set in the current major mode.
-\(When unsetting the macros, the second argument has no effect.\)"
+\(When unsetting the macros, the second argument has no effect.)"
(interactive "P")
(or noninteractive
(if (not unset)
(let (buffer buffer-name)
(setq buffer-name
(funcall viper-read-buffer-function
- (format "Kill buffer \(%s\): "
+ (format "Kill buffer (%s): "
(buffer-name (current-buffer)))))
(setq buffer
(if (null buffer-name)
(if (null buffer) (error "`%s': No such buffer" buffer-name))
(if (or (not (buffer-modified-p buffer))
(y-or-n-p
- (format
+ (format-message
"Buffer `%s' is modified, are you sure you want to kill it? "
buffer-name)))
(kill-buffer buffer)
(query-replace-regexp
str
(viper-read-string-with-history
- (format "Query replace regexp `%s' with: " str)
+ (format-message "Query replace regexp `%s' with: " str)
nil ; no initial
'viper-replace1-history
(car viper-replace1-history) ; default
(query-replace
str
(viper-read-string-with-history
- (format "Query replace `%s' with: " str)
+ (format-message "Query replace `%s' with: " str)
nil ; no initial
'viper-replace1-history
(car viper-replace1-history) ; default
;; etc.
(defun viper-cycle-through-mark-ring ()
"Visit previous locations on the mark ring.
-One can use `` and '' to temporarily jump 1 step back."
+One can use \\=`\\=` and \\='\\=' to temporarily jump 1 step back."
(let* ((sv-pt (point)))
;; if repeated `m,' command, pop the previously saved mark.
;; Prev saved mark is actually prev saved point. It is used if the
(interactive)
(if viper-cted
(let ((p (point)) (c (current-column)) bol (indent t))
- (if (looking-back "[0^]")
+ (if (looking-back "[0^]" (1- (point)))
(progn
(if (eq ?^ (preceding-char))
(setq viper-preserve-indent t))
(delete-region (point) p)
(if indent
(indent-to (- c viper-shift-width)))
- (if (or (bolp) (looking-back "[^ \t]"))
+ (if (or (bolp) (looking-back "[^ \t]" (1- (point))))
(setq viper-cted nil)))))
;; do smart indent
;; Viewing registers
(defun viper-ket-function (arg)
- "Function called by \], the ket. View registers and call \]\]."
+ "Function called by ], the ket. View registers and call ]]."
(interactive "P")
(let ((reg (read-char)))
(cond ((viper-valid-register reg '(letter Letter))
viper-InvalidRegister reg)))))
(defun viper-brac-function (arg)
- "Function called by \[, the brac. View textmarkers and call \[\[."
+ "Function called by [, the brac. View textmarkers and call [[."
(interactive "P")
(let ((reg (read-char)))
(cond ((viper= ?\[ reg)
(substring text 0 (- pos s))
reg (substring text (- pos s)))))
(princ
- (format
+ (format-message
"Textmarker `%c' is in buffer `%s' at line %d.\n"
reg (buffer-name buf) line-no))
(princ (format "Here is some text around %c:\n\n %s"
reg text)))
- (princ (format viper-EmptyTextmarker reg))))
+ (princ (format-message viper-EmptyTextmarker reg))))
))
(t (error viper-InvalidTextmarker reg)))))
(setq repeated t))
(setq dont-change-unless t
level-changed t)
- (insert "
+ (insert (substitute-command-keys "
Please specify your level of familiarity with the venomous VI PERil
\(and the VI Plan for Emacs Rescue).
-You can change it at any time by typing `M-x viper-set-expert-level RET'
+You can change it at any time by typing `\\[viper-set-expert-level]'
1 -- BEGINNER: Almost all Emacs features are suppressed.
Feels almost like straight Vi. File name completion and
viper-electric-mode, viper-want-ctl-h-help, viper-want-emacs-keys-in-vi,
and viper-want-emacs-keys-in-insert. Adjust these to your taste.
-Please, specify your level now: ")
+Please, specify your level now: "))
(setq viper-expert-level (- (viper-read-char-exclusive) ?0))
) ; end while
\f
;;; 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
'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!
trace in your bug report.
If you believe that one of Viper's commands goes into an infinite loop
-\(e.g., Emacs freezes\), type:
+\(e.g., Emacs freezes), type:
M-x set-variable <Return> debug-on-quit <Return> t <Return>