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