You have enabled both x-select-enable-clipboard
defaulting to t
and x-select-enable-primary
which you have set to t
. Therefore, the value of the clipboard and that one of the primary selection are put both onto the kill ring in that order both requested from X11 in function x-selection-value
.
The clipboard wins since the return value of x-selection-value
is
(or clip-text primary-text)
with the obvious meaning of the variables. But, if the text of the clipboard remains the same in two successive calls of x-selection-value
then clip-text
is set to nil. The last value of clip-text
is stored in x-last-selected-text-clipboard
. The start value of x-last-selected-text-clipboard
is nil.
Therefore, the first time you call x-selection-value
(indirectly through yank) you get the value of the clipboard even if you have set the primary selection with the mouse in emacs.
If you remain in emacs afterwards it even does not matter what is used -- the clipboard or the primary selection. You get the copied text. But, if you copy some text to the clipboard in an external application then your next yank in emacs is this text even if you mouse-select something else in emacs. Again, the clipboard wins over the primary selection.
Setting
(setq x-select-enable-clipboard nil)
would solve your problem.
If you want to get copied text from some application which only sets the clipboard then the above method is not appropriate.
Maybe, a better alternative would be in this case to age the clipboard when text is selected with the mouse:
(defadvice mouse-set-region (before age-x-clipboard activate)
(when (and x-select-enable-clipboard x-select-enable-primary)
(let (x-select-enable-primary) ;; Do not touch primary selection.
(x-selection-value))))
I thought that your actual problem would be the mix of two different copy-paste methods. You want to copy per primary selection (pure mouse selection method) and you want to paste via the clipboard (copy-yank via keyboard).
But, meanwhile I noticed that firefox puts everything also onto the primary selection.
The above workaround works as long as all programs you use put the stuff copied with C-c also on the primary.