4

I'm having a hell of a time with getting Org Mode's key bindings to work.

I thought that maybe the difficulties I was having had to do with what this page describes, since I was using Emacs text-mode via Terminal.app (on a Mac).

So I decided to try Emacs for Mac, which (presumably) I could use as a free-standing application, thereby circumventing whatever problems Terminal.app may be causing.

But it turns out that, with Emacs for Mac I can type even fewer Org Mode key-bound commands!

(In this post, I will abbreviate Emacs for Mac as McE, and Emacs via Terminal.app as TME, short for "text-mode Emacs".)

Let me start with the case of <M-right>, by way of example.

According to describe-bindings (C-h b) for Org Mode, <M-right> should be bound to org-metaright. This is not terribly informative, but the documentation for org-metaright says:

org-metaright is an interactive compiled Lisp function in `org.el'.

(org-metaright &optional ARG)

Demote a subtree, a list item or move table column to right. In front of a drawer or a block keyword, indent it correctly. With no specific context, calls the Emacs default `forward-word'. See the individual commands for more information.

Now, suppose that org-mode is the buffer's major mode, point is at a subtree's heading, and I type the key sequence I'd use for <M-right>, namely, esc followed by .

If I do this in TME, the subtree is demoted, exactly as the documentation says, but if I do it in McE, all I get is that point advances forward by one word.

Indeed, in McE, if I type the same sequence (esc , ) into describe-key (C-h k), I don't get the documentation for org-metaright, but rather the one for forward-word:

ESC <right> (translated from <escape> <right>) runs the command forward-word, which is an interactive built-in function in `C source code'.

It is bound to M-f, ESC <right>.

(forward-word &optional ARG)

Move point forward ARG words (backward if ARG is negative). If ARG is omitted or nil, move point forward one word. Normally returns t. If an edge of the buffer or a field boundary is reached, point is left there and the function returns nil. Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil.


It gets worse.

<M-right> at least works correctly in TME, but <M-S-right> I can't get to work anywhere.

According to describe-bindings, <M-S-right> is supposed to be bound to (you guessed it) org-shiftmetaright. In McE, however, if I type into describe-key the sequence for <M-S-right> (namely, esc, shift + , where I'm pressing the last two keys simultaneously), I again get the docs for forward-word pretty much as shown earlier, except for a small change in the first line:

ESC <right> (translated from <escape> <S-right>) runs the command forward-word, which is an interactive built-in function in `C source code'.
...

The silver lining is the mention of <escape> <S-right> in this first line, because it shows that McE is at least detecting the shift press (which is the reason I bothered to install McE in the first place). Unfortunately, it is discarding that piece information, and mistranslating what's left (after all ESC <right> should be bound to org-metaright, not to forward-word).

Doing the same thing in TME produces:

ESC <right> (translated from ESC M-O C) runs the command
org-metaright, which is an interactive compiled Lisp function in `org.el'.

It is bound to <M-right>, ESC <right>, C-c C-x r, <menu-bar> <Org>
<Edit Structure> <Demote Heading>, <menu-bar> <Tbl> <Column> <Move
Column Right>.

(org-metaright &optional ARG)

Demote a subtree, a list item or move table column to right. In front of a drawer or a block keyword, indent it correctly. With no specific context, calls the Emacs default `forward-word'. See the individual commands for more information.

...which sounds a bit better (it's the documentation for some Org Mode command at least!), but it seems that the shift is not getting through at all. I can't figure out what the M-O C in the first line is referring to.


What can I do to get these key bindings to work properly?

3 Answers 3

4

You can always access the meta prefix via

C-x @ m     

which is bound to event-apply-meta-modifier. Thus C-x @ m <right> in org-mode is bound to org-metaright and C-x @ m S-<right> is bound to org-shiftmetaright.

In general the ESC key is only related to the meta prefix in front of ordinary characters, not in front of special keys such as <f11> or <right>. The following two paragraphs of the Elisp manual explain this:

Keymaps do not directly record bindings for the meta characters. Instead, meta characters are regarded for purposes of key lookup as sequences of two characters, the first of which is <ESC> (or whatever is currently the value of ‘meta-prefix-char’). Thus, the key ‘M-a’ is internally represented as ‘<ESC> a’, and its global binding is found at the slot for ‘a’ in ‘esc-map’ (*note Prefix Keys::).

This conversion applies only to characters, not to function keys or other input events; thus, ‘M-<end>’ has nothing to do with ‘<ESC> <end>’.

from section 21.3 "Format of Keymaps"

Another approach is to use the option org-use-extra-keys. This is turned on automatically for emacs in a terminal and provides a number of alternative bindings. In particular M-<right> may be invoked by either C-c C-x r or <ESC> <right>. Also it defines a speed key r for use when at the beginning of a headline. See "Using Org on a tty" under the "Miscellaneous" section of the org manual.

3

Use iTerm2 instead of the built-in Terminal. iTerm2 lets you swap all the modifier keys on the keyboard however you like, right in the Preferences pane. iTerm is a work of art and it's open source.

When you make the switch to Linux try the technique I describe in the link below. My answer was not selected as Best Answer, but I think it is. https://unix.stackexchange.com/questions/60235/mapping-super-keys-to-control-without-xmodmap/156645#156645

0
  • if you need ⎋ ESC+right, just type ⌥ option+right.

  • If you need ⎋ ESC+⇧ shift+right, just type ⌥ option+⇧ shift+right.

  • If you need ⎋ ESC all the time in MacBook Pro Touch Bar model, just type ⌃ control+[. As miss Touch Bar is so cute, ⎋ ESC sometimes disappears.

  • I removed all buttons from unintentional miss-Touch Bar, such as Siri, Volume Control, Brightness Control, etc. Only My ⎋ ESC. Nothing except one ⎋ ESC is in my miss-Touch Bar. No more miss-Touch. I finally got the best Emacs machine ever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.