I've got:
(global-set-key '[f11] 'menu-bar-mode)
How can I bind it to left ALT / Meta and will there be conflicts of using alt as meta?
You can't bind a function to a modifier key, because Emacs does not receive any input when a modifier key is pressed on its own (or more accurately, when one or more modifier keys are pressed without a non-modifier key also being pressed).
n.b. Your operating system determines which keys are modifiers, not Emacs.
You could probably tell your OS not to use the left Alt key as the Meta modifier and to instead send some sequence which you could then configure Emacs to recognise. You would want to configure some other key as the Meta modifier in that case of course, unless you are happy using right Alt exclusively.
I'm unsure precisely how you'd do that, but in a Unix-like OS reading up on xmodmap is typically the first port of call.
Related
In Mac Os X using the alt key with some other key will produce a series of special symbols. E.g. alt-' results in æ, alt-3 results in £, etc. When using emacs, however, I can no longer input these special symbols this way since alt is now mapped to meta. Is there a way to map alt to some other key combo? Or maybe use the left alt as meta only and have the right behave as it normally does in other apps?
There are additional methods to obtain special characters other than the one mentioned in this answer, but I personally prefer the best of both worlds -- i.e., I use the left alt/option key as meta, and I use the right alt/option key for stock Apple stuff -- e.g., special characters like the ones mentioned by the original poster:
(setq ns-alternate-modifier 'meta)
(setq ns-right-alternate-modifier 'none)
I have never been able to understand keybinding syntax well (bc it's hard to google if you don't know the name of a symbol to begin with!).
In DrRacket, I see bindings like "c:g" or "esc;g" .. I have tried hitting those keys in order to no avail. I have tried hitting them simultaneously. Nothing seems to work.
What do they mean? And, in general, how does one go about understanding this syntax?
A generic shortcut:
<modifier-key-1>:<key-1>;<modifier-key-2>:<key-2>;...;<key-n>
means:
press both <modifier-key-1> and <key-1> (that is: start pressing the modifier key, and while it is pressed, press key-1, then release both),
then, immediately, perform the same operation for the remaining combinations of keys,
finally, press <key-n>
Where the standard modifier keys are:
c - the control key modifier
s - the shift key modifier
m - the meta key modifier (not present in many keyboards)
a - the alt key modifier (sometimes already used to insert special characters)
(actually there are other key modifiers in different keyboards).
So, c:x;c:g;s:t means the following combination: Control-X, followed by Control-g, followed by Shift T (this insert Σ, the greek uppercase letter sigma in DrRacket), while c:x;c:g;s means Control-X followed by Control-G followed by the key s (insert the greek letter ς). Finally, the combination m-c-right means press both the modifier keys Meta and Control with the right arrow key.
When the meta modifier key is not present, it is often replace by the ESC (escape) key. Since this is not a key modifier, but a regular key, in this case it must be pressed and released before the next character. In other words, esc:g means: press the ESC key, release it, then immediately press the regular G key. esc-c-right means: press ESC, release it, then press C-→.
Moreover, when the ALT key is already used by the operating system to insert special characters, like in Mac OS X, it can be used as regular modifier key in DrRacket by setting a special preference (in Preferences > Editing > General).
In DrRacket you can find the current keybinding with the menu item: Edit > Keybindings > Show Active Keybindings, and you can find the relevant documentation here.
In Emacs, I want to bind a particular key combination to a command. However, because I am using Emacs in terminal mode within iTerm2 on OS X, I need to translate the key combo to character escape sequence and register that sequence with iTerm2 so that it will recognize the key combination.
But how do I find out the corresponding sequence given a key combination? For example, I found that something like ^[[1;8A corresponds to Ctrl+Alt+up (where I have configured Alt to function as +Esc in iTerm2), but I have no idea how that key combination translates into this particular sequence.
Is there a way to look up or work out the escape sequence for any given key combo? For example, what is the sequence for Ctrl+Alt+r?
A related question, can someone explain to me the relationship between setting up a key combo with its corresponding sequence in iTerm2 and making Emacs translate a sequence into its internal key representation using input-decode-map inside .emacs (e.g. (define-key input-decode-map "[escape_sequencehere]" [internal_key_representation_here])? It seems to me that setting it up in iTerm2 alone is sufficient to make the binding work in Emacs, so when and why do we need to set up the latter in .emacs? (and perhaps when do we need both to make something work?)
Some of the key combinations are sent directly to the application running in iTerm2. You can get it
by using ctrl+v approach (see In bash, how do I bind a function key to a command?) or
bash-3.2$ ^[[1;10A (in this case I hit ctrl + v before shift+alt+up)
sed -n l (note it's lowercase L). For instance, you can see what the application receives if you send (shift+alt+up):
bash-3.2$ sed -n l
^[[1;10A
\033[1;10A$
If some key combination does not get through, you can instruct iTerm2 to let it pass and map it to a key combination that you can detect as described above. For instance, you can send through and map ctrl+alt+cmd+R to ESC+sdf and your terminal will receive ^[sdf which you can assign to a command in Emacs.
In your terminal type showkey -a and let the key-strokes fly.
I've rebound my caps lock key to be an additional ctrl key, but in emacs using the rebound key generates the C-S key combination. Pressing caps-p generates the sequence C-S-p, whereas using the the ctrl key to do the same generates C-p.
This results in some weird behaviour, such as C-n and C-p setting a mark and then highlighting the region that I go through.
I have not changed the definition of the caps key in X, instead using the setting built into my window manager (Cinnamon). Could this be what is causing the problem, or is this the intended behaviour of this key?
This question is probably relevant, basically just use xmodmap to set the keys directly. It worked for me when I had caps lock set to control and I think I was using gnome3 classic (which Cinammon is based on) at the time.
On a related note I'd also recommend having a look at space2ctrl, I found that reaching for caps lock all the time still hurt my fingers.
I'm running CrunchBang 10 "Statler" (derived from Debian 6 "Squeeze") on an Asus laptop
(yeah, I'm a little behind right now)
I've currently got GNU Emacs 23.2.1. It didn't even recognize the Caps Lock key as a keypress until I re-mapped it to Ctrl using xmodmap.
So first I created file ~/.Xmodmap:
! attempting to redefine the <Caps Lock> key to do <Ctrl>
remove Lock = Caps_Lock
add Control = Caps_Lock
Apparently Debian uses .xsession, vs..xinitrc.
file .xsession is where the window manager (Openbox) gets started with exec
I inserted the xmodmap call before the exec:
#!/bin/sh
# gonna modify the keys so <Caps Lock> is <Ctrl>
xmodmap /home/tom/.Xmodmap
exec openbox-session
The Caps Lock key seems to be working just like the Ctrl key
within Emacs now.
I also faced this problem before, my keyboard has problem with CTRL key. Maybe you have the same problem.
I'm using emacs 23 on ubuntu 10.04. I would like to remap the "C-[" binding. Currently, when I press it, it gives me "ESC". Is there a way to remap it?
This is not an Emacs binding, but has global effect in X and it's used as handier substitute for ESC for people practicing touch typing. I guess you'll have to modify the X keymap if you want to use it in another fashion, but I wouldn't advice that.
C-[ is the ASCII ESCAPE character, which Emacs usually writes as ESC.
There is no key involved here (it's a character), and there is no key binding involved here. Or rather, your keyboard's Escape key sends the control character ESCAPE (also written C-[ and ESC).