1

I'm on macOS 10.12.5 and Emacs 25.2.1. For some reason M-right is interpreted as M-f. ESC-right is correctly interpreted as ESC-right. I can't see anything in the macOS keyboard shortcuts list that might be capturing M-right/left. How might I figure out what's going on here?

I ended up switching to mitsuarhu's Emacs osx port instead, which doesn't have this problem. I noticed that terminal Emacs in iterm2 also doesn't have this problem. I guess terminal.app is capturing M-right and turning it in to M-f for some reason.

  • There is no such thing in Emacs as <esc>-right. To find out what function is bound to what keys, press 'C-h k [keys], and modify your question. It is common configuration under OSX that both Esc and Alt keys acts as meta. Both these keys plus 'f' are usually mapped to function forward-word. – Heikki Jul 5 '17 at 6:21
  • Meant to say that what function a key combination is mapped to depends on the major mode of the buffer. Typically all combinations of [esc|alt] and [f|right] are mapped functions like forward-word or right-word. – Heikki Jul 5 '17 at 6:32
  • 1
    Hm, not sure I understand "there is no such thing in emacs as <esc>-right" I'm just describing the keys I'm pressing. I have the default configuration which I believe maps both esc and alt to meta. I'm using org mode. pressing the escape key follow by right on a heading will correctly demote it. And 'c-h k escape right' tells me that it runs 'org-metaright'. Whereas alt-right runs the command forward-word, despite alt being my meta key as well. – ericsoderstrom Jul 5 '17 at 18:30
  • Start Emacs with -Q and see if the problem still occurs. If it doesn't then it's a problem with your Emacs config. – stevoooo Jul 5 '17 at 19:43
  • You should change your title and question to state that you are asking why esc-right and meta-right work differently in org mode headers. – Heikki Jul 5 '17 at 21:22
2

You have hit something quite interesting here that came clear when you added that you see the behaviour in org mode headers. Although surprising, your emacs works as it should.

According to emacs faq, "Emacs converts M-a internally into ESC a anyway (depending on the value of meta-prefix-char)." The value of meta-prefix-char is by default 27 (esc).

However, when the cursor is in org mode header, meta and escape are indeed doing different things:

  • ESC right (translated from escape right) runs the command forward-word (found in global-map), which is an interactive built-in function in ‘C source code’.

  • M-right runs the command org-metaright (found in org-mode-map), which is an interactive compiled Lisp function in ‘org.el’.

Based on these observations, the conversion of meta to esc happens at C source code level, and if any Emacs major modes written in lisp redifine the meta + key(s) mapping, it leaves the global escape mapping intact. That's is not clearly stated anywhere I looked and quite good to know!

2

I think it is due to the fact shown in the following picture.

enter image description here

Terminal app in MacOS capture the behaviour of the keyboard.

In the menu Terminal>Preferences go to Profiles tab and select the default profile or the profile it's been used then Select the keyboard tab.

Here the list show how the input is modified, sending special characters to the terminal.

In this case M-right is bounded to \033f.

To fix the issue remove the interested row.

The same solution could apply for other combination of keys in the list.

  • 1
    Please elaborate - explain the fact shown and how it answers the question. – Drew Jan 23 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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