[net.text] EDT-Emacs hybrid

lynno@tektronix.UUCP (Lynn Olson ) (02/07/84)

;  This .emacs_pro file maps the keypad of a VT-Series terminal
;into a command set resembling the DEC EDT (tm) editor. Most of the
;unshifted functions are unaltered - only keys that are nearly
;useless with the Emacs editor, such as the PAGE, CHAR, and ENTER
;keys, are altered. These are redefined into Paragraph, Window, and
;Newline-and-Indent.
;
;BackSpace is used in the usual UNIX (tm) fashion to delete previous
;characters, leaving the Delete key to serve as the 
;Beginning-of-Line. This is the reverse of the DEC EDT editor, true,
;but is preferable to having different delete keys in and out of
;Emacs. LineFeed is used for the EDT function of delete-previous-word.
;
;The shifted GOLD/Keys are mostly unaltered, with SPECINS replaced
;by ^\, UND W and UND C replaced by UND LWC. SUBS and RESET are eliminated.
;All of these keys are redefined as:
;
;SPECINS ->	: Copy Mark/Dot Region
;UND W ->	: Split Window
;UND C ->	: Visit Buffer
;SUBS  ->	: Visit File
;RESET ->	: Exchange Mark/Dot
;
;  New commands are GOLD/GOLD, which turns on the new-undo function.
;Other new commands are GOLD/keyboard pairs, which are mapped as follows:
;
;GOLD/up-arrow	: Current line to top of window.
;GOLD/down-arrow: Current line to bottom of window.
;GOLD/left-arrow: Backward sentence.
;GOLD/right-arrow: Forward sentence.
;GOLD/-		: Goto percentage of buffer.
;GOLD/=		: Goto line number.
;GOLD/`		: Display line number and character number.
;GOLD/p		: Delete selected buffer.
;GOLD/[		: Delete Mark/Dot region to selected buffer.
;GOLD/]		: Paste selected buffer to cursor.
;GOLD/BackSpace	: List Buffers.
;GOLD/Delete	: Delete other windows.
;GOLD/ \	: Capitalize word.
;GOLD/LineFeed	: Delete-next-word. (Deletes fragments, unlike Del W).
;
;  The following commands alter the Emacs default key map. Aside from
;these changes, all other Emacs commands retain the documented bindings.
;
;  Delete	: Beginning-of-Line.
;  LineFeed	: Delete-Previous-Word.
;  ^A		: Enlarge current window.
;  ^Z		: Shrink current window.
;  ^_		: Pause-Emacs.
;
;
(defun
	;This deletes the entire current line and allows chaining
	;similar to the ^K (kill-to-end-of-line) function. The
	;(chained) text is put in the Line buffer and retrieved by
	;the GOLD/Und LWC keys.
	;
	(delete-current-line
		(beginning-of-line)
		(set-mark)
		(next-line)
		(if	(= -48 (previous-command))
			(progn
				(append-region-to-buffer "Line\040buffer")
				(erase-region)
			)
			(delete-region-to-buffer "Line\040buffer")
		)
		(setq this-command -48)
	)
	;This allows the Del EOL to have a chaining feature similar to
	;the Del L function above. It is chained with Del W and Del C.
	;
	(delete-to-eol
		(if	(eolp)
			(progn
				(set-mark)
				(next-line)
				(end-of-line)
				(exchange-dot-and-mark)
			)
			(progn
				(set-mark)
				(end-of-line)
				(exchange-dot-and-mark)
			)
		)
		(if	(= -48 (previous-command))
			(progn
				(append-region-to-buffer "Line\040buffer")
				(erase-region)
			)
			(delete-region-to-buffer "Line\040buffer")
		)
		(setq this-command -48)
	)
	;This deletes the current word. It may be chained with Del L,
	;Del EOL, previously deleted words, or previously deleted characters.
	;The words are parked in the Line buffer.
	(delete-current-word
		(forward-word)
		(forward-word)
		(backward-word)
		(set-mark)
		(backward-word)
		(if	(= -48 (previous-command))
			(progn
				(append-region-to-buffer "Line\040buffer")
				(erase-region)
			)
			(delete-region-to-buffer "Line\040buffer")
		)
		(setq this-command -48)
	)
	;This deletes the current character. It may be chained with Del L,
	;Del EOL, previously deleted words, or previously deleted characters.
	;The characters are parked in the Line buffer.
	(delete-current-character
		(set-mark)
		(forward-character)
		(exchange-dot-and-mark)
		(if	(= -48 (previous-command))
			(progn
				(append-region-to-buffer "Line\040buffer")
				(erase-region)
			)
			(delete-region-to-buffer "Line\040buffer")
		)
		(setq this-command -48)
	)
	;Undelete Lines, Words, and Characters.
	(undelete-line
		(yank-buffer "Line\040buffer")
	)
	;Move EOL downward if key is pressed repeatedly.
	(repeat-end-of-line
		(if	(= -12 (previous-command))
			(next-line)
		)
		(end-of-line)
		(setq this-command -12)
	)
	;Move BOL upward if key is pressed repeatedly.
	(repeat-beginning-of-line
		(if	(= -10 (previous-command))
			(previous-line)
		)
		(beginning-of-line)
		(setq this-command -10)
	)
	;APPEND function. Append mark-dot region to Kill buffer.
	(append-to-killbuffer
		(append-region-to-buffer "Kill\040buffer")
		(message "Appended.")
		(send-string-to-terminal "\e#>")
	)
	;GOLD/COPY. Copy mark-dot region to Kill buffer.
	(copy-to-killbuffer
		(delete-to-killbuffer)
		(yank-from-killbuffer)
		(message "Copied.")
		(send-string-to-terminal "\e#>")
	)
	;WORD in the Advance mode.
	(next-word
		(forward-word)
		(forward-word)
		(backward-word)
	)
	;Puts the cursor at the beginning of indented paragraphs.
	(next-paragraph
		(next-line)
		(forward-paragraph)
		(previous-line)
		(if (eolp) (next-line))
	)
	;Puts the cursor at the beginning of indented paragraphs.
	(previous-paragraph
		(backward-paragraph)
		(previous-line)
		(if (eolp) (next-line))
	)
	;Set EDT Advance mode for cursor keys.
	(advance-direction
		(setq global-mode-string "ADVANCE  >>>>>>")
		(bind-to-key "search-forward" "\eOR")
		(bind-to-key "next-page" "\eOx")
		(bind-to-key "next-paragraph" "\eOw")
		(bind-to-key "next-word" "\eOq")
		(bind-to-key "next-window" "\eOs")
		(bind-to-key "scroll-one-line-up" "\eOp")
	)
	;Set EDT Backup mode for cursor keys.
	(backup-direction
		(setq global-mode-string "<<<<<<<  BACKUP")
		(bind-to-key "search-reverse" "\eOR")
		(bind-to-key "previous-page" "\eOx")
		(bind-to-key "previous-paragraph" "\eOw")
		(bind-to-key "backward-word" "\eOq")
		(bind-to-key "previous-window" "\eOs")
		(bind-to-key "scroll-one-line-down" "\eOp")
	)
	;CONTROL-SHIFT-^ function. Discards all but the original buffer,
	;writes this to a file, resets VT-Series keypad application mode,
	;and exits Emacs.
	(write-original-file-exit
		(delete-buffer "Line\040buffer")
		(send-string-to-terminal "\e>")
		(switch-to-buffer (argv 1))
		(write-current-file)
		(exit-emacs)
	)
	;Exit and reset VT-Series keypad application mode.
	(vt-write-file-exit
		(delete-buffer "Line\040buffer")
		(send-string-to-terminal "\e>")
		(write-file-exit)
	)
	;Exit and reset VT-Series keypad application mode.
	(vt-exit-emacs
		(if (< (recursion-depth) 1)
			(send-string-to-terminal "\e>")
		)
		(exit-emacs)
	)
)

;Here's an improved version of line-to-bottom-of-window based on Hans
;Koomen's message of 30 Jul 83:

(error-occurred		; window-width is already defined in some versions
    (defun (window-width 79)))
(defun
    (line-to-bottom-of-window	lines2skip chars2skip physlines
	(setq chars2skip (- (window-width) 1))
	(setq lines2skip (window-height))
	(setq physlines  (+ 1 (/ (- (current-column) 2) chars2skip)))
	(setq lines2skip (- lines2skip physlines))
	(save-excursion
	    (while (> lines2skip 0)
		   (previous-line)
		   (end-of-line)
		   (setq physlines (+ 1 (/ (- (current-column) 2) chars2skip)))
		   (setq lines2skip (- lines2skip physlines)))
	    (if (< lines2skip 0)
		(next-line))
	    (line-to-top-of-window)
	)
    )
)
(load "goto.ml")
(load "aton.ml")
(load "misc.ml")

(setq unlink-checkpoint-files 1)
(setq scroll-step 1)
(setq track-eol-on-^N-^P 0)
(setq quick-redisplay 1)
(setq default-right-margin 79)
(setq default-case-fold-search 1)
(setq default-mode-line-format " %[Dot: %p of: %b%*	|%m|	%M%]")
(setq wrap-long-lines 1)
(setq backup-before-writing 1)
(setq backup-by-copying-when-linked 1)
(setq silently-kill-processes 1)
(setq unlink-checkpoint-files 1)
(setq ctlchar-with-^ 1)

;Mask off X-ON, X-OFF codes and bind keyboard control-keys
(bind-to-key "enlarge-window" "\001")		;"ctrl-A"
(bind-to-key "delete-previous-word" "\012")	;"LineFeed"
(bind-to-key "novalue" "\021")			;control code
(bind-to-key "novalue" "\023")			;control code
(bind-to-key "shrink-window" "\032")		;"ctrl-Z"
(bind-to-key "quote-character" "\034")		;"ctrl-\"
(bind-to-key "write-original-file-exit" "\036")	;"ctrl-shift-^"
(bind-to-key "pause-emacs" "\037")		;"ctrl-shift-_"
(bind-to-key "repeat-beginning-of-line" "\177")	;"Delete"
(bind-to-key "vt-exit-emacs" "\^X\^C")		;Depart Emacs & reset keypad.
(bind-to-key "vt-write-file-exit" "\^X\^F")	;As above.

;Bind keyboard arrow keys
(bind-to-key "previous-line" "\e[A")		;"up-arrow"
(bind-to-key "next-line" "\e[B")		;"down-arrow"
(bind-to-key "backward-character" "\e[D")	;"left-arrow"
(bind-to-key "forward-character" "\e[C")	;"right-arrow"

;Bind keypad keys
(bind-to-key "describe-key" "\eOQ")		;HELP	"PF2"
(bind-to-key "delete-current-line" "\eOS")	;DEL L	"PF4"
(bind-to-key "append-to-killbuffer" "\eOy")	;APPEND "9"
(bind-to-key "delete-current-word" "\eOm")	;DEL W	"-"
(bind-to-key "advance-direction" "\eOt")	;ADV	"4"
(bind-to-key "backup-direction" "\eOu")		;BAK	"5"
(bind-to-key "delete-to-killbuffer" "\eOv")	;CUT	"6"
(bind-to-key "delete-current-character" "\eOl")	;DEL C	","
(bind-to-key "repeat-end-of-line" "\eOr")	;EOL	"2"
(bind-to-key "set-mark" "\eOn")			;SELECT	"."
(bind-to-key "newline-and-indent" "\eOM")	;ENTER	"ENTER"

;Bind GOLD/Keyboard keys
(bind-to-key "delete-other-windows" "\eOP\010")		;"BackSpace"
(bind-to-key "delete-next-word" "\eOP\012")		;"LineFeed"
(bind-to-key "goto-percent" "\eOP\055")			;"-"
(bind-to-key "goto-line" "\eOP\075")			;"="
(bind-to-key "delete-buffer" "\eOP\160")		;"p"
(bind-to-key "delete-region-to-buffer" "\eOP\133")	;"["
(bind-to-key "case-word-capitalize" "\eOP\134")		;"\"
(bind-to-key "yank-buffer" "\eOP\135")			;"]"
(bind-to-key "display-line-number" "\eOP\140")		;"`"
(bind-to-key "list-buffers" "\eOP\177")			;"Delete"
(bind-to-key "line-to-top-of-window" "\eOP\e[A")	;"up-arrow"
(bind-to-key "line-to-bottom-of-window" "\eOP\e[B")	;"down-arrow"
(bind-to-key "backward-sentence" "\eOP\e[D")		;"left-arrow"
(bind-to-key "forward-sentence" "\eOP\e[C")		;"right-arrow"

