emacs problem

Joe Smith jes at martnet.com
Tue Apr 3 02:26:42 UTC 2007


François Patte wrote:
> ...
> 1- Clipboard: it seems that there is a specific clipboard for Emacs
> under Fedora/Gnome; I am unable to copy something from any other
> application and paste it in emacs. It is always the last thing
> copied/cut *in* emacs which is pasted in emacs whatever you could have
> selected and copied in other windows (say: terminal, acroread...)
> ...

I am by no means an expert here, but I will try to explain what I know.

Right off the top, people see different behavior with emacs because (a) 
the default behavior is unusual and awkward for new users, and 
(therefore, b) emacs is often customized. I'm not sure what 
configuration Fedora ships with anymore, I've fiddled with mine so much.

The first problem is that emacs is an old-style X application, and X 
clipboard usage has evolved since emacs design was adopted. The status 
quo for X on Linux now is that there are actually TWO clipboards, as you 
experienced. One supports the old X usage, one supports the newer, 
Windows-style "CUA" clipboard. Most newer GUI apps also support both, 
but the interface hides the old-style, whereas in emacs, the old-style 
clipboard is the "normal" emacs UI.

The old-style clipboard works like this: as soon as you select text with 
the mouse in any X application, the text is available for pasting using 
the middle mouse button. No keys to press at all, but it only holds one 
item and if you select something else, the previous clipboard contents 
are replaced. This selection/clipboard is named PRIMARY. It works 
perfectly well for using the mouse to copy and paste text within emacs 
as well.

Emacs also has it's own "clipboard" independent of X, which is called 
the "kill-ring" it holds a bunch (configurable; mine is 60) of items. 
Many editing operations in emacs automatically copy text to the 
kill-ring; the top item can be retrieved with Ctrl-Y ("yank").

All the recent emacs installs that I've seen configure emacs to make the 
top item in the kill-ring _equivalent to the X selection PRIMARY_. Thus, 
whatever you can yank in emacs, you can also paste into any X app using 
the middle mouse button, and whatever you select in another X 
application, emacs will put that on the kill-ring.

The new-style X clipboard is the one that all newer apps connect to 
Ctrl+C/X/V. This is named CLIPBOARD, and it also holds only one item, 
but it is filled only when you issue a copy or cut request. The two 
buffers, PRIMARY and CLIPBOARD, are completely independent and you can 
have two different things "in the clipboard" at the same time: one 
(PRIMARY) pasted by the middle mouse button, and one pasted by Ctrl+V 
(CLIPBOARD).

Emacs can also use CLIPBOARD, but by default (AFAIK) there is no 
interactive interface, i.e. Ctrl+C/X/V do not do have anything to do 
with the clipboard in emacs. The emacs functions for accessing CLIPBOARD 
are:

clipboard-yank           ;; paste CLIPBOARD, like Ctrl+V
clipboard-kill-ring-save ;; copy the top kill-ring item to CLIPBOARD
clipboard-kill-region    ;; kill text in region and copy to CLIPBOARD

These functions can be run (like any emacs function) by M-x 
function-name; they may or may not be bound to some key (e.g. a function 
key) or mouse button, depending on your configuration. If you run them 
by name, emacs will tell you what altenate key bindings exist--watch the 
minibuffer at the bottom.

There is a package called "cua.el" that provides more "normal" key 
bindings for these, but I prefer to stick to the emacs standard 
bindings. There is another configurable setting that automatically 
copies items to CLIPBOARD as well as PRIMARY, but again, I prefer to 
just keep them separate.

There you go, FMTYEWTK.

If you're just a glutton for punishment, you can read more about the X 
clipboard here:
http://standards.freedesktop.org/clipboards-spec/clipboards-0.1.txt

and about emacs and the clipboard here:
http://www.jwz.org/doc/x-cut-and-paste.html

<Joe




More information about the fedora-list mailing list