Subject: bug#28631: 25.3.50; Deactivate mark with Ctrl-g mess up the primary-selection

From: Tino Calancha <[email-masked]>
Date: Thu, 12 Oct 2017 11:53:47 +0900

Noam Postavsky <[email-masked]> writes:
Thank you very much for the comments.  I have updated
the patch following your suggestion (see below).

>> To reproduce the problem:
>> emacs  -Q -eval '(winner-mode 1)' \
>> -eval "(customize-set-variable 'select-enable-clipboard nil)" \
>> -eval "(customize-set-variable 'select-enable-primary t)"
>>
>> < C-TAB M-f M-f ; `yank' would insert ";; This buffer"
>
> That should be 'M-< C-SPC M-f M-f' I guess.
Absolutely.

>> C-x C-b C-x 0
> C-x o, not C-x 0.
I think is OK.  After C-x C-b you are in *scratch* buffer and the window
is splited horizontally.  C-x 0 brings you at *Buffer List*.

>> I don't see a good reason why visiting a buffer with `C-x b' or
>> `winner-undo' makes a difference in the primary selection.
>
> It's because winner-undo tries to restore marks.
I see, thank you.

>
>> How about the following patch?
>>
>>     Set mark at point after keyboard-quit
>>     
>>     * lisp/simple.el (deactivate-mark): In transient-mark-mode
>>     always set the mark at point after keyboard-quit (Bug#28631).
>
> That seems quite disruptive.  Perhaps instead deactivate-mark could be
> changed so that it would not update the selection on winner-undo?
Yeah, my patch is kinda of lazy.  What you are suggesting sounds better.
Following one works to me

--8<-----------------------------cut here---------------start------------->8---
commit 6e4e47062daf54923928f6db096d4578bcecd6e2
Author: Tino Calancha <[email-masked]>
Date:   Thu Oct 12 11:41:44 2017 +0900

    Dont update primary selection with winner-undo
    
    * lisp/simple.el (deactivate-mark):
    Dont update primary selection if deactivate-mark is
    called by winner-undo (Bug#28631).

diff --git a/lisp/simple.el b/lisp/simple.el
index 5ef511ce0a..faedad4675 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5332,6 +5332,8 @@ deactivate-mark
 	     (if (gui-backend-selection-owner-p 'PRIMARY)
 		 (gui-set-selection 'PRIMARY saved-region-selection))
 	     (setq saved-region-selection nil))
+            ;; `winner-undo' shouldn't update the selection (Bug#28631).
+            ((eq this-command 'winner-undo) nil)
 	    ;; If another program has acquired the selection, region
 	    ;; deactivation should not clobber it (Bug#11772).
 	    ((and (/= (region-beginning) (region-end))

--8<-----------------------------cut here---------------end--------------->8---

In GNU Emacs 27.0.50 (build 14, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-10-12
Repository revision: 349c1f93021e49c63f076b602d3d228324105fd6