43a2dbc4704b4dbcea3bb6fed2af92d10f4e2162
[bpt/emacs.git] / doc / emacs / picture-xtra.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 2004-2011 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions.
4 @c
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).
7 @node Picture Mode
8 @section Editing Pictures
9 @cindex pictures
10 @cindex making pictures out of text characters
11 @findex picture-mode
12
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 picture-mode} to enter Picture mode.
16
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.
22
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.
28
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.
33
34 One of these keys, @kbd{C-c C-c}, is particularly important. Often
35 a picture is part of a larger file that is usually edited in some
36 other major mode. Picture mode records the name of the previous major
37 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
39 C-c} also deletes spaces from the ends of lines, unless given a
40 numeric argument.
41
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.
47
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
51 @file{artist.el}.
52
53 @menu
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.
59 @end menu
60
61 @node Basic Picture
62 @subsection Basic Editing in Picture Mode
63
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
69
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
83 lines.
84
85 @findex picture-newline
86 Insertion of text is adapted to the quarter-plane screen model
87 through the use of Overwrite mode
88 @iftex
89 (@pxref{Minor Modes,,, emacs, the Emacs Manual}.)
90 @end iftex
91 @ifnottex
92 (@pxref{Minor Modes}.)
93 @end ifnottex
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.
98
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.
111
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.
119
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
124 Picture}).
125
126 @node Insert in Picture
127 @subsection Controlling Motion after Insert
128
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.
150
151 @table @kbd
152 @item C-c <
153 @itemx C-c @key{LEFT}
154 Move left after insertion (@code{picture-movement-left}).
155 @item C-c >
156 @itemx C-c @key{RIGHT}
157 Move right after insertion (@code{picture-movement-right}).
158 @item C-c ^
159 @itemx C-c @key{UP}
160 Move up after insertion (@code{picture-movement-up}).
161 @item C-c .
162 @itemx C-c @key{DOWN}
163 Move down after insertion (@code{picture-movement-down}).
164 @item C-c `
165 @itemx C-c @key{HOME}
166 Move up and left (``northwest'') after insertion (@code{picture-movement-nw}).
167 @item C-c '
168 @itemx C-c @key{prior}
169 Move up and right (``northeast'') after insertion
170 (@code{picture-movement-ne}).
171 @item C-c /
172 @itemx C-c @key{END}
173 Move down and left (``southwest'') after insertion
174 @*(@code{picture-movement-sw}).
175 @item C-c \
176 @itemx C-c @key{next}
177 Move down and right (``southeast'') after insertion
178 @*(@code{picture-movement-se}).
179 @end table
180
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.
189
190 @node Tabs in Picture
191 @subsection Picture Mode Tabs
192
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{"!-~"}.
209
210 @findex picture-tab
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.
215
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.
224
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}.
229
230 @node Rectangles in Picture
231 @subsection Picture Mode Rectangle Commands
232 @cindex rectangles and Picture mode
233 @cindex Picture mode and rectangles
234
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.
238 @iftex
239 @xref{Rectangles,,, emacs, the Emacs Manual}.
240 @end iftex
241 @ifnottex
242 @xref{Rectangles}.
243 @end ifnottex
244
245 @table @kbd
246 @item C-c C-k
247 Clear out the region-rectangle with spaces
248 (@code{picture-clear-rectangle}). With a prefix argument, delete the
249 text.
250 @item C-c C-w @var{r}
251 Similar, but save rectangle contents in register @var{r} first
252 (@code{picture-clear-rectangle-to-register}).
253 @item C-c C-y
254 Copy last killed rectangle into the buffer by overwriting, with upper
255 left corner at point (@code{picture-yank-rectangle}). With argument,
256 insert instead.
257 @item C-c C-x @var{r}
258 Similar, but use the rectangle in register @var{r}
259 (@code{picture-yank-rectangle-from-register}).
260 @end table
261
262 @kindex C-c C-k @r{(Picture mode)}
263 @kindex C-c C-w @r{(Picture mode)}
264 @findex picture-clear-rectangle
265 @findex picture-clear-rectangle-to-register
266 The picture rectangle commands @kbd{C-c C-k}
267 (@code{picture-clear-rectangle}) and @kbd{C-c C-w}
268 (@code{picture-clear-rectangle-to-register}) differ from the standard
269 rectangle commands in that they normally clear the rectangle instead of
270 deleting it; this is analogous with the way @kbd{C-d} is changed in Picture
271 mode.
272
273 However, deletion of rectangles can be useful in Picture mode, so
274 these commands delete the rectangle if given a numeric argument.
275 @kbd{C-c C-k} either with or without a numeric argument saves the
276 rectangle for @kbd{C-c C-y}.
277
278 @kindex C-c C-y @r{(Picture mode)}
279 @kindex C-c C-x @r{(Picture mode)}
280 @findex picture-yank-rectangle
281 @findex picture-yank-rectangle-from-register
282 The Picture mode commands for yanking rectangles differ from the
283 standard ones in that they overwrite instead of inserting. This is
284 the same way that Picture mode insertion of other text differs from
285 other modes. @kbd{C-c C-y} (@code{picture-yank-rectangle}) inserts
286 (by overwriting) the rectangle that was most recently killed, while
287 @kbd{C-c C-x} (@code{picture-yank-rectangle-from-register}) does
288 likewise for the rectangle found in a specified register.