4

I am in shell-mode with bash-completion enabled. When I attempt tab completion, Emacs creates a new window to display completions.

For example, if I am in a directory with subdirectories foo and foobar, and I type cd foo TAB, Emacs will open a new buffer with the following contents:

Click on a completion to select it.
In this buffer, type RET to select the completion near point.

Possible completions are:
foo/
foobar/

If I C-x o into the other window and select a completion, then the window disappears. However, that takes a few keystrokes, so sometimes I end up instinctively completing the path myself. If I do that, the window sticks around.

How can I improve this workflow so that my shell stops generating extra windows? I didn't want to make this an XY problem, but I can think of a few ways. One idea would be to hide the window if I keep typing. Something better would be to hook the completion results into ido.

4
  • Do you really mean "Emacs creates a new frame"? (See Frames in the manual.) I think you mean "Emacs creates a new window. Commented Dec 22, 2014 at 21:18
  • @Constantine, you're absolutely right. I still get them confused sometimes. Commented Dec 22, 2014 at 21:25
  • I would give ido-ubiquitous a try. (It is not shell-specific, but does promise to do what you need.) Commented Dec 22, 2014 at 21:27
  • As it turns out, I have ido-ubiquitous-mode already active. Deactivating it does not seem to affect the problematic behavior. Commented Dec 22, 2014 at 21:31

2 Answers 2

5

I would recommend you to try out company-mode. It has a built-in backend company-capf which fetches completion candidates from emacs' completion-at-point-functions (the same mechanism that powers completion in the shell) as such completion offered by company are as accurate as the built-in shell-mode while making the user interface is very convenient.

You can activate it as follows

(eval-after-load "shell"
  '(define-key shell-mode-map (kbd "TAB") #'company-complete))
(add-hook 'shell-mode-hook #'company-mode)

Notice that I have rebound tab to company-complete so that hitting tab pops up company completion menu rather than the built-in completions buffer.

Ehvince has put a nice screenshot on wikiemacs about the above in action

Another option is to use helm, if you enable helm by doing (helm-mode +1) it replaces the default completion mechanism with its own more pleasant completion system.

4
  • OMG I didn't know about that this is mindblowing !!!
    – Ehvince
    Commented Dec 23, 2014 at 10:22
  • 1
    Here a screenshot of the result: wikemacs.org/wiki/…
    – Ehvince
    Commented Dec 23, 2014 at 11:08
  • Don't use define-key in a hook. It's sufficient to bind the key once. Also, company-complete is probably a better function for that key.
    – user227
    Commented Dec 28, 2014 at 9:01
  • @lunaryorn valid points, I do not remember why I used company-manual-begin in the first place. Commented Dec 28, 2014 at 15:15
3

This is a subset of your question, but it should help in that the following code may be extended to serve larger purposes and that I share my investigations.

I asked a similar question on SO about changing directory with ido. Someone answered, which maybe @iqbal-ansari will recognize, and I put the resulting code into a repo which I called fasd-shell. The goal was to cd as fast as possible, so the process is this (all help in above link):

  • install the fasd command line utility
  • install fasd-shell
  • and to use it: type d foo (d followed by a space) to trigger the fasd engine and the ido completion, which will ask you to cd to any directory containing foo in its full name that you already visited with an explicit cd.

So d triggers an action that calls ido for the completion. So we're not limited to d and cd, we could recognize any pattern and fire any action. (I'm nearly done for makefiles' targets completion)

I tried to put it on MELPA so I got a review and I've been asked to use either a completion-at-point function or to hook into pcomplete (pcmplt-*), instead of re-defining TAB.

So here I am.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.