4.4BSD/usr/src/contrib/emacs-18.57/lisp/picture.elc


(provide (quote picture))

(defun move-to-column-force (column) "\
Move to column COLUMN in current line.
Differs from move-to-column in that it creates or modifies whitespace
if necessary to attain exactly the specified column." (byte-code "Ã!ˆi	Wƒj‚+Ä	\"…hÅU…+ÆÇÈ!ˆ	jˆÃ!))‡" [column col indent-tabs-mode move-to-column /= 9 nil delete-char -1] 5))

(defun picture-end-of-line (&optional arg) "\
Position point after last non-blank character on current line.
With ARG not nil, move forward ARG - 1 lines first.
If scan reaches end of buffer, stop there without error." (interactive "P") (byte-code "Áˆ…ÂÃ!S!ˆÄ ˆÅÆ`Ç ˆ\"‡" [arg nil forward-line prefix-numeric-value beginning-of-line skip-chars-backward " 	" end-of-line] 8))

(defun picture-forward-column (arg) "\
Move cursor right, making whitespace if necessary.
With argument, move that many columns." (interactive "p") (byte-code "ÁˆÂi\\!‡" [arg nil move-to-column-force] 3))

(defun picture-backward-column (arg) "\
Move cursor left, making whitespace if necessary.
With argument, move that many columns." (interactive "p") (byte-code "ÁˆÂiZ!‡" [arg nil move-to-column-force] 3))

(defun picture-move-down (arg) "\
Move vertically down, making whitespace if necessary.
With argument, move that many lines." (interactive "p") (byte-code "ˆiÃ	!ˆÄ!)‡" [col arg nil picture-newline move-to-column-force] 3))

(defconst picture-vertical-step 0 "\
Amount to move vertically after text character in Picture mode.")

(defconst picture-horizontal-step 1 "\
Amount to move horizontally after text character in Picture mode.")

(defun picture-move-up (arg) "\
Move vertically up, making whitespace if necessary.
With argument, move that many lines." (interactive "p") (byte-code "ÁˆÂ[!‡" [arg nil picture-move-down] 2))

(defun picture-movement-right nil "\
Move right after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÃ\"‡" [nil picture-set-motion 0 1] 3))

(defun picture-movement-left nil "\
Move left after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÃ\"‡" [nil picture-set-motion 0 -1] 3))

(defun picture-movement-up nil "\
Move up after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÃ\"‡" [nil picture-set-motion -1 0] 3))

(defun picture-movement-down nil "\
Move down after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÃ\"‡" [nil picture-set-motion 1 0] 3))

(defun picture-movement-nw nil "\
Move up and left after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÂ\"‡" [nil picture-set-motion -1] 3))

(defun picture-movement-ne nil "\
Move up and right after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÃ\"‡" [nil picture-set-motion -1 1] 3))

(defun picture-movement-sw nil "\
Move down and left after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÃ\"‡" [nil picture-set-motion 1 -1] 3))

(defun picture-movement-se nil "\
Move down and right after self-inserting character in Picture mode." (interactive) (byte-code "ÀˆÁÂÂ\"‡" [nil picture-set-motion 1] 3))

(defun picture-set-motion (vert horiz) "\
Set VERTICAL and HORIZONTAL increments for movement in Picture mode.
The mode line is updated to reflect the current direction." (byte-code "	‰ˆÅÆÇÈÉÊË\"ÌÍÊ	Ë\"T\"#Î\"@\"‰ˆÏÐ !ˆÑÒ!‡" [picture-vertical-step vert picture-horizontal-step horiz mode-name format "Picture:%s" nthcdr + 1 % 2 * 3 (nw up ne left none right sw down se) set-buffer-modified-p buffer-modified-p message ""] 12))

(defun picture-move nil "\
Move in direction of  picture-vertical-step  and  picture-horizontal-step." (byte-code "Â!ˆÃ	!‡" [picture-vertical-step picture-horizontal-step picture-move-down picture-forward-column] 3))

(defun picture-motion (arg) "\
Move point in direction of current picture motion in Picture mode.
With ARG do it that many times.  Useful for delineating rectangles in
conjunction with diagonal picture motion.
Do \\[command-apropos]  picture-movement  to see commands which control motion." (interactive "p") (byte-code "ÈÄÅ	\"!ˆÆÅ
\"!‡" [arg picture-vertical-step picture-horizontal-step nil picture-move-down * picture-forward-column] 6))

(defun picture-motion-reverse (arg) "\
Move point in direction opposite of current picture motion in Picture mode.
With ARG do it that many times.  Useful for delineating rectangles in
conjunction with diagonal picture motion.
Do \\[command-apropos]  picture-movement  to see commands which control motion." (interactive "p") (byte-code "ÁˆÂ[!‡" [arg nil picture-motion] 2))

(defun picture-self-insert (arg) "\
Insert this character in place of character previously at the cursor.
The cursor then moves in the direction you previously specified
with the commands picture-movement-right, picture-movement-up, etc.
Do \\[command-apropos]  picture-movement  to see those commands." (interactive "p") (byte-code "ˆÃV…#S‰ˆÄiT!ˆÅÆ!ˆ	cˆÇÆ!ˆÈ ˆ‚‡" [arg last-input-char nil 0 move-to-column-force delete-char -1 forward-char picture-move] 6))

(defun picture-clear-column (arg) "\
Clear out ARG columns after point without moving." (interactive "p") (byte-code "Ĉ`i	\\Å
!ˆÆ`\"ˆŠ
	]j)+‡" [opoint original-col target-col arg nil move-to-column-force delete-region] 4))

(defun picture-backward-clear-column (arg) "\
Clear out ARG columns before point, moving back over them." (interactive "p") (byte-code "ÁˆÂ[!‡" [arg nil picture-clear-column] 2))

(defun picture-clear-line (arg) "\
Clear out rest of line; if at end of line, advance to next line.
Cleared-out line text goes into the kill ring, as do
newlines that are advanced over.
With argument, clear out (and save in kill ring) that many lines." (interactive "P") (byte-code "Áˆƒ!Â!‰ˆÃ!ˆÄÅVƒ‚[!‚9ÆÇ!ƒ2È`ÉÊ!ˆ`\"‚9Ë`Ì ˆ`\"‡" [arg nil prefix-numeric-value kill-line newline 0 looking-at "[ 	]*$" kill-ring-save forward-line 1 kill-region end-of-line] 10))

(defun picture-newline (arg) "\
Move to the beginning of the following line.
With argument, moves that many lines (up, if negative argument);
always moves to the beginning of a line." (interactive "p") (byte-code "ÁˆÂWƒÃ!‚,ÂV…,Ä ˆmƒ Å ‚#ÆÇ!ˆS‰ˆ‚‡" [arg nil 0 forward-line end-of-line newline forward-char 1] 7))

(defun picture-open-line (arg) "\
Insert an empty line after the current line.
With positive argument insert that many lines." (interactive "p") (byte-code "ÁˆŠÂ ˆÃ!)‡" [arg nil end-of-line open-line] 3))

(defun picture-duplicate-line nil "\
Insert a duplicate of the current line, below it." (interactive) (byte-code "ÁˆŠÂà ˆ`ÄÅ!ˆ`\"ÆÇ!ˆc))‡" [contents nil buffer-substring beginning-of-line picture-newline 1 forward-line -1] 5))

(defvar picture-tab-chars "!-~" "\
*A character set which controls behavior of commands
\\[picture-set-tab-stops] and \\[picture-tab-search].  It is NOT a
regular expression, any regexp special characters will be quoted.
It defines a set of \"interesting characters\" to look for when setting
(or searching for) tab stops, initially \"!-~\" (all printing characters).
For example, suppose that you are editing a table which is formatted thus:
| foo		| bar + baz | 23  *
| bubbles	| and + etc | 97  *
and that picture-tab-chars is \"|+*\".  Then invoking
\\[picture-set-tab-stops] on either of the previous lines would result
in the following tab stops
		:     :     :     :
Another example - \"A-Za-z0-9\" would produce the tab stops
  :		  :	:     :

Note that if you want the character `-' to be in the set, it must be
included in a range or else appear in a context where it cannot be
taken for indicating a range (e.g. \"-A-Z\" declares the set to be the
letters `A' through `Z' and the character `-').  If you want the
character `\\' in the set it must be preceded by itself: \"\\\\\".

The command \\[picture-tab-search] is defined to move beneath (or to) a
character belonging to this set independent of the tab stops list.")

(defun picture-set-tab-stops (&optional arg) "\
Set value of  tab-stop-list  according to context of this line.
This controls the behavior of \\[picture-tab].  A tab stop
is set at every column occupied by an \"interesting character\" that is
preceded by whitespace.  Interesting characters are defined by the
variable  picture-tab-chars,  see its documentation for an example
of usage.  With ARG, just (re)set  tab-stop-list  to its default value.
The tab stops computed are displayed in the minibuffer with `:' at
each stop." (interactive "P") (byte-code "ȈŠÈ	ƒÉÆ!‰‚CÊË!ÌQÍ ˆ`Î ˆÏ
Å#…5ÐÑ!ˆiB‰ˆ‚ ˆ?…AÒÓË!\"))ˆ‰ˆÔGS8TÕ\"…g@ÖIˆA‰ˆ‚Tˆ×!)))‡" [tabs arg regexp picture-tab-chars bol t tab-stop-list blurb nil default-value "[ 	]+[" regexp-quote "]" beginning-of-line end-of-line re-search-backward skip-chars-forward " 	" error "No characters in set %s on this line." make-string 32 58 message] 13))

(defun picture-tab-search (&optional arg) "\
Move to column beneath next interesting char in previous line.
With ARG move to column occupied by next interesting character in this
line.  The character must be preceded by whitespace.
\"interesting characters\" are defined by variable  picture-tab-chars.
If no such character is found, move to beginning of line." (interactive "P") (byte-code "ÈiŠ	?…Ä ˆÅÆÇ
!Pe\"ˆo?…È!ˆÉÊÇ
!ËQŠÌ ˆ`)Í#ƒ8iS‰‚;É)ˆƒGÎ!‚IÄ )‡" [target arg picture-tab-chars nil beginning-of-line skip-chars-backward "^" regexp-quote move-to-column re-search-forward "[ 	]+[" "]" end-of-line move move-to-column-force] 10))

