views:

5747

answers:

9

When I yank text in Emacs 22.1.1 (in its own window on X, in KDE, on Kubuntu), I can't paste it anywhere else. I'm reduced to opening kate to copy the text with ^C. Is there a better way?

A: 

Hmm, what platform and what version of emacs are you using? With GNU Emacs 22.1.1 on Windows Vista, it works fine for me.

If, by any chance, you are doing this from windows to linux through a RealVNC viewer, make sure you are running "vncconfig -iconic" on the linux box first.....

kfh
A: 

What I do is to use a good terminal tool (PuTTY on Windows, Konsole or Terminal on Linux) that has copy facilities built-in.

In PuTTY, you highlight the text you want with the mouse and then paste it elsewhere. Right-clicking in a PuTTY window pastes the contents of the Windows copy/paste buffer.

In Konsole or Terminal on Linux, you highlight what you want then press Shift+Ctrl+C for copy and Shift+Ctrl+V for paste.

In the win32 compile of emacs, yanking text does put it on the copy/paste buffer .. most of the time.

On Mac OS X, the Apple-key chortcuts work fine, because Terminal traps them.

There is no direct way of doing it on the commandline because the shell does not maintain a copy/paste buffer for each application. bash does maintain a copy/paste buffer for itself, and, by default, emacs ^k/^y shortcuts work.

warren
A: 

I always use quick paste -- drag selection in emacs, hit the middle mouse button in target window.

(From the reference to kate, I take it you're on linux or similar and probably using emacs in X one way or another.)

A: 

You might want to specify what platform you are using. Is it on linux, unix, macosx, windows, ms-dos?

I believe that for windows it should work. For MacOSX it will get added to the x-windows clipboard, which isn't the same thing as the macosx clipboard. For Linux, it depends on your flavour of window manager, but I believe that x-windows handles it in a nice way on most of them.

So, please specify.

Mats Fredriksson
+3  A: 

This EmacsWiki article explains some issues with copy & pasting under X and how to configure it to work.

cschol
+3  A: 

I assume by emacs you are meaning Emacs under X (ie not inside a terminal window).

There are two ways:

  1. (Applies to unix OS's only) Highlight the desired text with your mouse (this copies it to the X clipboard) and then middle click to paste.
  2. Highlight the desired text and then "M-x clipboard-kill-ring-save" (note you can bind this to an easier key). Then just "Edit->Paste" in your favorite app.

Clipboard operations available:

  • clipboard-kill-ring-save -- copy selection from Emacs to clipboard
  • clipboard-kill-region -- cut selection from Emacs to clipboard
  • clipboard-yank -- paste from clipboard to Emacs
pdq
+1  A: 

Insert the following into your .emacs file:

(setq x-select-enable-clipboard t)

Best answer in the thread and no upvotes...
Tomasz Zielinski
+23  A: 

Let's be careful with our definitions here

  • An Emacs copy is the command kill-ring-save (usually bound to META-W).
  • A system copy is what you typically get from pressing CTRL-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 CTRL-Y).
  • A system paste is what you typically get from pressing CTRL-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.

Chris Conway
+1  A: 

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 e with the cursor just after the close paren of each of those expressions in the .emacs buffer.

Good luck!

jfm3