14

How can I make eshell autocomplete behave like Bash and Emacs in general i.e. it offers a list of choices rather than arbitrary selects one for you?

For example, if I have two directories "Download" and "Downloads", when I type "Down" and hit TAB, I expect another buffer pops up and shows me the choices. But eshell just completes it for me, i.e. if I press TAB, it completes to "Download"; hit TAB again, it changes to "Downloads".

serv-inc
  • 35,772
  • 9
  • 166
  • 188
Amumu
  • 17,924
  • 31
  • 84
  • 131
  • You're probably getting some interference from your custom code. Try `emacs -q`: it works. – abo-abo Nov 07 '13 at 09:54
  • I tried `emacs -q` and it didn't work. For example, if I have two directories "Download" and "Downloads", when I type "Down" and hit TAB, I expect another buffer pops up and shows me the choices. But eshell just complete it for me, i.e. if I press TAB, it complete to "Download"; hit TAB again, it changes to "Downloads". – Amumu Nov 07 '13 at 10:59

3 Answers3

6

Use this:

(add-hook
 'eshell-mode-hook
 (lambda ()
   (setq pcomplete-cycle-completions nil)))
abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • It didn't work as well. I tried adding it to my init file as well as manually modified in my running Emacs then start a new eshell. Still not produced my desire behaviour. – Amumu Nov 07 '13 at 11:13
  • You need to set the value of the variable in `eshell-mode-hook` (or use setq-default) – juanleon Nov 07 '13 at 11:21
  • Normally it would be possible to customize the variable. But EShell seems to change the variable, which makes it necessary to update it in the hook. – ceving Dec 01 '15 at 08:15
  • Probably should use `setq-local` rather than `setq`? – xuhdev Nov 29 '16 at 21:25
  • 1
    @xuhdev: or do as proposed in the other answers and `(setq eshell-cmpl-cycle-completions nil)` – serv-inc May 11 '17 at 07:53
6
(add-hook
 'eshell-mode-hook
 (lambda ()
   (setq pcomplete-cycle-completions nil)))

and

(setq eshell-cmpl-cycle-completions nil)

Both do as you ask and show a buffer listing the completions when I run my emacs as 'emacs -q' to avoid my own customizations. This is with emacs 23.3, are you running a much older version?

Also see http://www.emacswiki.org/emacs/EshellCompletion which is where I first went to check this out.

Steps to try this out:

  1. Start emacs using 'emacs -q' as the command -- no other arguments.
  2. Change to the *scratch* buffer
  3. Paste or type in one of the above code snippets
  4. Put your cursor at the end of the snippet and press 'C-e' to execute the code.
  5. Start eshell
  6. test
  7. if neither one works, report back here with your version info and any other relevant details
Sean Perry
  • 3,776
  • 1
  • 19
  • 31
  • Thanks. I didn't know that I have to attach to eshell-mode-hook. Things work as expected. I am using the latest Emacs. – Amumu Nov 07 '13 at 16:08
2

You only need to have the following line:

(setq eshell-cmpl-cycle-completions nil)

eshell-mode automatically set pcomplete-cycle-completions to the value of eshell-cmpl-cycle-completions locally.

xuhdev
  • 8,018
  • 2
  • 41
  • 69