Mac – Alt-keys (option-keys) in emacs emulation (jetBrains PyCharm)

emacskeyboardshortcuttext-editor

I suspect this is a general issue with the Mac as opposed to anything specific to the app I'm struggling with now, which happens to be PyCharm from jetBrains. The reason I suspect this is a general problem is that I've struggled with it before with other apps, namely emacs itself and perhaps some other apps that have emacs keybinding emulation, but not sufficiently often (once a year or so) that I can remember the solution. What I do remember is that the solution was really obscure and perhaps not something we had to do to the app directly, but to the environment or context.

The problem is that alt keys don't work as expected as modifier keys, but instead input glyphs. For example, we want Alt-D to perform the editor function "Kill-to-end-of-word," but, instead, it inputs ∂; we want Alt-B to perform the editor function "Move-caret-to-previous-word," but, instead, in inputs ∫. Oddly, Alt-F works as expected to perform "Move-caret-to-next-word" instead of inputting ƒ.

Here are some more details:

Mac OSX yosemite, PyCharm CE 4.5.3, emacs key bindings
(command-, / Preferences; Keymap; Emacs)

I check the key bindings on the right hand side, the spyglass-with-cannonball icon says "Find Actions by Shortcut" on hover, I click that, enter "Alt-B" and it finds "Move Caret to Previous Word." However, when I go back to the editor window and press "Alt-B" I get ∫. Likewise, when I search keymap for Alt-D, I get "Kill to End of Word" (just what I want), but in the editor window, it prints as the curly derivative sign ∂.

Best Answer

You need a replacement layout to allow M- key bindings. This forum post offers a downloadable keylayout file that can be copied to /Library/Keyboard\ Layouts/. I also made a dvorak-shaped map here.