1 @c This is part of the Emacs manual.
2 @c Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions.
5 @c This file is included either in emacs-xtra.texi (when producing the
6 @c printed version) or in the main Emacs manual (for the on-line version).
8 @chapter Editing Pictures
10 @cindex making pictures out of text characters
13 To edit a picture made out of text characters (for example, a picture
14 of the division of a register into fields, as a comment in a program),
15 use the command @kbd{M-x edit-picture} to enter Picture mode.
17 In Picture mode, editing is based on the @dfn{quarter-plane} model of
18 text, according to which the text characters lie studded on an area that
19 stretches infinitely far to the right and downward. The concept of the end
20 of a line does not exist in this model; the most you can say is where the
21 last nonblank character on the line is found.
23 Of course, Emacs really always considers text as a sequence of
24 characters, and lines really do have ends. But Picture mode replaces
25 the most frequently-used commands with variants that simulate the
26 quarter-plane model of text. They do this by inserting spaces or by
27 converting tabs to spaces.
29 Most of the basic editing commands of Emacs are redefined by Picture mode
30 to do essentially the same thing but in a quarter-plane way. In addition,
31 Picture mode defines various keys starting with the @kbd{C-c} prefix to
32 run special picture editing commands.
34 One of these keys, @kbd{C-c C-c}, is particularly important. Often a
35 picture is part of a larger file that is usually edited in some other
36 major mode. @kbd{M-x edit-picture} records the name of the previous
37 major mode so you can use the @kbd{C-c C-c} command
38 (@code{picture-mode-exit}) later to go back to that mode. @kbd{C-c C-c}
39 also deletes spaces from the ends of lines, unless given a numeric
42 The special commands of Picture mode all work in other modes (provided
43 the @file{picture} library is loaded), but are not bound to keys except
44 in Picture mode. The descriptions below talk of moving ``one column''
45 and so on, but all the picture mode commands handle numeric arguments as
46 their normal equivalents do.
48 @vindex picture-mode-hook
49 Turning on Picture mode runs the hook @code{picture-mode-hook}.
50 Additional extensions to Picture mode can be found in
54 * Basic Picture:: Basic concepts and simple commands of Picture Mode.
55 * Insert in Picture:: Controlling direction of cursor motion
56 after "self-inserting" characters.
57 * Tabs in Picture:: Various features for tab stops and indentation.
58 * Rectangles in Picture:: Clearing and superimposing rectangles.
62 @section Basic Editing in Picture Mode
64 @findex picture-forward-column
65 @findex picture-backward-column
66 @findex picture-move-down
67 @findex picture-move-up
68 @cindex editing in Picture mode
70 Most keys do the same thing in Picture mode that they usually do, but
71 do it in a quarter-plane style. For example, @kbd{C-f} is rebound to
72 run @code{picture-forward-column}, a command which moves point one
73 column to the right, inserting a space if necessary so that the actual
74 end of the line makes no difference. @kbd{C-b} is rebound to run
75 @code{picture-backward-column}, which always moves point left one
76 column, converting a tab to multiple spaces if necessary. @kbd{C-n} and
77 @kbd{C-p} are rebound to run @code{picture-move-down} and
78 @code{picture-move-up}, which can either insert spaces or convert tabs
79 as necessary to make sure that point stays in exactly the same column.
80 @kbd{C-e} runs @code{picture-end-of-line}, which moves to after the last
81 nonblank character on the line. There is no need to change @kbd{C-a},
82 as the choice of screen model does not affect beginnings of
85 @findex picture-newline
86 Insertion of text is adapted to the quarter-plane screen model
87 through the use of Overwrite mode
89 (@pxref{Minor Modes,,, emacs, the Emacs Manual}.)
92 (@pxref{Minor Modes}.)
94 Self-inserting characters replace existing text, column by column,
95 rather than pushing existing text to the right. @key{RET} runs
96 @code{picture-newline}, which just moves to the beginning of the
97 following line so that new text will replace that line.
99 @findex picture-backward-clear-column
100 @findex picture-clear-column
101 @findex picture-clear-line
102 In Picture mode, the commands that normally delete or kill text,
103 instead erase text (replacing it with spaces). @key{DEL}
104 (@code{picture-backward-clear-column}) replaces the preceding
105 character with a space rather than removing it; this moves point
106 backwards. @kbd{C-d} (@code{picture-clear-column}) replaces the next
107 character or characters with spaces, but does not move point. (If you
108 want to clear characters to spaces and move forward over them, use
109 @key{SPC}.) @kbd{C-k} (@code{picture-clear-line}) really kills the
110 contents of lines, but does not delete the newlines from the buffer.
112 @findex picture-open-line
113 To do actual insertion, you must use special commands. @kbd{C-o}
114 (@code{picture-open-line}) creates a blank line after the current
115 line; it never splits a line. @kbd{C-M-o} (@code{split-line}) makes
116 sense in Picture mode, so it is not changed. @kbd{C-j}
117 (@code{picture-duplicate-line}) inserts another line with the same
118 contents below the current line.
120 @kindex C-c C-d @r{(Picture mode)}
121 To do actual deletion in Picture mode, use @kbd{C-w}, @kbd{C-c C-d}
122 (which is defined as @code{delete-char}, as @kbd{C-d} is in other
123 modes), or one of the picture rectangle commands (@pxref{Rectangles in
126 @node Insert in Picture
127 @section Controlling Motion after Insert
129 @findex picture-movement-up
130 @findex picture-movement-down
131 @findex picture-movement-left
132 @findex picture-movement-right
133 @findex picture-movement-nw
134 @findex picture-movement-ne
135 @findex picture-movement-sw
136 @findex picture-movement-se
137 @kindex C-c < @r{(Picture mode)}
138 @kindex C-c > @r{(Picture mode)}
139 @kindex C-c ^ @r{(Picture mode)}
140 @kindex C-c . @r{(Picture mode)}
141 @kindex C-c ` @r{(Picture mode)}
142 @kindex C-c ' @r{(Picture mode)}
143 @kindex C-c / @r{(Picture mode)}
144 @kindex C-c \ @r{(Picture mode)}
145 Since ``self-inserting'' characters in Picture mode overwrite and move
146 point, there is no essential restriction on how point should be moved.
147 Normally point moves right, but you can specify any of the eight
148 orthogonal or diagonal directions for motion after a ``self-inserting''
149 character. This is useful for drawing lines in the buffer.
153 @itemx C-c @key{LEFT}
154 Move left after insertion (@code{picture-movement-left}).
156 @itemx C-c @key{RIGHT}
157 Move right after insertion (@code{picture-movement-right}).
160 Move up after insertion (@code{picture-movement-up}).
162 @itemx C-c @key{DOWN}
163 Move down after insertion (@code{picture-movement-down}).
165 @itemx C-c @key{HOME}
166 Move up and left (``northwest'') after insertion (@code{picture-movement-nw}).
168 @itemx C-c @key{PAGEUP}
169 Move up and right (``northeast'') after insertion
170 (@code{picture-movement-ne}).
173 Move down and left (``southwest'') after insertion
174 @*(@code{picture-movement-sw}).
176 @itemx C-c @key{PAGEDOWN}
177 Move down and right (``southeast'') after insertion
178 @*(@code{picture-movement-se}).
181 @kindex C-c C-f @r{(Picture mode)}
182 @kindex C-c C-b @r{(Picture mode)}
183 @findex picture-motion
184 @findex picture-motion-reverse
185 Two motion commands move based on the current Picture insertion
186 direction. The command @kbd{C-c C-f} (@code{picture-motion}) moves in the
187 same direction as motion after ``insertion'' currently does, while @kbd{C-c
188 C-b} (@code{picture-motion-reverse}) moves in the opposite direction.
190 @node Tabs in Picture
191 @section Picture Mode Tabs
193 @kindex M-TAB @r{(Picture mode)}
194 @findex picture-tab-search
195 @vindex picture-tab-chars
196 Two kinds of tab-like action are provided in Picture mode. Use
197 @kbd{M-@key{TAB}} (@code{picture-tab-search}) for context-based tabbing.
198 With no argument, it moves to a point underneath the next
199 ``interesting'' character that follows whitespace in the previous
200 nonblank line. ``Next'' here means ``appearing at a horizontal position
201 greater than the one point starts out at.'' With an argument, as in
202 @kbd{C-u M-@key{TAB}}, this command moves to the next such interesting
203 character in the current line. @kbd{M-@key{TAB}} does not change the
204 text; it only moves point. ``Interesting'' characters are defined by
205 the variable @code{picture-tab-chars}, which should define a set of
206 characters. The syntax for this variable is like the syntax used inside
207 of @samp{[@dots{}]} in a regular expression---but without the @samp{[}
208 and the @samp{]}. Its default value is @code{"!-~"}.
211 @key{TAB} itself runs @code{picture-tab}, which operates based on the
212 current tab stop settings; it is the Picture mode equivalent of
213 @code{tab-to-tab-stop}. Normally it just moves point, but with a numeric
214 argument it clears the text that it moves over.
216 @kindex C-c TAB @r{(Picture mode)}
217 @findex picture-set-tab-stops
218 The context-based and tab-stop-based forms of tabbing are brought
219 together by the command @kbd{C-c @key{TAB}} (@code{picture-set-tab-stops}).
220 This command sets the tab stops to the positions which @kbd{M-@key{TAB}}
221 would consider significant in the current line. The use of this command,
222 together with @key{TAB}, can get the effect of context-based tabbing. But
223 @kbd{M-@key{TAB}} is more convenient in the cases where it is sufficient.
225 It may be convenient to prevent use of actual tab characters in
226 pictures. For example, this prevents @kbd{C-x @key{TAB}} from messing
227 up the picture. You can do this by setting the variable
228 @code{indent-tabs-mode} to @code{nil}.
230 @node Rectangles in Picture
231 @section Picture Mode Rectangle Commands
232 @cindex rectangles and Picture mode
233 @cindex Picture mode and rectangles
235 Picture mode defines commands for working on rectangular pieces of
236 the text in ways that fit with the quarter-plane model. The standard
237 rectangle commands may also be useful.
239 @xref{Rectangles,,, emacs, the Emacs Manual}.
247 Clear out the region-rectangle with spaces
248 (@code{picture-clear-rectangle}). With argument, delete the text.
249 @item C-c C-w @var{r}
250 Similar, but save rectangle contents in register @var{r} first
251 (@code{picture-clear-rectangle-to-register}).
253 Copy last killed rectangle into the buffer by overwriting, with upper
254 left corner at point (@code{picture-yank-rectangle}). With argument,
256 @item C-c C-x @var{r}
257 Similar, but use the rectangle in register @var{r}
258 (@code{picture-yank-rectangle-from-register}).
261 @kindex C-c C-k @r{(Picture mode)}
262 @kindex C-c C-w @r{(Picture mode)}
263 @findex picture-clear-rectangle
264 @findex picture-clear-rectangle-to-register
265 The picture rectangle commands @kbd{C-c C-k}
266 (@code{picture-clear-rectangle}) and @kbd{C-c C-w}
267 (@code{picture-clear-rectangle-to-register}) differ from the standard
268 rectangle commands in that they normally clear the rectangle instead of
269 deleting it; this is analogous with the way @kbd{C-d} is changed in Picture
272 However, deletion of rectangles can be useful in Picture mode, so
273 these commands delete the rectangle if given a numeric argument.
274 @kbd{C-c C-k} either with or without a numeric argument saves the
275 rectangle for @kbd{C-c C-y}.
277 @kindex C-c C-y @r{(Picture mode)}
278 @kindex C-c C-x @r{(Picture mode)}
279 @findex picture-yank-rectangle
280 @findex picture-yank-rectangle-from-register
281 The Picture mode commands for yanking rectangles differ from the
282 standard ones in that they overwrite instead of inserting. This is
283 the same way that Picture mode insertion of other text differs from
284 other modes. @kbd{C-c C-y} (@code{picture-yank-rectangle}) inserts
285 (by overwriting) the rectangle that was most recently killed, while
286 @kbd{C-c C-x} (@code{picture-yank-rectangle-from-register}) does
287 likewise for the rectangle found in a specified register.
290 arch-tag: 10e423ad-d896-42f2-a7e8-7018adeaf8c2