home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / emacs / 2964 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  13.8 KB

  1. Path: sparky!uunet!airgun!airgun.wg.waii.com!jct
  2. From: jct@se33.wg2.waii.com (Jim Thompson)
  3. Newsgroups: comp.emacs
  4. Subject: Re: Sun arrow keys with meta and control?
  5. Message-ID: <JCT.92Aug27082550@se33.wg2.waii.com>
  6. Date: 27 Aug 92 12:25:50 GMT
  7. References: <GRIFFITH.92Aug25201534@harris.earley.sns.neuphilologie.uni-tuebingen>
  8. Sender: news@airgun.wg.waii.com
  9. Distribution: comp
  10. Organization: Western Geophysical Exploration Products
  11. Lines: 299
  12. Nntp-Posting-Host: se33.wg2.waii.com
  13. In-reply-to: griffith@harris.earley.sns.neuphilologie.uni-tuebingen's message of 25 Aug 92 18:15:34 GMT
  14.  
  15. In article <GRIFFITH.92Aug25201534@harris.earley.sns.neuphilologie.uni-tuebingen> griffith@harris.earley.sns.neuphilologie.uni-tuebingen (John Griffith) writes:
  16. > I asked this question a couple weeks ago but got no response
  17. > so I'll try it once again before giving up.  I know how to
  18. > rebind the Sun function keys (including arrows) to whatever function
  19. > I want.  What I would like to do but have been unable to figure out is
  20. > how to bind meta-up-arrow to something different than plain up-arrow.
  21. > Is this possible?  It seems that meta-up-arrow and up-arrow and control-
  22. > up-arrow all put out the same key code as far as emacs is concerned.
  23.  
  24. If you run inside of an xterm, you can get modified function keys.
  25. Following is a short monograph I wrote for our local Epoch users to
  26. describe a scheme I use for function keys; it should get you started.
  27. The xterm translations that you'll need are at the end of the article.
  28.  
  29. Note that some people prefer to use C-c instead of ESC as the prefix
  30. for the function keys, so that function keys don't confuse interactive
  31. searches.  I prefer to use ESC so that my bindings work with the Sun
  32. console on those occasions when I use it.
  33.  
  34. Hope this helps.
  35.  
  36. --
  37.  
  38. When I first started using Xemacs here I learned how to bind the
  39. function keys on my Sun-4 keyboard to bits of elisp code.  But I also
  40. wanted to get modifier information on the keys so that Shift-F1 would
  41. invoke a different lisp function than (unmodified) F1;  ditto for
  42. Meta-F1 and Control-F1.  (Emacs stands for Esc Meta Alt Control Shift,
  43. you know.)  To do this in Xemacs, I had to modify the X event
  44. processing in the C source code.
  45.  
  46. In Epoch, fortunately, setting up for modified function keys is much
  47. easier because Epoch gives you access to X primitives.  You can do it
  48. all in elisp, no C-source hacking necessary.  Here, then, are some
  49. bits of elisp code that will allow Epoch to discriminate between
  50. modified and unmodified function keys.
  51.  
  52.                 * * *
  53.  
  54. Back when I first hacked up the C code for Xemacs I settled on a
  55. scheme for the values (character strings) that would be returned by
  56. modified function keys, and I have continued to use that scheme for
  57. the Epoch-elisp version.  That scheme was based on the processing
  58. already in place in Xemacs for function keys, and that processing was
  59. in turn based on the character sequences emitted by the Sun console
  60. for function keys.
  61.  
  62. The standard Sun sequences for function keys is as follows:
  63.  
  64.     ESC  [  0  0  0  z
  65.  
  66. where the digits 000 vary from key to key.  For example, F1 transmits 
  67.  
  68.     ESC  [  2  2  4  z.
  69.  
  70. There are some variations from this.  The num-lock key doesn't
  71. transmit anything, nor does the Stop key, and the arrow keys transmit
  72. sequences such as 
  73.  
  74.     ESC [ A
  75.  
  76. for up, with A being replaced by B, C, and D for down, right and left,
  77. respectively.
  78.  
  79. In my scheme for numbering, however, I wanted to have access to every
  80. key, and I wanted the values as consistent as possible.  So I overrode
  81. the Sun-terminal standard and gave ESC-[-digit-digit-digit-z codes to
  82. the arrow keys and the other "missing' keys.  Fortunately, the
  83. numbering convention chosen by Sun was consistent, and deducing the
  84. values to use for the missing keys was easy.
  85.  
  86. To encode modifier information, I chose to vary the terminating
  87. letter, working my way backward through the alphabet.  Thus, Shift-
  88. modified keys would transmit 'y' instead of 'z' as their terminal
  89. letter, Control-modified keys, 'x', and Meta-modified keys, 'w'.  (I
  90. did not make provisions for multiply-modified keys, but the same
  91. scheme could be extended, with 'v' representing Shift-Control, etc.)
  92.  
  93. So the scheme, then is: ESC [ identies a function or special key,
  94. three ASCII digits identify which key, and a terminal letter
  95. identifies the modifier.
  96.  
  97.                 * * *
  98.  
  99. Two sections of elisp code are needed to use the function keys.  The
  100. first assigns character sequences to the keys, and the second assigns
  101. character sequences to lisp functions.
  102.  
  103. [The first applies only to Epoch users, so I have deleted it for
  104.  posting to comp.emacs.  To get modified function keys with vanilla
  105.  emacs, you'll need to run inside of an xterm, and use the
  106.  translations at the end of the article.]
  107.  
  108.                 * * *
  109.  
  110. The second section of will vary greatly from person to person as
  111. preferences for key functions vary.  The following code fragment comes
  112. from my .emacs; I have deleted most of the actual define-key
  113. statements for the sake of brevity.
  114.  
  115. ;; This code shamelessly stolen from Jeff Peck's sun.el:
  116. ;;  Jeff Peck, Sun Microsystems Inc  <peck@sun.com>
  117. ;;
  118.  
  119. ;; This function can be bound to unused keys
  120. (defun unbound-key () (interactive))
  121.  
  122. ;; Define a new keymap for the Sun function keys
  123. (defvar sun-raw-map (make-sparse-keymap) "*Keymap for ESC-[ encoded keyboard")
  124.  
  125. ;; Place bindings to useful functions into the new map
  126. ; Left group of function keys
  127. (define-key sun-raw-map "233z" 'start-kbd-macro)    ; F10
  128. (define-key sun-raw-map "192z" 'end-kbd-macro)        ; F11 & L1
  129. (define-key sun-raw-map "193z" 'call-last-kbd-macro)    ; L2
  130. (define-key sun-raw-map "193y" 'repeat-complex-command) ; S-L2
  131.  
  132. ; ... many other assignments deleted
  133.  
  134. ;; Tell Emacs that "ESC-[" sequences should divert to the new map for
  135. ;; further interpretation
  136. (define-key esc-map "[" sun-raw-map)
  137.  
  138. ;; Keep the default bindings for the arrow keys, so this code can be
  139. ;; used with Epoch or with plain Emacs running in a Sun terminal
  140. (define-key esc-map "[A" 'previous-line )        ; R8
  141. (define-key esc-map "[B" 'next-line)        ; R14
  142. (define-key esc-map "[C" 'forward-char)        ; R12
  143. (define-key esc-map "[D" 'backward-char)        ; R10
  144. (define-key esc-map "[[" 'backward-paragraph)    ; the original esc-[
  145.  
  146.                 * * *
  147.  
  148. My suggestions for using all this are as follows.  First, put the
  149. entire first section into a file called "epokeys.el" and place this
  150. file somewhere in your load-path.  Byte-compile epokeys.el; it won't
  151. make a great deal of difference in the speed of loading, but it will
  152. make you feel better.  In your .emacs, load epokeys if you're running
  153. Epoch: 
  154.  
  155. (defvar in-epoch (boundp 'epoch::version))
  156.  
  157. (if in-epoch
  158.     (progn
  159.       (setq load-path (cons (expand-file-name "~/Epoch") load-path))
  160.       (load "epokeys")
  161.  
  162.       ;; other epoch-specific processing
  163.  
  164.      ))
  165.  
  166. How to load the second bit of code depends upon personal preference;
  167. I have the entire section in my .emacs, since I'm always running
  168. either in Epoch or from a sun terminal.
  169.  
  170. Which reminds me, there's a set of translations that you can place in
  171. your .Xdefaults to make your xterm function keys look like sunterm
  172. function keys; by using it you still have access to modified function
  173. keys even in xterm.  (Except for Meta-modified keys; for some reason,
  174. I didn't include that set of definitions.  It wouldn't be hard to add,
  175. though.)
  176.  
  177.                 * * *
  178.  
  179. Place the following resource definition in your .Xdefaults:
  180.  
  181. xterm*vt100*Translations: #override \n\
  182.         Shift    <Key>L1:    string("0x1b") string("[192y") \n\
  183.         Shift    <Key>L2:    string("0x1b") string("[193y") \n\
  184.         Shift    <Key>L3:    string("0x1b") string("[194y") \n\
  185.         Shift    <Key>L4:    string("0x1b") string("[195y") \n\
  186.         Shift    <Key>L5:    string("0x1b") string("[196y") \n\
  187.         Shift    <Key>L6:    string("0x1b") string("[197y") \n\
  188.         Shift    <Key>L7:    string("0x1b") string("[198y") \n\
  189.         Shift    <Key>L8:    string("0x1b") string("[199y") \n\
  190.         Shift    <Key>L9:    string("0x1b") string("[200y") \n\
  191.         Shift    <Key>L10:    string("0x1b") string("[201y") \n\
  192.         Shift    <Key>Help:    string("0x1b") string("[207y") \n\
  193.         Shift    <Key>R1:    string("0x1b") string("[208y") \n\
  194.         Shift    <Key>R2:    string("0x1b") string("[209y") \n\
  195.         Shift    <Key>R3:    string("0x1b") string("[210y") \n\
  196.         Shift    <Key>R4:    string("0x1b") string("[211y") \n\
  197.         Shift    <Key>R5:    string("0x1b") string("[212y") \n\
  198.         Shift    <Key>R6:    string("0x1b") string("[213y") \n\
  199.         Shift    <Key>R7:    string("0x1b") string("[214y") \n\
  200.         Shift    <Key>Up:    string("0x1b") string("[215y") \n\
  201.         Shift    <Key>R9:    string("0x1b") string("[216y") \n\
  202.         Shift    <Key>Left:    string("0x1b") string("[217y") \n\
  203.         Shift    <Key>R11:    string("0x1b") string("[218y") \n\
  204.         Shift    <Key>Right:    string("0x1b") string("[219y") \n\
  205.         Shift    <Key>R13:    string("0x1b") string("[220y") \n\
  206.         Shift    <Key>Down:    string("0x1b") string("[221y") \n\
  207.         Shift    <Key>R15:    string("0x1b") string("[222y") \n\
  208.         Shift    <Key>F1:    string("0x1b") string("[224y") \n\
  209.         Shift    <Key>F2:    string("0x1b") string("[225y") \n\
  210.         Shift    <Key>F3:    string("0x1b") string("[226y") \n\
  211.         Shift    <Key>F4:    string("0x1b") string("[227y") \n\
  212.         Shift    <Key>F5:    string("0x1b") string("[228y") \n\
  213.         Shift    <Key>F6:    string("0x1b") string("[229y") \n\
  214.         Shift    <Key>F7:    string("0x1b") string("[230y") \n\
  215.         Shift    <Key>F8:    string("0x1b") string("[231y") \n\
  216.         Shift    <Key>F9:    string("0x1b") string("[232y") \n\
  217.         Shift    <Key>F10:    string("0x1b") string("[233y") \n\
  218.         Shift    <Key>Insert:      string("0x1b") string("[247y") \n\
  219.         Shift    <Key>KP_Decimal:  string("0x1b") string("[249y") \n\
  220.         Shift    <Key>KP_Enter:      string("0x1b") string("[250y") \n\
  221.         Shift    <Key>KP_Add:      string("0x1b") string("[253y") \n\
  222.         Shift    <Key>KP_Subtract: string("0x1b") string("[254y") \n\
  223.         Shift    <Key>Num_Lock:      string("0x1b") string("[255y") \n\
  224.         Ctrl    <Key>L1:    string("0x1b") string("[192x") \n\
  225.         Ctrl    <Key>L2:    string("0x1b") string("[193x") \n\
  226.         Ctrl    <Key>L3:    string("0x1b") string("[194x") \n\
  227.         Ctrl    <Key>L4:    string("0x1b") string("[195x") \n\
  228.         Ctrl    <Key>L5:    string("0x1b") string("[196x") \n\
  229.         Ctrl    <Key>L6:    string("0x1b") string("[197x") \n\
  230.         Ctrl    <Key>L7:    string("0x1b") string("[198x") \n\
  231.         Ctrl    <Key>L8:    string("0x1b") string("[199x") \n\
  232.         Ctrl    <Key>L9:    string("0x1b") string("[200x") \n\
  233.         Ctrl    <Key>L10:    string("0x1b") string("[201x") \n\
  234.         Ctrl    <Key>Help:    string("0x1b") string("[207x") \n\
  235.         Ctrl    <Key>R1:    string("0x1b") string("[208x") \n\
  236.         Ctrl    <Key>R2:    string("0x1b") string("[209x") \n\
  237.         Ctrl    <Key>R3:    string("0x1b") string("[210x") \n\
  238.         Ctrl    <Key>R4:    string("0x1b") string("[211x") \n\
  239.         Ctrl    <Key>R5:    string("0x1b") string("[212x") \n\
  240.         Ctrl    <Key>R6:    string("0x1b") string("[213x") \n\
  241.         Ctrl    <Key>R7:    string("0x1b") string("[214x") \n\
  242.         Ctrl    <Key>Up:    string("0x1b") string("[215x") \n\
  243.         Ctrl    <Key>R9:    string("0x1b") string("[216x") \n\
  244.         Ctrl    <Key>Left:    string("0x1b") string("[217x") \n\
  245.         Ctrl    <Key>R11:    string("0x1b") string("[218x") \n\
  246.         Ctrl    <Key>Right:    string("0x1b") string("[219x") \n\
  247.         Ctrl    <Key>R13:    string("0x1b") string("[220x") \n\
  248.         Ctrl    <Key>Down:    string("0x1b") string("[221x") \n\
  249.         Ctrl    <Key>R15:    string("0x1b") string("[222x") \n\
  250.         Ctrl    <Key>F1:    string("0x1b") string("[224x") \n\
  251.         Ctrl    <Key>F2:    string("0x1b") string("[225x") \n\
  252.         Ctrl    <Key>F3:    string("0x1b") string("[226x") \n\
  253.         Ctrl    <Key>F4:    string("0x1b") string("[227x") \n\
  254.         Ctrl    <Key>F5:    string("0x1b") string("[228x") \n\
  255.         Ctrl    <Key>F6:    string("0x1b") string("[229x") \n\
  256.         Ctrl    <Key>F7:    string("0x1b") string("[230x") \n\
  257.         Ctrl    <Key>F8:    string("0x1b") string("[231x") \n\
  258.         Ctrl    <Key>F9:    string("0x1b") string("[232x") \n\
  259.         Ctrl    <Key>F10:    string("0x1b") string("[233x") \n\
  260.         Ctrl    <Key>Insert:      string("0x1b") string("[247x") \n\
  261.         Ctrl    <Key>KP_Decimal:  string("0x1b") string("[249x") \n\
  262.         Ctrl    <Key>KP_Enter:      string("0x1b") string("[250x") \n\
  263.         Ctrl    <Key>KP_Add:      string("0x1b") string("[253x") \n\
  264.         Ctrl    <Key>KP_Subtract: string("0x1b") string("[254x") \n\
  265.         Ctrl    <Key>Num_Lock:      string("0x1b") string("[255x") \n\
  266.             <Key>L1:    string("0x1b") string("[192z") \n\
  267.             <Key>L2:    string("0x1b") string("[193z") \n\
  268.             <Key>L3:    string("0x1b") string("[194z") \n\
  269.             <Key>L4:    string("0x1b") string("[195z") \n\
  270.             <Key>L5:    string("0x1b") string("[196z") \n\
  271.             <Key>L6:    string("0x1b") string("[197z") \n\
  272.             <Key>L7:    string("0x1b") string("[198z") \n\
  273.             <Key>L8:    string("0x1b") string("[199z") \n\
  274.             <Key>L9:    string("0x1b") string("[200z") \n\
  275.             <Key>L10:    string("0x1b") string("[201z") \n\
  276.             <Key>Help:    string("0x1b") string("[207z") \n\
  277.             <Key>R1:    string("0x1b") string("[208z") \n\
  278.             <Key>R2:    string("0x1b") string("[209z") \n\
  279.             <Key>R3:    string("0x1b") string("[210z") \n\
  280.             <Key>R4:    string("0x1b") string("[211z") \n\
  281.             <Key>R5:    string("0x1b") string("[212z") \n\
  282.             <Key>R6:    string("0x1b") string("[213z") \n\
  283.             <Key>R7:    string("0x1b") string("[214z") \n\
  284.             <Key>Up:    string("0x1b") string("[215z") \n\
  285.             <Key>R9:    string("0x1b") string("[216z") \n\
  286.             <Key>Left:    string("0x1b") string("[217z") \n\
  287.             <Key>R11:    string("0x1b") string("[218z") \n\
  288.             <Key>Right:    string("0x1b") string("[219z") \n\
  289.             <Key>R13:    string("0x1b") string("[220z") \n\
  290.             <Key>Down:    string("0x1b") string("[221z") \n\
  291.             <Key>R15:    string("0x1b") string("[222z") \n\
  292.             <Key>F1:    string("0x1b") string("[224z") \n\
  293.             <Key>F2:    string("0x1b") string("[225z") \n\
  294.             <Key>F3:    string("0x1b") string("[226z") \n\
  295.             <Key>F4:    string("0x1b") string("[227z") \n\
  296.             <Key>F5:    string("0x1b") string("[228z") \n\
  297.             <Key>F6:    string("0x1b") string("[229z") \n\
  298.             <Key>F7:    string("0x1b") string("[230z") \n\
  299.             <Key>F8:    string("0x1b") string("[231z") \n\
  300.             <Key>F9:    string("0x1b") string("[232z") \n\
  301.             <Key>F10:    string("0x1b") string("[233z") \n\
  302.             <Key>Insert:      string("0x1b") string("[247z") \n\
  303.             <Key>KP_Decimal:  string("0x1b") string("[249z") \n\
  304.             <Key>KP_Enter:      string("0x1b") string("[250z") \n\
  305.             <Key>KP_Add:      string("0x1b") string("[253z") \n\
  306.             <Key>KP_Subtract: string("0x1b") string("[254z") \n\
  307.             <Key>Num_Lock:      string("0x1b") string("[255z") \n
  308.  
  309. --
  310.    _    Jim Thompson           |  Wanted:
  311.  _| ~-  thompson@wg2.waii.com  |    Nick Park's "Grand Day Out"
  312.  \,  _} Western Geophysical    |    on VHS-format videotape
  313.    \(   Houston, Texas         |  Email me if you know where I can buy it.
  314.