O'Reilly Network    

 Published on The O'Reilly Network (http://www.oreillynet.com/)
 http://www.oreillynet.com/pub/wlg/6162

Quick tip for Linux users having trouble with Emacs (or XEmacs) copy/paste

by Uche Ogbuji
Jan. 6, 2005
URL: http://www.emacswiki.org/cgi-bin/wiki/CopyAndPaste

The above link probably has enough information in disjointed form for you to cobble together a working solution for you, but in a nutshell what worked for me with GNU Emacs 21.3-17 in Fedora Core 3 was adding the following to my .emacs::

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

Why these settings aren't the default on Linux completely bewilders me. How does anyone conceive that the average user will not want reliable cut and paste between their editor and other apps? Certainly most users will not be willing or able to go through what I did to get this sorted out.

The problem that I was seeing was that sometimes middle mouse click would work for cut and paste, and sometimes it wouldn't. It was very erratic, even within the same emacs session. Every now and then using keyboard rather than mouse, or using menu, or some other random variation would seem to help ephemerally. I've seen numerous reports from other users with this same problem on emacs lists and elsewhere, and I almost invariably see either no response, or some comment from from emacs gurus completely discounting the poor user's problems. Clearly this is a widespread problem that needs some attention in the Emacs communities.

I had never been able to use the typical GNOME clipboard operations at all in the past (e.g. yank from emacs then Ctrl-V to Firefox/Mozilla/Gedit or Shift-Ctrl-V to gnome-terminal). I've similar reports from KDE users.

With the above lines in my .emacs, cut/copy/paste now seems reliable with middle mouse, and I can indeed use GNOME clipboard ops as expected in GNU Emacs. In XEmacs (21.4.15) paste to XEmacs works fine from clipboard, though explicit clipboard events do not seem to work from XEmacs to other apps. Middle mouse click does work better, so that's good enough for me. Besides, I've migrated from XEmacs to GNU Emacs because XEmacs does not support nXML, James Clark's superlative XML mode. If you do use XEmacs the top link includes some suggested variations for XEmacs users.

Overall, I hope that XEmacs, GNU Emacs and their various distributors work out the kinks so that such a simple matter as cut and paste is not a matter of medieval alchemical incantations. Until then, I hope my notes are of help to someone else.

Uche Ogbuji is a Partner at Zepheira, LLC, a solutions firm specializing in the next generation of Web technologies.

oreillynet.com Copyright © 2006 O'Reilly Media, Inc.