Subject: 24.3.93 regression: undo boundary inserted by delete-selection-mode (CUA)

From: David Reitter <[email-masked]>
Date: Fri, 5 Sep 2014 12:37:06 -0400

This is a regression in the 24.4 pretest compared to 24.3.

M-x cua-mode
(enter and) select a word “hello", e.g., via double-click
enter single char, e.g., “x”
C-_   (undo)

In Emacs 24.3, the undo will restore “hello”.

In Emacs 24.3.93 pretest, the undo will only delete “x”, but not restore “hello”.
An undo boundary is present in buffer-undo-list between the delete-selection step and the insertion of “x”.

The relevant change, I think, were changes to CUA on Dec 8 and 11, 2013:

commit f38bbfce43b11667ee1a09acf4f4f932bf7c9043
Author: Stefan Monnier <[email-masked]>
Date:   Sun Dec 8 01:24:54 2013 -0500

    Use delete-selection-mode in cya-mode.

As a fix...

Looking at how self-insert-command deletes the undo boundary to merge itself, we can either prevent the undo boundary from being inserted (I couldn’t figure out where that happens), or pretend that the delete-selection action was a self-insert-command.  The patch below is a proof of concept.

I think the right fix would be not to insert the undo boundary in the first place, if this is reasonably doable.

commit abf13771ad1b3dbc542a35393230eb43baa55d1c
Author: David Reitter <[email-masked]>
Date:   Fri Sep 5 12:26:11 2014 -0400

    delsel: delete-active-region: avoid undo boundary
    
    Set last-command so that self-insert-command removes any
    undo boundary.

diff --git a/lisp/delsel.el b/lisp/delsel.el
index 1ada027..c1b1eba 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -80,6 +80,8 @@ If KILLP in not-nil, the active region is killed instead of deleted."
       (let (this-command)
 	(kill-region (point) (mark) t))
     (funcall region-extract-function 'delete-only))
+  ;; do not add undo-boundary in self-insert-command:
+  (setq last-command this-command)
   t)
 
 (defun delete-selection-helper (type)