简体   繁体   English

emacs gdb tab-用空格而不是/来完成目录

[英]emacs gdb tab-completes directory with space instead of /

When I run gdb within emacs (with Mx gdb ) and I try to tab-complete directory names, it completes with a space instead of a slash. 当我在emacs(使用Mx gdb )中运行gdb并尝试选项卡完成目录名称时,它以空格而不是斜杠完成。 So, for example: 所以,例如:

(gdb) run/mn

tab-completes to tab-completed to

(gdb) run /mnt

when it should tab-complete to 什么时候应该tab-complete到

(gdb) run /mnt/

If I run gdb outside of emacs, tab-completion works as expected. 如果我在emacs之外运行gdb,tab-completion按预期工作。

I'm running gdb 7.4.1-debian and emacs 23.4.1 on debian testing. 我在debian测试中运行gdb 7.4.1-debian和emacs 23.4.1。

Any help you could give me here would be greatly appreciated; 你能给我的任何帮助将不胜感激; this is really irritating! 这真是太刺激了!

gud-mode retrieves the list of possible completitions by calling gdb 's complete command. gud-mode通过调用gdbcomplete命令来检索可能的completition列表。 In your example, the returned list would contain the following (assuming that there's only one directory in your file system that starts with "/mn"): 在您的示例中,返回的列表将包含以下内容(假设文件系统中只有一个以“/ mn”开头的目录):

(run /mnt)

The first part of each entry in the returned list is cut off, so that the remaining complete-list is 返回列表中每个条目的第一部分被截断,以便剩下的完整列表是

(/mnt)

As you can see, this entry returned by gdb's complete command already lacks the trailing slash. 如您所见, gdb的 complete命令返回的此条目已经缺少尾部斜杠。 Your only hope to fix this would be to either patch gdb 's complete command, or to patch Emacs' gud-mode , by somehow detecting that the completed word is a directory and then appending a slash (and suppressing the auto-insertion of the space character). 你修复这个问题的唯一希望就是修补gdbcomplete命令,或修补Emacs的gud-mode ,通过某种方式检测已完成的单词是一个目录,然后附加一个斜杠(并禁止自动插入空间角色)。

But of course, you could simply bind the TAB key to a different completion function, potentially one that falls back on the default gud-gdb-complete-command , but perhaps does a different kind of completion when called for. 但是,当然,您可以简单地将TAB键绑定到不同的完成函数,可能是一个返回默认gud-gdb-complete-command函数,但是在调用时可能会执行不同类型的完成。

For this, try putting the following in your .emacs file: 为此,请尝试将以下内容放在.emacs文件中:

(defun my-gud-gdb-setup ()
  (define-key (current-local-map) "\t" 'my-gud-gdb-complete-command))

(defun my-gud-gdb-complete-command (&optional COMMAND PREDICATE FLAGS)
  (interactive)
  (unless (comint-dynamic-complete-filename)
    (gud-gdb-complete-command COMMAND PREDICATE FLAGS)))

(add-hook 'gdb-mode-hook 'my-gud-gdb-setup)

This code binds a new function to the TAB key which first tries to expand the current word as a file, and only if that fails calls the default gud-gdb-complete-command . 此代码将新函数绑定到TAB键,该键首先尝试将当前单词扩展为文件,并且只有在失败时才调用默认的gud-gdb-complete-command

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

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