views:

5087

answers:

10

Is there a way to use "alt/option" key as a meta key but still be able to use the key to make some characters which need it?

For example in my local keyboard layout: @ is alt-2 \ is alt-shift-7 | is alt-7

etc. So if I set alt as meta key, I can't make those characters. On the other hand using "press esc, release esc, press a key" to make meta key sequences makes my hands hurt.

Any emacs users with international keyboards who have solved this, please give any tips you might have! :)

edit: It appears that I can set alt as meta key and then add these kind of settings in inputrc: "\e2": "@" This works in bash shell but it still won't work with emacs though, so no good.

+4  A: 

Two work-arounds I use:

  • I use xterm running under X11.app. X11.app uses the command key as meta.
  • When running emacs in Terminal.app, I just use the rfc1345 input-method, which allows me to enter all kinds of crazy non-ascii characters without needing an option key.
bendin
+3  A: 

Think about using a full featured Emacs for Mac OS X. I use Carbon Emacs but I believe others (say Aqua Emacs or X11 Emacs) would do the trick.

If you insist on using Emacs in a terminal you can use the C-x 8 prefix as a compose key. Try C-x 8 C-h to get a list of possibilities.

See http://www.emacswiki.org/emacs/EmacsForMacOS

kmkaplan
Unfortunately Carbon emacs doesn't fix my problem. I'm still not able to make there characters "@ \ | " while having a functional meta key.It seems that emacs is just incompatible with international keyboards on mac unless I completely remap the keyboard. I'm already thinking of learning vim ;).
abababa22
Mmm, that’s strange. Here Carbon Emacs does not use the Alt key but the Cmd key as meta. Is there a particular reason Cmd is not suitable as a meta for you?
kmkaplan
Ah, I didn't know that it uses Cmd as meta key. I tried it now, and it works. :)
abababa22
+2  A: 

The above answers mention ways to enter non-ascii input, but that's not really the problem here. The C-x 8 method lets you enter a bunch of non-ascii, but the problem is that you need the option key on mac just to enter the (ascii) character `|' (vertical bar)!

So how do you then enter stuff like M-| (region to shell command) when running emacs in ssh under Terminal.app? No way for it but to use the escape key, since | is option-7 and Terminal.app for some stupid reason won't let you use Cmc as meta :-(

(If anyone knows of a hack (SIMBL perhaps?) that actually does let Terminal.app use Cmd as meta, I'd be very grateful...)

unhammer
A: 

I bit the grass and started hitting the escape key instead. You get use to it...

KristianR
A: 

I would like to mod this question up or something because i also use a Swedish keyboard where i must press alt+7 or alt+shift+7 to make | and \ respectively.

I also use Irssi in Terminal.app and these don't mix well.

I'm a long time vim user though so emacs is not an issue to me.

Isn't there some way to remap CMD to be Meta in Terminal.app?

So far i've been surviving by simply typing /wg N in Irssi because having those characters in my Terminal is much more important than IRC.

A solution would be worth gold to me though! :)

nocturnal
+2  A: 

Check out cmd-key-happy. This little app has worked wonders for me. It allows you to use command as meta, with exceptions that you can configure.

Author's info follows:

This program allows you to swap the command and alt (or option) keys in any application, but in particular Terminal.app.

http://github.com/aim-stuff/cmd-key-happy

stuntmouse
+3  A: 

I've written a small iTerm patch, that allows you to do exactly that. See here for details.

yacoob
+1 Even though I decided long time ago to use GUI version of Emacs whenever I can, your patch is very cool in that it leaves right option as the option key. I hope this gets merged upstream. :)
abababa22
+2  A: 

I use a Swedish keyboard in Mac OS X and use the following setup for Emacs.app:

First I have KeyRemap4MacBook installed and I have it setup to change the left Option key to Command.

I then have the following in my .emacs:

(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)

This makes Emacs treat command as Meta and ignore Option. Since the left Alt/Option key is remapped to command, this makes it work lite meta while the right Alt/Option key still works for entering special characters like @ [] and {}.

App specific Mac shortcuts like Cmd+C and Cmd+V no longer work, but global shortcuts like Cmd+space for Spotlight and Cmd+Tab for app switching do.

Sadly this doesn't work in Terminal.app, but I just use M-x shell or Mx-ansi-term instead.

Joakim Hårsman
A: 

This is so freakin stupid to have to switch between hitting the escape and command buttons, it's really inefficient not to mention a strain on the hands. It so ridiculous that I quit using e-macs. If only I could get that stupid meta-key to bind successfully with the option button in Terminal.app.

bk1
A: 

Aquamacs supports that, at least for my (french) keyboard. Once Aquamacs is installed (via drag'n'drop), you can go to Options -> Option, Command, Meta keys and choose an appropriate setting for your keyboard (in my case, ...Meta & French). I am not proficient with Emacs, but all the useful combinations I have tried seem to work ([, {, |, and so forth).

Supported keyboards, according to the menu items as of version 2.1, are :

  • British
  • US
  • Swiss-french
  • Swiss-german
  • Finnish
  • Italian-Pro
  • Italian
  • Spanish
  • French
  • German

I would guess the Aquamacs team would be grateful for any contribution, though, should your keyboard not appear in the list.

Gary Verhaegen