4

当我在 emacs (with) 中运行 gdbM-x gdb并尝试使用制表符完成目录名称时,它以空格而不是斜杠完成。因此,例如:

(gdb) run/mn

制表符完成到

(gdb) run /mnt 

什么时候应该制表符完成

(gdb) run /mnt/

如果我在 emacs 之外运行 gdb,tab-completion 会按预期工作。

我在 debian 测试中运行 gdb 7.4.1-debian 和 emacs 23.4.1。

您可以在这里给我的任何帮助将不胜感激;这真的很烦人!

4

1 回答 1

3

gud-mode retrieves the list of possible completitions by calling gdb's complete command. 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"):

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

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.

For this, try putting the following in your .emacs file:

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

于 2012-09-11T01:34:43.027 回答