home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / emacs / 3794 < prev    next >
Encoding:
Text File  |  1992-12-15  |  5.7 KB  |  183 lines

  1. Path: sparky!uunet!noc.near.net!ceylon!steve
  2. From: steve@eowyn.gte.com (Steve Preston)
  3. Newsgroups: comp.emacs
  4. Subject: Re: emacs key bindings for the keypad
  5. Message-ID: <STEVE.92Dec15191333@eowyn.gte.com>
  6. Date: 16 Dec 92 00:13:33 GMT
  7. References: <19735@sunfse.ese.lmsc.lockheed.com>
  8. Sender: news@ceylon.gte.com
  9. Organization: GTE Laboratories
  10. Lines: 170
  11. In-reply-to: page@leadse5.UUCP's message of 11 Dec 92 01:44:29 GMT
  12.  
  13. >>>>> In article <19735@sunfse.ese.lmsc.lockheed.com>, page@leadse5.UUCP (Dan Page) writes:
  14. > I have been trying furiously to map the keypad of my X terminal to
  15. > emacs functions. Success has been spotty and not satisfactory. Mapping
  16. > of the F1-F12 keys went off without a hitch using the sun-raw-map.
  17. > However, my keypad is set to send a numeric value (or '.', or '-')
  18. > when these keys are hit. So remapping the '5' key on the keypad also
  19. > remaps the '5' key on the keyboard. Further, the PF1-PF4 keys seem to
  20. > be dead when I am in emacs. I have successfully set the keypad to
  21. > application mode when I am in an X window, but this somehow gets reset
  22. > by emacs. I cannot find the equivalent of sun-raw-map that deals with
  23. > the keypad. Calling all large brains to help me with this problem.
  24.  
  25. The problem is that, when running as an X client, emacs does not check
  26. for "keypad" keysyms when a KeyPress event occurs.  It *does* check
  27. for "function key" keysyms (at least on non-AIX machines).  There is
  28. thus no way that emacs can know the difference between "keypad 5" and
  29. regular "5".
  30.  
  31. I patched x11term to remedy this.  My emacs will act as if a keypad
  32. key generates ESC O plus an alphabetic character.  This is what the
  33. vt100 keypad keys transmit in keypad application mode.  Here is the
  34. patch :
  35. ------------------------------cut here------------------------------
  36. *** x11term.c.orig    Sat Oct 24 00:31:56 1992
  37. --- x11term.c    Tue Dec 15 18:51:28 1992
  38. ***************
  39. *** 1463,1468 ****
  40. --- 1463,1528 ----
  41.   #endif /* sun */
  42.       nbytes = strlen(mapping_buf);
  43.         }
  44. +       else if (IsKeypadKey(keysym)) {
  45. +      strcpy(mapping_buf,"\033O");  /* ESC - O (aka SS3) */
  46. +      switch (keysym) {
  47. +      case XK_KP_F1:
  48. +        mapping_buf[2]='P';
  49. +        break;
  50. +      case XK_KP_F2:
  51. +        mapping_buf[2]='Q';
  52. +        break;
  53. +      case XK_KP_F3:
  54. +        mapping_buf[2]='R';
  55. +        break;
  56. +      case XK_KP_F4:
  57. +        mapping_buf[2]='S';
  58. +        break;
  59. +      case XK_KP_Subtract:
  60. +        mapping_buf[2]='m';
  61. +        break;
  62. +      case XK_KP_Separator:
  63. +        mapping_buf[2]='l';
  64. +        break;
  65. +      case XK_KP_Enter:
  66. +        mapping_buf[2]='e';
  67. +        break;
  68. +      case XK_KP_Decimal:
  69. +        mapping_buf[2]='n';
  70. +        break;
  71. +      case XK_KP_0:
  72. +        mapping_buf[2]='p';
  73. +        break;
  74. +      case XK_KP_1:
  75. +        mapping_buf[2]='q';
  76. +        break;
  77. +      case XK_KP_2:
  78. +        mapping_buf[2]='r';
  79. +        break;
  80. +      case XK_KP_3:
  81. +        mapping_buf[2]='s';
  82. +        break;
  83. +      case XK_KP_4:
  84. +        mapping_buf[2]='t';
  85. +        break;
  86. +      case XK_KP_5:
  87. +        mapping_buf[2]='u';
  88. +        break;
  89. +      case XK_KP_6:
  90. +        mapping_buf[2]='v';
  91. +        break;
  92. +      case XK_KP_7:
  93. +        mapping_buf[2]='w';
  94. +        break;
  95. +      case XK_KP_8:
  96. +        mapping_buf[2]='x';
  97. +        break;
  98. +      case XK_KP_9:
  99. +        mapping_buf[2]='y';
  100. +        break;
  101. +      }
  102. +      nbytes = 3;
  103. +       }
  104.         else {
  105.   #endif /* not AIX */
  106.       switch (keysym) {
  107. ------------------------------cut here------------------------------
  108.  
  109. And here are the relavent lines in my .emacs file
  110.  
  111. (setq load-path (cons  "/usr/local/emacs/emacs-lisp" load-path))
  112. (setq term-setup-hook
  113.  (function
  114.   (lambda ()
  115.     (if (eq window-system 'x)
  116.     (progn (define-key mouse-map x-button-left 'x-mouse-ignore)
  117.            (define-key mouse-map x-button-middle 'x-mouse-set-point)
  118.            (define-key mouse-map x-button-right 'x-mouse-set-mark)
  119.            (load "term/x11.el")
  120.            )))))
  121. (define-key function-keymap "8" 'scroll-one-line-down)
  122. (define-key function-keymap "2" 'scroll-one-line-up)
  123. (define-key function-keymap "5" 'goto-line)
  124. (define-key function-keymap "3" 'forward-page-top)
  125. (define-key function-keymap "9" 'backward-page-top)
  126. (define-key function-keymap "7" 'top-of-window)
  127. (define-key function-keymap "4" 'middle-of-window)
  128. (define-key function-keymap "1" 'bottom-of-window)
  129.  
  130. The file x11.el to be loaded is just a cut-and-paste from vt100.el;
  131. it should have the GPL header, like all the other FSF .el files.  I
  132. put it into /usr/local/emacs/emacs-lisp/term/x11.el.
  133.  
  134. ------------------------------x11.el------------------------------
  135. ;; Map VT100 function key escape sequences
  136. ;; into the standard slots in function-keymap.
  137.  
  138. (require 'keypad)
  139.  
  140. (defvar SS3-map nil
  141.   "SS3-map maps the SS3 function keys on the VT100 keyboard.
  142. The SS3 keys are the numeric keypad keys in keypad application mode
  143. \(DECKPAM).  SS3 is DEC's name for the sequence <ESC>O which is
  144. the common prefix of what these keys transmit.")
  145.  
  146. (if (not SS3-map)
  147.     (progn
  148.  
  149.      (setq SS3-map (lookup-key global-map "\eO"))
  150.      (if (not (keymapp SS3-map))
  151.      (setq SS3-map (make-keymap)))  ;; <ESC>O commands
  152.      (setup-terminal-keymap SS3-map
  153.         '(("A" . ?u)       ; up arrow
  154.           ("B" . ?d)       ; down-arrow
  155.           ("C" . ?r)       ; right-arrow
  156.           ("D" . ?l)       ; left-arrow
  157.           ("M" . ?e)       ; Enter
  158.           ("P" . ?\C-a)       ; PF1
  159.           ("Q" . ?\C-b)       ; PF2
  160.           ("R" . ?\C-c)       ; PF3
  161.           ("S" . ?\C-d)       ; PF4
  162.           ("l" . ?,)       ; ,
  163.           ("m" . ?-)       ; -
  164.           ("n" . ?.)       ; .
  165.           ("p" . ?0)       ; 0
  166.           ("q" . ?1)       ; 1
  167.           ("r" . ?2)       ; 2
  168.           ("s" . ?3)       ; 3
  169.           ("t" . ?4)       ; 4
  170.           ("u" . ?5)       ; 5
  171.           ("v" . ?6)       ; 6
  172.           ("w" . ?7)       ; 7
  173.           ("x" . ?8)       ; 8
  174.           ("y" . ?9)))       ; 9
  175.  
  176.      (define-key global-map "\eO" SS3-map)))
  177.  
  178. (global-set-key "\e[" nil)  ; so function keys can be remapped.
  179. ------------------------end of x11.el------------------------------
  180. --
  181. --
  182. Steve Preston (spreston@gte.com)
  183.