Subject: bug#16208: 24.3.50; `locate-file-completion-table' uses NAMES with duplicates

From: Drew Adams <[email-masked]>
Date: Fri, 20 Dec 2013 14:16:07 -0800 (PST)

`completion-all-completions' with `locate-file-completion-table' returns
this list, when doing `M-x load-library mule TAB TAB':

(#("mule-cmds" 0 4 (face (completions-common-part)) 4 5 (face
(completions-first-difference))) #("mule-conf" 0 4 (face
(completions-common-part)) 4 5 (face (completions-first-difference)))
#("mule-conf" 0 4 (face (completions-common-part)) 4 5 (face
(completions-first-difference))) #("mule-diag" 0 4 (face
(completions-common-part)) 4 5 (face (completions-first-difference)))
#("mule-diag" 0 4 (face (completions-common-part)) 4 5 (face
(completions-first-difference))) #("mule-util" 0 4 (face
(completions-common-part)) 4 5 (face (completions-first-difference)))
#("mule-util" 0 4 (face (completions-common-part)) 4 5 (face
(completions-first-difference))) #("mule" 0 4 (face
(completions-common-part))) #("mule" 0 4 (face
(completions-common-part))) . 0)

Each candidate in the list, except the first, `mule-cmds', is repeated
(two occurrences of each).

Please remove the duplicates.  The duplicates are not seen in emacs -Q
- they are apparently being filtered out afterward.

In my context, `completing-read' (my version) does not necessarily
remove duplicates, as they can have different associated data and I
sometimes make use of this data.  IOW, there can be candidates with
different associated data but with the same display string in
*Completions*.

In my context, it is up to the particular command calling
`completing-read' to decide whether to remove duplicates.

In this case, the command is a standard one, `load-library'.  I do not
want to have to define my own version (e.g. wrapper) of `load-library',
just to have it remove the duplicates.  My code uses
`completion-all-completions', and in this case, that is returning
duplicates.  This is rare, fortunately - I don't think I've encountered
this problem before.

A naive guess would be that this is the problematic code, in
`locate-file-completion-table', but this is really a wild guess:

 ;; Remove duplicates of the first element, so that we can easily check
 ;; if `names' really only contains a single element.
 (when (cdr names) (setcdr names (delete (car names) (cdr names))))

The guess would be that perhaps `when' should be `while', here (?).
Dunno.  But the comment makes it clear that this is not intended to
remove duplicates in general, so perhaps this is not the culprit.

Anyway, I'd apprciate it if `locate-file-completion-table' were fixed so
that when `completion-all-completions' uses it it did not return
duplicates.

In GNU Emacs 24.3.50.1 (i686-pc-mingw32)
 of 2013-12-16 on ODIEONE
Bzr revision: 115543 [email-masked]
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/Devel/emacs/binary --enable-checking=yes,glyphs
 'CFLAGS=-O0 -g3' LDFLAGS=-Lc:/Devel/emacs/lib
 CPPFLAGS=-Ic:/Devel/emacs/include'