首页 > 解决方案 > 如何在 Emacs 25 中将 Cx SPC 本地绑定到 gud 模式

问题描述

类似于如何将 GUD 断点键绑定更改为旧的,但我想绑定CTRL+x后跟SPACEto gud-break

我的工作(嗯,这是一个黑客;继续阅读)是:

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

但是ctl-x-map是一个类似于全局映射的全局变量。事实上,如果我切换到另一个 C++ 缓冲区并键入 Ch k Cx 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。

有没有办法“插入”或以某种方式影响 Cx 的本地键映射,我相信这是gud-mode-map因为我希望该绑定不是对所有 C++ 缓冲区都是全局的。例如,CTRL+的全局绑定x后跟SPACEis rectangle-mark-mode

是的,我意识到标准绑定是C-x C-a C-bfor gud-break,但那是要求 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

define-key作为一个实验,我在我添加到的钩子中注释掉了我的绑定gud-gdb-mode-hook,重新运行 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 模式时,某些东西阻止它在该缓冲区中正确绑定。

标签: emacskey-bindingsgud

解决方案


我不太清楚你想要什么。但是,如果您只想在激活C-x SPC时重新定义键,那么告诉您要使用该映射:。gud-mode-mapdefine-key(define-key gud-mode-map ...)


推荐阅读