Subject: Re: Antw: Re: Antw: Re: bug#24984: Emacs 25.1.1: Problems with file completion in Windows shell

From: Eli Zaretskii <[email-masked]>
Date: Fri, 25 Nov 2016 10:58:08 +0200

[Please keep the bug address on the CC list.]

> Date: Fri, 25 Nov 2016 08:58:37 +0100
> From: "Ulrich Windl" <[email-masked]>
> 
> >> This nasty bug makes shell-mode practically unusable; why do you suggest to 
> > close the bug?
> > 
> > Because it isn't a bug in Emacs, it's a user error: cmd.exe requires
> > such names to be quoted.  Am I missing something here?
> 
> Yes (reproduction):
> c:\Users\Ulrich Windl>cd ..
> cd ..
> 
> c:\Users>cd Ulrich Windl/     ### completed from Ul<TAB> (where <TAB> is the TAB key being pressed)
> cd Ulrich Windl/                     ### the command produced by Emacs is without quotes!
> 
> c:\Users\Ulrich Windl>cd Do    ### 1: The chdir seems to have succeeded (see prompt)
> ### "Do<TAB>" does not list any completions, because EMacs thinks the directory is different.
> c:\Users\Ulrich Windl>cd U<TAB> ### lets complete Emacs to "Ulrich Windl" again, because it thinks the directory is "C:\Users"
> ### When executing the "cd", it failes, od course:
> c:\Users\Ulrich Windl>cd Ulrich Windl/
> cd Ulrich Windl/
> Das System kann den angegebenen Pfad nicht finden.
> 
> ### So the shell does things correctly, but Emacs does not.

So you expect Emacs to quote such file names automatically?

Note that the Windows cmd.exe shell does it automatically only in some
cases.  For example:

  C:\>cd Docu TAB

produces

  C:\>cd "Documents and Settings"

as you'd expect, but

  C:\>cd Documents and Settings\My TAB

does not, it simply fails to complete.  Instead, you need to type
this:

  C:\>cd "Documents and Settings\My TAB

i.e. start the file name with a quote.

So there's no consistency in what the shell does here, either.

> Specifically if EMacs completes a name containing a space without putting quotes around, you cannot complein the shell for it (Compare to BASH: It does the quoting correctly is such a case)

What I see in "M-x shell" with Bash (on a GNU/Linux system) is not
entirely correct either:

  $ cd /home/e/eliz/foo TAB

produces

  $ cd /home/e/eliz/foo\ bar\ baz/

which is correct.  But

  $ cd '/home/e/eliz/foo TAB

produces this:

  $ cd '/home/e/eliz/foo\ bar\ baz/'
  bash: cd: /home/e/eliz/foo\ bar\ baz/: No such file or directory

If you try the same from the Bash command line, it does work
correctly: Bash completes "'foo " into "'foo bar baz'/", with the
closing quote and the slash added.

So my conclusion is that completion of such file names in "M-x shell"
does not work reliably on Posix hosts, either.

I'm okay with leaving this bug report open, with its subject retitled
"Completion of file names with embedded white space is broken in 'M-x
shell'", if you agree with my analysis.

Thanks.