;Bind GOLD/Keypad keys
(bind-to-key "new-undo" "\eOP\eOP")		;Gold		"PF1"
(bind-to-key "describe-command" "\eOP\eOQ")	;Help		"PF2"
(bind-to-key "aton" "\eOP\eOR")			;Find		"PF3"
(bind-to-key "undelete-line" "\eOP\eOS")	;Und LWC	"PF4"
(bind-to-key "execute-extended-command" "\eOP\eOw") ;Command	"7"
(bind-to-key "justify-paragraph" "\eOP\eOx")	;Fill		"8"
(bind-to-key "query-replace-string" "\eOP\eOy")	;Replace	"9"
(bind-to-key "split-current-window" "\eOP\eOm")	;Split Wind	"-"
(bind-to-key "end-of-file" "\eOP\eOt")		;Bottom 	"4"
(bind-to-key "beginning-of-file" "\eOP\eOu")	;Top		"5"
(bind-to-key "yank-from-killbuffer" "\eOP\eOv")	;Paste		"6"
(bind-to-key "pop-to-buffer" "\eOP\eOl") 	;Visit Buffer 	","
(bind-to-key "case-word-invert" "\eOP\eOq")	;Chgcase	"1"
(bind-to-key "delete-to-eol" "\eOP\eOr")	;Del EOL	"2"
(bind-to-key "copy-to-killbuffer" "\eOP\eOs")	;Copy		"3"
(bind-to-key "newline-and-backup" "\eOP\eOp")	;Open L		"0"
(bind-to-key "exchange-dot-and-mark" "\eOP\eOn");Mark/Dot	"."
(bind-to-key "visit-file" "\eOP\eOM")		;Visit-File	"ENTER" 

