简体   繁体   English

如何在Emacs 25中将Cx SPC本地绑定到Gud模式

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

Similar to How to change GUD breakpoint keybinding to the old one but I would like to bind CTRL + x followed by SPACE to be gud-break . 类似于如何将GUD断点键绑定更改为旧的键绑定,但是我想将CTRL + x绑定后跟SPACE绑定为gud-break

What I have working (well it is a hack; keep reading) is: 我正在工作的东西(嗯,这是hack;请继续阅读)是:

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

but ctl-x-map is a global variable akin to the global map. 但是ctl-x-map是类似于全局图的全局变量。 And in fact, if I switch to another C++ buffer and type Ch k Cx SPC I get: 实际上,如果我切换到另一个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.

which means the global definition across all buffers is what was changed, which is not correct AFAIK. 这意味着更改了所有缓冲区的全局定义,这是不正确的AFAIK。

Is there a way to "insert" or somehow affect the local key map for Cx, which I believe is gud-mode-map , because I want that binding to not be global for all C++ buffers. 有没有一种方法可以“插入”或以某种方式影响Cx的本地键映射,我认为它是gud-mode-map ,因为我希望该绑定对于所有C ++缓冲区都不是全局的。 Eg, the global binding for CTRL + x followed by SPACE is rectangle-mark-mode . 例如, CTRL + xSPACE的全局绑定是rectangle-mark-mode

Yes I realize the standard binding is Cx Ca Cb for gud-break , but that is asking for RSI. 是的,我知道标准绑定是用于gud-break Cx Ca Cb ,但这要求RSI。

Update #1 更新#1

Since I need the local key map for gud-mode-map , this needs to be active only when I'm running a debugger. 由于我需要gud-mode-map的本地键映射,因此仅在运行调试器时才需要激活它。 In my case, this is in C++ mode buffers, but my understanding is that gud-mode-map becomes active in those C++ mode buffers only during the debug session, and is removed from the key bindings when gud mode is finished. 就我而言,这是在C ++模式缓冲区中,但是我的理解是gud-mode-map仅在调试会话期间才在那些C ++模式缓冲区中处于活动状态,并在gud模式完成时从键绑定中删除。

Update #2 更新#2

This did not work: 这不起作用:

(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.

Update #3 更新#3

As an experiment, I commented out my define-key bindings in my hook I add to gud-gdb-mode-hook , reran gdb, then switched to the gud buffer (not the C++ source file) and typed Ch k Cx SPC I get this: 作为一个实验,我注释掉了我的钩子中的define-key绑定,然后将其添加到gud-gdb-mode-hook ,重新运行gdb,然后切换到gud缓冲区(不是C ++源文件)并输入Ch k Cx 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.

But then when I switch over to the C++ buffer that should also have the same bindings inserted temporarily (while gud mode is active), and then do the same thing I get this instead: 但后来当我切换到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.

Switching back to the gud buffer, and typing Ch m shows this: 切换回gud缓冲区,然后输入Ch 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.

...

Notice the reference to Cx SPC above. 请注意上面对Cx SPC的引用。 It is as if they intended to bind Cx SPC but it did not work, or something is preventing it from being bound properly in that buffer when gud mode is entered. 好像他们打算绑定Cx SPC但是它不起作用,或者是当进入Gud模式时,有某种原因阻止了它在该缓冲区中的正确绑定。

I'm not exactly clear on what you want. 我不是你想要什么十分清楚。 But if you only want to redefine the key Cx SPC when the gud-mode-map is active, then tell define-key you want to use that map: (define-key gud-mode-map ...) . 但是,如果您只想在gud-mode-map处于活动状态时重新定义Cx SPC密钥,则告诉define-key您要使用该映射: (define-key gud-mode-map ...)

I've chosen to give up on this altogether. 我选择完全放弃这一点。 using Cx SPC in the buffer is problematic anyhow. 无论如何,在缓冲区中使用Cx SPC都是有问题的。 I noticed that the Cx Ca prefix that is used for the gud bindings are left in the C++ buffer even after gud finishes, so the gud mode is not cleaning up after itself anyhow. 我注意到,即使在gud完成之后,用于gud绑定的Cx Ca前缀也留在了C ++缓冲区中,因此gud模式无论如何都不会自行清除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM