summaryrefslogtreecommitdiff
path: root/lisp/emulation
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emulation')
-rw-r--r--lisp/emulation/viper-cmd.el90
-rw-r--r--lisp/emulation/viper-util.el4
-rw-r--r--lisp/emulation/viper.el6
3 files changed, 69 insertions, 31 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el
index 645f4f26eaf..0dce3b94ff0 100644
--- a/lisp/emulation/viper-cmd.el
+++ b/lisp/emulation/viper-cmd.el
@@ -887,12 +887,15 @@ Vi's prefix argument will be used. Otherwise, the prefix argument passed to
(setq ch (aref (read-key-sequence nil) 0)))
(insert ch))
(t
- (setq ch (read-char-exclusive))
+ ;;(setq ch (read-char-exclusive))
+ (setq ch (aref (read-key-sequence nil) 0))
;; replace ^M with the newline
(if (eq ch ?\C-m) (setq ch ?\n))
;; Make sure ^V and ^Q work as quotation chars
(if (memq ch '(?\C-v ?\C-q))
- (setq ch (read-char-exclusive)))
+ ;;(setq ch (read-char-exclusive))
+ (setq ch (aref (read-key-sequence nil) 0))
+ )
(insert ch))
)
(setq last-command-event
@@ -1730,20 +1733,34 @@ invokes the command before that, etc."
;; undoing
+;; hook used inside undo
+(defvar viper-undo-functions nil)
+
+;; Runs viper-before-change-functions inside before-change-functions
+(defun viper-undo-sentinel (beg end length)
+ (run-hook-with-args 'viper-undo-functions beg end length))
+
+(add-hook 'after-change-functions 'viper-undo-sentinel)
+
+;; Hook used in viper-undo
+(defun viper-after-change-undo-hook (beg end len)
+ (setq undo-beg-posn beg
+ undo-end-posn (or end beg))
+ ;; some other hooks may be changing various text properties in
+ ;; the buffer in response to 'undo'; so remove this hook to avoid
+ ;; its repeated invocation
+ (remove-hook 'viper-undo-functions 'viper-after-change-undo-hook 'local))
+
(defun viper-undo ()
"Undo previous change."
(interactive)
(message "undo!")
(let ((modified (buffer-modified-p))
(before-undo-pt (point-marker))
- (after-change-functions after-change-functions)
undo-beg-posn undo-end-posn)
- ;; no need to remove this hook, since this var has scope inside a let.
- (add-hook 'after-change-functions
- '(lambda (beg end len)
- (setq undo-beg-posn beg
- undo-end-posn (or end beg))))
+ ;; the viper-after-change-undo-hook removes itself after the 1st invocation
+ (add-hook 'viper-undo-functions 'viper-after-change-undo-hook nil 'local)
(undo-start)
(undo-more 2)
@@ -1765,7 +1782,8 @@ invokes the command before that, etc."
(goto-char undo-beg-posn)))
(push-mark before-undo-pt t))
(if (and (eolp) (not (bolp))) (backward-char 1))
- (if (not modified) (set-buffer-modified-p t)))
+ ;;(if (not modified) (set-buffer-modified-p t))
+ )
(setq this-command 'viper-undo))
;; Continue undoing previous changes.
@@ -1813,7 +1831,7 @@ invokes the command before that, etc."
(setq viper-undo-needs-adjustment t)))))
-
+;;; Viper's destructive Command ring utilities
(defun viper-display-current-destructive-command ()
(let ((text (nth 4 viper-d-com))
@@ -1927,12 +1945,15 @@ Undo previous insertion and inserts new."
(end-of-line)
;; make sure all lines end with newline, unless in the minibuffer or
;; when requested otherwise (require-final-newline is nil)
- (if (and (eobp)
- (not (bolp))
- require-final-newline
- (not (viper-is-in-minibuffer))
- (not buffer-read-only))
- (insert "\n"))))
+ (save-restriction
+ (widen)
+ (if (and (eobp)
+ (not (bolp))
+ require-final-newline
+ (not (viper-is-in-minibuffer))
+ (not buffer-read-only))
+ (insert "\n")))
+ ))
(defun viper-yank-defun ()
(mark-defun)
@@ -3045,19 +3066,34 @@ On reaching beginning of line, stop and signal error."
(setq this-command 'next-line)
(if com (viper-execute-com 'viper-next-line val com))))
+
(defun viper-next-line-at-bol (arg)
- "Next line at beginning of line."
+ "Next line at beginning of line.
+If point is on a widget or a button, simulate clicking on that widget/button."
(interactive "P")
- (viper-leave-region-active)
- (save-excursion
- (end-of-line)
- (if (eobp) (error "Last line in buffer")))
- (let ((val (viper-p-val arg))
- (com (viper-getCom arg)))
- (if com (viper-move-marker-locally 'viper-com-point (point)))
- (forward-line val)
- (back-to-indentation)
- (if com (viper-execute-com 'viper-next-line-at-bol val com))))
+ (let* ((field (get-char-property (point) 'field))
+ (button (get-char-property (point) 'button))
+ (doc (get-char-property (point) 'widget-doc))
+ (widget (or field button doc)))
+ (if (and widget
+ (if (symbolp widget)
+ (get widget 'widget-type)
+ (and (consp widget)
+ (get (widget-type widget) 'widget-type))))
+ (widget-button-press (point))
+ (if (button-at (point))
+ (push-button)
+ ;; not a widget or a button
+ (viper-leave-region-active)
+ (save-excursion
+ (end-of-line)
+ (if (eobp) (error "Last line in buffer")))
+ (let ((val (viper-p-val arg))
+ (com (viper-getCom arg)))
+ (if com (viper-move-marker-locally 'viper-com-point (point)))
+ (forward-line val)
+ (back-to-indentation)
+ (if com (viper-execute-com 'viper-next-line-at-bol val com)))))))
(defun viper-previous-line (arg)
diff --git a/lisp/emulation/viper-util.el b/lisp/emulation/viper-util.el
index c7fe792b5f2..252088a476d 100644
--- a/lisp/emulation/viper-util.el
+++ b/lisp/emulation/viper-util.el
@@ -139,8 +139,8 @@
(defsubst viper-get-cursor-color ()
(viper-cond-compile-for-xemacs-or-emacs
- ;; xemacs
- (color-instance-name (frame-property (selected-frame) 'cursor-color))
+ (color-instance-name
+ (frame-property (selected-frame) 'cursor-color)) ; xemacs
(cdr (assoc 'cursor-color (frame-parameters))) ; emacs
))
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index fc55d291550..8f858526da3 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -534,6 +534,10 @@ If Viper is enabled, turn it off. Otherwise, turn it on."
(defun viper-mode ()
"Turn on Viper emulation of Vi in Emacs. See Info node `(viper)Viper'."
(interactive)
+ (if (null viper-vi-state-cursor-color)
+ (modify-frame-parameters
+ (selected-frame)
+ (list (cons 'viper-vi-state-cursor-color (viper-get-cursor-color)))))
(if (not noninteractive)
(progn
;; if the user requested viper-mode explicitly
@@ -545,8 +549,6 @@ If Viper is enabled, turn it off. Otherwise, turn it on."
(if viper-first-time ; Important check. Prevents mix-up of startup
(progn ; and expert-level msgs when viper-mode recurses
(setq viper-first-time nil)
- (setq viper-vi-state-cursor-color
- (viper-get-cursor-color))
(if (not viper-inhibit-startup-message)
(save-window-excursion
(setq viper-inhibit-startup-message t)