;Set VT-Series keypad application mode, initialize direction, and
;prevent the two temporary buffers from being checkpointed.
(send-string-to-terminal "\e=")
(advance-direction)
(save-excursion
	(switch-to-buffer "Line\040buffer")
	(setq needs-checkpointing 0)
	(switch-to-buffer "Kill\040buffer")
	(setq needs-checkpointing 0)
)
;
;<insert ^L here> --------------------------------------------------
;Here's the keypad diagram (the keyboard functions are below).
;For each key, uppercase functions are on the top line; GOLD-shifted
;functions are on the bottom line.
;
;
;                           K E Y P A D
;+---------------+---------------+---------------+---------------+
;|     GOLD      |   HELP KEY    |     FIND      |   DEL LINE    |
;|     ----      |   --------    |     ----      |   --------    |
;|     Undo      | Help Command  |Find in Context|  Und L, W, C  |
;+---------------+---------------+---------------+---------------+
;|   PARAGRAPH   |     SECT      |     APPEND    |   DEL WORD    |
;|   ---------   |     ----      |     ------    |   --------    |
;|    Command    |     Fill      |    Replace    | Split Window  |
;+---------------+---------------+---------------+---------------+
;|    ADVANCE    |    BACKUP     |      CUT      |   DEL CHAR    |
;|    -------    |    ------     |      ---      |   --------    |
;|    Bottom     |     Top       |     Paste     | Visit Buffer  |
;+---------------+---------------+---------------+---------------+
;|     WORD      |     EOL       |     WINDOW    |               |
;|     ----      |     ---       |     ------    |               |
;|   Chgcase     |  Delete-EOL   |      Copy     |  <CR> Indent  |
;+---------------+---------------+---------------+  -----------  |
;|          LINE  SCROLL         |     SELECT    |  Visit File   |
;|          ------------         |     ------    |               |
;|           Open Line           | Swap Mark/Dot |               |
;+-------------------------------+---------------+---------------+
;
;
;                             K E Y B O A R D
;    +---------------+---------------+---------------+---------------+
;    |       ^       |       v       |     <----     |     ---->     |
;    |     -----     |     -----     |     -----     |     -----     |
;    |  Line-to-Top  |Line-to-Bottom |Begin Sentence | End Sentence  |
;    +---------------+---------------+---------------+---------------+
;    |       -       |       =       |       `       |  BACK SPACE   |
;    |     -----     |     -----     |     -----     |  ----------   |
;    | Goto Percent  |  Goto Line #  |  Show Line #  |Del Other Wind |
;+---------------+---+-----------+---+-----------+---+---+-----------+---+
;|       P       |       [       |       ]       |       | DEL (now BOL) |
;|     -----     |     -----     |     -----     |       | ------------- |
;| Delete Buffer | Cut-to-Buffer |Paste-from-Buff|       | List Buffers  |
;+---------------+---------------+---------------+       +---------------+
;                                                        |       \       |
;Ctrl-Shift-^	:Write Original File & Exit		 |     -----     |
;Ctrl-X-F	:Write All Files & Exit			 | Capitalize W  |
;Ctrl-X-C	:Discard Changes & Exit			 +---------------+
;							 | LF (RUBOUT W) |
;Ctrl-A		:Enlarge Window				 | ------------  |
;Ctrl-Z		:Shrink Window				 |Delete-to-W-End|
;							 +---------------+
;Ctrl-L		:Redraw Display 
;Ctrl-T		:Transpose Characters
;
;Ctrl-X-I	:Insert File at Dot
;Ctrl-X-S	:Write Current Buffer to File
;
;ESC-r		:Replace String (all occurances in buffer)
;ESC-?		:Apropos Command
;
;<insert ^L here> -------------------------------------------
;DEC and EDT are trademarks of Digital Equipment Corporation,
;UNIX is a trademark of American Telephone & Telegraph.
;
;Hacked by Lynn Olson at Tektronix on tekcrd on about 1/30/84.
; ------------------------------------------------------------