2

Is there any way to bind a command to a key combination like AltGr-f?

The reason I ask is the following: I use the “US international” keyboard layout (on Linux), which remaps the right Alt key to AltGr (aka Level3 shift), so that I can type certain accented characters I need. But this keyboard layout also has the nice side-effect of making some new (and very convenient) key combinations available; for instance, AltGr-t inserts þ, which I never use, so I can rebind it to something else. The problem is that AltGr-f inserts an f, and not some useless symbol, so I can't bind that key to a command (similar issue with the characters g, h, b). I know I could use xmodmap to assign some random symbol to AltGr-f, but is there a pure Emacs way to do that?

6
  • 1
    I suspect that's not possible since Emacs just receives keysyms. So, since AltGr is no modifier (it enables the third level map), Emacs just gets the generated keysyms like þ which you can inspect with F1 k þ.
    – wasamasa
    Commented Nov 11, 2014 at 22:15
  • Actually, X provides both the keysym and the keycode to the client, but I don't know if Emacs can bind a command to a keycode. It's certainly possible to remap AltGr-f to a different keysym at the xkb level.
    – jch
    Commented Nov 11, 2014 at 23:15
  • 4
    Shouldn't you add a tag for the platform you're on? AltGr obviously doesn't apply to OS X, and the way the OS affects the way AltGr is generated/intercepted/caught might be different on Linux, Windows and other operating systems. Commented Nov 12, 2014 at 0:48
  • @wasamasa That sounds right, but on the other hand there is the key-translation-map and similar stuff that seem to work at a lower level and might know about AltGr.
    – Augusto
    Commented Nov 29, 2014 at 19:36
  • Not an answer but hopefully some approximation -- use the compose key. That is after doing (something like) $ setxkbmap -option compose:menu the menu key will now behave like a compose key After that use something like pointless-xcompose as a starting point to set up your own compose sequences.
    – Rusi
    Commented Jan 17, 2015 at 15:10

2 Answers 2

3

Yes and no.

No. AltGr isn't a modifier known to Emacs.

Yes. Emacs knows more modifiers than Control, Meta and Shift: Hyper and Super.

What you have to do is tell our OS or window system that the key/scan code generated by pressing the key labelled [AltGr] is "Super". I haven't done that in a while, but inspecting my own xkb (for X11) configuration this would probably look like this:

key <RALT> { [ Super_L ] };
key <SUPR> { [ NoSymbol, Super_L ] };
modifier_map Mod4 { <SUPR> };

Unfortunately you cannot just drop that into a file and toggle a switch somewhere and it just works. Xkb is a monstrosity and you will have to learn how to tame it. Unfortunately no decent user documentation exists.

0

This is an old question and I use the CLI Emacs over X, but this might still be helpful for someone. I don't know of a pure Emacs way but I know what I did to fix this.

I prefer UK layout, but keystrokes like M-x are difficult. loadkeys loads keymaps on the fly.

Messing around, I found the linux-with-two-alt-keys.inc file. For a UK layout with both two Alt keys:

$ loadkeys /usr/share/kbd/keymaps/i386/qwerty/uk.map.gz /usr/share/kbd/keymaps/i386/include/linux-with-two-alt-keys.inc

I could have stopped and chucked that in .bash_profile, but I am petty.

I tried editing /etc/rc.conf which alters the bootup keymap, but I was couldn't get both keymaps recognised.

(Note, I am on Void Linux; the file changes between distros. /etc/vconsole.conf on Fedora, /etc/rc.local on Ubuntu, I believe)

So I gave up and made my own keymap. Less scary than it sounds. I copied and decompressed uk.map.gz, adding:

keycode 100 = Alt

Before compressing, saving as /usr/share/kbd/keymaps/i386/qwerty/custom.map.gz, and editing rc.conf:

KEYMAP=custom

Both Alt and AltGr now both work as Alt in CLI Emacs.

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.