2

When using Emacs shell with the auto-completion feature enabled, I notice that whenever I perform typing and auto-completing a command, Emacs shell always adds an extra space after the first word. I illustrate this issue by an example as follow:

  • Suppose that my current working directory is user@linux ~/foo/bar $

  • Now if I want to type the command mkdir by auto-completion, I first type mk, and then press TAB to show a list of completion possibilities and press ENTER choose mkdir. Now, a whitespace is added at the end of mkdir, which is indicated by the pair [ ]

    user@linux ~/foo/bar $ mkdir[ ]

    In this scenario, adding a whitespace after the command mkdir is fine since mkdir is a full command, I certainly want to type a new word after that.

  • But if the first word is not a full command, but a part of a command, a white-space is still added and it is quite inconvenient.

    For example, I want to type and auto-complete the command such as ~/workspace/tool/my-command

    Then, if I type ~/work first and then press TAB to auto-complete, Emacs shell will automatically add a new white-space after the first directory ~/workspace, which is indicated by [ ]

    user@linux ~/foo/bar $ ~/workspace[ ]

    This is an unwanted white-space, since I have to delete it, in order to continue typing the rest of ~/workspace/tool/my-command

Is there anybody know how to make Emacs shell knows when an extra white-space should be added?

FYI, I am using the Spacemacs distribution of Emacs.

I discovered that this is due to the package bash-completion of Emacs. After removing it, the Emacs shell works as usual.

  • 1
    It shouldn't do that, and I can't reproduce this on Emacs 26.0.50. But I use shell-mode a lot and for years, and this is not normal behaviour - the space should not be added. Try to reproduce the problem starting from emacs -Q. If that fixes the issue, as it should, then there's something in your config that has caused the problem. – Tyler Aug 25 '17 at 14:49
  • Thanks @Tyler for the suggestion. Yes, you are right! This issue doesn't happen with emacs -Q. I also use Emacs 26.0.50. I will look into my configuration. – Trung Ta Aug 26 '17 at 2:08
  • I discovered that this is due to the package bash-completion of Emacs. After removing it, the Emacs shell works as usual – Trung Ta Aug 26 '17 at 15:21
0

The bash-completion package addresses that issue with this setting:

(setq bash-completion-nospace t)

I find that is not perfect but it's a better compromise.

There doesn't seem to be a thorough treatment of the issue anywhere but there is a little discussion of it on github: https://github.com/szermatt/emacs-bash-completion/search?q=nospace&type=Issues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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