emacs - M-S-<left> 未按预期处理

标签 emacs

当我像这样在终端中启动一个新的 emacs 时

emacs -nw -Q

我可以尝试通过键入 C-h k 来检查某个键盘快捷键绑定(bind)的是什么。当我为 *scratch* 中的快捷方式 M-S- 执行此操作时在启动 Emacs 后立即缓冲,我得到:

<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 kM-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/

相关文章:

Emacs:如何在 dired 模式下重命名目录?

c++ - CPlusPlus 模式 : create matching parenthesis or curly brace

windows - Emacs 23.1.50.1 在 Windows XP 上随机挂起 6-8 秒

javascript - 如何阻止 emacs 缩进 javascript 逗号分隔列表(例如数组或 json)的第二行?

emacs - 为需要迷你缓冲区的函数赋值

emacs - 如何获取字符串/缓冲区的字符集?

emacs - 如何在 emacs lisp 中硬编码参数?

Emacs 组织模式 : how to hide the details of plain list items by default

c++ - Emacs 支持 VS2012 构建

Emacs:使用功能键 (F19) 作为元