[comp.emacs] Alt key to Meta-key binding on SGI for GNU

scotth@sgi.com (Scott Henry) (06/09/89)

I might as well repost this, as there is continuing interest. I made this
change by modifying the keyboard map for 4Sight. I started the process
because I hate the location of the CAPS-LOCK and CTRL keys...

-----------

Several months ago, someone (I'm sorry, but I lost the reference) dug deep
into the 4Sight code and figured out how to make the ALT keys into META
keys (and also make the CAPS-LOCK into a CTRL key where it belongs).

The basic instructions are: patch the following diff file against
/usr/NeWS/lib/NeWS/UI.ps, and put it in ~/NeWS (since you don't want to
mess up your real UI.ps, and 4Sight looks in ~/NeWS before
/usr/NeWS/lib/NeWS for loading code). I am also including the entries in
my ~/user.ps which implement the key mappings.

--------------- UI.ps.diff -----------------------------
*** /usr/NeWS/lib/NeWS/UI.ps	Thu Mar  9 16:51:01 1989
--- ~/NeWS/UI.ps	Wed Mar  8 09:39:49 1989
***************
*** 318,326 ****
--- 318,358 ----
  	} ifelse
      } def
  
+ % new code for meta key
+ /MetaDown false def			% true when either alt key is down
+ 
+ {
+     createevent dup begin 		% gobble alt key
+                                         % Do not eat the right ctrl key.
+                                         % We will need it to swap with capslock
+                                         % in user.ps.
+ 	    /Name [28419 28560 28559] def % first one is left ctrl key
+ 	    /Priority 4 def
+ 	    /Exclusivity true def
+ 	end
+     expressinterest
+     {
+ 	awaitevent
+ 	dup /Action get /DownTransition eq
+ 		{/MetaDown true store}     % downtrans -> set  flag
+ 		{/MetaDown false store}	   % uptrans -> clear flag
+ 	ifelse
+     } loop
+ } fork
+ %end new code
+ 
      /deliver_keyboard_to_focus {				% event => -
  	dup dup begin						% ev ev
  	    sgi_translatekey					% ev (string)
+ % new code for meta key
+ 	    dup dup type /stringtype eq		% if there's a string
+ 	    exch length 0 ne and		% of nonzero length
+ 	    MetaDown and			% and meta is down
+ 	    Action /DownTransition eq and	% and ev is a keypress
+ 	    {dup dup 0 get 128 or		% then ior 128 into
+ 	     0 exch put				% the 1st char in the string
+ 	    } if
+ % end new code
  	    /ClientData exch def				% ev
  	end
  	InteractionLock monitorlocked MenuBusy 0 ne or {
----------------- end UI.ps.diff -------------------------

Here are the relevant parts of my ~/user.ps

------------------ ~/user.ps -------------------------
%
% User customization file.
%

%   Earlier, I posted some code to swap the functionality of the Caps Lock
% and left-hand Ctrl key.  I have now written some code to make key
% remapping more flexible.  This code is also better because Caps Lock was
% still Caps Lock for an instant in the old code.  It not does function as
% Caps Lock at all in this code.  If you put the following in your user.ps
% (and take out the stuff I sent out before, if you have it), you can make
% any IRIS key behave as any other.  This will only work under 3.1 however,
% so if you haven't upgraded, you may want to keep the old code until you
% do upgrade.

/replacekeys { % origkeyvals_array changedkeyvals_array -> -
    {
        /changedvals exch def
        /origvals exch def
        /keysdict origvals length dict def
        keysdict begin
            0 1 origvals length 1 sub {
                dup origvals exch get changedvals
                3 2 roll get def
            } for
        end
        createevent dup begin
            /Name origvals def
            /Priority 2 def
            /Exclusivity true def
        end
        expressinterest
        {
            awaitevent dup dup begin
                /Name get keysdict exch get /Name exch def
            end
            redistributeevent
        } loop
    } fork pop pop pop
} def

%
% customizations
%
/RestartActions [ 
    { [ 28420 ] [ 28561 ] replacekeys }
    % other startup actions here
] def

------------------------ end of ~/user.ps -------------------

I have been using these patches for several months on a 4D70G under IRIX
3.1 and 3.1D and now have full Meta-key access to GNUEmacs. This posted
code will map both ALT keys and the left CTRL key to work as Meta-keys,
and maps the CAPS-Lock and right CTRL keys as CTRL keys. Note that you no
longer have a Caps-Lock key after these modifications. (I almost never use
it, so I don't miss it). Note that this modification only works when in
4Sight (since it is done in the NeWS server), and the keyboard has normal
functionality when in NOGRAPHICS mode...

Disclaimer: these are my own modifications to SGI-supplied code based upon
previously posted public domain code. No warranty is expressed or implied.
It works for me!

--
      Scott Henry <scotth@sgi.com>
      Silicon Graphics, Inc
      Mountain View, CA
#include <std_disclaimer.h>
--
         Scott Henry <scotth@sgi.com>
#include <std_disclaimer.h>