1 ;;; picture.el --- "Picture mode" -- editing using quarter-plane screen model.
3 ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
5 ;; Author: K. Shane Hartman
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This code provides the picture-mode commands documented in the Emacs
28 ;; manual. The screen is treated as a semi-infinite quarter-plane with
29 ;; support for rectangle operations and `etch-a-sketch' character
30 ;; insertion in any of eight directions.
35 "Picture mode --- editing using quarter-plane screen model."
39 (defcustom picture-rectangle-ctl ?+
40 "*Character `picture-draw-rectangle' uses for top left corners."
43 (defcustom picture-rectangle-ctr ?+
44 "*Character `picture-draw-rectangle' uses for top right corners."
47 (defcustom picture-rectangle-cbr ?+
48 "*Character `picture-draw-rectangle' uses for bottom right corners."
51 (defcustom picture-rectangle-cbl ?+
52 "*Character `picture-draw-rectangle' uses for bottom left corners."
55 (defcustom picture-rectangle-v ?|
56 "*Character `picture-draw-rectangle' uses for vertical lines."
59 (defcustom picture-rectangle-h ?-
60 "*Character `picture-draw-rectangle' uses for horizontal lines."
65 ;; Picture Movement Commands
67 ;; When a cursor is on a wide-column character (e.g. Chinese,
68 ;; Japanese, Korean), this variable tells the desired current column
69 ;; which may be different from (current-column).
70 (defvar picture-desired-column 0)
72 ;; If the value of picture-desired-column is far from the current
73 ;; column, or if the arg ADJUST-TO-CURRENT is non-nil, set it to the
74 ;; current column. Return the current column.
75 (defun picture-update-desired-column (adjust-to-current)
76 (let ((current-column (current-column)))
77 (if (or adjust-to-current
78 (< picture-desired-column (1- current-column))
79 (> picture-desired-column (1+ current-column)))
80 (setq picture-desired-column current-column))
83 (defun picture-beginning-of-line (&optional arg)
84 "Position point at the beginning of the line.
85 With ARG not nil, move forward ARG - 1 lines first.
86 If scan reaches end of buffer, stop there without error."
88 (if arg (forward-line (1- (prefix-numeric-value arg))))
90 (setq picture-desired-column 0)
91 ;; This call will go away when Emacs gets real horizontal autoscrolling
92 (hscroll-point-visible))
94 (defun picture-end-of-line (&optional arg)
95 "Position point after last non-blank character on current line.
96 With ARG not nil, move forward ARG - 1 lines first.
97 If scan reaches end of buffer, stop there without error."
99 (if arg (forward-line (1- (prefix-numeric-value arg))))
101 (skip-chars-backward " \t" (prog1 (point) (end-of-line)))
102 (setq picture-desired-column (current-column))
103 ;; This call will go away when Emacs gets real horizontal autoscrolling
104 (hscroll-point-visible))
106 (defun picture-forward-column (arg)
107 "Move cursor right, making whitespace if necessary.
108 With argument, move that many columns."
110 (picture-update-desired-column (interactive-p))
111 (setq picture-desired-column (max 0 (+ picture-desired-column arg)))
112 (let ((current-column (move-to-column picture-desired-column t)))
113 (if (and (> current-column picture-desired-column)
115 ;; It seems that we have just tried to move to the right
116 ;; column of a multi-column character.
119 (defun picture-backward-column (arg)
120 "Move cursor left, making whitespace if necessary.
121 With argument, move that many columns."
123 (picture-update-desired-column (interactive-p))
124 (picture-forward-column (- arg)))
126 (defun picture-move-down (arg)
127 "Move vertically down, making whitespace if necessary.
128 With argument, move that many lines."
130 (picture-update-desired-column nil)
131 (picture-newline arg)
132 (let ((current-column (move-to-column picture-desired-column t)))
133 (if (> current-column picture-desired-column)
136 (defconst picture-vertical-step 0
137 "Amount to move vertically after text character in Picture mode.")
139 (defconst picture-horizontal-step 1
140 "Amount to move horizontally after text character in Picture mode.")
142 (defun picture-move-up (arg)
143 "Move vertically up, making whitespace if necessary.
144 With argument, move that many lines."
146 (picture-update-desired-column nil)
147 (picture-move-down (- arg)))
149 (defun picture-movement-right ()
150 "Move right after self-inserting character in Picture mode."
152 (picture-set-motion 0 1))
154 (defun picture-movement-left ()
155 "Move left after self-inserting character in Picture mode."
157 (picture-set-motion 0 -1))
159 (defun picture-movement-up ()
160 "Move up after self-inserting character in Picture mode."
162 (picture-set-motion -1 0))
164 (defun picture-movement-down ()
165 "Move down after self-inserting character in Picture mode."
167 (picture-set-motion 1 0))
169 (defun picture-movement-nw (&optional arg)
170 "Move up and left after self-inserting character in Picture mode.
171 With prefix argument, move up and two-column left."
173 (picture-set-motion -1 (if arg -2 -1)))
175 (defun picture-movement-ne (&optional arg)
176 "Move up and right after self-inserting character in Picture mode.
177 With prefix argument, move up and two-column right."
179 (picture-set-motion -1 (if arg 2 1)))
181 (defun picture-movement-sw (&optional arg)
182 "Move down and left after self-inserting character in Picture mode.
183 With prefix argument, move down and two-column left."
185 (picture-set-motion 1 (if arg -2 -1)))
187 (defun picture-movement-se (&optional arg)
188 "Move down and right after self-inserting character in Picture mode.
189 With prefix argument, move down and two-column right."
191 (picture-set-motion 1 (if arg 2 1)))
193 (defun picture-set-motion (vert horiz)
194 "Set VERTICAL and HORIZONTAL increments for movement in Picture mode.
195 The mode line is updated to reflect the current direction."
196 (setq picture-vertical-step vert
197 picture-horizontal-step horiz)
200 (nth (+ 2 (% horiz 3) (* 5 (1+ (% vert 2))))
201 '(wnw nw up ne ene Left left none right Right
202 wsw sw down se ese))))
203 (force-mode-line-update)
206 (defun picture-move ()
207 "Move in direction of `picture-vertical-step' and `picture-horizontal-step'."
208 (if (/= picture-vertical-step 0)
209 (picture-move-down picture-vertical-step))
210 (if (/= picture-horizontal-step 0)
211 (picture-forward-column picture-horizontal-step)))
213 (defun picture-motion (arg)
214 "Move point in direction of current picture motion in Picture mode.
215 With ARG do it that many times. Useful for delineating rectangles in
216 conjunction with diagonal picture motion.
217 Do \\[command-apropos] picture-movement to see commands which control motion."
219 (picture-move-down (* arg picture-vertical-step))
220 (picture-forward-column (* arg picture-horizontal-step)))
222 (defun picture-motion-reverse (arg)
223 "Move point in direction opposite of current picture motion in Picture mode.
224 With ARG do it that many times. Useful for delineating rectangles in
225 conjunction with diagonal picture motion.
226 Do \\[command-apropos] `picture-movement' to see commands which control motion."
228 (picture-motion (- arg)))
231 ;; Picture insertion and deletion.
233 (defun picture-insert (ch arg)
234 (let* ((width (char-width ch))
235 ;; We must be sure that the succeeding insertion won't delete
236 ;; the just inserted character.
237 (picture-horizontal-step
238 (if (and (= picture-vertical-step 0)
240 (< (abs picture-horizontal-step) 2))
241 (* picture-horizontal-step 2)
242 picture-horizontal-step)))
245 (if (/= picture-desired-column (current-column))
246 (move-to-column-force picture-desired-column))
247 (let ((col (+ picture-desired-column width)))
250 (move-to-column-force col)
251 (delete-region pos (point)))))
256 (defun picture-self-insert (arg)
257 "Insert this character in place of character previously at the cursor.
258 The cursor then moves in the direction you previously specified
259 with the commands `picture-movement-right', `picture-movement-up', etc.
260 Do \\[command-apropos] `picture-movement' to see those commands."
262 (picture-update-desired-column (not (eq this-command last-command)))
263 (picture-insert last-command-event arg)) ; Always a character in this case.
265 (defun picture-clear-column (arg)
266 "Clear out ARG columns after point without moving."
268 (let* ((original-col (current-column))
269 (target-col (max 0 (+ original-col arg)))
271 (move-to-column-force target-col)
273 (move-to-column original-col)
274 (delete-region pos (point))
276 (indent-to (max target-col original-col))))
277 (setq picture-desired-column (current-column)))
279 (defun picture-backward-clear-column (arg)
280 "Clear out ARG columns before point, moving back over them."
282 (picture-clear-column (- arg)))
284 (defun picture-clear-line (arg)
285 "Clear out rest of line; if at end of line, advance to next line.
286 Cleared-out line text goes into the kill ring, as do newlines that are
287 advanced over. With argument, clear out (and save in kill ring) that
292 (setq arg (prefix-numeric-value arg))
294 (newline (if (> arg 0) arg (- arg))))
295 (if (looking-at "[ \t]*$")
296 (kill-ring-save (point) (progn (forward-line 1) (point)))
297 (kill-region (point) (progn (end-of-line) (point))))))
299 (defun picture-newline (arg)
300 "Move to the beginning of the following line.
301 With argument, moves that many lines (up, if negative argument);
302 always moves to the beginning of a line."
308 (if (eobp) (newline) (forward-char 1))
309 (setq arg (1- arg))))
310 ;; This call will go away when Emacs gets real horizontal autoscrolling
311 (hscroll-point-visible))
313 (defun picture-open-line (arg)
314 "Insert an empty line after the current line.
315 With positive argument insert that many lines."
320 ;; This call will go away when Emacs gets real horizontal autoscrolling
321 (hscroll-point-visible))
323 (defun picture-duplicate-line ()
324 "Insert a duplicate of the current line, below it."
329 (progn (beginning-of-line) (point))
330 (progn (picture-newline 1) (point)))))
334 ;; Like replace-match, but overwrites.
335 (defun picture-replace-match (newtext fixedcase literal)
336 (let (ocolumn change pos)
337 (goto-char (setq pos (match-end 0)))
338 (setq ocolumn (current-column))
339 ;; Make the replacement and undo it, to see how it changes the length.
340 (let ((buffer-undo-list nil)
342 (replace-match newtext fixedcase literal)
343 (setq change (- (current-column) ocolumn))
344 (setq list1 buffer-undo-list)
346 (setq list1 (primitive-undo 1 list1))))
349 (delete-region (point)
351 (move-to-column (+ change (current-column)) t)
353 (replace-match newtext fixedcase literal)
355 (insert-char ?\ (- change)))))
359 (defcustom picture-tab-chars "!-~"
360 "*A character set which controls behavior of commands.
361 \\[picture-set-tab-stops] and \\[picture-tab-search]. It is NOT a
362 regular expression, any regexp special characters will be quoted.
363 It defines a set of \"interesting characters\" to look for when setting
364 \(or searching for) tab stops, initially \"!-~\" (all printing characters).
365 For example, suppose that you are editing a table which is formatted thus:
366 | foo | bar + baz | 23 *
367 | bubbles | and + etc | 97 *
368 and that `picture-tab-chars' is \"|+*\". Then invoking
369 \\[picture-set-tab-stops] on either of the previous lines would result
370 in the following tab stops
372 Another example - \"A-Za-z0-9\" would produce the tab stops
375 Note that if you want the character `-' to be in the set, it must be
376 included in a range or else appear in a context where it cannot be
377 taken for indicating a range (e.g. \"-A-Z\" declares the set to be the
378 letters `A' through `Z' and the character `-'). If you want the
379 character `\\' in the set it must be preceded by itself: \"\\\\\".
381 The command \\[picture-tab-search] is defined to move beneath (or to) a
382 character belonging to this set independent of the tab stops list."
386 (defun picture-set-tab-stops (&optional arg)
387 "Set value of `tab-stop-list' according to context of this line.
388 This controls the behavior of \\[picture-tab]. A tab stop is set at
389 every column occupied by an \"interesting character\" that is preceded
390 by whitespace. Interesting characters are defined by the variable
391 `picture-tab-chars', see its documentation for an example of usage.
392 With ARG, just (re)set `tab-stop-list' to its default value. The tab
393 stops computed are displayed in the minibuffer with `:' at each stop."
398 (setq tabs (default-value 'tab-stop-list))
399 (let ((regexp (concat "[ \t]+[" (regexp-quote picture-tab-chars) "]")))
403 (while (re-search-backward regexp bol t)
404 (skip-chars-forward " \t")
405 (setq tabs (cons (current-column) tabs)))
407 (error "No characters in set %s on this line."
408 (regexp-quote picture-tab-chars))))))
409 (setq tab-stop-list tabs)
410 (let ((blurb (make-string (1+ (nth (1- (length tabs)) tabs)) ?\ )))
412 (aset blurb (car tabs) ?:)
413 (setq tabs (cdr tabs)))
416 (defun picture-tab-search (&optional arg)
417 "Move to column beneath next interesting char in previous line.
418 With ARG move to column occupied by next interesting character in this
419 line. The character must be preceded by whitespace.
420 \"interesting characters\" are defined by variable `picture-tab-chars'.
421 If no such character is found, move to beginning of line."
423 (let ((target (current-column)))
429 (concat "^" (regexp-quote picture-tab-chars))
432 (move-to-column target))
433 (if (re-search-forward
434 (concat "[ \t]+[" (regexp-quote picture-tab-chars) "]")
435 (save-excursion (end-of-line) (point))
437 (setq target (1- (current-column)))
440 (move-to-column target t)
441 (beginning-of-line))))
443 (defun picture-tab (&optional arg)
444 "Tab transparently (just move point) to next tab stop.
445 With prefix arg, overwrite the traversed text with spaces. The tab stop
446 list can be changed by \\[picture-set-tab-stops] and \\[edit-tab-stops].
447 See also documentation for variable `picture-tab-chars'."
449 (let* ((opoint (point)))
452 (let (indent-tabs-mode
453 (column (current-column)))
454 (delete-region opoint (point))
455 (indent-to column)))))
457 ;; Picture Rectangles
459 (defconst picture-killed-rectangle nil
460 "Rectangle killed or copied by \\[picture-clear-rectangle] in Picture mode.
461 The contents can be retrieved by \\[picture-yank-rectangle]")
463 (defun picture-clear-rectangle (start end &optional killp)
464 "Clear and save rectangle delineated by point and mark.
465 The rectangle is saved for yanking by \\[picture-yank-rectangle] and replaced
466 with whitespace. The previously saved rectangle, if any, is lost. With
467 prefix argument, the rectangle is actually killed, shifting remaining text."
469 (setq picture-killed-rectangle (picture-snarf-rectangle start end killp)))
471 (defun picture-clear-rectangle-to-register (start end register &optional killp)
472 "Clear rectangle delineated by point and mark into REGISTER.
473 The rectangle is saved in REGISTER and replaced with whitespace. With
474 prefix argument, the rectangle is actually killed, shifting remaining text."
475 (interactive "r\ncRectangle to register: \nP")
476 (set-register register (picture-snarf-rectangle start end killp)))
478 (defun picture-snarf-rectangle (start end &optional killp)
479 (let ((column (current-column))
480 (indent-tabs-mode nil))
481 (prog1 (save-excursion
483 (delete-extract-rectangle start end)
484 (prog1 (extract-rectangle start end)
485 (clear-rectangle start end))))
486 (move-to-column column t))))
488 (defun picture-yank-rectangle (&optional insertp)
489 "Overlay rectangle saved by \\[picture-clear-rectangle]
490 The rectangle is positioned with upper left corner at point, overwriting
491 existing text. With prefix argument, the rectangle is inserted instead,
492 shifting existing text. Leaves mark at one corner of rectangle and
493 point at the other (diagonally opposed) corner."
495 (if (not (consp picture-killed-rectangle))
496 (error "No rectangle saved.")
497 (picture-insert-rectangle picture-killed-rectangle insertp)))
499 (defun picture-yank-at-click (click arg)
500 "Insert the last killed rectangle at the position clicked on.
501 Also move point to one end of the text thus inserted (normally the end).
502 Prefix arguments are interpreted as with \\[yank].
503 If `mouse-yank-at-point' is non-nil, insert at point
504 regardless of where you click."
506 (or mouse-yank-at-point (mouse-set-point click))
507 (picture-yank-rectangle arg))
509 (defun picture-yank-rectangle-from-register (register &optional insertp)
510 "Overlay rectangle saved in REGISTER.
511 The rectangle is positioned with upper left corner at point, overwriting
512 existing text. With prefix argument, the rectangle is
513 inserted instead, shifting existing text. Leaves mark at one corner
514 of rectangle and point at the other (diagonally opposed) corner."
515 (interactive "cRectangle from register: \nP")
516 (let ((rectangle (get-register register)))
517 (if (not (consp rectangle))
518 (error "Register %c does not contain a rectangle." register)
519 (picture-insert-rectangle rectangle insertp))))
521 (defun picture-insert-rectangle (rectangle &optional insertp)
522 "Overlay RECTANGLE with upper left corner at point.
523 Optional argument INSERTP, if non-nil causes RECTANGLE to be inserted.
524 Leaves the region surrounding the rectangle."
525 (let ((indent-tabs-mode nil))
528 (delete-rectangle (point)
530 (picture-forward-column (length (car rectangle)))
531 (picture-move-down (1- (length rectangle)))
534 (insert-rectangle rectangle)))
536 (defun picture-current-line ()
537 "Return the vertical position of point. Top line is 1."
538 (+ (count-lines (point-min) (point))
539 (if (= (current-column) 0) 1 0)))
541 (defun picture-draw-rectangle (start end)
542 "Draw a rectangle around region."
543 (interactive "*r") ; start will be less than end
544 (let* ((sl (picture-current-line))
545 (sc (current-column))
546 (pvs picture-vertical-step)
547 (phs picture-horizontal-step)
548 (c1 (progn (goto-char start) (current-column)))
549 (r1 (picture-current-line))
550 (c2 (progn (goto-char end) (current-column)))
551 (r2 (picture-current-line))
555 (bottom (max r1 r2)))
557 (move-to-column-force left)
558 (picture-update-desired-column t)
560 (picture-movement-right)
561 (picture-insert picture-rectangle-ctl 1)
562 (picture-insert picture-rectangle-h (- right picture-desired-column))
564 (picture-movement-down)
565 (picture-insert picture-rectangle-ctr 1)
566 (picture-insert picture-rectangle-v (- bottom (picture-current-line)))
568 (picture-movement-left)
569 (picture-insert picture-rectangle-cbr 1)
570 (picture-insert picture-rectangle-h (- picture-desired-column left))
572 (picture-movement-up)
573 (picture-insert picture-rectangle-cbl 1)
574 (picture-insert picture-rectangle-v (- (picture-current-line) top))
576 (picture-set-motion pvs phs)
578 (move-to-column sc t)))
581 ;; Picture Keymap, entry and exit points.
583 (defconst picture-mode-map nil)
585 (defun picture-substitute (oldfun newfun)
586 (substitute-key-definition oldfun newfun picture-mode-map global-map))
588 (if (not picture-mode-map)
590 (setq picture-mode-map (make-keymap))
591 (picture-substitute 'self-insert-command 'picture-self-insert)
592 (picture-substitute 'completion-separator-self-insert-command
593 'picture-self-insert)
594 (picture-substitute 'completion-separator-self-insert-autofilling
595 'picture-self-insert)
596 (picture-substitute 'forward-char 'picture-forward-column)
597 (picture-substitute 'backward-char 'picture-backward-column)
598 (picture-substitute 'delete-char 'picture-clear-column)
599 ;; There are two possibilities for what is normally on DEL.
600 (picture-substitute 'backward-delete-char-untabify 'picture-backward-clear-column)
601 (picture-substitute 'delete-backward-char 'picture-backward-clear-column)
602 (picture-substitute 'kill-line 'picture-clear-line)
603 (picture-substitute 'open-line 'picture-open-line)
604 (picture-substitute 'newline 'picture-newline)
605 (picture-substitute 'newline-and-indent 'picture-duplicate-line)
606 (picture-substitute 'next-line 'picture-move-down)
607 (picture-substitute 'previous-line 'picture-move-up)
608 (picture-substitute 'beginning-of-line 'picture-beginning-of-line)
609 (picture-substitute 'end-of-line 'picture-end-of-line)
611 (define-key picture-mode-map "\C-c\C-d" 'delete-char)
612 (define-key picture-mode-map "\e\t" 'picture-toggle-tab-state)
613 (define-key picture-mode-map "\t" 'picture-tab)
614 (define-key picture-mode-map "\e\t" 'picture-tab-search)
615 (define-key picture-mode-map "\C-c\t" 'picture-set-tab-stops)
616 (define-key picture-mode-map "\C-c\C-k" 'picture-clear-rectangle)
617 (define-key picture-mode-map "\C-c\C-w" 'picture-clear-rectangle-to-register)
618 (define-key picture-mode-map "\C-c\C-y" 'picture-yank-rectangle)
619 (define-key picture-mode-map "\C-c\C-x" 'picture-yank-rectangle-from-register)
620 (define-key picture-mode-map "\C-c\C-r" 'picture-draw-rectangle)
621 (define-key picture-mode-map "\C-c\C-c" 'picture-mode-exit)
622 (define-key picture-mode-map "\C-c\C-f" 'picture-motion)
623 (define-key picture-mode-map "\C-c\C-b" 'picture-motion-reverse)
624 (define-key picture-mode-map "\C-c<" 'picture-movement-left)
625 (define-key picture-mode-map "\C-c>" 'picture-movement-right)
626 (define-key picture-mode-map "\C-c^" 'picture-movement-up)
627 (define-key picture-mode-map "\C-c." 'picture-movement-down)
628 (define-key picture-mode-map "\C-c`" 'picture-movement-nw)
629 (define-key picture-mode-map "\C-c'" 'picture-movement-ne)
630 (define-key picture-mode-map "\C-c/" 'picture-movement-sw)
631 (define-key picture-mode-map "\C-c\\" 'picture-movement-se)))
633 (defcustom picture-mode-hook nil
634 "If non-nil, its value is called on entry to Picture mode.
635 Picture mode is invoked by the command \\[picture-mode]."
639 (defvar picture-mode-old-local-map)
640 (defvar picture-mode-old-mode-name)
641 (defvar picture-mode-old-major-mode)
642 (defvar picture-mode-old-truncate-lines)
645 (defun picture-mode ()
646 "Switch to Picture mode, in which a quarter-plane screen model is used.
647 Printing characters replace instead of inserting themselves with motion
648 afterwards settable by these commands:
649 C-c < Move left after insertion.
650 C-c > Move right after insertion.
651 C-c ^ Move up after insertion.
652 C-c . Move down after insertion.
653 C-c ` Move northwest (nw) after insertion.
654 C-c ' Move northeast (ne) after insertion.
655 C-c / Move southwest (sw) after insertion.
656 C-c \\ Move southeast (se) after insertion.
657 C-u C-c ` Move westnorthwest (wnw) after insertion.
658 C-u C-c ' Move eastnortheast (ene) after insertion.
659 C-u C-c / Move westsouthwest (wsw) after insertion.
660 C-u C-c \\ Move eastsoutheast (ese) after insertion.
661 The current direction is displayed in the mode line. The initial
662 direction is right. Whitespace is inserted and tabs are changed to
663 spaces when required by movement. You can move around in the buffer
665 \\[picture-move-down] Move vertically to SAME column in previous line.
666 \\[picture-move-up] Move vertically to SAME column in next line.
667 \\[picture-end-of-line] Move to column following last non-whitespace character.
668 \\[picture-forward-column] Move right inserting spaces if required.
669 \\[picture-backward-column] Move left changing tabs to spaces if required.
670 C-c C-f Move in direction of current picture motion.
671 C-c C-b Move in opposite direction of current picture motion.
672 Return Move to beginning of next line.
673 You can edit tabular text with these commands:
674 M-Tab Move to column beneath (or at) next interesting character.
675 `Indents' relative to a previous line.
676 Tab Move to next stop in tab stop list.
677 C-c Tab Set tab stops according to context of this line.
678 With ARG resets tab stops to default (global) value.
679 See also documentation of variable picture-tab-chars
680 which defines \"interesting character\". You can manually
681 change the tab stop list with command \\[edit-tab-stops].
682 You can manipulate text with these commands:
683 C-d Clear (replace) ARG columns after point without moving.
684 C-c C-d Delete char at point - the command normally assigned to C-d.
685 \\[picture-backward-clear-column] Clear (replace) ARG columns before point, moving back over them.
686 \\[picture-clear-line] Clear ARG lines, advancing over them. The cleared
687 text is saved in the kill ring.
688 \\[picture-open-line] Open blank line(s) beneath current line.
689 You can manipulate rectangles with these commands:
690 C-c C-k Clear (or kill) a rectangle and save it.
691 C-c C-w Like C-c C-k except rectangle is saved in named register.
692 C-c C-y Overlay (or insert) currently saved rectangle at point.
693 C-c C-x Like C-c C-y except rectangle is taken from named register.
694 C-c C-r Draw a rectangular box around mark and point.
695 \\[copy-rectangle-to-register] Copies a rectangle to a register.
696 \\[advertised-undo] Can undo effects of rectangle overlay commands
697 commands if invoked soon enough.
698 You can return to the previous mode with:
699 C-c C-c Which also strips trailing whitespace from every line.
700 Stripping is suppressed by supplying an argument.
702 Entry to this mode calls the value of picture-mode-hook if non-nil.
704 Note that Picture mode commands will work outside of Picture mode, but
705 they are not defaultly assigned to keys."
707 (if (eq major-mode 'picture-mode)
708 (error "You are already editing a picture.")
709 (make-local-variable 'picture-mode-old-local-map)
710 (setq picture-mode-old-local-map (current-local-map))
711 (use-local-map picture-mode-map)
712 (make-local-variable 'picture-mode-old-mode-name)
713 (setq picture-mode-old-mode-name mode-name)
714 (make-local-variable 'picture-mode-old-major-mode)
715 (setq picture-mode-old-major-mode major-mode)
716 (setq major-mode 'picture-mode)
717 (make-local-variable 'picture-killed-rectangle)
718 (setq picture-killed-rectangle nil)
719 (make-local-variable 'tab-stop-list)
720 (setq tab-stop-list (default-value 'tab-stop-list))
721 (make-local-variable 'picture-tab-chars)
722 (setq picture-tab-chars (default-value 'picture-tab-chars))
723 (make-local-variable 'picture-vertical-step)
724 (make-local-variable 'picture-horizontal-step)
725 (make-local-variable 'picture-mode-old-truncate-lines)
726 (setq picture-mode-old-truncate-lines truncate-lines)
727 (setq truncate-lines t)
728 (picture-set-motion 0 1)
730 ;; edit-picture-hook is what we used to run, picture-mode-hook is in doc.
731 (run-hooks 'edit-picture-hook 'picture-mode-hook)
732 (message "Type %s in this buffer to return it to %s mode."
733 (substitute-command-keys "\\[picture-mode-exit]")
734 picture-mode-old-mode-name)))
737 (defalias 'edit-picture 'picture-mode)
739 (defun picture-mode-exit (&optional nostrip)
740 "Undo picture-mode and return to previous major mode.
741 With no argument strips whitespace from end of every line in Picture buffer
742 otherwise just return to previous mode."
744 (if (not (eq major-mode 'picture-mode))
745 (error "You aren't editing a Picture.")
746 (if (not nostrip) (picture-clean))
747 (setq mode-name picture-mode-old-mode-name)
748 (use-local-map picture-mode-old-local-map)
749 (setq major-mode picture-mode-old-major-mode)
750 (kill-local-variable 'tab-stop-list)
751 (setq truncate-lines picture-mode-old-truncate-lines)
752 (force-mode-line-update)))
754 (defun picture-clean ()
755 "Eliminate whitespace at ends of lines."
757 (goto-char (point-min))
758 (while (re-search-forward "[ \t][ \t]*$" nil t)
759 (delete-region (match-beginning 0) (point)))))
763 ;;; picture.el ends here