[net.emacs] Arrow Key Problems

btb@hogpc.UUCP (B.BURGER) (08/20/84)

I would greatly appreciate some help getting my arrow keys to work
with EMACS 4.5 on an AT&T 3B20.  My terminal is an AT&T PC6300
(IBM-compatible) using an AT&T 4410 terminal emulator.  While this
may not yet be a common configuration, I believe the same problem
has come up using an hp2621 emulator or a real live vt100.

The problem is that, when I press an arrow key, it isn't
transmitted/read by emacs (one or the other) correctly.
The 4410 terminal description that I'm using defines up=M-[A
(it appears as ^[[A, with the initial ^[ as one character).
Pressting cntrl-Q up_arrow while in emacs shows me the same thing.
On the vt100 the same thing happens but the terminal file says up=M-A
(it appears as ^[A).  I've tried every other imaginable up= but get
the same results.  I've also been unsuccessful writing a macro that
understands what my keyboard is saying.

Any ideas on how I can get the arrow keys to do somethingt? 
Anything?  Thanks in advance.

--Bruce Burger     AT&T-Information Systems     Freehold, NJ
  {...ihnp4!}hogpc!btb    (201) 577-5230

pedz@smu.UUCP (08/23/84)

#R:hogpc:-44600:smu:12400007:000:917
smu!pedz    Aug 22 21:13:00 1984

I will post this since I have been asked this many times at our
site so I feel that there may be a general use for it.

The basic reason that the arrow keys do not work is that emacs
does not use that part of termcap.  If you want an arrow key (or
a special funtion key) to perform some function within emacs,
then simply bind those keystrokes to a function.  A better
method which works on some terminals is to configure the
terminal to send the proper codes that emacs wants to see.

The function inside emacs you need to use is bind-to-key if the
key sequence is suitable for it.  If it is not, then you must
define keymaps and bind the keys to keymaps.  The best example
of this is the pseudo-vi mode that is done in the manual.
(Hint, I have actually used the bind-to-key function on key
sequences that did not start with ESC or ^X but I do not know if
this will continue to work or not.)

Perry
convex!smu!pedz

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

As I recall, emacs really doesn't know anything about your terminal's arrow
keys, even though they are part of your 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.

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


;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))))
)

chris@umcp-cs.UUCP (Chris Torek) (08/26/84)

*	From: pedz@smu.UUCP

	... I have actually used the bind-to-key function on key
	sequences that did not start with ESC or ^X but I do not know
	if this will continue to work or not.

Sure it will.  (Assuming this is Gosling Emacs.)  The keyboard
interpreter is simply a `while' loop that traverses keymaps.  When
a leaf is found, the function it points to is executed.  Thus you
can do silly things like:

	(bind-to-key "ESC-keymap" "\e\e")
or
	(bind-to-key "that-was-silly" "silly")

The first gives an endless loop for ESC-ESC, and can only be undone
with ESC-x execute-extended-command (bind-to-key
"execute-extended-command" "\e\e").  The second binds ``s'' and creates
keymaps such that the whole word invokes the "that-was-silly" function.
(Makes it hard to type 's'; you have to quote it first.)  All the
created keymaps are returned as ``BOGUS!'' if you ask for their name
with, e.g., ESC-ESC (return-global-binding "si").  Keys within them can
then be bound (from the keyboard or from mlisp).

Note that because of the way Emacs does interactive (non-mlisp) bind-
to-key's, you can only create ``BOGUS!'' keymaps from MLisp.  For
prettiness' sake I use (define-keymap) to make a named map first.  I
use a ^C keymap myself.  From my .emacs_pro:

	(define-keymap "^C-prefix")
	(bind-to-key "^C-prefix" "\^C")
	(bind-to-key "execute-shell-command" "\^C!")
	(bind-to-key "list-marks" "\^C\^M")
	(bind-to-key "newtime-exit-emacs" "\^C\^C")
	(bind-to-key "pop-to-existing-buffer" "\^C\^P")
	(bind-to-key "repeat-until-stopped" "\^Cr")
	(bind-to-key "visit-RCS-file" "\^C\^V")

and so forth.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland

warren@ihnss.UUCP (Warren Montgomery) (08/29/84)

The posting that originally triggered this was using my emacs, which
has quite different mechanisms for macros and key bindings.  I see
occasional postings for other emacs's in this list.  To avoid
confusion, I strongly suggest that posters identify their versions.
(Most of the gosling and unipress ones do).  It is easy to identify
the source from the version number, at least for mine and Gosling's:

Messages relating to versions identified by a single digit, decimal
point, one digit to the right of a decimal point, and possibly a
letter (like 4.6g) pertain to my emacs, which presently is available
only within AT&T.

Two or 3 digit version numbers with no decimal point are Gosling or
Unipress versions.  I don't know how CCA identifies theirs, but I
hope that it is different.

-- 

	Warren Montgomery
	ihnss!warren
	IH (8-367) x2494

r.johnston@glasgow.UUCP (Rob. Johnston) (08/31/84)

With reference to Bruce Burger's problem with a vt100 lookalike, a simple 
way of using the cursor control keys with emacs involves binding the 
required emacs functions as follows:

(progn
(bind-to-key "previous-line" "\e[A")  ; or bind your own macro
(bind-to-key "next-line" "\e[B")
(bind-to-key "forward-character" "\e[C")
(bind-to-key "backward-character" "\e[D")
(message "done")
)