Thirty deletions by default is a nice size—far more generous than most programs offer. But you can enlarge or reduce the size of the kill ring if you wish, using a variable called kill-ring-max. To experiment, give the command: M-x set-variable Enter kill-ring-max Enter new-value Enter(where new-value is a number).
2.3.3 Selecting and Pasting
Using the menus, you can access text from the kill ring in a more straightforward way: by choosing Edit → Select and Paste. A menu showing deletions appears, with the most recent ones on top. To show you as many deletions as possible, each line in the window represents a separate deletion. So if you've killed a large region, say 500 lines, you see only the beginning of the first line of that deletion, ellipses, and the end of the deletion. Your selection is pasted into the buffer at the cursor position.
Table 2-5summarizes commands for working with regions.
Table 2-5. Commands for working with regions
Keystrokes |
Command name |
Action |
C-@or C- Space |
set-mark-command |
Mark the beginning (or end) of a region. |
C-x C-x |
exchange-point-and-mark |
Exchange location of cursor and mark. |
C-w |
kill-region |
Delete the region. |
C-y |
yank |
Paste most recently killed or copied text. |
M-w |
kill-ring-save |
Copy the region (so it can be pasted with C-y). |
M-h |
mark-paragraph |
Mark paragraph. |
C-x C-p |
mark-page |
Mark page. |
C-x h |
mark-whole-buffer |
Mark buffer. |
M-y |
yank-pop |
After C-y, pastes earlier deletion. |
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-wor M-wis 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-6shows 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-7on 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-yankworks, however). C-yinserts 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-ypastes? |
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-yankpastes? |
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.
Table 2-8summarizes clipboard-related commands.
Table 2-8. Clipboard commands
Keystrokes |
Command name |
Action |
(none) |
clipboard-kill-region |
Cut region and place both in kill ring and on system clipboard. |
(none) |
clipboard-yank |
Paste text from clipboard. |
(none) |
clipboard-kill-ring-save |
Copy text to clipboard. |
2.5 Editing Tricks and Shortcuts
Now that you've learned the basics of editing—moving the cursor to the right position, deleting, copying, and moving text—you can learn some tricks that make editing easier.
2.5.1 Fixing Transpositions
The most common typo involves the transposition of two letters, and most typos are noticed immediately after you make them. Pressing C-ttransposes two letters, to put them in the right order:
Before C-t |
After C-t |
the best of tims e, it |
the best of times _ it |
To transpose two letters, put the cursor on the second of the two letters to be transposed. Press C-t. (If you often transpose letters, word abbreviation mode, discussed in Chapter 3 Chapter 3. Search and Replace The commands we discussed in the first two chapters are enough to get you started, but they're certainly not enough to do any serious editing. If you're using Emacs for anything longer than a few paragraphs, you'll want the support this chapter describes. In this chapter, we cover the various ways that Emacs lets you search for and replace text. Emacs provides the traditional search and replace facilities you would expect in any editor; it also provides several important variants, including incremental searches, regular expression searches, and query-replace. We also cover spell-checking here, because it is a type of replacement (errors are sought and replaced with corrections). Finally, we cover word abbreviation mode; this feature is a type of automatic replacement that can be a real timesaver.
, cleans up typos automatically.)
Читать дальше