How do read DrRacket keybindings (and in general) - racket

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.

Related

Detect special characters keypresses in AutoHotkey

How can I detect a key combination such as AltGr and special characters (I want to detect AltGr + ì, I have an Italian keyboard layout). Looking up online I came across SC combinations, which would be SC236, so I tried
<^>!SC236::send ~
Hotkeys can be triggered by using the hexadecimal virtual key (VK) code of a key
<^>!vkDD::send ~
in the rare case where a key has no name or the standard code doesn't work.
The virtual key code of such a key can be determined by following the steps at Special Keys. (On step 6 note the value in the first column of the list (VK)).

Bind keyboard shortcut to one key in AutoHotkey with delay

I am using the Japanese IME on Windows 10. TL;DR there is a shortcut to switch from alphanumeric (latin alphabet) to Japanese input. The combination is ALT+` [l or r alt + tilde key]. For it to work, both keys must be held down but the alt key must be pressed first. I am trying to bind this combination to one key.
I have been able to bind normal letter keys to a combination of other letters (e.g. a -> b + c) but I cannot get it to work with the keys I need, and especially not because there needs to be a delay between them. The code confuses me.

Emacs: relation between keystrokes and keys

I am slightly confused by the difference between keys and key-bindings in emacs after reading the first chapter of "Writing GNU Emacs Extensions" (O'Reilly book).
The chapter starts by noting that in some emacs version the keys backspace and DEL, invoke the help menu instead of deleting. In other words, they invoke what is invoked by C-h.
The chapter then goes on to show how to change this behaviour using Lisp code. This is done by binding the keystroke C-h to the delete command.
This is a bit confusing to me. In my mind DEL, Backspace and C-h are three different keystrokes (the first two consisting of a single key).
Why does remapping C-h effect what DEL and Backspace does?
I would have thought to change what backspace does for example, you would remap backspace to another command, not the keystroke C-h.
Unless remapped by a low-level keybord driver, the effect of the Backspace key is to send the character with numeric code 8, which, in certain operating systems, is exactly the same code generated by pressing Control-h. You can verify this fact by simply writing anything on a unix (or linux) shell and then pressing Backspace and Control-h: both of them have the effect of erasing the previous character, since the character with numeric code 8 is interpreted by the operating system as the control character BS, backspace, used either to erase the last character printed or to overprint it (see wikipedia). Analogously, Control-J is equivalent to the RETURN key, etc.
The same Wikipedia page describe DEL as “originally intended to be an ignored character, but now used in some systems to erase a character”.
So, when you assign a command to a keystroke you are actually assigning a command to a character code, and if two or more keys generate the same code, by pressing them you are invoking the same command.
#Renzo answered your question about how these keys are related and how binding one can seem to affect another. Here is some more information about what's going on in this particular case.
See the Emacs manual, node DEL Does Not Delete.
There you will see this, following an explanation of the problem/confusion:
To fix the problem in every Emacs session, put one of the following
lines into your initialization file (*note Init File::). For the first
case above, where BACKSPACE deletes forwards instead of backwards, use
this line to make BACKSPACE act as DEL:
(normal-erase-is-backspace-mode 0)
For the other two cases, use this line:
(normal-erase-is-backspace-mode 1)
Another way to fix the problem for every Emacs session is to
customize the variable normal-erase-is-backspace: the value t
specifies the mode where BS or BACKSPACE is DEL, and nil
specifies the other mode. *Note Easy Customization::.
See also the GNU Emacs FAQ question about Backspace invoking help. There you will see, in addition to information similar to that above, information about how to remap DEL on UNIX - use this:
stty erase '^?'
Wrt C-j and RET (not mentioned in the question, but mentioned in #Renzo's answer): The default behavior of Emacs changed in most programming modes, in Emacs 24.4.
Starting with that release, electric--indent-mode is turned on by default, which means that RET inserts a newline character and indents, whereas C-j just inserts a newline character. Prior to that release, these keys had the opposite behaviors. If you prefer the old behavior then do this, to turn off electric-indent-mode:
(when (fboundp 'electric-indent-mode)
(electric-indent-mode -1)) ; Use classic `C-j' and `RET'.

Can I bind something to ALT (Meta)

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.

How to determine whether command should be control or meta?

Is there a set of criteria to determine whether a command should be a ctrl keybinding or a meta keybinding?
For example, file handling commands seem to fall under C-x bindings. Cursor movements are a mix of ctrl and meta. I don't notice much of a pattern other than built-in bindings leaning towards ctrl which suggets meta may be somewhat reserved for user bindings.
I'm not aware of a fixed set of criteria to distinguish between commands bound to Ctrl or Meta. However, the Emacs Lisp manual has a section on Key Binding Conventions that should be interesting to you.
Meta is not officially reserved for user-defined bindings:
Sequences consisting of C-c and a letter (either upper or lower case) are reserved for users; they are the only sequences reserved for users, [...].
If you're asking because you want to set up custom key bindings for commands that don't have any by default, I suggest you also take a look at Emacs: How to choose good custom key bindings? and Are there any emacs key combinations reserved for custom commands?
Additionally, when binding keys be aware that
A <Control>-modified alphabetical character is always considered case-insensitive: Emacs always treats C-A as C-a, C-B as C-b, and so forth. [...]
For all other modifiers, you can make the modified alphabetical characters case-sensitive when you customize Emacs. For instance, you could make M-a and M-A run different commands.
... as described here.