diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2016-07-18 21:04:39 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2016-07-18 21:04:39 -0400 |
commit | 99fe98d37a39d26f5dea424926d0e0a082655fe5 (patch) | |
tree | 636e1f79d4b85206ea7281f08ad053fb84902abe /lisp/emulation | |
parent | 73f0715df53c6a12a3d9039ac1a1664d30c293ff (diff) | |
download | emacs-99fe98d37a39d26f5dea424926d0e0a082655fe5.tar.gz emacs-99fe98d37a39d26f5dea424926d0e0a082655fe5.tar.bz2 emacs-99fe98d37a39d26f5dea424926d0e0a082655fe5.zip |
* lisp/simple.el (undo-amalgamate-change-group): New function
* lisp/emulation/viper-cmd.el (viper-adjust-undo): Use it.
(viper-set-complex-command-for-undo): Save current state with
prepare-change-group.
* lisp/emulation/viper-init.el (viper-undo-needs-adjustment)
(viper-buffer-undo-list-mark): Remove.
Diffstat (limited to 'lisp/emulation')
-rw-r--r-- | lisp/emulation/viper-cmd.el | 42 | ||||
-rw-r--r-- | lisp/emulation/viper-init.el | 9 |
2 files changed, 11 insertions, 40 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el index 3d9d1cc59f2..3ce1b4d6a75 100644 --- a/lisp/emulation/viper-cmd.el +++ b/lisp/emulation/viper-cmd.el @@ -1709,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 diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el index cd71925590a..ee093906771 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 |