Subject: bug#11339: 24.1.50; read-{buffer,file-name}-completion-ignore-case fails on non-ascii

From: Stephen Berman <[email-masked]>
Date: Mon, 04 Nov 2019 17:22:30 +0100

On Mon, 04 Nov 2019 14:39:25 +0100 Stephen Berman <[email-masked]> wrote:

> On Sun, 03 Nov 2019 18:16:01 +0200 Eli Zaretskii <[email-masked]> wrote:
>
>>> From: Stephen Berman <[email-masked]>
>>> Cc: [email-masked],  [email-masked]
>>> Date: Sat, 02 Nov 2019 16:09:31 +0100
>>> 
>>> Concerning my followup to my OP, that involved another difference I
>>> observed in completion behavior between buffer names and file names with
>>> non-ASCII characters when *-completion-ignore-case is non-nil, and
>>> that's what the recipe above shows in more detail than in my followup,
>>> which didn't explicitly contrast the behavior with ASCII-only characters
>>> (the above recipe also uses names that differ beyond the case
>>> differences, to avoid the question of expectations where only case
>>> differs): with buffer names, all completions are shown regardless of the
>>> case of the input, but with file names, completion is done according to
>>> the case of the input, i.e. read-file-name-completion-ignore-case
>>> appears to have no effect (again, only when the names contain non-ASCII
>>> characters).  This seems to be a clear bug.
>>
>> Yes, it was a bug, and a very old one: our case-insensitive comparison
>> of file names worked by bytes, which is only TRT for pure-ASCII
>> strings.
>>
>> I hope I fixed this now, please try the latest master.
>
> I've now updated and, the above bug is now fixed; thanks.

I'd like to return to the bevahior I originally reported.  I think my
previous recapitulation of it was inaccurate, so here are explicit
recipes comparing current emacs-26 (representing the situation prior to
your fix) and current emacs-master (including your fix).

Add test files (crucially differing only in case and "asciiness"):

0. $ touch /tmp/{bah,bAh,bäh,bÄh}

Before your fix:

1. $ emacs-26 -Q  --eval '(setq read-buffer-completion-ignore-case tread-file-name-completion-ignore-case t)' /tmp/{bah,bAh,bäh,bÄh}
(*Buffer List* show the buffers bah,bAh,bäh,bÄh)
2. C-x b *scratch*
3a. C-x b ba TAB
   => completes to bah and after TAB displays [Sole completion]
3b. C-g C-x b bA TAB
   => completes to bAh and after TAB displays [Sole completion]
4a. C-g C-x b bä TAB
   => completes to bäh and after TAB displays [Sole completion]
4b. C-g C-x b bÄ TAB
   => completes to bÄh and after TAB displays [Sole completion]
5a. C-g C-x C-f /tmp/ba TAB
   => completes to bah and after TAB displays [Complete, but not unique]
      and *Completions* pops up showing `bAh' and `bah'
5b. C-g C-x C-f /tmp/bA TAB
   => completes to bAh and after TAB displays [Complete, but not unique]
      and *Completions* pops up showing `bAh' and `bah'
6a. C-g C-x C-f /tmp/bä TAB
   => completes to /tmp/bäh and after TAB displays [Sole completion]
6a. C-g C-x C-f /tmp/bÄ TAB
   => completes to /tmp/bÄh and after TAB displays [Sole completion]

After your fix:

1. $ emacs-master -Q  --eval '(setq read-buffer-completion-ignore-case tread-file-name-completion-ignore-case t)' /tmp/{bah,bAh,bäh,bÄh}
(*Buffer List* show the buffers bah,bAh,bäh,bÄh)
2. C-x b *scratch*
3a. C-x b ba TAB
   => completes to bah and after TAB displays [Sole completion]
3b. C-g C-x b bA TAB
   => completes to bAh and after TAB displays [Sole completion]
4a. C-g C-x b bä TAB
   => completes to bäh and after TAB displays [Sole completion]
4b. C-g C-x b bÄ TAB
   => completes to bÄh and after TAB displays [Sole completion]
5a. C-g C-x C-f /tmp/ba TAB
   => completes to bah and after TAB displays [Complete, but not unique]
      and *Completions* pops up showing `bAh' and `bah'
5b. C-g C-x C-f /tmp/bA TAB
   => completes to bAh and after TAB displays [Complete, but not unique]
      and *Completions* pops up showing `bAh' and `bah'
6a. C-g C-x C-f /tmp/bä TAB
   => completes to /tmp/bäh and after TAB displays [Complete, but not unique]
      and *Completions* pops up showing `bAh' and `bah'
6a. C-g C-x C-f /tmp/bÄ TAB
   => completes to /tmp/bÄh and after TAB displays [Complete, but not unique]
      and *Completions* pops up showing `bAh' and `bah'

So, before your fix file name completion involving non-ASCII strings
behaved the same as buffer name completion involving both ASCII-only and
non-ASCII strings, but file name completion involving ASCII-only strings
differed.  Now, after your fix, file name completion involving non-ASCII
strings works the same as file name completion involving ASCII-only
strings did before your fix and still does after, but all the cases of
file name completion differ from the corresponding cases of buffer name
completion.  I would prefer buffer name completion to work the way file
name completion uniformly works after your fix.

Steve Berman