home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / input-remapping / text0001.txt < prev    next >
Encoding:
Text File  |  1990-07-22  |  4.1 KB  |  164 lines

  1.  
  2.     HP/ISI input remapping files:  Part 1 of 8
  3.  
  4.     These are differences relative to the original src/x11fns.c
  5.     in GNU emacs version 18.54.
  6.  
  7.     Changes are to add function x-rebind-keysym, which allows
  8.     changing the keysym-to-string binding for X11 keyboard input.
  9.  
  10.  
  11. ------------------------------  Cut  Here  --------------------------------
  12. 24a25,26
  13. > /*    Modified by Paul Raveling @ ISI to add keysym rebinding        */
  14. 110a113,256
  15. > extern    char    *keysymtostring ();    /*  In x11term.c    */
  16. > extern    KeySym     stringtokeysym ();    /*  In x11term.c    */
  17. > /*    Alternative modifier lists;    */
  18. > static    KeySym    noshifts[2]    = {0, 0};
  19. > static    KeySym    shiftshifts[2]    = {XK_Shift_L, XK_Shift_R};
  20. > static    KeySym    ctlshifts[2]    = {XK_Control_L, XK_Control_R};
  21. > static    KeySym    metashifts[2]    = {XK_Meta_L, XK_Meta_R};
  22. > /*------------------    x-rebind-keysym    -------------------*/
  23. > DEFUN ("x-rebind-keysym", Fx_rebind_keysym, Sx_rebind_keysym, 3, 3,
  24. > "sKey to rebind (KeySym, without \"XK_\"):  \n\
  25. > sShift key ([nil], None, Shift, Ctl, Meta):  \n\
  26. > sNew string bound to key:  ",
  27. > "Rebind KEYSYM, with SHIFT-KEY, to NEWSTRING.\n\
  28. >     KEYSYM is the key's name as given in /usr/include/X11/keysymdef.h,\n\
  29. >     but without the \"XK_\" prefix.\n\
  30. >     SHIFT-KEY is nil, \"NONE\", \"SHIFT\", \"CTL\", or \"META\";\n\
  31. >     nil selects all combinations of shift keys.\n\
  32. >     NEWSTRING is an arbitrary string of keystrokes.\n\
  33. > \n")
  34. >   (keysym, shift_key, newstring)
  35. >      register Lisp_Object keysym;
  36. >      register Lisp_Object shift_key;
  37. >      register Lisp_Object newstring;
  38. > {
  39. >     char    *keysymstring, *shiftstring, *mapstring;
  40. >     int     keysymslen,    shiftslen,    mapslen;
  41. >     KeySym     target_key;
  42. >     KeySym    *modlist;
  43. >     int     num_mods;
  44. >     int     i;
  45. >     char    *cp;
  46. >     CHECK_STRING (keysym, 1);
  47. >     if (!NULL (shift_key))
  48. >        CHECK_STRING (shift_key,2);
  49. >     CHECK_STRING (newstring, 3);
  50. > #define    setstring(src,dst,len) { \
  51. >     len = XSTRING (src) -> size; \
  52. >     dst = (char *) xmalloc (len+1); \
  53. >     bcopy (XSTRING (src) -> data, dst, len); \
  54. >     dst[len] = 0; }
  55. >     setstring (keysym,    keysymstring,    keysymslen)
  56. >     if ( !NULL (shift_key) )
  57. >        setstring (shift_key,shiftstring,    shiftslen)
  58. >     else
  59. >        shiftslen = 0;
  60. >     setstring (newstring,    mapstring,    mapslen)
  61. >     /*------------------------------*/
  62. >     /*    Identify key to remap    */
  63. >     /*------------------------------*/
  64. >     target_key = stringtokeysym ( keysymstring );
  65. >     if ( target_key == 0 )
  66. >        {
  67. >        error ("Keysym \"%s\" is not defined", keysymstring);
  68. >        return Qnil;
  69. >        }
  70. >     /*----------------------------------------------*/
  71. >     /*    Identify modifier list(s) to use    */
  72. >     /*----------------------------------------------*/
  73. >     if ( shiftslen != 0 )
  74. >        {
  75. >        cp = shiftstring;
  76. >        i  = shiftslen;
  77. >        while ( i-- > 0 )        /*  Fold string to upper case    */
  78. >          {
  79. >              if ((*cp >= 'a') && (*cp <= 'z'))
  80. >             *cp -= 'a' - 'A';
  81. >          ++ cp;
  82. >          }
  83. >        }
  84. >     if ( shiftslen == 0 )
  85. >        num_mods = -1;
  86. >     else if ( strcmp (shiftstring, "NONE") == 0 )
  87. >         {
  88. >         modlist  = noshifts;
  89. >         num_mods = 0;
  90. >         }
  91. >     else if ( strcmp (shiftstring, "SHIFT") == 0 )
  92. >         {
  93. >         modlist  = shiftshifts;
  94. >         num_mods = 2;
  95. >         }
  96. >     else if ( strcmp (shiftstring, "CTL") == 0 )
  97. >         {
  98. >         modlist  = ctlshifts;
  99. >         num_mods = 2;
  100. >         }
  101. >     else if ( strcmp (shiftstring, "META") == 0 )
  102. >         {
  103. >         modlist  = metashifts;
  104. >         num_mods = 2;
  105. >         }
  106. >     else
  107. >         {
  108. >         error ( "Shift key \"%s\" not recognized", shiftstring );
  109. >         return Qnil;
  110. >         }
  111. >     /*----------------------*/
  112. >     /*    Map the key    */
  113. >     /*----------------------*/
  114. >     if ( num_mods != -1 )
  115. >        XRebindKeysym ( XXdisplay, target_key, modlist, num_mods,
  116. >                 mapstring, mapslen );
  117. >     else
  118. >        {
  119. >        XRebindKeysym ( XXdisplay, target_key, noshifts, 0,
  120. >                 mapstring, mapslen );
  121. >        XRebindKeysym ( XXdisplay, target_key, shiftshifts, 2,
  122. >                 mapstring, mapslen );
  123. >        XRebindKeysym ( XXdisplay, target_key, ctlshifts, 2,
  124. >                 mapstring, mapslen );
  125. >        XRebindKeysym ( XXdisplay, target_key, metashifts, 2,
  126. >                 mapstring, mapslen );
  127. >        }
  128. >     return Qt;
  129. > }
  130. 847a994
  131. >   defsubr (&Sx_rebind_keysym);
  132.  
  133.  
  134.