Mon 04 September 2017 | -- (permalink)
Finally got around to fixing the "Meta" key handling on my laptop so that XQuartz, Terminal, and Emacs would all agree on which key is Meta. A friend asked me to document this.
Emacs
Just works out of the box. Well, if one picks the right box.
I had been running an ancient Carbon Emacs from much too long ago, because it was tightly integrated with some packages I cared about and didn't have time to cut loose from that. Finally made time and moved everything up to Emacs 25, which is what started me into the Meta key swamp.
Carbon Emacs 22 used the Mac's Command
key. Cocoa Emacs 25 uses the
Mac's Option
key. Overall, Option
is a much better choice,
because it doesn't interfere with things like task switching or other
sort-of-built-in stuff, so this was pretty clearly a good move, but
switching back and forth was driving me nuts.
The one catch with upgrading to Cocoa Emacs 25 was that the pre-compiled binary version everybody seems to recommend (https://emacsformacosx.com/) dumped core when I tried it (not immediately, it waited until I used a library which runs subprocesses, but still, clearly unacceptable). Don't know why, don't much care.
Homebrew to the rescue:
brew install -s emacs --with-cocoa --with-gnutls
I'll try the precompiled version again eventually (brew cask
makes
this easy) but not this week.
Terminal
Getting Terminal
to send the Option
key as the Meta key turned out
to be trivial, wish I'd known about this years ago:
- Open
Terminal
'sPreference
menu (Command-,
); - Select
Profiles
; - Down near the bottom click
Use Option as Meta key
.
This Just Works, and means that the Meta key now works properly for ssh connections too.
Well, ignoring locale issues -- on Linux, the Meta key sort of
defaults to supporting character composition, but if you're willing to
switch to LOCALE=C
you get a real 1980s Meta key. On the rare
occasions when I need to compose non-ASCII characters, I don't
generally do it on the bash command line, so having a working Meta key
is more useful to me. YMMV.
XQuartz
This one had me stumped for a while, but the solution turned out to be
simple: xmodmap
. Which is even automatic, if one uses the right
filename, so just place:
! Map MacBookAir "Option" key to mod2, ie, the meta bit.
! This assumes XQuartz "Option sends Alt_L and Alt_R" config box is checked.
!
clear mod1
add mod2 = Alt_L Alt_R
into ~/.XModmap
and set the Option sends Alt_L and Alt_R
option
checkbox in XQuartz's preferences menu.