当我像这样在终端中启动一个新的 emacs 时
emacs -nw -Q
我可以尝试通过键入 C-h k 来检查某个键盘快捷键绑定(bind)的是什么。当我为 *scratch*
中的快捷方式 M-S-
<M-left> runs the command left-word (found in global-map), which is an interactive compiled Lisp function in ‘bindings.el’.
It is bound to <C-left>, <M-left>.
[...]
请注意在识别的键序列中缺少“Shift”修饰符。
现在,第一直觉是终端(在我的例子中是 gnome-terminal)没有产生正确的转义序列,但它确实产生了:输入 CTRL-V ALT-SHIFT-left终端(即不在 Emacs 中)产生
^[[1;4D
并在 Emacs 中键入 C-q C-S-^[
是单个字符,即 ASCII 27(“转义”)。)
正在检查 input-decode-map
显示以下值(为简洁起见,省略了一些部分(标记为 ...
)):
(keymap
(27 keymap ... )
keymap
(keymap
(27 keymap
...
(91 keymap
...
(51 keymap
...
(59 keymap
(51 keymap
...
(68 .
[M-left])
(52 keymap
...
(68 .
[M-S-left])
...)
...)
...)
...))))
用下面的代码验证两个键序列给出了预期的结果:
(mapc '(lambda (c) (insert (format "%c" c))) '(27 91 49 59 51 68)) ; ^[[1;3D
(mapc '(lambda (c) (insert (format "%c" c))) '(27 91 49 59 52 68)) ; ^[[1;4D
但是,我不明白为什么这些序列嵌入到一个二级内部 (keymap ...)
名单?!
它变得更奇怪了。
回到 *scratch*
, 当我输入时
M-x local-set-key
然后 M-S-
Set key <M-S-left> locally to command:
如果我继续并提供一个随机函数,比如说 beginning-of-line
, 随后调用 C-h k 后跟 M-S-
<M-S-left> runs the command beginning-of-line (found in lisp-interaction-mode-map), which is an interactive built-in function in ‘C source code’.
It is bound to <M-S-left>.
[...]
本地设置 M-S-nil
将恢复 C-h k 将 M-S-<M-left>
的初始行为.
这是怎么回事?这是一个配置问题,还是预期的行为,或者是否涉及透明地添加另一层重新映射的其他一些键映射?
最佳答案
这是一个功能。
M-x elisp-index-search
RET shift-translation
说:
If an input character is upper-case (or has the shift modifier) and has no key binding, but its lower-case equivalent has one, then ‘read-key-sequence’ converts the character to lower case. Note that ‘lookup-key’ does not perform case conversion in this way.
When reading input results in such a “shift-translation”, Emacs sets the variable ‘this-command-keys-shift-translated’ to a non-‘nil’ value. Lisp programs can examine this variable if they need to modify their behavior when invoked by shift-translated keys. For example, the function ‘handle-shift-selection’ examines the value of this variable to determine how to activate or deactivate the region (*note handle-shift-selection: The Mark.).
关于emacs - M-S-<left> 未按预期处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54587647/