Question

When I run gdb within emacs (with M-x gdb) and I try to tab-complete directory names, it completes with a space instead of a slash. So, for example:

(gdb) run/mn

tab-completes to

(gdb) run /mnt 

when it should tab-complete to

(gdb) run /mnt/

If I run gdb outside of emacs, tab-completion works as expected.

I'm running gdb 7.4.1-debian and emacs 23.4.1 on debian testing.

Any help you could give me here would be greatly appreciated; this is really irritating!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top