[net.emacs] arrow keys and emacs

rzdz@fluke.UUCP (Rick Chinn) (08/27/84)

As I recall, emacs really doesn't know anything about a terminal's arrow
keys, even though they are part of the termcap. Here is how I handle the
problem of the arrow keys on our vt100s. We really don't use them very much,
since we mostly just use emacs for writing text.

The following mlisp function alternately binds the arrow keys on a vt100 to
the directional functions or to cutting and pasting (put and yank). If a
user has bound these keys to something else, then those functions get
remembered instead of the default ones.


;Thu Aug 23 14:13:50 1984 rzdz
;   ARROW KEYS
;	
(setq-default arrow-mode 0) ;default to cut and paste
;
; set the default arrow key defs if not already done
(if (! (is-bound old-down-arrow-def))
    (setq-default old-down-arrow-def "next-line"))
(if (! (is-bound old-up-arrow-def))
       (setq-default old-up-arrow-def "previous-line"))
(if (! (is-bound old-left-arrow-def))
    (setq-default old-left-arrow-def "paste"))
(if (! (is-bound old-right-arrow-def))
    (setq-default old-right-arrow-def "cut"))
;
; initial bindings
(bind-to-key old-up-arrow-def "\eOA")
(bind-to-key old-down-arrow-def "\eOB")
(bind-to-key old-left-arrow-def "\eOD")
(bind-to-key old-right-arrow-def "\eOC")
; this function toggles the arrow keys between the two sets of functions
(defun
    (toggle-arrow-mode down-arrow up-arrow left-arrow right-arrow
	(if (= arrow-mode 0)
	    (progn
		(message "arrow keys control direction")
		(sit-for 0)
		 ; save the current arrow key bindings
		(setq old-down-arrow-def (global-binding-of "\eOB"))
		(setq old-up-arrow-def (global-binding-of "\eOA"))
		(setq old-left-arrow-def (global-binding-of "\eOD"))
		(setq old-right-arrow-def (global-binding-of "\eOC"))
                 ; now rebind them for direction control
		(bind-to-key "previous-line" "\eOA")
		(bind-to-key "next-line" "\eOB")
		(bind-to-key "backward-character" "\eOD")
		(bind-to-key "forward-character" "\eOC")
		(setq arrow-mode 1)
		(nothing))
	    (progn
		(message "arrow keys cut and paste")
		(sit-for 0)
		   ; rebind the arrow keys to the old bindings
		(bind-to-key old-up-arrow-def "\eOA")
		(bind-to-key old-down-arrow-def "\eOB")
		(bind-to-key old-left-arrow-def "\eOD")
		(bind-to-key old-right-arrow-def "\eOC")
		(setq arrow-mode 0)
		(nothing))))
)

Rick Chinn
John Fluke Mfg. Co MS 232E
PO Box C9090 Everett WA 98206

ihnp4!uw-beaver----\
decvax!microsof     \
ucbvax!lbl-csam      \ 
                      +====!fluke!rzdz
sun                  /
sb1!allegra         /
ssc-vax------------/ 

(206) 356-5232