aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhillip Lord2016-05-21 10:06:12 +0100
committerPhillip Lord2016-05-23 09:12:49 +0100
commitc0139e32f1f3bb287b04e02a69a7848d6a040003 (patch)
treebb3f6f0038516f4ef0a41b6c49497c9f5070aa4c
parent920d76c2084f0621dec8664840dd3fb2e9b34891 (diff)
downloademacs-c0139e32f1f3bb287b04e02a69a7848d6a040003.tar.gz
emacs-c0139e32f1f3bb287b04e02a69a7848d6a040003.zip
Fix viper undo breakage from undo-boundary changes
* 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
-rw-r--r--lisp/emulation/viper-cmd.el43
-rw-r--r--lisp/emulation/viper-init.el9
-rw-r--r--lisp/simple.el23
3 files changed, 32 insertions, 43 deletions
diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el
index 93cf3b0fb10..6b8fa46362d 100644
--- a/lisp/emulation/viper-cmd.el
+++ b/lisp/emulation/viper-cmd.el
@@ -631,7 +631,7 @@
631 (viper-over-whitespace-line)) 631 (viper-over-whitespace-line))
632 (indent-to-left-margin)) 632 (indent-to-left-margin))
633 (viper-add-newline-at-eob-if-necessary) 633 (viper-add-newline-at-eob-if-necessary)
634 (viper-adjust-undo) 634 (viper-complete-complex-command-for-undo)
635 635
636 (if (eq viper-current-state 'emacs-state) 636 (if (eq viper-current-state 'emacs-state)
637 (viper-restore-cursor-color 'after-emacs-mode) 637 (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'."
1570 (if (and (eolp) (not (bolp))) 1570 (if (and (eolp) (not (bolp)))
1571 (backward-char 1)) 1571 (backward-char 1))
1572 )) 1572 ))
1573 (viper-adjust-undo) ; take care of undo 1573 (viper-complete-complex-command-for-undo) ; take care of undo
1574 ;; If the prev cmd was rotating the command ring, this means that `.' has 1574 ;; If the prev cmd was rotating the command ring, this means that `.' has
1575 ;; just executed a command from that ring. So, push it on the ring again. 1575 ;; just executed a command from that ring. So, push it on the ring again.
1576 ;; If we are just executing previous command , then don't push viper-d-com 1576 ;; If we are just executing previous command , then don't push viper-d-com
@@ -1671,6 +1671,7 @@ invokes the command before that, etc."
1671 1671
1672 (undo-start) 1672 (undo-start)
1673 (undo-more 2) 1673 (undo-more 2)
1674 (viper-complete-complex-command-for-undo)
1674 ;;(setq undo-beg-posn (or undo-beg-posn (point)) 1675 ;;(setq undo-beg-posn (or undo-beg-posn (point))
1675 ;; undo-end-posn (or undo-end-posn (point))) 1676 ;; undo-end-posn (or undo-end-posn (point)))
1676 ;;(setq undo-beg-posn (or undo-beg-posn before-undo-pt) 1677 ;;(setq undo-beg-posn (or undo-beg-posn before-undo-pt)
@@ -1710,37 +1711,17 @@ invokes the command before that, etc."
1710;; The following two functions are used to set up undo properly. 1711;; The following two functions are used to set up undo properly.
1711;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines, 1712;; In VI, unlike Emacs, if you open a line, say, and add a bunch of lines,
1712;; they are undone all at once. 1713;; they are undone all at once.
1713(defun viper-adjust-undo () 1714(defun viper-complete-complex-command-for-undo ()
1714 (if viper-undo-needs-adjustment 1715 (setq undo-auto-disable-boundaries nil)
1715 (let ((inhibit-quit t) 1716 (setq viper-undo-in-complex-command nil)
1716 tmp tmp2) 1717 (undo-boundary))
1717 (setq viper-undo-needs-adjustment nil)
1718 (if (listp buffer-undo-list)
1719 (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list))
1720 (progn
1721 (setq tmp2 (cdr tmp)) ; the part after mark
1722
1723 ;; cut tail from buffer-undo-list temporarily by direct
1724 ;; manipulation with pointers in buffer-undo-list
1725 (setcdr tmp nil)
1726
1727 (setq buffer-undo-list (delq nil buffer-undo-list))
1728 (setq buffer-undo-list
1729 (delq viper-buffer-undo-list-mark buffer-undo-list))
1730 ;; restore tail of buffer-undo-list
1731 (setq buffer-undo-list (nconc buffer-undo-list tmp2)))
1732 (setq buffer-undo-list (delq nil buffer-undo-list)))))
1733 ))
1734 1718
1735 1719
1736(defun viper-set-complex-command-for-undo () 1720(defun viper-set-complex-command-for-undo ()
1737 (if (listp buffer-undo-list) 1721 (when (not viper-undo-in-complex-command)
1738 (if (not viper-undo-needs-adjustment) 1722 (setq undo-auto-disable-boundaries t)
1739 (let ((inhibit-quit t)) 1723 (setq viper-undo-in-complex-command t)
1740 (setq buffer-undo-list 1724 (undo-boundary)))
1741 (cons viper-buffer-undo-list-mark buffer-undo-list))
1742 (setq viper-undo-needs-adjustment t)))))
1743
1744 1725
1745;;; Viper's destructive Command ring utilities 1726;;; Viper's destructive Command ring utilities
1746 1727
@@ -2604,7 +2585,7 @@ These keys are ESC, RET, and LineFeed."
2604 (delete-char 1 t) 2585 (delete-char 1 t)
2605 (insert char)) 2586 (insert char))
2606 2587
2607 (viper-adjust-undo) 2588 (viper-complete-complex-command-for-undo)
2608 (backward-char arg) 2589 (backward-char arg)
2609 )) 2590 ))
2610 2591
diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el
index 104245b7571..c1e76629477 100644
--- a/lisp/emulation/viper-init.el
+++ b/lisp/emulation/viper-init.el
@@ -370,13 +370,8 @@ Use `\\[viper-set-expert-level]' to change this.")
370;; VI-style Undo 370;; VI-style Undo
371 371
372;; Used to 'undo' complex commands, such as replace and insert commands. 372;; Used to 'undo' complex commands, such as replace and insert commands.
373(viper-deflocalvar viper-undo-needs-adjustment nil) 373(viper-deflocalvar viper-undo-in-complex-command nil)
374(put 'viper-undo-needs-adjustment 'permanent-local t) 374(put 'viper-undo-in-complex-command 'permanent-local t)
375
376;; A mark that Viper puts on buffer-undo-list. Marks the beginning of a
377;; complex command that must be undone atomically. If inserted, it is
378;; erased by viper-change-state-to-vi and viper-repeat.
379(defconst viper-buffer-undo-list-mark 'viper)
380 375
381(defcustom viper-keep-point-on-undo nil 376(defcustom viper-keep-point-on-undo nil
382 "Non-nil means not to move point while undoing commands. 377 "Non-nil means not to move point while undoing commands.
diff --git a/lisp/simple.el b/lisp/simple.el
index 97b40bd214e..c5aa2922475 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2839,6 +2839,18 @@ buffers that were changed during the last command.")
2839 2839
2840If set to non-nil, this will effectively disable the timer.") 2840If set to non-nil, this will effectively disable the timer.")
2841 2841
2842(defvar-local undo-auto-disable-boundaries nil
2843 "Disable the automatic addition of boundaries.
2844
2845If set to non-nil, `undo-boundary' will not be called
2846automatically in a buffer either at the end of a command, or as a
2847result of `undo-auto-current-boundary-timer'.
2848
2849When this is set to non-nil, it is important to ensure that
2850`undo-boundary' is called frequently enough. Failure to do so
2851will result in user-visible warnings that the situation is
2852probably a bug.")
2853
2842(defvar undo-auto--this-command-amalgamating nil 2854(defvar undo-auto--this-command-amalgamating nil
2843 "Non-nil if `this-command' should be amalgamated. 2855 "Non-nil if `this-command' should be amalgamated.
2844This variable is set to nil by `undo-auto--boundaries' and is set 2856This 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
2878 (dolist (b undo-auto--undoably-changed-buffers) 2890 (dolist (b undo-auto--undoably-changed-buffers)
2879 (when (buffer-live-p b) 2891 (when (buffer-live-p b)
2880 (with-current-buffer b 2892 (with-current-buffer b
2881 (undo-auto--ensure-boundary cause)))) 2893 (unless undo-auto-disable-boundaries
2894 (undo-auto--ensure-boundary cause)))))
2882 (setq undo-auto--undoably-changed-buffers nil)) 2895 (setq undo-auto--undoably-changed-buffers nil))
2883 2896
2884(defun undo-auto--boundary-timer () 2897(defun undo-auto--boundary-timer ()
@@ -2905,10 +2918,10 @@ See also `undo-auto--buffer-undoably-changed'.")
2905 "Add an `undo-boundary' in appropriate buffers." 2918 "Add an `undo-boundary' in appropriate buffers."
2906 (undo-auto--boundaries 2919 (undo-auto--boundaries
2907 (let ((amal undo-auto--this-command-amalgamating)) 2920 (let ((amal undo-auto--this-command-amalgamating))
2908 (setq undo-auto--this-command-amalgamating nil) 2921 (setq undo-auto--this-command-amalgamating nil)
2909 (if amal 2922 (if amal
2910 'amalgamate 2923 'amalgamate
2911 'command)))) 2924 'command))))
2912 2925
2913(defun undo-auto-amalgamate () 2926(defun undo-auto-amalgamate ()
2914 "Amalgamate undo if necessary. 2927 "Amalgamate undo if necessary.