简体   繁体   中英

User super key for meta commands in emacs

I'm trying to learn emacs and would like to use the super key on my keyboard for any meta commands in emacs, because I use dwm as my window manager and it uses the meta key extensively. I have read this page , using it to try

(setq x-meta-keysym 'super)
(setq x-super-keysym 'meta)

with no luck. Ideally I'd like to simply flip them, but only in emacs. when I inspect the variables x-meta-keysym and x-super-keysym with Ch v the commands do seem to be evaluated correctly. When I check the super key with the linux utility xev it confirms that the key I'm pressing is mapped to Super_L.

I agree with @Tyler

In my case I use dwm as window manager, so meta (ALT) key is used to control almost all its features. When using emacs, meta key conflicts with some key bindings, eg: when I'm moving around words Mf or Mb (that's why I came to this thread ;)), so I found three choices to get rid with this issue:

1) change emacs key binding and use super key as meta key

(setq  x-meta-keysym 'super
       x-super-keysym 'meta)

Both symbols (variables) are required, because if you just use only x-super-keysym 'meta, it enables both keys as meta key. If you just use only x-meta-keysym 'super, it disables both and de command buffer will return sx is undefined.

2) change dwm key binding for meta to super key in config.h file. take a look in http://dwm.suckless.org/customisation/windows_key

 /* key definitions */
 -#define MODKEY Mod1Mask /* meta (ALT) key */
 +#define MODKEY Mod4Mask /* super (windows or cmd) key */

3) override xmodmap keymap bindings swapping mod1 to super and mod4 to meta (be sure to check what xmodmap returns at first glance, and not affect keybindings of other programs)

Finally, I recommend not to change default emacs meta key because is less comfortable to your fingers and may cause you to respond slowly to keystrokes. Try options 2 or 3 depending your environment.

So, it turns out that the above commands work when emacs is not used in terminal mode. I had been trying it in the terminal exclusively which is why it wasn't working. I'm not sure how to fix it in the terminal, but it's good enough I suppose.

edit: it was the terminal emulator that was gobbling the keypresses before they got to emacs, so the original commands do work, so long as the keypress actually makes it to emacs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM