[comp.emacs] Arrow keys for gnuemacs...

ccs015@castor.ucdavis.edu (Kambiz Aghaiepour) (09/20/89)

Brian C Hill writes:
>Hi Kambiz....
>Can you tell me how to change the key bindings for the direction keys so that
>I can use my cursor keys instead of the control keys to move the cursor around\
?
.
:
>HELP!
>Brian

I don't know the answer to this question, and I know it's probably been asked
here before...but I guess I wasn't with it.  Can someone please tell me how to
do this .  I will pass the info on to Brian C Hill.

			---Kambiz

rock@rancho.UUCP (Rock Kent) (09/20/89)

In article <5352@ucdavis.ucdavis.edu> ccs015@castor.ucdavis.edu (Kambiz Aghaiepour) writes:
  >Can you tell me how to change the key bindings for the direction keys
  >so that I can use my cursor keys instead of the control keys to move
  >the cursor around?
  I don't know the answer to this question, and I know it's probably
  been asked here before...but I guess I wasn't with it.  Can someone
  please tell me how to do this .  I will pass the info on to Brian C
  Hill.

I've used two different approaches to this problem.  

1.  Hardcode the escape sequences into my .emacs.  Yes, this is
an inelegant, brute force approach which locks the user into a single
terminal type.  It was, however, the easiest for me to understand.  
(global-unset-key "<keystroke>") as necessary to clear the way for
those vt100 <esc>O sequences and go on to define your own, <esc><home>
to (beginning-of-buffer), for example.  Oh yeah, use <ctrl>Q to
figure out what you're sending when you type one of those function
keys and (global-set-key "keysequence" 'function) to assign 'em.

1.a.  A slight improvement over harcoding the terminal into your
.emacs is to make the assignments conditional on your TERM variable.
Keep in mind that setup.el runs your .emacs first, then the
appropriate <TERM>.el file, then keypad.el.  You have to use
'term-setup-hook in order to avoid having your laboriously derived
assignments smashed by the <TERM>.el file.
I used to use code like:

>> (setq term-setup-hook 'term-setup-hook-procedures)
>> 
>> (defun term-setup-hook-procedures () "
>> The stuff I want to run after the terminals get installed."
>>   (enable-arrow-keys)
>>   (if (or (string= (getenv "TERM") "AT386")
>> 	  (string= (getenv "TERM") "at386")
>> 	  (string= (getenv "TERM") "root_at386"))
>>       (progn
>> 	(global-set-key "OT" 'minkey)
>> 	(global-set-key "[H" 'beginning-of-buffer)
>> 	(global-set-key "[Y" 'end-of-buffer)))
>>   (if (or (string= (getenv "TERM") "pro_vt100")
>> 	  (string= (getenv "TERM") "PRO_VT100"))
>>       (progn
>> 	(global-set-key "Ot" 'minkey)
>>         (setq meta-flag t)
>> 	(global-set-key "[H" 'beginning-of-buffer)
>> 	(global-set-key "[K" 'end-of-buffer)))
>>   )

2.  The second way I've used to enable the cursor control and function
keys is to update and/or clone the appropriate files in 
<emacs' parent dir>/emacs/lisp/term.  The ~emacs/lisp/term files
establish the cross reference between terminal key and internal emacs
key representations.  Then the ~emacs/list/keypad.el file establishes
the relationship between internal key representation and function.
The default binding in keypad.el, for instance, binds <F1> to
(beginning-of-line).  I prefer to have <F1> bound to (suspend-emacs).
Keep in mind, however, that assignments done in keypad.el affect all
users.  I suppose that you could set things up so to use a personal
keypad.el, just drop your version of keypad.el into your home
directory somewhere and update your load path in .emacs
   (setq load-path (list (concat (getenv "HOME") "/Emacs") 
   	                 "/usr/local/lib/emacs/lisp/local" 
		         "/usr/local/lib/emacs/lisp" ))

Hope this helps.

***************************************************************************
*Rock Kent    rock@rancho.uucp        POB 8964, Rancho Sante Fe, CA. 92067*
***************************************************************************

ben@nsf1.mth.msu.edu (Ben Lotto) (09/20/89)

On 19 Sep 89 17:17:01 GMT,
ccs015@castor.ucdavis.edu (Kambiz Aghaiepour) said:

Kambiz> Brian C Hill writes:
>Can you tell me how to change the key bindings for the direction keys so that
>I can use my cursor keys instead of the control keys to move the cursor
> around\ ?  .  :

If you put the line

	(setq sun-esc-bracket t)

into your .emacs file, wonderful things will happen.  Since when you're
on a SUN, emacs loads the file .../emacs/lisp/term/sun.el, you can look
there to see all of the bindings that get set when you have this.  In
particular, it rebinds the arrow keys to forward-char, backward-char,
etc. 
--

-B. A. Lotto  (ben@nsf1.mth.msu.edu)
Department of Mathematics/Michigan State University/East Lansing, MI  48824