]> code.delx.au - gnu-emacs/commitdiff
Fix viper undo breakage from undo-boundary changes
authorPhillip Lord <phillip.lord@russet.org.uk>
Sat, 21 May 2016 09:06:12 +0000 (10:06 +0100)
committerPhillip Lord <phillip.lord@russet.org.uk>
Mon, 23 May 2016 08:12:49 +0000 (09:12 +0100)
* lisp/simple.el (undo-auto-disable-boundaries): New variable
* lisp/emulation/viper-init.el (viper-undo-in-complex-command,
  viper-undo-needs-adjustment): Rename
  variable to reflect new purpose,
  (viper-buffer-undo-list-mark): Remove
* lisp/emulation/viper-cmd.el (viper-set-complex-command-for-undo):
  Add undo using `undo-boundary', disable default undo-boundary
  addition.
* lisp/emulation/viper-cmd.el
  (viper-complete-complex-command-for-undo,viper-adjust-undo):
  Change function name, remove old undo list manipulation.
* lisp/emulation/viper-cmd.el (viper-undo,viper-repeat,
  viper-change-state-to-vi,viper-change-state):
  Update for function name change.

Addresses Bug #22295

lisp/emulation/viper-cmd.el
lisp/emulation/viper-init.el
lisp/simple.el

index 93cf3b0fb10ac87d93e52ec58bd5469ce87b41b5..6b8fa46362d7998d575620087e3bff768f396f83 100644 (file)
             (viper-over-whitespace-line))
        (indent-to-left-margin))
     (viper-add-newline-at-eob-if-necessary)
-    (viper-adjust-undo)
+    (viper-complete-complex-command-for-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-adjust-undo) ; take care of undo
+  (viper-complete-complex-command-for-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,6 +1671,7 @@ 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,37 +1711,17 @@ 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)
-       (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-complete-complex-command-for-undo ()
+  (setq undo-auto-disable-boundaries nil)
+  (setq viper-undo-in-complex-command nil)
+  (undo-boundary))
 
 
 (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)))))
-
+  (when (not viper-undo-in-complex-command)
+    (setq undo-auto-disable-boundaries t)
+    (setq viper-undo-in-complex-command t)
+    (undo-boundary)))
 
 ;;; Viper's destructive Command ring utilities
 
@@ -2604,7 +2585,7 @@ These keys are ESC, RET, and LineFeed."
                (delete-char 1 t)
                (insert char))
 
-    (viper-adjust-undo)
+    (viper-complete-complex-command-for-undo)
     (backward-char arg)
     ))
 
index 104245b757192e2748054726d102841a55fae2da..c1e76629477007cdfdfd1379ab21bfe0e00728c6 100644 (file)
@@ -370,13 +370,8 @@ 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)
+(viper-deflocalvar viper-undo-in-complex-command nil)
+(put 'viper-undo-in-complex-command 'permanent-local t)
 
 (defcustom viper-keep-point-on-undo nil
   "Non-nil means not to move point while undoing commands.
index 97b40bd214e7f9b8537094f1eeb5926c5389d401..c5aa2922475b7f5e4f087f53a9804bbc69ac2f63 100644 (file)
@@ -2839,6 +2839,18 @@ buffers that were changed during the last command.")
 
 If set to non-nil, this will effectively disable the timer.")
 
+(defvar-local undo-auto-disable-boundaries nil
+  "Disable the automatic addition of boundaries.
+
+If set to non-nil, `undo-boundary' will not be called
+automatically in a buffer either at the end of a command, or as a
+result of `undo-auto-current-boundary-timer'.
+
+When this is set to non-nil, it is important to ensure that
+`undo-boundary' is called frequently enough. Failure to do so
+will result in user-visible warnings that the situation is
+probably a bug.")
+
 (defvar undo-auto--this-command-amalgamating nil
   "Non-nil if `this-command' should be amalgamated.
 This variable is set to nil by `undo-auto--boundaries' and is set
@@ -2878,7 +2890,8 @@ REASON describes the reason that the boundary is being added; see
   (dolist (b undo-auto--undoably-changed-buffers)
           (when (buffer-live-p b)
             (with-current-buffer b
-              (undo-auto--ensure-boundary cause))))
+              (unless undo-auto-disable-boundaries
+                (undo-auto--ensure-boundary cause)))))
   (setq undo-auto--undoably-changed-buffers nil))
 
 (defun undo-auto--boundary-timer ()
@@ -2905,10 +2918,10 @@ See also `undo-auto--buffer-undoably-changed'.")
   "Add an `undo-boundary' in appropriate buffers."
   (undo-auto--boundaries
    (let ((amal undo-auto--this-command-amalgamating))
-       (setq undo-auto--this-command-amalgamating nil)
-       (if amal
-           'amalgamate
-         'command))))
+     (setq undo-auto--this-command-amalgamating nil)
+     (if amal
+         'amalgamate
+       'command))))
 
 (defun undo-auto-amalgamate ()
   "Amalgamate undo if necessary.