How to copy text from Emacs to another application on Linux

When I cut (kill) text in Emacs 22.1.1 (in its own window on X, in KDE, on Kubuntu), I can't paste (yank) it in any other application.


Let's be careful with our definitions here

  • An Emacs copy is the command kill-ring-save (usually bound to M-w).
  • A system copy is what you typically get from pressing C-c (or choosing "Edit->Copy" in a application window).
  • An X copy is "physically" highlighting text with the mouse cursor.
  • An Emacs paste is the command yank (usually bound to C-y).
  • A system paste is what you typically get from pressing C-v (or choosing "Edit-Paste" in an application window).
  • An X paste is pressing the "center mouse button" (simulated by pressing the left and right mouse buttons together).

In my case (on GNOME):

  • Both Emacs and system copy usually work with X paste.
  • X copy usually works with Emacs paste.
  • To make system copy work with Emacs paste and Emacs copy work with system paste, you need to add (setq x-select-enable-clipboard t) to your .emacs. Or try

    META-X set-variable RET x-select-enable-clipboard RET t
    

I think this is pretty standard modern Unix behavior.

It's also important to note (though you say you're using Emacs in a separate window) that when Emacs is running in a console, it is completely divorced from the system and X clipboards: cut and paste in that case is mediated by the terminal. For example, "Edit->Paste" in your terminal window should act exactly as if you typed the text from the clipboard into the Emacs buffer.


Insert the following into your .emacs file:

(setq x-select-enable-clipboard t)

I stick this in my .emacs:

(setq x-select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)

I subsequently have basically no problems cutting and pasting back and forth from anything in Emacs to any other X11 or Gnome application.

Bonus: to get these things to happen in Emacs without having to reload your whole .emacs, do C-x C-e with the cursor just after the close paren of each of those expressions in the .emacs buffer.

Good luck!