Subject: bug#11715: 24.1; Error in post-command-hook: wrong-number-of-arguments -read-file-internal

From: "Drew Adams" <[email-masked]>
Date: Sat, 23 Jun 2012 20:54:55 -0700

I found the problem - in my version of `icomplete-completions' (in
`icomplete+.el').  Thanks for your help.

FYI -

I make these changes to the vanilla version of `icomplete-completions':

1. Prepend the total number of candidates.
2. Sort candidates alphabetically, put them in a different face,
   and separate them more (2 spaces instead of ",").
3. Highlight the key-binding text.  Truncate it if too long.
4. Append the number of remaining cycle candidates (for Icicles).

The problem was that when I updated the Emacs 23 code to fit the vanilla Emacs
24 changes I understood things only partially.

In particular:

I do not use `completion-all-sorted-completions', since I need the number of
COMPS and I do not need the sort order that `c-a-s-c' provides.  So I do not use
LAST or BASE-SIZE.

Where I went wrong was replacing this code:

(if (and base-size (> base-size 0))
    (completion-try-completion name candidates predicate (length name) md)
  ;; If the COMPS are 0-based, the result should be the same with COMPS.
  (completion-try-completion name comps nil (length name) md)))

Since I do not use BASE-SIZE I tried using just the second `if' clause, without
really understanding things.  That was the mistake, as I'm sure you can tell.

It worked OK when the arg CANDIDATES was an alist, but not when it was a
function.

I changed the code to just (try-completion name candidates predicate), and it
seems to work well now.

There is unfortunately no description of any of the arguments in the doc string.
Apparently CANDIDATES corresponds to the COLLECTION arg of `completing-read' (is
that correct in all respects?).  If so, you might consider renaming it
COLLECTION.

And you might consider documenting the args.  Perhaps something like this:

NAME is the name to complete.
COLLECTION is the collection of candidates to match.  See
`completing-read' for its possible values.
PREDICATE filters matches: they succeed only if it returns non-nil.
REQUIRE-MATCH non-nil means the input must match a candidate.

(Maybe REQUIRE-MATCH corresponds to REQUIRE-MATCH in `completing-read', but
that's not clear to me.)

The possibility of arg CANDIDATES being a function is not new in Emacs 24, but
in Emacs 23 the Icomplete code was different and I did not run into such an
error.

(BTW, AFAICT there is nothing in the Emacs 23 NEWS about Icomplete supporting
file-name completion.)

Anyway, thanks for your help.  I will close this bug.