2.4 Emacs and the Clipboard
Emacs 21 plays well with the clipboard, though it still may not do what you want it to in some cases. Let's dig into this in a little more detail.
2.4.1 Placing Text on the Clipboard
By default, text that you cut or copy using icons on the toolbar or options on the Edit menu is placed on the clipboard and is accessible to other applications.
Unfortunately, Emacs diverges by platform on this issue. Normally we save platform-specific issues for Chapter 13, but cutting and pasting is such a vital operation that we must describe the differences here.
On Windows and Mac OS X (but not on Linux) any text you cut or copy using C-w or M-w is also copied to the clipboard.
On Windows and Mac OS X, simply selecting text with the mouse places it on the clipboard. (This doesn't work on Linux.). Most applications require you to highlight text, then issue a copy command. Emacs doesn't. Table 2-6 shows how this works on various platforms.
Table 2-6. Selecting text with the mouse
Linux | Windows | Mac OS X graphical | Mac OS X terminal | |
---|---|---|---|---|
Sends to clipboard? | no | yes | yes | no[13] |
Sends to kill ring? | yes | yes | yes | no |
To send text to the clipboard on Linux, select it with the mouse (or mark it as a region), then click on the cut or copy toolbar icon or menu option. You can also use the clipboard-specific commands listed in Table 2-7 on any platform.
2.4.2 Retrieving Text from the Clipboard
As we mentioned, in other applications, you typically cut and paste by selecting text, then issuing a copy command. How do you then paste that text into Emacs?
Not surprisingly, the paste icon on the toolbar and the associated option on the Edit menu do this in most cases (see Table 2-7; Emacs on Mac OS X disables both the icon and the option inappropriately; the associated command name clipboard-yank works, however). C-y inserts text from the clipboard too. Additionally, an easy mouse gesture works on most platforms: simply click the middle mouse button or mouse wheel in the Emacs window to paste from the clipboard. The caveat here is that you must have a mouse with a middle button.
Table 2-7. Pasting from the clipboard
Linux | Windows | Mac OS X graphical | Mac OS X terminal | |
---|---|---|---|---|
C-y pastes? | yes | yes | yes | no[14] |
Toolbar paste icon pastes? | yes | yes | no | no |
Edit → Paste option pastes? | yes | yes | no | no |
Middle mouse button pastes? | yes | yes | yes | no |
M-x clipboard-yank pastes? | yes | yes | yes | no |
Another issue with cutting and pasting is encoding. Encoding is a complex topic in Emacs; full Unicode support is slated for Emacs 22. At this point, we can only point you to a variable that may help you resolve cut-and-paste related encoding issues: set-clipboard-coding-system.
If you're interested in the clipboard, you may want to change Emacs' keys for cutting and pasting to the more universal C-x, C-c, and C-v. See "Making Emacs Work the Way You Want" later in this chapter for more details.
13
You can make this happen if you highlight the text and then press xxxMacSymxxx-C. Simply highlighting the text doesn't copy it to the clipboard.