Subject: RE: bug#16274: 24.3.50; Error in post-command-hook (icomplete-post-command-hook): (invalid-function ("..." ...))

From: Drew Adams <[email-masked]>
Date: Wed, 19 Feb 2014 21:09:59 -0800 (PST)

> > Drew, any news on this bug?

An update, but I'm not sure whether it is the exact same problem I
have seen before.  After changing some of my code recently, and doing
something different, I can now get such an assertion violation.
If I turn off icomplete-mode then the problem goes away.

The assertion violation occurs in `completion--nth-completion', after
(when (completion-metadata-get metadata 'completion--unquote-requote).

I inserted this debug code just after that arg to `when':

(message "N: %S, STRING: %S, TABLE: %S, PRED: %S, POINT: %S, METADATA: %S"
         n string table pred point metadata)
(cl-assert (functionp table) nil
           "=================== INVALID FUNCTION ==================")

This is what I see in *Messages* (I've added some newlines for the mail):

N: 2, STRING: "ls", TABLE: read-file-name-internal, PRED: file-exists-p,
POINT: 2, METADATA: (metadata (category . file) (completion--unquote-requote . t))

N: 1, STRING: "ls", TABLE: (#("ls-lisp+.el" 0 1 (face completions-common-part)
 1 2 (face completions-common-part) 2 3 (face (completions-first-difference)))
 #("ls-lisp-20.el" 0 1 (face completions-common-part) 1 2
 (face completions-common-part) 2 3 (face (completions-first-difference)))),
 PRED: nil, POINT: 2, METADATA: (metadata (category . file)
 (completion--unquote-requote . t))
Error in post-command-hook (icomplete-post-command-hook):
 (error "=================== INVALID FUNCTION ==================")

There are two calls to `completion--nth-completion' here, of which the
first (which I guess corresponds to `completion-all-completions') goes OK.
For the second (which I guess corresponds to `completion-try-completion'),
arg TABLE is a list of (propertized) strings, not a function.

I do not understand this code very well.  Hope this sheds some light for you.

I doubt if describing what I was doing at the time will help, but here
it is, just in case:

With my code (Icicles), I use a different kind of completion for `!'
in Dired (e.g.).  It is file-name completion (against program files in
the path etc.), but the minibuffer history in this case is
`shell-command-history'.  I hit `!' on a file in Dired, then hit `M-p'
to access the first item of the history, which was `ls' (which matches
a couple of file names).  It was when I hit `M-p' that I got the assertion
violation.

The same thing happened using my icomplete+.el and using vanilla
icomplete.el.

With a little more debug I determined that it is the second call to
`completion-try-completion' that causes the problem: the one that
is used when BASE-SIZE is not > 0.  In this case, BASE-SIZE = 0, so
this code is executed:

;; If the `comps' are 0-based, the result should be the same with `comps'.
(completion-try-completion name comps nil (length name) md)))

The problem is apparently that COMPS is a list of strings (file names),
not a function.

HTH.  Let me know if you have further debugging suggestions or need
more info.