Subject: Re: bug#37883: 27.0.50; read-file-name: Scrambled INITIAL

From: Michael Albinus <[email-masked]>
Date: Wed, 23 Oct 2019 18:24:55 +0200

Michael Heerdegen <[email-masked]> writes:

Hi Michael,

>> The docstring of `read-file-name' says
>>
>> If DEFAULT-FILENAME is omitted or nil, then if INITIAL is non-nil, the
>> default is DIR combined with INITIAL
>
> But I'm talking about the initial minibuffer contents, not the default.
> Is it due to historic reasons that the initial contents resemble this
> default?

It is not said explicitly, but INITIAL is expected to be a trailing
string of DEFAULT-FILENAME, where the cursor stays in the minibuffer.

And yes, in your case (with a nil DIR and a nil DEFAUL-FILENAME), DIR is
set to "~/", and DEFAUL-FILENAME is set to "~/.bash_history". Finally,
(minibuffer-maybe-quote-filename (concat dir initial)) is called.
(concat dir initial) expands to "~/~/.bash_history", and
(minibuffer-maybe-quote-filename ...) adds the leading "/:".

You better call (read-file-name-default "File: " "~/" nil nil ".bash_history" nil)

If read-file-name-default does not satisfy your needs, you might write
your own read-file-name-function, and bind it to
read-file-name-function.

> What you cite also doesn't explain why this combination happens in the
> way it does.  The doubled ~/ seems not useful, and the /: is...some
> Tramp thing?

It isn't Tramp, rather the contrary. "/:" marks quoted file names,
i.e. file names which shouldn't be given to a file name handler.

> Michael.

Best regards, Michael.