]> code.delx.au - gnu-emacs/blobdiff - lisp/emulation/viper-cmd.el
* lisp/simple.el (undo-amalgamate-change-group): New function
[gnu-emacs] / lisp / emulation / viper-cmd.el
index 72fc89817a16f1de2a9743f7a113dd0b24b18173..3ce1b4d6a75e31910412f307bba24f2289adffa3 100644 (file)
             (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
@@ -1670,7 +1670,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)
@@ -1710,17 +1709,21 @@ 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))
+(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 ()
-  (when (not viper-undo-in-complex-command)
-    (setq undo-auto-disable-boundaries t)
-    (setq viper-undo-in-complex-command t)
-    (undo-boundary)))
+  (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
 
@@ -2588,7 +2591,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)
     ))