picture-xtra.texi 12 KB

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