如何在 Emacs 25 中将 C-x SPC 本地绑定到 gud 模式

How to bind C-x SPC locally to gud mode in Emacs 25

类似于 但我想绑定 CTRL+x 后跟 SPACEgud-break

我正在做的事情(好吧,这是一个 hack;继续阅读)是:

  (define-key ctl-x-map " " 'gud-break)

但是ctl-x-map是一个类似于全局地图的全局变量。事实上,如果我切换到另一个 C++ 缓冲区并键入 C-h k C-x SPC,我会得到:

C-x SPC runs the command gud-break (found in global-map), which is an interactive compiled Lisp function.

It is bound to C-x SPC, C-x C-a C-b.

(gud-break ARG)

Set breakpoint at current line.

这意味着所有缓冲区的全局定义都发生了变化,这是不正确的 AFAIK。

有没有办法 "insert" 或以某种方式影响 C-x 的本地键映射,我认为它是 gud-mode-map,因为我希望该绑定不是所有 C++ 缓冲区的全局绑定。例如,CTRL+x 后跟 SPACE 的全局绑定是 rectangle-mark-mode.

是的,我知道 gud-break 的标准绑定是 C-x C-a C-b,但这是要求 RSI。

更新 #1

因为我需要 gud-mode-map 的本地键映射,所以只有当我是 运行 调试器时才需要激活它。在我的例子中,这是在 C++ 模式缓冲区中,但我的理解是 gud-mode-map 仅在调试会话期间在那些 C++ 模式缓冲区中变得活跃,并在 gud 模式完成时从键绑定中删除。

更新 #2

这没有用:

(define-key gud-mode-map [(control x ?\ )] 'gud-break) ;; <-- gave "Two bases given in one event" error too.
(define-key gud-mode-map (kbd "C-x SPC") 'gud-break) ;; <-- this does not work either.

更新 #3

作为实验,我注释掉了我添加到 gud-gdb-mode-hook 的钩子中的 define-key 绑定,重新运行 gdb,然后切换到 gud 缓冲区(不是 C++ 源文件)并键入 C-h k C-x SPC 我明白了:

C-x SPC runs the command gud-break (found in gud-mode-map), which is
an interactive Lisp closure.

It is bound to <menu-bar> <debug> <break>, C-x SPC, C-c C-b, C-x C-a
C-b.

(gud-break ARG)

Set breakpoint at current line.

但是当我切换到 C++ 缓冲区时,应该 临时插入相同的绑定(当 gud 模式处于活动状态时),然后做同样的事情我得到改为:

C-x SPC runs the command rectangle-mark-mode (found in global-map),
which is an interactive autoloaded compiled Lisp function in
'rect.el'.

It is bound to C-x SPC.

(rectangle-mark-mode &optional ARG)

Toggle the region as rectangular.
Activates the region if needed.  Only lasts until the region is deactivated.

切换回 gud 缓冲区,然后键入 C-h m 显示:

Debugger mode defined in 'gud.el':
Major mode for interacting with an inferior debugger process.

   You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx,
M-x perldb, M-x xdb, or M-x jdb.  Each entry point finishes by executing a
hook; 'gdb-mode-hook', 'sdb-mode-hook', 'dbx-mode-hook',
'perldb-mode-hook', 'xdb-mode-hook', or 'jdb-mode-hook' respectively.

After startup, the following commands are available in both the GUD
interaction buffer and any source buffer GUD visits due to a breakpoint stop
or step operation:

C-x SPC sets a breakpoint at the current file and line.  In the
GUD buffer, the current file and line are those of the last breakpoint or
step.  In a source buffer, they are the buffer's file and current line.

...

注意上面对 C-x SPC 的引用。就好像他们打算绑定 C-x SPC 但它不起作用,或者当进入 gud 模式时有什么东西阻止它在该缓冲区中正确绑定。

完全不清楚你想要什么。但是,如果您只想在 gud-mode-map 处于活动状态时重新定义键 C-x SPC,则告诉 define-key 您想要使用该映射:(define-key gud-mode-map ...).

我选择完全放弃。无论如何,在缓冲区中使用 C-x SPC 是有问题的。我注意到即使在 gud 完成后,用于 gud 绑定的 C-x C-a 前缀仍留在 C++ 缓冲区中,因此 gud 模式无论如何都不会自行清理。