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.

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

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.

  • OMG I didn't know about that this is mindblowing !!! – Ehvince Dec 23 '14 at 10:22
  • 1
    Here a screenshot of the result: wikemacs.org/wiki/… – Ehvince Dec 23 '14 at 11:08
  • @Ehvince Cool! Thanks – Iqbal Ansari Dec 26 '14 at 13:06
  • 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. – lunaryorn Dec 28 '14 at 9:01
  • @lunaryorn valid points, I do not remember why I used company-manual-begin in the first place. – Iqbal Ansari Dec 28 '14 at 15:15

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

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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