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-xto cut and C-vto 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-xor C-vrespectively. 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.
7.6 Making Simple Drawings
Emacs is not, by any means, a graphics package, but it does provide some limited drawing capabilities. Emacs includes a picture mode that allows you to draw simple pictures using keyboard characters; it also includes artist mode, which enables you to draw quickly using the mouse.
Why would you want to draw with Emacs? Well, Emacs is useful for inserting a quick drawing or diagram in a mail message, something that most graphics packages can't do. It's also good for making block diagrams, timing diagrams (for electrical engineers), timelines, and other simple drawings.
Don't overlook this simple facility! We have seen many papers that were carefully formatted with a simple star-and-bar diagram dropped in the middle. Sure, you can use a graphics package to create a much nicer drawing, but if that's not your area of expertise, an Emacs ASCII drawing might be just the ticket. [40]We discuss picture mode first and then artist mode.
Picture mode turns the area being edited into a kind of drawing board consisting of columns and rows. In picture mode, you can create simple pictures (such as the one in Figure 7-3) using keyboard characters without having them "rearranged" by the word-wrap capabilities of auto-fill mode, for example.
Figure 7-3. Drawing in picture mode
To enter picture mode, type M-x edit-picture. The word Picture
appears on the mode line, followed by the default drawing direction (more on that shortly). Typing C-c C-cexits picture mode and returns you to whatever major mode you were in before.
7.6.1 Drawing in Picture Mode
In picture mode, you can "draw" with any character in any of eight directions. Although you can draw in eight directions, only one direction is available at a time; this direction is referred to as the default direction . When you first enter picture mode, the default direction is right, meaning that if you press the hyphen key four times, you would draw a line to the right, as follows: ——
. The default direction is displayed on the mode line, like this:
(Picture: right)
By typing special commands that change the default direction, you can draw in seven other directions as well. For example, C-c \makes the default direction "southeast;" the mode line would then read (Picture: se)
. If you typed four hyphens in this direction, they would look like stair steps:
-
-
-
-
Figure 7-4illustrates the commands for setting various directions as the default in picture mode.
Figure 7-4. Moving around in picture mode
Picture mode tries to make these commands easy to remember, and it doesn't do too badly: for example, C-c ^points upward, C-c-`arguably points to the northwest, and so on. If you can come up with a good mnemonic device for C-c. let us know! Maybe you can think of it as "dot for down."
After you set a default direction, pressing any character repeatedly draws a line of characters in that direction. Give it a try in a scratch buffer, using the commands in the figure to change the default direction. Try drawing a box. [41]
Type: M-x picture-mode

Putting the buffer into picture mode, default direction "right."
Type: Tab M-20 -

Emacs draws a line to the right. Next, we'll change the default direction to down, and use |for the right side of the square.
Type: C-c . M-5 |

Emacs draws a line down. Now we'll set the default direction to "left," then draw the bottom of the square.
Type: C-c < M-20 -

Emacs draws a line to the left. Next, use C-c ^to set the default direction to "up," and then draw vertical bars back to the starting point.
Type: C-c ^ M-5 |

Emacs draws a line up that completes the box.
7.6.2 Editing in Picture Mode
By now, you should have a basic understanding of what picture mode can do for you. It's one of the more complicated minor modes because it redefines what many of the major editing keys do—and with good reason. The editing techniques you use for most ASCII files just won't work well for pictures. You don't really want to insert characters; the standard insert mode would prevent you from editing effectively, because any character you type distorts the rest of the line. Therefore, picture mode implicitly changes to overwrite mode. Many other features are redefined—some in insignificant ways, others in more substantial ways.
Читать дальше