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.[6] 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 modeTo 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-c exits picture mode and returns you to whatever major mode you were in before. 7.6.1 Drawing in Picture ModeIn 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-4 illustrates the commands for setting various directions as the default in picture mode. Figure 7-4. Moving around in picture modePicture 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.[7]
7.6.2 Editing in Picture ModeBy 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. Therefore, to do justice to picture mode, we have to revisit most of the basic editing concepts. Please bear with us, or skip this section if you aren't interested in pictures. Let's start at the beginning: basic cursor motion. 7.6.2.1 Cursor motion in picture modePicture mode makes some small but important changes in the basic cursor commands. There's an easy way to summarize these changes: in picture mode the buffer becomes a grid of rows and columns. For example, consider what C-f does in most other modes: it moves forward through the file, one character at a time. Typing C-f repeatedly moves the cursor to the left, then at the end of the line, it jumps to the first character on the next line. picture mode, C-f means "move to the right." When you reach the end of the line in picture mode, C-f doesn't wrap to the next line; it continues adding characters to the current line. C-p and C-n become vertical "up" and "down" commands, respectively. Try editing some sample text, moving to the end of a line, and typing C-p. Normally, as you type C-p, the cursor stays at the end of the line; if the previous line is short, the cursor moves to the left when it goes up. In picture mode, C-p and C-n always move up (or down) in a straight line. You can get to every place you need to go with C-f, C-b, C-p, and C-n. The arrow keys work too, but you may want to know the cursor movement commands for moving in the default direction as well, so you can also go sideways when it's faster. C-c C-f moves you forward in the default direction (so "forward" here could mean to the left, right, up, or down, as well as all directions in between). C-c C-b moves you backward in the default direction. (Moving "up" or "down" relative to the default direction isn't defined.) For example, let's say you had drawn the house shown in Figure 7-1 and you wanted to move the cursor down the left side of the roof. You would set the default direction to "southwest" by typing C-c /. If the cursor were on the top shingle on the left side of the roof, typing C-c C-f would move you down the left side of the roof and typing C-f would move you to the top-right shingle, as shown in Figure 7-5. Figure 7-5. Using the default direction versus typical cursor movement commands7.6.2.2 Inserting blank linesAs you continue to work in picture mode, you'll find a few more surprises. Pressing Enter in picture mode moves you to the beginning of the next line, without inserting a blank line on the assumption that you probably don't want to change the relationship between lines. If you want to insert a new line, type C-o; an empty line appears beneath the current line, and the cursor does not move. For example, the cursor is initially on the 0 in the first line. If we want to open another line between the two, we type C-o.
One of the more difficult things to do in picture mode is to type a standard carriage return that breaks a line in the middle. You can move to a point in the middle of a line, type C-k to kill the right-hand portion, type C-o to insert a blank line; type Enter to move to the beginning of this blank line, and type C-y to yank the right-hand part of the line back. Or you can use the split-line command (C-M-o), and then delete the blank space at the beginning of the new line. Deletion isn't quite the same, either. In picture mode C-c C-d is the delete character command that you're used to: it deletes the character under the cursor and moves the rest of the line to the left. An unadorned C-d deletes the character under the cursor, replacing it with a space. Del deletes the character to the left of the cursor, replacing it with a space. Table 7-6 contrasts the picture mode commands with their normal text mode behavior.
If you want to insert a block of blank space, you can use a rectangle command such as open-rectangle. See the discussion of this command earlier in this chapter for more information. Also, if you want to insert blank space at the end of a line, you can use C-f. To perform some tasks, you may find it easier to switch back temporarily to the mode you're used to. C-c C-c moves you back to the mode you were in before you entered picture mode. Make any necessary changes, then enter picture mode again by typing M-x picture-mode. If you want to move something you've drawn, the easiest way is to use rectangles, as described earlier in this chapter. Tabs are also different in picture mode. By default, picture mode interprets the following characters as tab stops if they appear by themselves on a line: exclamation point (!), hyphen (-) and tilde (~). If these characters appear on a line and the user presses tab on the next line, these characters are presumed to denote tab stops. You can change this behavior by setting the variable picture-tab-chars to other characters. If the characters appear with normal text, they are not interpreted as tab stops. To use these characters as tab stops, press Esc-Tab (for picture-tab-search). Table 7-7 summarizes the commands for editing in picture mode.
7.6.3 Drawing with the Mouse Using ArtistWe would be remiss if we didn't introduce you to artist mode, an easy way to create ASCII art using the mouse. (You can also use keyboard commands, but trust us you won't want to.) Artist mode is a minor mode related to picture mode, so you use them together. For example, you might draw using artist mode, then edit the picture in picture mode. Or you might choose to use artist mode alone for your creations. We're going to give you a taste of artist mode; you can perfect your skills in your spare time. When you start artist mode, picture mode starts automatically.
When you start artist mode, pen drawing is selected by default.
With the pen, you can draw freestyle. Hold down the middle mouse button and a menu appears, with Drawing, Edit, and Settings submenus. The Drawing menu offers a variety of shapes from which to choose. Now that we've scribbled, let's create some graffiti using the spray can.
We aren't going to go deep into artist mode, but we would like to give you a flavor of the basic drawing choices. You can draw rectangles (our personal favorite), ellipses, lines (which strive to be straight), and poly-lines (which strive to be polygon-angular). Figure 7-5 shows a representative sample of shapes. With practice, you can create complex drawings and edit them, either using the mouse or using standard picture mode commands. Figure 7-6. A representative sample of artist shapesFor rectangles, lines, and ellipses, hold down the left mouse and pull them to the size and, in the case of lines, angle you prefer. (Ellipses are made of straight lines, so use your imagination; this is ASCII art after all.) For poly-lines, draw a line by holding down the left mouse button, then release it. Move the mouse away from that line to the next corner of the polygon and click. Emacs draws a line connecting the two points. Poly-lines allow you to create polygons quickly. Table 7-8 provides an overview of artist commands. Artist works very well with the mouse and the middle-button mouse menu; if you're mouse-averse, you'll prefer picture mode.
7.6.4 Problems You May Encounter
|