Move to the space following the last phone number and type: C-x r c
The clear-rectangle command removes the "Cell Phone" column and leaves a blank space in its place.
As you can see, the spacing of our table still isn't perfect; you'd probably want to use the delete-rectangle command[39] to delete the extra space between the second and the third columns. To delete the blank space without storing it, start by moving the cursor to the space following the longest email address and press C-Space to set the mark, then move to the opposite corner of the box you want to delete and type C-x r d.
On the header line, move to the column after the longest email address and press C-Space
The upper-left corner of the rectangle to be deleted is marked.
Move a few spaces before 6:00 on the last line and type C-x r d
The delete-rectangle command deletes the blank space.
If you're doing some really fancy table editing, being able to store several rectangles is helpful. That way, you can have every column as a rectangle, as well as having a rectangle for the exact amount of blank space to put between each column. You can store rectangles in registers by typing C-x r r r where r is any alphanumeric character, including punctuation. To insert a rectangle you've stored, type C-x r i r. Registers don't persist between sessions.
Table 7-5 lists rectangle commands.
Table 7-5. Rectangle commands
| Keystrokes | Command name | Action |
|---|---|---|
| C-x r k | kill-rectangle | Delete a rectangle and store it. |
| C-x r d | delete-rectangle | Delete a rectangle and do not store it. |
| C-x r y | yank-rectangle | Insert the last rectangle killed. |
| C-x r c | clear-rectangle | Using spaces, blank out the area marked as a rectangle and do not store it. |
| C-x r o | open-rectangle | Insert a blank rectangle in the area marked. |
| C-x r r r | copy-rectangle-to-register | Copy rectangle to register r (where r is any character) . |
| C-x r i r | insert-register | Insert rectangle from register r (where r is any character). |
| (none) | delete-whitespace-rectangle | If a rectangle includes initial whitespace, deletes it, narrowing rectangle. |
| C-x r t string Enter | string-rectangle | Change contents of marked rectangle to string (if string is narrower or wider than rectangle, dimensions change accordingly). |
| (none) | string-insert-rectangle | Prompts for string and inserts rectangle. |
7.5.1 CUA Rectangle Editing
If you are familiar with CUA mode, which is part of Emacs starting with 21.3.5, you may know that it provides cut and paste key sequences familiar to Windows users, as in C-x to cut and C-v to paste (see Chapter 13). The second most commonly touted feature of CUA mode is its superior rectangle support.
We've just looked at a myriad of rectangle commands. CUA's rectangle support is far simpler. By learning essentially one command, you can cut and paste rectangles in CUA mode.
Unfortunately at present, CUA mode support is standard but not nuanced on Emacs 21.3.5. You either take the whole enchilada or you don't. To turn it on, select C-x/C-c/C-v cut and paste (CUA) from the Options menu. If you don't generally like to use the CUA keybindings for cut and paste, you might turn this option on only when you are doing rectangle editing.
To select a rectangle, type Shift-Enter. Emacs starts to highlight in a dark pink color by default. You extend the highlighting with normal cursor movement keys (the mouse does not work at present).
Move to the C in Cell and type: Shift-Enter
The upper-left corner of our rectangle is marked (Windows).
The minibuffer displays an array of CUA mode rectangle commands. For now, we'll just mark the rectangle and experiment with one of these commands momentarily.
Move the cursor to the last number in Alvin's phone number.
The rectangle is marked (Windows).
Note that the marked rectangle isn't strictly rectangular in shape. The phone numbers form a true rectangle, but in order to create a rectangle that includes the column header, we need to ask CUA mode to "pad" the rectangle using M-p, one of the commands listed in the minibuffer earlier.
Type: M-p
The pad command makes this a true rectangle (Windows).
We can now cut or paste the rectangle using C-x or C-v respectively. This is just a taste of the CUA mode rectangle commands. You can explore more of them on your own. We thought you should be aware of this method as an alternative to the more keyboard-intensive rectangle commands that have been part of Emacs for many years.
39
Like all Emacs delete commands, delete-rectangle doesn't store what you delete in the kill ring.