home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / modes / picture.el < prev    next >
Encoding:
Text File  |  1995-05-23  |  25.5 KB  |  671 lines

  1. ;;; picture.el --- "Picture mode" -- editing using quarter-plane screen model.
  2.  
  3. ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: K. Shane Hartman
  6. ;; Maintainer: FSF
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Synched up with: FSF 19.28.
  25.  
  26. ;; XEmacs changes:
  27. ;; -- set zmacs-region-stays
  28. ;; -- set mouse-track-rectangle-p
  29. ;; -- use redraw-modeline instead of kludge
  30.  
  31.  
  32. ;;; Commentary:
  33.  
  34. ;; This code provides the picture-mode commands documented in the Emacs 
  35. ;; manual.  The screen is treated as a semi-infinite quarter-plane with
  36. ;; support for rectangle operations and `etch-a-sketch' character
  37. ;; insertion in any of eight directions.
  38.  
  39. ;;; Code:
  40.  
  41. (defun move-to-column-force (column)
  42.   "Move to column COLUMN in current line.
  43. Differs from `move-to-column' in that it creates or modifies whitespace
  44. if necessary to attain exactly the specified column."
  45.   (or (natnump column) (setq column 0))
  46.   (move-to-column column)
  47.   (let ((col (current-column)))
  48.     (if (< col column)
  49.     (indent-to column)
  50.       (if (and (/= col column)
  51.            (= (preceding-char) ?\t))
  52.       (let (indent-tabs-mode)
  53.         (delete-char -1)
  54.         (indent-to col)
  55.         (move-to-column column))))
  56.     (prog1
  57.     ;; FSFmacs
  58.     ;; This call will go away when Emacs gets real horizontal autoscrolling
  59.     ;; (hscroll-point-visible)
  60.       ;; XEmacs addition:
  61.       (setq zmacs-region-stays t))))
  62.  
  63.  
  64. ;; Picture Movement Commands
  65.  
  66. (defun picture-beginning-of-line (&optional arg)
  67.   "Position point at the beginning of the line.
  68. With ARG not nil, move forward ARG - 1 lines first.
  69. If scan reaches end of buffer, stop there without error."
  70.   (interactive "P")
  71.   (if arg (forward-line (1- (prefix-numeric-value arg))))
  72.   (beginning-of-line)
  73.   ;; FSFmacs
  74.   ;; This call will go away when Emacs gets real horizontal autoscrolling
  75.   ;;(hscroll-point-visible)
  76.   )
  77.  
  78. (defun picture-end-of-line (&optional arg)
  79.   "Position point after last non-blank character on current line.
  80. With ARG not nil, move forward ARG - 1 lines first.
  81. If scan reaches end of buffer, stop there without error."
  82.   (interactive "P")
  83.   (if arg (forward-line (1- (prefix-numeric-value arg))))
  84.   (beginning-of-line)
  85.   (skip-chars-backward " \t" (prog1 (point) (end-of-line)))
  86.   ;; FSFmacs
  87.   ;; This call will go away when Emacs gets real horizontal autoscrolling
  88.   ;;(hscroll-point-visible)
  89.   )
  90.  
  91. (defun picture-forward-column (arg)
  92.   "Move cursor right, making whitespace if necessary.
  93. With argument, move that many columns."
  94.   (interactive "p")
  95.   (let ((target-column (+ (current-column) arg)))
  96.     (move-to-column-force target-column)
  97.     ;; Picture mode isn't really suited to multi-column characters,
  98.     ;; but we might as well let the user move across them.
  99.     (and (< arg 0)
  100.      (> (current-column) target-column)
  101.      (forward-char -1))))
  102.  
  103. (defun picture-backward-column (arg)
  104.   "Move cursor left, making whitespace if necessary.
  105. With argument, move that many columns."
  106.   (interactive "p")
  107.   (picture-forward-column (- arg)))
  108.  
  109. (defun picture-move-down (arg)
  110.   "Move vertically down, making whitespace if necessary.
  111. With argument, move that many lines."
  112.   (interactive "p")
  113.   (let ((col (current-column)))
  114.     (picture-newline arg)
  115.     (move-to-column-force col)))
  116.  
  117. (defconst picture-vertical-step 0
  118.   "Amount to move vertically after text character in Picture mode.")
  119.  
  120. (defconst picture-horizontal-step 1
  121.   "Amount to move horizontally after text character in Picture mode.")
  122.  
  123. (defun picture-move-up (arg)
  124.   "Move vertically up, making whitespace if necessary.
  125. With argument, move that many lines."
  126.   (interactive "p")
  127.   (picture-move-down (- arg)))
  128.  
  129. (defun picture-movement-right ()
  130.   "Move right after self-inserting character in Picture mode."
  131.   (interactive)
  132.   (picture-set-motion 0 1))
  133.  
  134. (defun picture-movement-left ()
  135.   "Move left after self-inserting character in Picture mode."
  136.   (interactive)
  137.   (picture-set-motion 0 -1))
  138.  
  139. (defun picture-movement-up ()
  140.   "Move up after self-inserting character in Picture mode."
  141.   (interactive)
  142.   (picture-set-motion -1 0))
  143.  
  144. (defun picture-movement-down ()
  145.   "Move down after self-inserting character in Picture mode."
  146.   (interactive)
  147.   (picture-set-motion 1 0))
  148.  
  149. (defun picture-movement-nw ()
  150.   "Move up and left after self-inserting character in Picture mode."
  151.   (interactive)
  152.   (picture-set-motion -1 -1))
  153.  
  154. (defun picture-movement-ne ()
  155.   "Move up and right after self-inserting character in Picture mode."
  156.   (interactive)
  157.   (picture-set-motion -1 1))
  158.  
  159. (defun picture-movement-sw ()
  160.   "Move down and left after self-inserting character in Picture mode."
  161.   (interactive)
  162.   (picture-set-motion 1 -1))
  163.  
  164. (defun picture-movement-se ()
  165.   "Move down and right after self-inserting character in Picture mode."
  166.   (interactive)
  167.   (picture-set-motion 1 1))
  168.  
  169. (defun picture-set-motion (vert horiz)
  170.   "Set VERTICAL and HORIZONTAL increments for movement in Picture mode.
  171. The modeline is updated to reflect the current direction."
  172.   (setq picture-vertical-step vert
  173.     picture-horizontal-step horiz)
  174.   (setq mode-name
  175.     (format "Picture:%s"
  176.         (car (nthcdr (+ 1 (% horiz 2) (* 3 (1+ (% vert 2))))
  177.                  '(nw up ne left none right sw down se)))))
  178.   (redraw-modeline)
  179.   (message nil))
  180.  
  181. (defun picture-move ()
  182.   "Move in direction of `picture-vertical-step' and `picture-horizontal-step'."
  183.   (picture-move-down picture-vertical-step)
  184.   (picture-forward-column picture-horizontal-step))
  185.  
  186. (defun picture-motion (arg)
  187.   "Move point in direction of current picture motion in Picture mode.
  188. With ARG do it that many times.  Useful for delineating rectangles in
  189. conjunction with diagonal picture motion.
  190. Do \\[command-apropos]  picture-movement  to see commands which control motion."
  191.   (interactive "p")
  192.   (picture-move-down (* arg picture-vertical-step))
  193.   (picture-forward-column (* arg picture-horizontal-step)))
  194.  
  195. (defun picture-motion-reverse (arg)
  196.   "Move point in direction opposite of current picture motion in Picture mode.
  197. With ARG do it that many times.  Useful for delineating rectangles in
  198. conjunction with diagonal picture motion.
  199. Do \\[command-apropos] `picture-movement' to see commands which control motion."
  200.   (interactive "p")
  201.   (picture-motion (- arg)))
  202.  
  203.  
  204. ;; Picture insertion and deletion.
  205.  
  206. (defun picture-self-insert (arg)
  207.   "Insert this character in place of character previously at the cursor.
  208. The cursor then moves in the direction you previously specified
  209. with the commands `picture-movement-right', `picture-movement-up', etc.
  210. Do \\[command-apropos] `picture-movement' to see those commands."
  211.   (interactive "p")
  212.   (while (> arg 0)
  213.     (setq arg (1- arg))
  214.     (move-to-column-force (1+ (current-column)))
  215.     (delete-char -1)
  216.     (insert last-input-char)
  217.     (forward-char -1)
  218.     (picture-move)
  219.     ;; XEmacs addition:
  220.     (setq zmacs-region-stays nil)))
  221.  
  222. (defun picture-clear-column (arg)
  223.   "Clear out ARG columns after point without moving."
  224.   (interactive "p")
  225.   (let* ((opoint (point))
  226.      (original-col (current-column))
  227.      (target-col (+ original-col arg)))
  228.     (move-to-column-force target-col)
  229.     (delete-region opoint (point))
  230.     (save-excursion
  231.      (indent-to (max target-col original-col)))))
  232.  
  233. (defun picture-backward-clear-column (arg)
  234.   "Clear out ARG columns before point, moving back over them."
  235.   (interactive "p")
  236.   (picture-clear-column (- arg)))
  237.  
  238. (defun picture-clear-line (arg)
  239.   "Clear out rest of line; if at end of line, advance to next line.
  240. Cleared-out line text goes into the kill ring, as do newlines that are
  241. advanced over.  With argument, clear out (and save in kill ring) that
  242. many lines."
  243.   (interactive "P")
  244.   (if arg
  245.       (progn
  246.        (setq arg (prefix-numeric-value arg))
  247.        (kill-line arg)
  248.        (newline (if (> arg 0) arg (- arg))))
  249.     (if (looking-at "[ \t]*$")
  250.     (kill-ring-save (point) (progn (forward-line 1) (point)))
  251.       (kill-region (point) (progn (end-of-line) (point))))
  252.     ;; XEmacs addition:
  253.     (setq zmacs-region-stays nil)))
  254.  
  255. (defun picture-newline (arg)
  256.   "Move to the beginning of the following line.
  257. With argument, moves that many lines (up, if negative argument);
  258. always moves to the beginning of a line."
  259.   (interactive "p")
  260.   (if (< arg 0)
  261.       (forward-line arg)
  262.     (while (> arg 0)
  263.       (end-of-line)
  264.       (if (eobp) (newline) (forward-char 1))
  265.       (setq arg (1- arg))))
  266.   ;; FSFmacs
  267.   ;; This call will go away when Emacs gets real horizontal autoscrolling
  268.   ;;(hscroll-point-visible)
  269.   )
  270.  
  271. (defun picture-open-line (arg)
  272.   "Insert an empty line after the current line.
  273. With positive argument insert that many lines."
  274.   (interactive "p")
  275.   (save-excursion
  276.    (end-of-line)
  277.    (open-line arg))
  278.   ;; FSFmacs
  279.   ;; This call will go away when Emacs gets real horizontal autoscrolling
  280.   ;;(hscroll-point-visible)
  281.   )
  282.  
  283. (defun picture-duplicate-line ()
  284.   "Insert a duplicate of the current line, below it."
  285.   (interactive)
  286.   (save-excursion
  287.    (let ((contents
  288.       (buffer-substring
  289.        (progn (beginning-of-line) (point))
  290.        (progn (picture-newline 1) (point)))))
  291.      (forward-line -1)
  292.      (insert contents))))
  293.  
  294. ;; Like replace-match, but overwrites.
  295. (defun picture-replace-match (newtext fixedcase literal)
  296.   (let (ocolumn change pos)
  297.     (goto-char (setq pos (match-end 0)))
  298.     (setq ocolumn (current-column))
  299.     ;; Make the replacement and undo it, to see how it changes the length.
  300.     (let ((buffer-undo-list nil)
  301.       list1)
  302.       (replace-match newtext fixedcase literal)
  303.       (setq change (- (current-column) ocolumn))
  304.       (setq list1 buffer-undo-list)
  305.       (while list1
  306.     (setq list1 (primitive-undo 1 list1))))
  307.     (goto-char pos)
  308.     (if (> change 0)
  309.     (delete-region (point)
  310.                (progn
  311.              (move-to-column-force (+ change (current-column)))
  312.              (point))))
  313.     (replace-match newtext fixedcase literal)
  314.     (if (< change 0)
  315.     (insert-char ?\ (- change)))))
  316.  
  317. ;; Picture Tabs
  318.  
  319. (defvar picture-tab-chars "!-~"
  320.   "*A character set which controls behavior of commands
  321. \\[picture-set-tab-stops] and \\[picture-tab-search].  It is NOT a
  322. regular expression, any regexp special characters will be quoted.
  323. It defines a set of \"interesting characters\" to look for when setting
  324. \(or searching for) tab stops, initially \"!-~\" (all printing characters).
  325. For example, suppose that you are editing a table which is formatted thus:
  326. | foo        | bar + baz | 23  *
  327. | bubbles    | and + etc | 97  *
  328. and that `picture-tab-chars' is \"|+*\".  Then invoking
  329. \\[picture-set-tab-stops] on either of the previous lines would result
  330. in the following tab stops
  331.         :     :     :     :
  332. Another example - \"A-Za-z0-9\" would produce the tab stops
  333.   :          :    :     :
  334.  
  335. Note that if you want the character `-' to be in the set, it must be
  336. included in a range or else appear in a context where it cannot be
  337. taken for indicating a range (e.g. \"-A-Z\" declares the set to be the
  338. letters `A' through `Z' and the character `-').  If you want the
  339. character `\\' in the set it must be preceded by itself: \"\\\\\".
  340.  
  341. The command \\[picture-tab-search] is defined to move beneath (or to) a
  342. character belonging to this set independent of the tab stops list.")
  343.  
  344. (defun picture-set-tab-stops (&optional arg)
  345.   "Set value of `tab-stop-list' according to context of this line.
  346. This controls the behavior of \\[picture-tab].  A tab stop is set at
  347. every column occupied by an \"interesting character\" that is preceded
  348. by whitespace.  Interesting characters are defined by the variable
  349. `picture-tab-chars', see its documentation for an example of usage.
  350. With ARG, just (re)set `tab-stop-list' to its default value.  The tab
  351. stops computed are displayed in the minibuffer with `:' at each stop."
  352.   (interactive "P")
  353.   (save-excursion
  354.     (let (tabs)
  355.       (if arg
  356.       (setq tabs (default-value 'tab-stop-list))
  357.     (let ((regexp (concat "[ \t]+[" (regexp-quote picture-tab-chars) "]")))
  358.       (beginning-of-line)
  359.       (let ((bol (point)))
  360.         (end-of-line)
  361.         (while (re-search-backward regexp bol t)
  362.           (skip-chars-forward " \t")
  363.           (setq tabs (cons (current-column) tabs)))
  364.         (if (null tabs)
  365.         (error "No characters in set %s on this line."
  366.                (regexp-quote picture-tab-chars))))))
  367.       (setq tab-stop-list tabs)
  368.       (let ((blurb (make-string (1+ (nth (1- (length tabs)) tabs)) ?\ )))
  369.     (while tabs
  370.       (aset blurb (car tabs) ?:)
  371.       (setq tabs (cdr tabs)))
  372.     (message blurb)))))
  373.  
  374. (defun picture-tab-search (&optional arg)
  375.   "Move to column beneath next interesting char in previous line.
  376. With ARG move to column occupied by next interesting character in this
  377. line.  The character must be preceded by whitespace.
  378. \"interesting characters\" are defined by variable `picture-tab-chars'.
  379. If no such character is found, move to beginning of line."
  380.   (interactive "P")
  381.   (let ((target (current-column)))
  382.     (save-excursion
  383.       (if (and (not arg)
  384.            (progn
  385.          (beginning-of-line)
  386.          (skip-chars-backward
  387.           (concat "^" (regexp-quote picture-tab-chars))
  388.           (point-min))
  389.          (not (bobp))))
  390.       (move-to-column target))
  391.       (if (re-search-forward
  392.        (concat "[ \t]+[" (regexp-quote picture-tab-chars) "]")
  393.        (save-excursion (end-of-line) (point))
  394.        'move)
  395.       (setq target (1- (current-column)))
  396.     (setq target nil)))
  397.     (if target
  398.     (move-to-column-force target)
  399.       (beginning-of-line))))
  400.  
  401. (defun picture-tab (&optional arg)
  402.   "Tab transparently (just move point) to next tab stop.
  403. With prefix arg, overwrite the traversed text with spaces.  The tab stop
  404. list can be changed by \\[picture-set-tab-stops] and \\[edit-tab-stops].
  405. See also documentation for variable `picture-tab-chars'."
  406.   (interactive "P")
  407.   (let* ((opoint (point)))
  408.     (move-to-tab-stop)
  409.     (if arg
  410.     (let (indent-tabs-mode
  411.           (column (current-column)))
  412.       (delete-region opoint (point))
  413.       (indent-to column))
  414.       ;; XEmacs addition:
  415.       (setq zmacs-region-stays t))))
  416.  
  417. ;; Picture Rectangles
  418.  
  419. (defconst picture-killed-rectangle nil
  420.   "Rectangle killed or copied by \\[picture-clear-rectangle] in Picture mode.
  421. The contents can be retrieved by \\[picture-yank-rectangle]")
  422.  
  423. (defun picture-clear-rectangle (start end &optional killp)
  424.   "Clear and save rectangle delineated by point and mark.
  425. The rectangle is saved for yanking by \\[picture-yank-rectangle] and replaced
  426. with whitespace.  The previously saved rectangle, if any, is lost.  With
  427. prefix argument, the rectangle is actually killed, shifting remaining text."
  428.   (interactive "r\nP")
  429.   (setq picture-killed-rectangle (picture-snarf-rectangle start end killp)))
  430.  
  431. (defun picture-clear-rectangle-to-register (start end register &optional killp)
  432.   "Clear rectangle delineated by point and mark into REGISTER.
  433. The rectangle is saved in REGISTER and replaced with whitespace.  With
  434. prefix argument, the rectangle is actually killed, shifting remaining text."
  435.   (interactive "r\ncRectangle to register: \nP")
  436.   (set-register register (picture-snarf-rectangle start end killp)))
  437.  
  438. (defun picture-snarf-rectangle (start end &optional killp)
  439.   (let ((column (current-column))
  440.     (indent-tabs-mode nil))
  441.     (prog1 (save-excursion
  442.              (if killp
  443.                  (delete-extract-rectangle start end)
  444.                (prog1 (extract-rectangle start end)
  445.                       (clear-rectangle start end))))
  446.        (move-to-column-force column)
  447.        ;; XEmacs addition:
  448.        (setq zmacs-region-stays nil))))
  449.  
  450. (defun picture-yank-rectangle (&optional insertp)
  451.   "Overlay rectangle saved by \\[picture-clear-rectangle]
  452. The rectangle is positioned with upper left corner at point, overwriting
  453. existing text.  With prefix argument, the rectangle is inserted instead,
  454. shifting existing text.  Leaves mark at one corner of rectangle and
  455. point at the other (diagonally opposed) corner."
  456.   (interactive "P")
  457.   (if (not (consp picture-killed-rectangle))
  458.       (error "No rectangle saved.")
  459.     (picture-insert-rectangle picture-killed-rectangle insertp)))
  460.  
  461. (defun picture-yank-rectangle-from-register (register &optional insertp)
  462.   "Overlay rectangle saved in REGISTER.
  463. The rectangle is positioned with upper left corner at point, overwriting
  464. existing text.  With prefix argument, the rectangle is
  465. inserted instead, shifting existing text.  Leaves mark at one corner
  466. of rectangle and point at the other (diagonally opposed) corner."
  467.   (interactive "cRectangle from register: \nP")
  468.   (let ((rectangle (get-register register)))
  469.     (if (not (consp rectangle))
  470.     (error "Register %c does not contain a rectangle." register)
  471.       (picture-insert-rectangle rectangle insertp))))
  472.  
  473. (defun picture-insert-rectangle (rectangle &optional insertp)
  474.   "Overlay RECTANGLE with upper left corner at point.
  475. Optional argument INSERTP, if non-nil causes RECTANGLE to be inserted.
  476. Leaves the region surrounding the rectangle."
  477.   (let ((indent-tabs-mode nil))
  478.     (if (not insertp)
  479.     (save-excursion
  480.       (delete-rectangle (point)
  481.                 (progn
  482.                   (picture-forward-column (length (car rectangle)))
  483.                   (picture-move-down (1- (length rectangle)))
  484.                   (point)))))
  485.     (push-mark)
  486.     (insert-rectangle rectangle)))
  487.  
  488.  
  489. ;; Picture Keymap, entry and exit points.
  490.  
  491. (defconst picture-mode-map nil)
  492.  
  493. (defun picture-substitute (oldfun newfun)
  494.   (substitute-key-definition oldfun newfun picture-mode-map global-map))
  495.  
  496. (if (not picture-mode-map)
  497.     (let ((i ?\ ))
  498.       (setq picture-mode-map (make-keymap))
  499.       (while (< i ?\177)
  500.     (define-key picture-mode-map (make-string 1 i) 'picture-self-insert)
  501.     (setq i (1+ i)))
  502.  
  503.       (picture-substitute 'forward-char 'picture-forward-column)
  504.       (picture-substitute 'backward-char 'picture-backward-column)
  505.       (picture-substitute 'delete-char 'picture-clear-column)
  506.       ;; There are two possibilities for what is normally on DEL.
  507.       (picture-substitute 'backward-delete-char-untabify 'picture-backward-clear-column)
  508.       (picture-substitute 'delete-backward-char 'picture-backward-clear-column)
  509.       (picture-substitute 'kill-line 'picture-clear-line)
  510.       (picture-substitute 'open-line 'picture-open-line)
  511.       (picture-substitute 'newline 'picture-newline)
  512.       (picture-substitute 'newline-andindent 'picture-duplicate-line)
  513.       (picture-substitute 'next-line 'picture-move-down)
  514.       (picture-substitute 'previous-line 'picture-move-up)
  515.       (picture-substitute 'beginning-of-line 'picture-beginning-of-line)
  516.       (picture-substitute 'end-of-line 'picture-end-of-line)
  517.  
  518.       (define-key picture-mode-map "\C-c\C-d" 'delete-char)
  519.       (define-key picture-mode-map "\e\t" 'picture-toggle-tab-state)
  520.       (define-key picture-mode-map "\t" 'picture-tab)
  521.       (define-key picture-mode-map "\e\t" 'picture-tab-search)
  522.       (define-key picture-mode-map "\C-c\t" 'picture-set-tab-stops)
  523.       (define-key picture-mode-map "\C-c\C-k" 'picture-clear-rectangle)
  524.       (define-key picture-mode-map "\C-c\C-w" 'picture-clear-rectangle-to-register)
  525.       (define-key picture-mode-map "\C-c\C-y" 'picture-yank-rectangle)
  526.       (define-key picture-mode-map "\C-c\C-x" 'picture-yank-rectangle-from-register)
  527.       (define-key picture-mode-map "\C-c\C-c" 'picture-mode-exit)
  528.       (define-key picture-mode-map "\C-c\C-f" 'picture-motion)
  529.       (define-key picture-mode-map "\C-c\C-b" 'picture-motion-reverse)
  530.       (define-key picture-mode-map "\C-c<" 'picture-movement-left)
  531.       (define-key picture-mode-map "\C-c>" 'picture-movement-right)
  532.       (define-key picture-mode-map "\C-c^" 'picture-movement-up)
  533.       (define-key picture-mode-map "\C-c." 'picture-movement-down)
  534.       (define-key picture-mode-map "\C-c`" 'picture-movement-nw)
  535.       (define-key picture-mode-map "\C-c'" 'picture-movement-ne)
  536.       (define-key picture-mode-map "\C-c/" 'picture-movement-sw)
  537.       (define-key picture-mode-map "\C-c\\" 'picture-movement-se)))
  538.  
  539. (defvar picture-mode-hook nil
  540.   "If non-nil, its value is called on entry to Picture mode.
  541. Picture mode is invoked by the command \\[picture-mode].")
  542.  
  543. (defvar picture-mode-old-local-map)
  544. (defvar picture-mode-old-mode-name)
  545. (defvar picture-mode-old-major-mode)
  546. (defvar picture-mode-old-truncate-lines)
  547.  
  548. ;;;###autoload
  549. (defun picture-mode ()
  550.   "Switch to Picture mode, in which a quarter-plane screen model is used.
  551. Printing characters replace instead of inserting themselves with motion
  552. afterwards settable by these commands:
  553.   C-c <      Move left after insertion.
  554.   C-c >      Move right after insertion.
  555.   C-c ^      Move up after insertion.
  556.   C-c .      Move down after insertion.
  557.   C-c `      Move northwest (nw) after insertion.
  558.   C-c '      Move northeast (ne) after insertion.
  559.   C-c /      Move southwest (sw) after insertion.
  560.   C-c \\   Move southeast (se) after insertion.
  561. The current direction is displayed in the modeline.  The initial
  562. direction is right.  Whitespace is inserted and tabs are changed to
  563. spaces when required by movement.  You can move around in the buffer
  564. with these commands:
  565.   \\[picture-move-down]      Move vertically to SAME column in previous line.
  566.   \\[picture-move-up]      Move vertically to SAME column in next line.
  567.   \\[picture-end-of-line]      Move to column following last non-whitespace character.
  568.   \\[picture-forward-column]      Move right inserting spaces if required.
  569.   \\[picture-backward-column]      Move left changing tabs to spaces if required.
  570.   C-c C-f Move in direction of current picture motion.
  571.   C-c C-b Move in opposite direction of current picture motion.
  572.   Return  Move to beginning of next line.
  573. You can edit tabular text with these commands:
  574.   M-Tab      Move to column beneath (or at) next interesting character.
  575.         `Indents' relative to a previous line.
  576.   Tab      Move to next stop in tab stop list.
  577.   C-c Tab Set tab stops according to context of this line.
  578.         With ARG resets tab stops to default (global) value.
  579.         See also documentation of variable    picture-tab-chars
  580.         which defines \"interesting character\".  You can manually
  581.         change the tab stop list with command \\[edit-tab-stops].
  582. You can manipulate text with these commands:
  583.   C-d      Clear (replace) ARG columns after point without moving.
  584.   C-c C-d Delete char at point - the command normally assigned to C-d.
  585.   \\[picture-backward-clear-column]  Clear (replace) ARG columns before point, moving back over them.
  586.   \\[picture-clear-line]      Clear ARG lines, advancing over them.     The cleared
  587.         text is saved in the kill ring.
  588.   \\[picture-open-line]      Open blank line(s) beneath current line.
  589. You can manipulate rectangles with these commands:
  590.   C-c C-k Clear (or kill) a rectangle and save it.
  591.   C-c C-w Like C-c C-k except rectangle is saved in named register.
  592.   C-c C-y Overlay (or insert) currently saved rectangle at point.
  593.   C-c C-x Like C-c C-y except rectangle is taken from named register.
  594.   \\[copy-rectangle-to-register]   Copies a rectangle to a register.
  595.   \\[advertised-undo]   Can undo effects of rectangle overlay commands
  596.         commands if invoked soon enough.
  597. You can return to the previous mode with:
  598.   C-c C-c Which also strips trailing whitespace from every line.
  599.         Stripping is suppressed by supplying an argument.
  600.  
  601. Entry to this mode calls the value of  picture-mode-hook  if non-nil.
  602.  
  603. Note that Picture mode commands will work outside of Picture mode, but
  604. they are not defaultly assigned to keys."
  605.   (interactive)
  606.   (if (eq major-mode 'picture-mode)
  607.       (error "You are already editing a picture.")
  608.     (make-local-variable 'picture-mode-old-local-map)
  609.     (setq picture-mode-old-local-map (current-local-map))
  610.     (use-local-map picture-mode-map)
  611.     (make-local-variable 'picture-mode-old-mode-name)
  612.     (setq picture-mode-old-mode-name mode-name)
  613.     (make-local-variable 'picture-mode-old-major-mode)
  614.     (setq picture-mode-old-major-mode major-mode)
  615.     (setq major-mode 'picture-mode)
  616.     (make-local-variable 'picture-killed-rectangle)
  617.     (setq picture-killed-rectangle nil)
  618.     (make-local-variable 'tab-stop-list)
  619.     (setq tab-stop-list (default-value 'tab-stop-list))
  620.     (make-local-variable 'picture-tab-chars)
  621.     (setq picture-tab-chars (default-value 'picture-tab-chars))
  622.     (make-local-variable 'picture-vertical-step)
  623.     (make-local-variable 'picture-horizontal-step)
  624.     (make-local-variable 'picture-mode-old-truncate-lines)
  625.     (setq picture-mode-old-truncate-lines truncate-lines)
  626.     (setq truncate-lines t)
  627.  
  628.     ;; XEmacs addition:
  629.     (make-local-variable 'mouse-track-rectangle-p)
  630.     (setq mouse-track-rectangle-p t)
  631.  
  632.     (picture-set-motion 0 1)
  633.  
  634.     ;; edit-picture-hook is what we used to run, picture-mode-hook is in doc.
  635.     (run-hooks 'edit-picture-hook 'picture-mode-hook)
  636.     (message
  637.      (substitute-command-keys
  638.       "Type \\[picture-mode-exit] in this buffer to return it to %s mode.")
  639.      picture-mode-old-mode-name)))
  640.  
  641. ;;;###autoload
  642. (defalias 'edit-picture 'picture-mode)
  643.  
  644. (defun picture-mode-exit (&optional nostrip)
  645.   "Undo picture-mode and return to previous major mode.
  646. With no argument strips whitespace from end of every line in Picture buffer
  647.   otherwise just return to previous mode."
  648.   (interactive "P")
  649.   (if (not (eq major-mode 'picture-mode))
  650.       (error "You aren't editing a Picture.")
  651.     (if (not nostrip) (picture-clean))
  652.     (setq mode-name picture-mode-old-mode-name)
  653.     (use-local-map picture-mode-old-local-map)
  654.     (setq major-mode picture-mode-old-major-mode)
  655.     (kill-local-variable 'tab-stop-list)
  656.     (setq truncate-lines picture-mode-old-truncate-lines)
  657.     ;; XEmacs change/addition:
  658.     (kill-local-variable 'mouse-track-rectangle-p)
  659.     (redraw-modeline)))
  660.  
  661. (defun picture-clean ()
  662.   "Eliminate whitespace at ends of lines."
  663.   (save-excursion
  664.    (goto-char (point-min))
  665.    (while (re-search-forward "[ \t][ \t]*$" nil t)
  666.      (delete-region (match-beginning 0) (point)))))
  667.  
  668. (provide 'picture)
  669.  
  670. ;;; picture.el ends here
  671.