Subject: bug#32747: 26; `C-M-w M-w' with non-nil `mouse-drag-copy-region', if selected with mouse

From: Drew Adams <[email-masked]>
Date: Wed, 19 Sep 2018 06:51:40 -0700 (PDT)

> > 1. emacs -Q
> > 2. (setq mouse-drag-copy-region t) ; Mouse selection copies to kill-ring.
> > 3. In *scratch*, select some text, e.g. "This buffer".
> > 4. Use `M-w' to copy the selected text to the kill ring.
> > 5. With the mouse, select some other text, e.g. "visit that file".
> > 6. Use `C-M-w M-w', to append the second selection to the first as the
> >    last kill.  The kill should thus be "This buffervisit that file".
> > 7. `C-y' to yank the last kill.
> >
> > The text yanked should be "This buffervisit that file".  Instead, it is
> > "visit that filevisit that file".  That is, the second selection is
> > added to the kill ring and appended to itself.
> 
> I see something almost opposite:
> 
>  . in Emacs 23.4, the above recipe produces the "wrong" behavior,
>    unless I set mouse-drag-copy-region to nil (it is t by default)
> 
>  . in Emacs 24 and later, mouse-drag-copy-region is nil by default, so
>    the recipe works in "emacs -Q" without any customizations, but if I
>    set mouse-drag-copy-region to t, I get the old "wrong" Emacs 23
>    behavior
> 
> So I wonder what is going on with your system that you seem to see
> such strikingly different results.

Thanks for checking this.

Apologies. Dunno what I was seeing, or thought I was seeing, for
Emacs 23.4. Perhaps I was mixed up by not realizing that the
default value for the variable was different, and perhaps not
testing both cases or something.

Anyay, replaying the recipe now (again, from -Q), I see the bad
behavior in _all_ Emacs releases (including back to Emacs 20,
when there was no variable `mouse-drag-copy-region').

In Emacs 23.4, changing `mouse-drag-copy-region' to nil does _not_
fix the behavior, for me. Are you sure that it does, for you? Both nil
and t values just duplicate the mouse selection - the first text selected
and copied to the kill-ring with `M-w' is not present in either case.

In Emacs 24.5 and later the bad behavior exists only when the
variable is non-nil.

So the bug does not seem to be a regression, and it is longstanding.
Perhaps no one ever tried to use `C-M-w M-w' with a mouse
selection when testing?

Do you agree that this is a bug? If not, do you agree that it is a
worthwhile enhancement request that `C-M-w' be able to affect
a mouse selection the same way it affects a selection made with
the keyboard?

To me, this is a bug. The behavior contradicts what the doc says for
`C-M-w', and the behavior is useless (why would anyone want
duplication of the mouse selection - appending it to itself instead
of the previous kill?)

(The same problem exists for an actual kill, BTW. E.g. following
`C-M-w' with `C-w' instead of `M-w'.)

That I see the problem in Emacs 23.4 with both values of the
variable, and I see it in older releases where the variable does
not exist yet, maybe provides a clue for fixing the bug; dunno.
Whatever is done now for the nil case works correctly.