【发布时间】:2018-06-13 17:19:11
【问题描述】:
类似于How to change GUD breakpoint keybinding to the old one,但我想将 CTRL+x 后跟 SPACE 绑定为gud-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 中是不正确的。
有没有办法“插入”或以某种方式影响 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 模式时,有些东西阻止它在该缓冲区中正确绑定。
【问题讨论】:
-
您说您希望绑定是本地的,但您没有说本地到什么。 IOW,您希望
C-x SPC在哪些缓冲区中调用gud-break? -
@Stefan 我刚刚更新了问题的结尾以澄清。
标签: emacs key-bindings gud