10.3: Get xmodmap to remap alt / option in X11

Apr 27, '04 10:51:00AM

Contributed by: dphaffner

I had a tough time getting the alt / option key to work as the Meta (M-x) key in emacs. The escape key does it, but I wanted the key to be where I was most familiar. I'm on a new AlBook with Panther (10.3) and the Apple X11.app installed. Older postings here and elsewhere show how to remap using xmodmap. This works, but I think there are some particulars specific to Panther and Apple's X11.app that aren't reflected in the previous postings. Here are the details. There are just two steps to get this done.

First, put your remapping commands into an .Xmodmap file in your home directory ($HOME/.Xmodmap). With the help of the X11 program xev, I wrote a file that did what I wanted it to.

   clear Mod1
   keycode 66 = Meta_L
   add Mod1 = Meta_L

It tested perfectly in emacs after running

   xmodmap ~/.Xmodmap

You can see what your mod (modifier) keys are mapped to using

   xmodmap -p
Second, open up the X11 preferences from the menu on the top bar. On the "Input" tab, uncheck "Follow system keyboard layout" to allow your keymap changes to overlay on the default X keymap. Then restart X, fire up emacs, and your alt / option key, or others you remapped, should work. Here's a bit more background on what I've discovered:

Reading the man page for Xquartz, I learned that it copies the default aqua keyboard layout into an X11 keymap before startup. Xquartz appears to start up in a non-standard way compared to the standard X, and it won't let you override the keymap unless you allow it as I described above. Other postings elsewhere said you should copy the /etc -> X11 -> xinit -> xinitrc file to ~/.xinitrc and add xmodmap ~/.Xmodmap to the end But this is redundant -- the stock xinitrc script in /etc already checks for an xmodmap file in your home directory. I think those who posted this info were using a pre-Panther version of X11.

Some useful general info on Apple's X11 startup is in the Apple X11 FAQ under "Does X11.app process my ~/.xinitrc?"

Comments (11)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040425231058862