(defun picture-tab (&optional arg) "\
Tab transparently (move) to next tab stop.
With ARG overwrite the traversed text with spaces.  The tab stop
list can be changed by \\[picture-set-tab-stops] and \\[edit-tab-stops].
See also documentation for variable  picture-tab-chars." (interactive "P") (byte-code "Ĉ`Å ˆiÆ`\"ˆÇ	!ˆ
… ÄÆ`\"ˆ	j)*‡" [opoint target arg indent-tabs-mode nil tab-to-tab-stop delete-region move-to-column-force] 6))

(defconst picture-killed-rectangle nil "\
Rectangle killed or copied by \\[picture-clear-rectangle] in Picture mode.
The contents can be retrieved by \\[picture-yank-rectangle]")

(defun picture-clear-rectangle (start end &optional killp) "\
Clear and save rectangle delineated by point and mark.
The rectangle is saved for yanking by \\[picture-yank-rectangle] and replaced
with whitespace.  The previously saved rectangle, if any, is lost.
With prefix argument, the rectangle is actually killed, shifting remaining
text." (interactive "r
P") (byte-code "ĈÅ	
#‰‡" [picture-killed-rectangle start end killp nil picture-snarf-rectangle] 4))

(defun picture-clear-rectangle-to-register (start end register &optional killp) "\
Clear rectangle delineated by point and mark into REGISTER.
The rectangle is saved in REGISTER and replaced with whitespace.
With prefix argument, the rectangle is actually killed, shifting remaining
text." (interactive "r
cRectangle to register: 
P") (byte-code "ĈÅÆ	
#\"‡" [register start end killp nil set-register picture-snarf-rectangle] 6))

(defun picture-snarf-rectangle (start end &optional killp) (byte-code "iŠƒÆ
\"‚Ç
\"È
\"ˆ)É!ˆ*‡" [column indent-tabs-mode nil killp start end delete-extract-rectangle extract-rectangle clear-rectangle move-to-column-force] 6))

(defun picture-yank-rectangle (&optional insertp) "\
Overlay rectangle saved by \\[picture-clear-rectangle]
The rectangle is positioned with upper left corner at point, overwriting
existing text.  With prefix argument, the rectangle is inserted instead,
shifting existing text.  Leaves mark at one corner of rectangle and
point at the other (diagonally opposed) corner." (interactive "P") (byte-code "ˆ:?ƒÃÄ!‚Å	\"‡" [picture-killed-rectangle insertp nil error "No rectangle saved." picture-insert-rectangle] 4))

(defun picture-yank-rectangle-from-register (register &optional insertp) "\
Overlay rectangle saved in REGISTER.
The rectangle is positioned with upper left corner at point, overwriting
existing text.  With prefix argument, the rectangle is
inserted instead, shifting existing text.  Leaves mark at one corner
of rectangle and point at the other (diagonally opposed) corner." (interactive "cRectangle from register: 
P") (byte-code "ÈÄ	!:?ƒÅÆ	\"‚Ç
\")‡" [rectangle register insertp nil get-register error "Register %c does not contain a rectangle." picture-insert-rectangle] 5))

(defun picture-insert-rectangle (rectangle &optional insertp) "\
Overlay RECTANGLE with upper left corner at point.
Optional argument INSERTP, if non-nil causes RECTANGLE to be inserted.
Leaves the region surrounding the rectangle." (byte-code "Á
?…ŠÄ`Å@G!ˆÆGS!ˆ`\")ˆÇ ˆÈ!)‡" [indent-tabs-mode nil insertp rectangle delete-rectangle picture-forward-column picture-move-down push-mark insert-rectangle] 6))

(defconst picture-mode-map nil)

(if (not picture-mode-map) (let ((i 32)) (setq picture-mode-map (make-keymap)) (while (< i 127) (aset picture-mode-map i (quote picture-self-insert)) (setq i (1+ i))) (define-key picture-mode-map "" (quote picture-forward-column)) (define-key picture-mode-map "" (quote picture-backward-column)) (define-key picture-mode-map "" (quote picture-clear-column)) (define-key picture-mode-map "" (quote delete-char)) (define-key picture-mode-map "" (quote picture-backward-clear-column)) (define-key picture-mode-map "" (quote picture-clear-line)) (define-key picture-mode-map "" (quote picture-open-line)) (define-key picture-mode-map "
" (quote picture-newline)) (define-key picture-mode-map "
" (quote picture-duplicate-line)) (define-key picture-mode-map "" (quote picture-move-down)) (define-key picture-mode-map "" (quote picture-move-up)) (define-key picture-mode-map "" (quote picture-end-of-line)) (define-key picture-mode-map "	" (quote picture-toggle-tab-state)) (define-key picture-mode-map "	" (quote picture-tab)) (define-key picture-mode-map "	" (quote picture-tab-search)) (define-key picture-mode-map "	" (quote picture-set-tab-stops)) (define-key picture-mode-map "" (quote picture-clear-rectangle)) (define-key picture-mode-map "" (quote picture-clear-rectangle-to-register)) (define-key picture-mode-map "" (quote picture-yank-rectangle)) (define-key picture-mode-map "" (quote picture-yank-rectangle-from-register)) (define-key picture-mode-map "" (quote picture-mode-exit)) (define-key picture-mode-map "" (quote picture-motion)) (define-key picture-mode-map "" (quote picture-motion-reverse)) (define-key picture-mode-map "<" (quote picture-movement-left)) (define-key picture-mode-map ">" (quote picture-movement-right)) (define-key picture-mode-map "^" (quote picture-movement-up)) (define-key picture-mode-map "." (quote picture-movement-down)) (define-key picture-mode-map "`" (quote picture-movement-nw)) (define-key picture-mode-map "'" (quote picture-movement-ne)) (define-key picture-mode-map "/" (quote picture-movement-sw)) (define-key picture-mode-map "\\" (quote picture-movement-se))))

(defvar edit-picture-hook nil "\
If non-nil, it's value is called on entry to Picture mode.
Picture mode is invoked by the command \\[edit-picture].")

(defun edit-picture nil "\
Switch to Picture mode, in which a quarter-plane screen model is used.
Printing characters replace instead of inserting themselves with motion
afterwards settable by these commands:
  C-c <	  Move left after insertion.
  C-c >	  Move right after insertion.
  C-c ^	  Move up after insertion.
  C-c .	  Move down after insertion.
  C-c `	  Move northwest (nw) after insertion.
  C-c '	  Move northeast (ne) after insertion.
  C-c /	  Move southwest (sw) after insertion.
  C-c \\   Move southeast (se) after insertion.
The current direction is displayed in the mode line.  The initial
direction is right.  Whitespace is inserted and tabs are changed to
spaces when required by movement.  You can move around in the buffer
with these commands:
  C-p	  Move vertically to SAME column in previous line.
  C-n	  Move vertically to SAME column in next line.
  C-e	  Move to column following last non-whitespace character.
  C-f	  Move right inserting spaces if required.
  C-b	  Move left changing tabs to spaces if required.
  C-c C-f Move in direction of current picture motion.
  C-c C-b Move in opposite direction of current picture motion.
  Return  Move to beginning of next line.
You can edit tabular text with these commands:
  M-Tab	  Move to column beneath (or at) next interesting character.
	    `Indents' relative to a previous line.
  Tab	  Move to next stop in tab stop list.
  C-c Tab Set tab stops according to context of this line.
	    With ARG resets tab stops to default (global) value.
	    See also documentation of variable	picture-tab-chars
	    which defines \"interesting character\".  You can manually
	    change the tab stop list with command \\[edit-tab-stops].
You can manipulate text with these commands:
  C-d	  Clear (replace) ARG columns after point without moving.
  C-c C-d Delete char at point - the command normally assigned to C-d.
  Delete  Clear (replace) ARG columns before point, moving back over them.
  C-k	  Clear ARG lines, advancing over them.	 The cleared
	    text is saved in the kill ring.
  C-o	  Open blank line(s) beneath current line.
You can manipulate rectangles with these commands:
  C-c C-k Clear (or kill) a rectangle and save it.
  C-c C-w Like C-c C-k except rectangle is saved in named register.
  C-c C-y Overlay (or insert) currently saved rectangle at point.
  C-c C-x Like C-c C-y except rectangle is taken from named register.
  \\[copy-rectangle-to-register]   Copies a rectangle to a register.
  \\[advertised-undo]   Can undo effects of rectangle overlay commands
	    commands if invoked soon enough.
You can return to the previous mode with:
  C-c C-c Which also strips trailing whitespace from every line.
	    Stripping is suppressed by supplying an argument.

Entry to this mode calls the value of  edit-picture-hook  if non-nil.

Note that Picture mode commands will work outside of Picture mode, but
they are not defaultly assigned to keys." (interactive) (byte-code "LjÊ=ƒËÌ!‚eÍÁ!ˆÎ ‰ˆÏ
!ˆÍÃ!ˆ‰ˆÍÅ!ˆ‰ˆÊ‰ˆÍÆ!ˆÇ‰ˆÍÈ!ˆÐÈ!‰ˆÍÉ!ˆÐÉ!‰	ˆÍÑ!ˆÍÒ!ˆÓÔÕ\"ˆÖ×!ˆØÙÚ!\"‡" [major-mode picture-mode-old-local-map picture-mode-map picture-mode-old-mode-name mode-name picture-mode-old-major-mode picture-killed-rectangle nil tab-stop-list picture-tab-chars edit-picture error "You are already editing a Picture." make-local-variable current-local-map use-local-map default-value picture-vertical-step picture-horizontal-step picture-set-motion 0 1 run-hooks edit-picture-hook message substitute-command-keys "Type \\[picture-mode-exit] in this buffer to return it to %s mode."] 19))

(fset (quote picture-mode) (quote edit-picture))

(defun picture-mode-exit (&optional nostrip) "\
Undo edit-picture and return to previous major mode.
With no argument strips whitespace from end of every line in Picture buffer
  otherwise just return to previous mode." (interactive "P") (byte-code "ƈÇ=?ƒÈÉ!‚+	?…Ê ˆ‰ˆË!ˆ
‰ˆÌÍ!ˆÎÏ !‡" [major-mode nostrip mode-name picture-mode-old-mode-name picture-mode-old-local-map picture-mode-old-major-mode nil edit-picture error "You aren't editing a Picture." picture-clean use-local-map kill-local-variable tab-stop-list set-buffer-modified-p buffer-modified-p] 7))

(defun picture-clean nil "\
Eliminate whitespace at ends of lines." (byte-code "ŠebˆÂÃÀÁ#…ÄÅÆ!`\"ˆ‚)‡" [nil t re-search-forward "[ 	][ 	]*$" delete-region match-beginning 0] 6))