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

From: Stefan Monnier <[email-masked]>
Date: Fri, 03 Jan 2014 23:51:48 -0500

>> > Can you identify the code that issues that error message?
>> It's the C code that runs `post-command-hook', AFAIK.
> I was looking for the function that issued the `invalid-function'
> error.  It seems to be `eval_sub' (via `Qinvalid_function').

Right, it's probably eval of funcall.

> So no special help there.

Indeed.

> So far, my best guess is still that in
> (completion-try-completion name comps nil (length name) md)
> the list COMPS is for some reason being treated as a function (the
> second argument can of course be either).

Oh, you mean that the error could come from the fact that `md' goes with
`candidates', so some code might assume that the completion table is
a function based on the `md' data, whereas we passed `comps' which is
a list of strings?

Hmm... that sounds plausible.

> Maybe `completion--nth-completion' (called by
> `completion-try-completion') for some reason finds 
> (completion-metadata-get metadata 'completion--unquote-requote) to be
> non-nil, and so calls its TABLE argument, trying to requote?

Apply the patch below.  That should replace your error message with
a different one, so if the error message stays the same, the problem
is elsewhere.  And if a new message appears we've found a culprit.
Of course, minibuffer.el is preloaded, so you'll want to re-dump your
Emacs, force reloading minibuffer.el(c) from your .emacs, or do some
other dance to make sure you use the new definition of
completion--nth-completion.

        Stefan

=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2014-01-01 07:43:34 +0000
+++ lisp/minibuffer.el	2014-01-04 04:48:56 +0000
@@ -819,6 +819,7 @@
   ;; part of the string (e.g. substitute-in-file-name).
   (let ((requote
          (when (completion-metadata-get metadata 'completion--unquote-requote)
+           (cl-assert (functionp table))
            (let ((new (funcall table string point 'completion--unquote)))
              (setq string (pop new))
              (setq table (pop new))