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