From 291fe0aade6560490abbe5c08d231c18edbb4737 Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Fri, 10 Jun 2016 22:30:49 +0100 Subject: Revert "Fix viper undo breakage from undo-boundary changes" This reverts commit c0139e32f1f3bb287b04e02a69a7848d6a040003. --- lisp/emulation/viper-cmd.el | 43 +++++++++++++++++++++++++++++++------------ lisp/emulation/viper-init.el | 9 +++++++-- 2 files changed, 38 insertions(+), 14 deletions(-) (limited to 'lisp/emulation') diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el index 6b8fa46362d..93cf3b0fb10 100644 --- a/lisp/emulation/viper-cmd.el +++ b/lisp/emulation/viper-cmd.el @@ -631,7 +631,7 @@ (viper-over-whitespace-line)) (indent-to-left-margin)) (viper-add-newline-at-eob-if-necessary) - (viper-complete-complex-command-for-undo) + (viper-adjust-undo) (if (eq viper-current-state 'emacs-state) (viper-restore-cursor-color 'after-emacs-mode) @@ -1570,7 +1570,7 @@ If the prefix argument ARG is non-nil, it is used instead of `val'." (if (and (eolp) (not (bolp))) (backward-char 1)) )) - (viper-complete-complex-command-for-undo) ; take care of undo + (viper-adjust-undo) ; take care of undo ;; If the prev cmd was rotating the command ring, this means that `.' has ;; just executed a command from that ring. So, push it on the ring again. ;; If we are just executing previous command , then don't push viper-d-com @@ -1671,7 +1671,6 @@ invokes the command before that, etc." (undo-start) (undo-more 2) - (viper-complete-complex-command-for-undo) ;;(setq undo-beg-posn (or undo-beg-posn (point)) ;; undo-end-posn (or undo-end-posn (point))) ;;(setq undo-beg-posn (or undo-beg-posn before-undo-pt) @@ -1711,17 +1710,37 @@ 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-complete-complex-command-for-undo () - (setq undo-auto-disable-boundaries nil) - (setq viper-undo-in-complex-command nil) - (undo-boundary)) +(defun viper-adjust-undo () + (if viper-undo-needs-adjustment + (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)) + (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))))) + )) (defun viper-set-complex-command-for-undo () - (when (not viper-undo-in-complex-command) - (setq undo-auto-disable-boundaries t) - (setq viper-undo-in-complex-command t) - (undo-boundary))) + (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))))) + ;;; Viper's destructive Command ring utilities @@ -2585,7 +2604,7 @@ These keys are ESC, RET, and LineFeed." (delete-char 1 t) (insert char)) - (viper-complete-complex-command-for-undo) + (viper-adjust-undo) (backward-char arg) )) diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el index c1e76629477..104245b7571 100644 --- a/lisp/emulation/viper-init.el +++ b/lisp/emulation/viper-init.el @@ -370,8 +370,13 @@ 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-in-complex-command nil) -(put 'viper-undo-in-complex-command 'permanent-local t) +(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. -- cgit v1.2.1 From 12e009e52f09c27e5b29cf8394eff5e8efdba9b6 Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Fri, 10 Jun 2016 22:59:55 +0100 Subject: Restore initial undo boundary with viper * lisp/emulation/viper-cmd.el (viper-adjust-undo): Add back last undo boundary if it has been removed. Addresses Bug#22295. --- lisp/emulation/viper-cmd.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lisp/emulation') diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el index 93cf3b0fb10..4bd819ab828 100644 --- a/lisp/emulation/viper-cmd.el +++ b/lisp/emulation/viper-cmd.el @@ -1715,8 +1715,9 @@ invokes the command before that, etc." (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 @@ -1729,8 +1730,11 @@ invokes the command before that, etc." (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 () -- cgit v1.2.1