[gnu.emacs] Anything You Can Do, I Can Do "Meta"

srt@aero.ARPA (Scott "CBS" Turner) (04/12/89)

The keyboard on my home computer has the single quote key where the
ESC key should be (on the upper left) and the ESC key on the numeric
keypad.  Needless to say, I find this fairly annoying.

Is there any way in Gnu Emacs to switch the bindings of these two keys
so that hitting the single quote key becomes *exactly the same* as
hitting the (normal) ESC key and the ESC key becomes the single quote
key?  Binding esc-map to the single quote seems to work, but getting
ESC to insert a single quote seems to be beyond my abilities.

I'd prefer something that works in all modes, needless to say.  It
seems as if Gnu Emacs should have some kind of initial key mapping -
ie., ascii codes to key names, but if it does I don't know about it.

Your help is much appreciated.

						-- Scott Turner

mdb@bridge2.3Com.COM (Mark D. Baushke) (04/13/89)

In article <49058@aero.ARPA> srt@aerospace.aero.org (Scott "CBS"
Turner) writes:
>   The keyboard on my home computer has the single quote key where the
>   ESC key should be (on the upper left) and the ESC key on the numeric
>   keypad.  Needless to say, I find this fairly annoying.
>
>   Is there any way in Gnu Emacs to switch the bindings of these two keys
>   so that hitting the single quote key becomes *exactly the same* as
>   hitting the (normal) ESC key and the ESC key becomes the single quote
>   key?  Binding esc-map to the single quote seems to work, but getting
>   ESC to insert a single quote seems to be beyond my abilities.

Try putting the following into your ~/.emacs

;;
;; This keyboard-translate-table swaps ESC (\033) with ' (\047)
;;
;; To reset to the default issue the following list command.
;;
;;(setq keyboard-translate-table nil)

(setq keyboard-translate-table	
      (concat
       "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
       "\020\021\022\023\024\025\026\027\030\031\032'\034\035\036\037"
       " !\042#$%&\033()*+,-./"
       "0123456789:;<=>?"
       "@ABCDEFGHIJKLMNO"
       "PQRSTUVWXYZ[\134]^_"
       "`abcdefghijklmno"
       "pqrstuvwxyz{|}~\177"))

Enjoy!
--
Mark Baushke
sun!bridge2!mdb		or		mdb@bridge2.3com.com

spencer@eecs.umich.edu (Spencer W. Thomas) (04/13/89)

In article <49058@aero.ARPA> srt@aero.ARPA (Scott "CBS" Turner) writes:

> Is there any way in Gnu Emacs to switch the bindings of these two keys
> so that hitting the single quote key becomes *exactly the same* as
> hitting the (normal) ESC key and the ESC key becomes the single quote
> key?

Yes, see the documentation for the variable keyboard-translate-table:

keyboard-translate-table's value is nil

Documentation:
String used as translate table for keyboard input, or nil.
Each character is looked up in this string and the contents used instead.
If string is of length N, character codes N and up are untranslated.

--
=Spencer (spencer@eecs.umich.edu)

huxtable@kuhub.cc.ukans.edu (Kathryn Huxtable) (04/14/89)

I tried mailing this directly, but it bounced.  So I'm posting.

In article <49058@aero.ARPA>, srt@aero.ARPA (Scott "CBS" Turner) writes:
> Is there any way in Gnu Emacs to switch the bindings of these two keys
> so that hitting the single quote key becomes *exactly the same* as
> hitting the (normal) ESC key and the ESC key becomes the single quote
> key?  Binding esc-map to the single quote seems to work, but getting
> ESC to insert a single quote seems to be beyond my abilities.
> 
> I'd prefer something that works in all modes, needless to say.  It
> seems as if Gnu Emacs should have some kind of initial key mapping -
> ie., ascii codes to key names, but if it does I don't know about it.
> 

It's somewhere in the documentation.  Here is the stuff I use:

(defun lk201 ()
  "Set stuff so we can use an lk201 keyboard in a rational way."
  (interactive)

  ;; First make a translate table that does the identity translation.
  (setq keyboard-translate-table (make-string 128 0))

  (let ((i 0))
    (while (< i 128)
      (aset keyboard-translate-table i i)
      (setq i (1+ i))))

  ;; Now alter translations of some characters.
  (aset keyboard-translate-table ?\` ?\^[)
  (aset keyboard-translate-table ?\^[ ?\`)
)

The DEC LK201 keyboard (standard with VT200 and VT300 series
terminals) has a grave accent where the escape should be.  I have to
type CTRL/[ to get an escape.  So I swapped the meanings in the
translate table.

The translate table is nil by default.  When it's nil, no translation
is done, otherwise all keyboard input is mapped through the table.
You could even remap XON/XOFF if these bother you.

Have fun!

-Kathryn Huxtable
huxtable@kuhub.cc.ukans.edu