The M-<TAB> key in Emacs provides a useful completion function (`completion-at-point’), which tries to complete the current symbol at point to something useful, usually based on other symbols in the buffer which have the current partial symbol as a prefix.
However, using this key is a pain in most OS GUI systems, since it is usually mapped to the Task Switching function as well. Note that the <Alt> key doubles as <Meta> on most keyboards.
Emacs provides two documented alternatives, <Esc>-<TAB> – which requires a trip away from the home rows to the <Esc> key, and “C-M-i”, which is far easier to type.
In fact, there is a third way of inputting an equivalent key sequence: “C-[ C-i”, which is “<Control>-[“ followed by “<Control>-i”.
This works because “<Control>-[“ (that is the left square bracket) is equivalent to the <Esc> key, and also works as a <Meta> key.
The Alternative to <Meta>
In fact, “C-[“ can be used anywhere a <Meta> is required. E.g.,
“M-x” can be replaced with “C-[ x”
<Esc> <Esc> <Esc> (to invoke `keyboard-command-quit’) can be replaced with “C-[ C-[ C-[“.
Using “C-[“ instead of <Esc> or <Meta> has the advantage that the key sequences can be invoked from the home screen, reduces hand movement (at least on a QWERTY keyboard), and also helps avoid the finger contortions that are otherwise often needed to access the <Meta> key.
Note that sequences which involve both <Meta> and <Control> keys can also be invoked, as long as the “C-[“ is entered first. E.g.,
“C-M-x” (to invoke `eval-defun’ in an Emacs lisp buffer) can be replaced with “C-[ C-x”. Sweet.
Oh, I can’t thank you enough. I’ve really not been happy with my keybindings on OS X versus what I use on Ubuntu. Now I can remove part of my .emacs file
(setq mac-command-key-is-meta t)
(setq mac-command-modifier ‘meta)
and instead use C-[ for and Cmd-H works when hiding Emacs as per all other applications on OS X.
Thanks again!
Hi James,
Glad to be of help. Just wanted to mention that if you are only looking to access <Cmd>-H for hiding the Emacs window in OSX, you may want to keep the current binding of <Cmd> to <Meta>, and instead use the following steps:
1. Use <Cmd>-<TAB> to invoke the task switched in OSX (note that even after the mapping of <Cmd> to <Meta>, this still invokes switcher). Select the Emacs icon by repeated presses of <Cmd>-<TAB> (the normal task selection operation)
2. Do NOT let go of the <Cmd> key one you have selected the Emacs Icon. Instead, press <H> while <Cmd> remains pressed.
3. The Emacs window will hide.
This actually works for all applications in OSX. You can of course hide Emacs using the “Hide Emacs” option under the application menu as well.
if you are looking to minimize the window (somewhat different than hiding the window, but often similar enough effect), use C-z.
On a related note C-c-i also brings up the automatic completions and is probably less keyboard work since the finger on the control key does not have to move at all