[gnu.emacs] X cutbuffer weirdness

jwz@lucid.com (Jamie Zawinski) (09/15/90)

I've been encountering some strange interactions between GNU Emacs and the X
server cutbuffer.  I am using some code which transfers text from Emacs to the
server cutbuffer with a form like (x-store-cut-buffer (buffer-substring ...
)).  This usually works - I can, for example, click middle in an Xterm and
have the text pasted there.  And also, the form (insert (x-get-cut-buffer))
will put the text back into emacs.

But every now and then, the text seems to go to a different place - say I copy
the form "FOO" from Emacs to the cut buffer; and then some time later, I copy
"BAR".  If I click middle in an Xterm, it pastes "FOO" instead of "BAR",
although pasting it into emacs (with x-get-cut-buffer) pastes "BAR".  Also,
sometimes clicking in one Xterm will paste "FOO" and clicking in another will
paste "BAR".  It is as if one of the Xterms is deciding that it should be
using a different cut buffer or something.

I'm not sure exactly what is the thing between copying "FOO" and "BAR" that
makes the behavior change, but I suspect it might have something to do with
copying or pasting large blocks of text.  Does it seem possible that something
like that could cause Emacs or an Xterm to use a different cut buffer?  Is
there a way to examine the contents of the various server cut buffers?  Any
suggestions would be appreciated.  Thanks,

		-- Jamie <jwz@lucid.com>

PS: Emacs 18.55, X11R4 patchlevel 11, Sun3.

jwz@lucid.com (Jamie Zawinski) (09/16/90)

The strange interaction between Emacs, Xterm, and the cut buffers is because
most Xterm clients use selections instead of (well, superceding) cut buffers.
If there is a selection around, Xterms will use that instead of the cut
buffer.  Emacs doesn't know about selections, but you can convince Xterm to
always use the cut buffer instead of selections by adding this to you
.Xdefaults: 

! emacs only copies to cut buffer 0.  xterm by default 
! wants to paste from the PRIMARY selection 
XTerm*VT100.Translations: #override ~Meta <Btn2Up>: insert-selection(CUT_BUFFER0)

This works under R3, and probably R4, but not R2.  Thanks to Thomas Narten for
the prizewinning answer.  He's going on to our bonus round where the scores
can really change. 

		-- Jamie