aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond1993-04-27 21:59:55 +0000
committerEric S. Raymond1993-04-27 21:59:55 +0000
commitca9c75792e0ea47196f75ec861d93d2fde88d38e (patch)
tree20964c6efb7639ae036333864e346b9a24b85b95
parentf03e319c88b4f7f23ec80d7c50369fc6c804d641 (diff)
downloademacs-ca9c75792e0ea47196f75ec861d93d2fde88d38e.tar.gz
emacs-ca9c75792e0ea47196f75ec861d93d2fde88d38e.zip
Completed the package entry point's name change from edit-picture to
picture-mode. (move-to-column-force, picture-end-of-line): When movement is completed, scroll horizontally if necessary to make point visible. (picture-beginning-of-line): New function. Exists to force horizontal scrolling if the buffer is wide. (picture-mode-map): Instead of rebinding common keystrokes, use substitute-key-definition to remap all keystrokes attached to the corresponding commands.
-rw-r--r--lisp/textmodes/picture.el94
1 files changed, 60 insertions, 34 deletions
diff --git a/lisp/textmodes/picture.el b/lisp/textmodes/picture.el
index f1808c2ec7c..8435376a8b7 100644
--- a/lisp/textmodes/picture.el
+++ b/lisp/textmodes/picture.el
@@ -43,11 +43,23 @@ if necessary to attain exactly the specified column."
43 (let (indent-tabs-mode) 43 (let (indent-tabs-mode)
44 (delete-char -1) 44 (delete-char -1)
45 (indent-to col) 45 (indent-to col)
46 (move-to-column column)))))) 46 (move-to-column column))))
47 ;; This call will go away when Emacs gets real horizonal autoscrolling
48 (hscroll-point-visible)))
47 49
48 50
49;; Picture Movement Commands 51;; Picture Movement Commands
50 52
53(defun picture-beginning-of-line (&optional arg)
54 "Position point at the beginning of the line.
55With ARG not nil, move forward ARG - 1 lines first.
56If scan reaches end of buffer, stop there without error."
57 (interactive "P")
58 (if arg (forward-line (1- (prefix-numeric-value arg))))
59 (beginning-of-line)
60 ;; This call will go away when Emacs gets real horizonal autoscrolling
61 (hscroll-point-visible))
62
51(defun picture-end-of-line (&optional arg) 63(defun picture-end-of-line (&optional arg)
52 "Position point after last non-blank character on current line. 64 "Position point after last non-blank character on current line.
53With ARG not nil, move forward ARG - 1 lines first. 65With ARG not nil, move forward ARG - 1 lines first.
@@ -55,7 +67,9 @@ If scan reaches end of buffer, stop there without error."
55 (interactive "P") 67 (interactive "P")
56 (if arg (forward-line (1- (prefix-numeric-value arg)))) 68 (if arg (forward-line (1- (prefix-numeric-value arg))))
57 (beginning-of-line) 69 (beginning-of-line)
58 (skip-chars-backward " \t" (prog1 (point) (end-of-line)))) 70 (skip-chars-backward " \t" (prog1 (point) (end-of-line)))
71 ;; This call will go away when Emacs gets real horizonal autoscrolling
72 (hscroll-point-visible))
59 73
60(defun picture-forward-column (arg) 74(defun picture-forward-column (arg)
61 "Move cursor right, making whitespace if necessary. 75 "Move cursor right, making whitespace if necessary.
@@ -223,7 +237,9 @@ always moves to the beginning of a line."
223 (while (> arg 0) 237 (while (> arg 0)
224 (end-of-line) 238 (end-of-line)
225 (if (eobp) (newline) (forward-char 1)) 239 (if (eobp) (newline) (forward-char 1))
226 (setq arg (1- arg))))) 240 (setq arg (1- arg))))
241 ;; This call will go away when Emacs gets real horizonal autoscrolling
242 (hscroll-point-visible))
227 243
228(defun picture-open-line (arg) 244(defun picture-open-line (arg)
229 "Insert an empty line after the current line. 245 "Insert an empty line after the current line.
@@ -231,7 +247,9 @@ With positive argument insert that many lines."
231 (interactive "p") 247 (interactive "p")
232 (save-excursion 248 (save-excursion
233 (end-of-line) 249 (end-of-line)
234 (open-line arg))) 250 (open-line arg))
251 ;; This call will go away when Emacs gets real horizonal autoscrolling
252 (hscroll-point-visible))
235 253
236(defun picture-duplicate-line () 254(defun picture-duplicate-line ()
237 "Insert a duplicate of the current line, below it." 255 "Insert a duplicate of the current line, below it."
@@ -417,24 +435,30 @@ Leaves the region surrounding the rectangle."
417 435
418(defconst picture-mode-map nil) 436(defconst picture-mode-map nil)
419 437
438(defun picture-substitute (oldfun newfun)
439 (substitute-key-definition oldfun newfun picture-mode-map global-map))
440
420(if (not picture-mode-map) 441(if (not picture-mode-map)
421 (let ((i ?\ )) 442 (let ((i ?\ ))
422 (setq picture-mode-map (make-keymap)) 443 (setq picture-mode-map (make-keymap))
423 (while (< i ?\177) 444 (while (< i ?\177)
424 (define-key picture-mode-map (make-string 1 i) 'picture-self-insert) 445 (define-key picture-mode-map (make-string 1 i) 'picture-self-insert)
425 (setq i (1+ i))) 446 (setq i (1+ i)))
426 (define-key picture-mode-map "\C-f" 'picture-forward-column) 447
427 (define-key picture-mode-map "\C-b" 'picture-backward-column) 448 (picture-substitute 'forward-char 'picture-forward-column)
428 (define-key picture-mode-map "\C-d" 'picture-clear-column) 449 (picture-substitute 'backward-char 'picture-backward-column)
450 (picture-substitute 'delete-char 'picture-clear-column)
451 (picture-substitute 'backward-delete-char-untabify 'picture-backward-clear-column)
452 (picture-substitute 'kill-line 'picture-clear-line)
453 (picture-substitute 'open-line 'picture-open-line)
454 (picture-substitute 'newline 'picture-newline)
455 (picture-substitute 'newline-andindent 'picture-duplicate-line)
456 (picture-substitute 'next-line 'picture-move-down)
457 (picture-substitute 'previous-line 'picture-move-up)
458 (picture-substitute 'beginning-of-line 'picture-beginning-of-line)
459 (picture-substitute 'end-of-line 'picture-end-of-line)
460
429 (define-key picture-mode-map "\C-c\C-d" 'delete-char) 461 (define-key picture-mode-map "\C-c\C-d" 'delete-char)
430 (define-key picture-mode-map "\177" 'picture-backward-clear-column)
431 (define-key picture-mode-map "\C-k" 'picture-clear-line)
432 (define-key picture-mode-map "\C-o" 'picture-open-line)
433 (define-key picture-mode-map "\C-m" 'picture-newline)
434 (define-key picture-mode-map "\C-j" 'picture-duplicate-line)
435 (define-key picture-mode-map "\C-n" 'picture-move-down)
436 (define-key picture-mode-map "\C-p" 'picture-move-up)
437 (define-key picture-mode-map "\C-e" 'picture-end-of-line)
438 (define-key picture-mode-map "\e\t" 'picture-toggle-tab-state) 462 (define-key picture-mode-map "\e\t" 'picture-toggle-tab-state)
439 (define-key picture-mode-map "\t" 'picture-tab) 463 (define-key picture-mode-map "\t" 'picture-tab)
440 (define-key picture-mode-map "\e\t" 'picture-tab-search) 464 (define-key picture-mode-map "\e\t" 'picture-tab-search)
@@ -455,16 +479,16 @@ Leaves the region surrounding the rectangle."
455 (define-key picture-mode-map "\C-c/" 'picture-movement-sw) 479 (define-key picture-mode-map "\C-c/" 'picture-movement-sw)
456 (define-key picture-mode-map "\C-c\\" 'picture-movement-se))) 480 (define-key picture-mode-map "\C-c\\" 'picture-movement-se)))
457 481
458(defvar edit-picture-hook nil 482(defvar picture-mode-hook nil
459 "If non-nil, it's value is called on entry to Picture mode. 483 "If non-nil, its value is called on entry to Picture mode.
460Picture mode is invoked by the command \\[edit-picture].") 484Picture mode is invoked by the command \\[picture-mode].")
461 485
462(defvar picture-mode-old-local-map) 486(defvar picture-mode-old-local-map)
463(defvar picture-mode-old-mode-name) 487(defvar picture-mode-old-mode-name)
464(defvar picture-mode-old-major-mode) 488(defvar picture-mode-old-major-mode)
465 489
466;;;###autoload 490;;;###autoload
467(defun edit-picture () 491(defun picture-mode ()
468 "Switch to Picture mode, in which a quarter-plane screen model is used. 492 "Switch to Picture mode, in which a quarter-plane screen model is used.
469Printing characters replace instead of inserting themselves with motion 493Printing characters replace instead of inserting themselves with motion
470afterwards settable by these commands: 494afterwards settable by these commands:
@@ -480,11 +504,11 @@ The current direction is displayed in the mode line. The initial
480direction is right. Whitespace is inserted and tabs are changed to 504direction is right. Whitespace is inserted and tabs are changed to
481spaces when required by movement. You can move around in the buffer 505spaces when required by movement. You can move around in the buffer
482with these commands: 506with these commands:
483 C-p Move vertically to SAME column in previous line. 507 \\[picture-move-down] Move vertically to SAME column in previous line.
484 C-n Move vertically to SAME column in next line. 508 \\[picture-move-up] Move vertically to SAME column in next line.
485 C-e Move to column following last non-whitespace character. 509 \\[picture-end-of-line] Move to column following last non-whitespace character.
486 C-f Move right inserting spaces if required. 510 \\[picture-forward-column] Move right inserting spaces if required.
487 C-b Move left changing tabs to spaces if required. 511 \\[picture-backward-column] Move left changing tabs to spaces if required.
488 C-c C-f Move in direction of current picture motion. 512 C-c C-f Move in direction of current picture motion.
489 C-c C-b Move in opposite direction of current picture motion. 513 C-c C-b Move in opposite direction of current picture motion.
490 Return Move to beginning of next line. 514 Return Move to beginning of next line.
@@ -500,10 +524,10 @@ You can edit tabular text with these commands:
500You can manipulate text with these commands: 524You can manipulate text with these commands:
501 C-d Clear (replace) ARG columns after point without moving. 525 C-d Clear (replace) ARG columns after point without moving.
502 C-c C-d Delete char at point - the command normally assigned to C-d. 526 C-c C-d Delete char at point - the command normally assigned to C-d.
503 Delete Clear (replace) ARG columns before point, moving back over them. 527 \\[picture-backward-clear-column] Clear (replace) ARG columns before point, moving back over them.
504 C-k Clear ARG lines, advancing over them. The cleared 528 \\[picture-clear-line] Clear ARG lines, advancing over them. The cleared
505 text is saved in the kill ring. 529 text is saved in the kill ring.
506 C-o Open blank line(s) beneath current line. 530 \\[picture-open-line] Open blank line(s) beneath current line.
507You can manipulate rectangles with these commands: 531You can manipulate rectangles with these commands:
508 C-c C-k Clear (or kill) a rectangle and save it. 532 C-c C-k Clear (or kill) a rectangle and save it.
509 C-c C-w Like C-c C-k except rectangle is saved in named register. 533 C-c C-w Like C-c C-k except rectangle is saved in named register.
@@ -516,13 +540,13 @@ You can return to the previous mode with:
516 C-c C-c Which also strips trailing whitespace from every line. 540 C-c C-c Which also strips trailing whitespace from every line.
517 Stripping is suppressed by supplying an argument. 541 Stripping is suppressed by supplying an argument.
518 542
519Entry to this mode calls the value of edit-picture-hook if non-nil. 543Entry to this mode calls the value of picture-mode-hook if non-nil.
520 544
521Note that Picture mode commands will work outside of Picture mode, but 545Note that Picture mode commands will work outside of Picture mode, but
522they are not defaultly assigned to keys." 546they are not defaultly assigned to keys."
523 (interactive) 547 (interactive)
524 (if (eq major-mode 'edit-picture) 548 (if (eq major-mode 'picture-mode)
525 (error "You are already editing a Picture.") 549 (error "You are already editing a picture.")
526 (make-local-variable 'picture-mode-old-local-map) 550 (make-local-variable 'picture-mode-old-local-map)
527 (setq picture-mode-old-local-map (current-local-map)) 551 (setq picture-mode-old-local-map (current-local-map))
528 (use-local-map picture-mode-map) 552 (use-local-map picture-mode-map)
@@ -530,7 +554,7 @@ they are not defaultly assigned to keys."
530 (setq picture-mode-old-mode-name mode-name) 554 (setq picture-mode-old-mode-name mode-name)
531 (make-local-variable 'picture-mode-old-major-mode) 555 (make-local-variable 'picture-mode-old-major-mode)
532 (setq picture-mode-old-major-mode major-mode) 556 (setq picture-mode-old-major-mode major-mode)
533 (setq major-mode 'edit-picture) 557 (setq major-mode 'picture-mode)
534 (make-local-variable 'picture-killed-rectangle) 558 (make-local-variable 'picture-killed-rectangle)
535 (setq picture-killed-rectangle nil) 559 (setq picture-killed-rectangle nil)
536 (make-local-variable 'tab-stop-list) 560 (make-local-variable 'tab-stop-list)
@@ -539,7 +563,9 @@ they are not defaultly assigned to keys."
539 (setq picture-tab-chars (default-value 'picture-tab-chars)) 563 (setq picture-tab-chars (default-value 'picture-tab-chars))
540 (make-local-variable 'picture-vertical-step) 564 (make-local-variable 'picture-vertical-step)
541 (make-local-variable 'picture-horizontal-step) 565 (make-local-variable 'picture-horizontal-step)
566 (setq truncate-lines t)
542 (picture-set-motion 0 1) 567 (picture-set-motion 0 1)
568
543 ;; edit-picture-hook is what we used to run, picture-mode-hook is in doc. 569 ;; edit-picture-hook is what we used to run, picture-mode-hook is in doc.
544 (run-hooks 'edit-picture-hook 'picture-mode-hook) 570 (run-hooks 'edit-picture-hook 'picture-mode-hook)
545 (message 571 (message
@@ -548,14 +574,14 @@ they are not defaultly assigned to keys."
548 picture-mode-old-mode-name))) 574 picture-mode-old-mode-name)))
549 575
550;;;###autoload 576;;;###autoload
551(defalias 'picture-mode 'edit-picture) 577(defalias 'edit-picture 'picture-mode)
552 578
553(defun picture-mode-exit (&optional nostrip) 579(defun picture-mode-exit (&optional nostrip)
554 "Undo edit-picture and return to previous major mode. 580 "Undo picture-mode and return to previous major mode.
555With no argument strips whitespace from end of every line in Picture buffer 581With no argument strips whitespace from end of every line in Picture buffer
556 otherwise just return to previous mode." 582 otherwise just return to previous mode."
557 (interactive "P") 583 (interactive "P")
558 (if (not (eq major-mode 'edit-picture)) 584 (if (not (eq major-mode 'picture-mode))
559 (error "You aren't editing a Picture.") 585 (error "You aren't editing a Picture.")
560 (if (not nostrip) (picture-clean)) 586 (if (not nostrip) (picture-clean))
561 (setq mode-name picture-mode-old-mode-name) 587 (setq mode-name picture-mode-old-mode-name)