User super key for meta commands in emacs - 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 C-h 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 M-f 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 s-x 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.

Related

unsetting regular key on emacs

This is a little embarrassing, but recently I happen to bind regular keys on the fly using global-set-key every week or two.
e.g.
I bound the q key to quoted-insert and toggle-read-only today (not on purpose)
I tried global-unset-key, but now pressing the q key gives me q is undefined message (and writes nothing).
Since it isn't the first time this happens to me recently and since I hate losing all the buffers opened in my emacs every time it happens to me, I'm looking for a way to unset a char key without losing the ability to write this char OR to rebind the char to itself (global-set-key not allowing it). Trying to bind to insert-char 71 failed as well
(global-set-key (kbd "q") #'self-insert-command)
This is the default binding for all alphanumeric keys (which of course can be overridden in some major or minor mode).
There isn't a way to reset a key to its default that I'm aware of. If you want to play around with key bindings in a reversible way, probably the best thing to do is make your own minor mode and only bind keys to it (see http://shallowsky.com/blog/linux/editors/emacs-global-key-bindings.html). Then you can easily toggle the mode off, or undefine a key in its map, to get the global binding.
Finally, I use save-visited-files (in melpa) to remember (most of) my buffers. There are more complete solutions like desktop to save and restore state as well.

emacs + konsole: key binding problems [duplicate]

In org-mode, pressing M-S-RET (meta-shift-return) will create a new TODO on a new line. This key sequence sends M-RET to emacs through my terminal. I've checked this with C-h c ESC-S-RET, which returns M-RET is undefined in the mini-buffer.
I'm using Snow Leopard with Emacs 23.2.1 running in Terminal.app. There is no option to define a RET sequence in the terminal keyboard preferences.
Any idea what's causing the missing SHIFT? Workarounds?
You can get Emacs to pretend that it got S-RET with C-x # S RET (note uppercase S).
This also works for adding control, meta, alt, hyper or super modifiers; type C-x # C-h for the list of bindings. The Modifier Keys section in the Emacs manual mentions this as well.
In general, lots of keystrokes are simply impossible to send via a terminal, since terminals emulate an old protocol that only allowed 256 separate keys (or maybe only 128).
Chances are, when you press S-RET, Terminal.app does exactly the same thing as if you'd pressed RET. Thus Emacs has no way to distinguish those two cases.
Cross-linking to other Q&As:
If you are using an xterm, then the modifyOtherKeys option may facilitate that binding. See the following for details:
Send "C-(" to Emacs in VT100/xterm terminal (Mac OS X's Terminal)?
I suspect Emacs recognises those codes by default, but if not then also see input-decode-map as described here: Binding M-<up> / M-<down> in Emacs 23.1.1
See explanation and alternative shortcuts for TTY here.
Some of these have worked for me in a terminal in Ubuntu Linux (both locally and over SSH), but not all of them seem to work. For example, the alternative provided for S-RET (which I expected to run org-table-copy-down) instead seems to run org-clone-subtree-with-time-shift for some reason. However, I have found the list of alternatives useful, particularly those with the M- prefix. For example ESC UP for M-UP to move text around in tables.

Some shortcuts don't work on emacs beginning with C-c

In Haskell-mode, the shortcut C-c C-= is defined to do something.
Trying this shortcut, I realized that emacs do not recognize the shortcut C-c C-=.
Indeed, when I try the shortcut on emacs, the buffer write C-c = is not defined although I pressed C- C-=. I have the same problem with some other symbols like '.' or '§'. But shortcuts like C-c C-l or C-c C-c work.
I try to remove my .emacs but I have the same problem.
a friend have the same problem as me.
Both we are on ArchLinux (64 bits) and we use emacs in console. The keyboard is an azerty.
The problem come from emacs ? Arch Linux ?
Your terminal can't send Emacs C-= so you can't use that key sequence. (Emacs would recognise it if it received it, but that won't happen.)
Your options are:
Run GUI Emacs.
Use M-x name-of-command RET (for whatever command is bound to the key sequence you're not able to use). Use C-hm to see the major mode's bindings, or C-hb to see all current bindings, in order to learn what those command names are.
Create new custom keybindings for the commands in question (i.e. bindings which your terminal can send to Emacs).
Find a different terminal emulator with enhanced key sequence abilities. The vast majority of them will be no better than what you have, because they're all adhering to the limitations of the terminals they're emulating. The most capable one I know of is http://invisible-island.net/xterm/xterm.html but you may need to compile it yourself, and then expect to spend lots of time configuring it. (It's not a trivial solution, though, and xterm requires a GUI environment, so running GUI Emacs is much simpler.)
Use C-x#c<key> instead of C-<key>.
With that last option, you can use a sequence your terminal can send to fake a sequence that it can't send.
C-cC-= would become C-cC-x#c=
If you really wanted to use that last option, you can set a custom binding to simplify the sequence (may be necessary in some instances to avoid conflicting with existing sequences). See the end of https://stackoverflow.com/a/24804434/324105 for more information.
To add to phils' post - another option is an Emacs package (which I wrote), which can teach Emacs and terminals how to properly recognize all PC keyboard keys and modifier key combinations:
https://github.com/CyberShadow/term-keys
The default configuration already includes encoding key combinations like Ctrl=, as well as similar variations.

emacs key "deletechar"?

which is emacs key <deletechar>?
Is there any emacs command to check specified character name?
There are two keys mapped to delete-char functions: Delete, and <deletechar>.
Delete key I have remapped, so <deletechar> left, but I can't figure out which one it is.
In Emacs, "delete" and "deletechar" are not specific keyboard keys, they are mapped to specific "key sequences". If you look at the content of the local-function-key-map variable, you may see that "deletechar" is mapped to other "key sequences". Looking at the content of the function-key-map variable will show you what terminal device mapping is in place. The variables key-translation-map and input-decode-map may also have an entry for "deletechar".
If you use both terminal and windowed versions of emacs or you use different terminal types or if you use emacs on different hardware platforms or if you use different versions of emacs, you may find that pressing a keyboard key sometimes generates a "delete" key sequence and sometimes it will generate a "deletechar" key sequence depending on what the specific key sequence mappings are. Therefore, if you have set "delete" to execute one function and "deletechar" to execute another function, the actual function that is executed may vary depending on whether you are running on terminal or windowed emacs, the terminal type, and the version of emacs.
For more info, have a look at the Keymaps for Translating Sequences of Events section of the Emacs manual and the links off the Keymaps section of the Emacs manual.

M-RET and M-UP/DOWN not working in Emacs org-mode in console/terminal

I'm using emacs23 on Ubuntu 32-bit 10.04/10.10 with GNOME and Compiz.
Pressing M-RET in an org-mode plain list in Emacs (GUI) inserts a new item. Pressing M-Up moves the item up in the list.
These keys don't work as expected in emacs -nw under Terminator and gnome-terminal. The M-Up key does nothing, whereas the M-RET key simply moves the cursor down one line and indents the position. The keys also don't "work" in xterm, which inserts \215 instead. Pressing ESC-RET or ESC-Up instead produces the expected functionality. The same problems exist if I run emacs -nw on a headless server accessed via ssh under Terminator, gnome-terminal and xterm.
I've searched both generally and on the org-mode Gmane list for an answer to this, but have not found anything. Is this a known issue with org-mode or is it related to the terminal emulator and/or the Window Manager?
In addition to the keys in my question, S-TAB, S-Left, S-Right, S-Up and S-Down were not working over ssh and PuTTY. Using certain keys on a TTY connection (ssh, screen, PuTTY) is a known issue.
Alternative keys are included in org-mode as detailed in 'Using Org on a TTY' in the org-mode manual.
Alternative key combinations exist
for equivalent to M-RET
M C-m
"<return>" is the Return ↩ key while emacs runs in a graphical user interface.
"RET" is the Return ↩ key while emacs runs in a terminal.
"RET" is also equivalent to "C-m" (【Ctrl+m】). (http://ergoemacs.org/emacs/emacs_key_notation_return_vs_RET.html)
as equivalents for M-<up/down> you can use
ESC-<up>
ESC-<down>
The menubar of terminal emulator is not letting the M key that is meant for Emacs be passed down to Emacs. For Emacs to receive the M key as it is supposed to, you could either use the Esc or disable the menubar and use M key in Emacs as usual.
ADDED:
For the xterm, if you do CTRL+Mouse Button 1, you will see "Meta sends Escape". You need to make sure that option is checked/enabled to make M work as it should in Emacs.