【问题标题】:How to bind C-x SPC locally to gud mode in Emacs 25如何在 Emacs 25 中将 C-x SPC 本地绑定到 gud 模式
【发布时间】: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


【解决方案1】:

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

【讨论】:

  • 谢谢,你在正确的轨道上,但这对我不起作用。有关我尝试过的内容,请参阅我的描述中的更新 #2。也许我的(kbd...) 需要调整?
  • @bgoodr 在完成(define-key gud-mode-map (kbd "C-x SPC") 'gud-break) 并在gud-mode 之后,C-h C-x SPC RET 会显示什么?
  • C-h C-x SPC 不是我认为您的意思,因为这样做会使C-h C-x SPC 未定义。我怀疑你的意思是C-h k C-x SPC 使用C-h k(对于describe-key)然后输入C-x SPC。所以我这样做并得到了C-x SPC runs the command rectangle-mark-mode。我是在 gud-mode 下的 C++ 缓冲区中完成的。
  • 但这很奇怪。 describe-mode 不应该显示一些关于 gud 模式以某种方式“活跃”的信息吗?我在帮助缓冲区中没有看到任何对任何带有“gud”的内容的引用。
  • 在主要描述中添加了更新#3,希望它能帮助解决这个难题。我还是一头雾水。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多