Next: Secondary Selection, Previous: Word and Line Mouse, Up: Cut and Paste
When running Emacs under the X window system, you can easily transfer text between Emacs and other X applications using the primary selection (also called the X selection). This is not the same thing as the clipboard, which is a separate facility used on desktop environments such as Gnome, and on operating systems such as Microsoft Windows (see Clipboard).
Under X, whenever you select some text in Emacs by dragging or clicking the mouse (see Mouse Commands), it is also saved in the primary selection. You can then paste that text into any other X application, usually by clicking Mouse-2 in that application. Unlike the Emacs kill ring (see Kill Ring), the primary selection has no “memory”: each time you save something in the primary selection, either in Emacs or in another X application, the previous contents of the primary selection are lost.
Whenever you kill some text using a command such as C-w
(kill-region), or copy it into the kill ring using a command
such as M-w (kill-ring-save), that text is also saved in
the primary selection. See Killing.
Whenever Emacs saves some text to the primary selection, it may also
save it to the cut buffer. The cut buffer is an obsolete
predecessor to the primary selection; most modern applications do not
make use of it. Because saving text to the cut buffer is slow and
inefficient, Emacs only does it if the text is shorter than the value
of x-cut-buffer-max (the default is 20000 characters).
You can yank the primary selection into Emacs using the usual yank
commands, such as C-y (yank) and Mouse-2
(mouse-yank-at-click). These commands actually check the
primary selection before referring to the kill ring; if no primary
selection is available, the kill ring contents are used. To prevent
yank commands from accessing the primary selection, set the variable
x-select-enable-primary to nil.
The standard coding system for the primary selection is
compound-text-with-extensions. You may find that the pasted
text is not what you expected. In such a case, you can specify
another coding system for the selection by typing C-x <RET>
x or C-x <RET> X. Alternatively, you can request a
different data type by modifying the variable
x-select-request-type. See Communication Coding.