Subject: bug#18939: 24.4; middle-click sometimes pastes data other than the PRIMARY selection

From: [email-masked] (Riku Saikkonen)
Date: Tue, 30 Dec 2014 12:45:12 +0200

I tried to trace where the bug occurs, and got as far as this:

mouse-drag-track contains the lines

	  ;; Otherwise, run binding of terminating up-event.
          (deactivate-mark)
	  (if do-multi-click
	      (goto-char start-point)
	    (unless moved-off-start
	      (pop-mark)))

(lines 858-863 of mouse.el in Emacs 24.4.1)

Commenting out the last (pop-mark) fixes the bug, but leaves extra marks
in the mark ring (accessible with C-u C-SPC) at every point you click.
There's a corresponding push-mark on line 796 which this pop-mark
appears to try to undo, but it appears that as a side effect pop-mark
sets the primary selection (in the situation described in the bug).

I am not sure what would be a proper fix. Perhaps mouse-drag-track
should not push the mark at all until it detects something else than a
single click (i.e., (or moved-off-start do-multi-click) or something)?
(From a quick look at the source, that seems to be how mouse-drag-track
worked in Emacs 23.4.1. But the source has changed quite a lot since
then.)

PS. I found out about this bug because Debian currently considers it to
    be a release-critical bug; see <http://bugs.debian.org/774090>.