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

From: [email-masked] (Charles A. Roelli)
Date: Sun, 22 Oct 2017 17:06:35 +0200

> From: Stefan Monnier <[email-masked]>
> Date: Fri, 03 Jan 2014 23:51:48 -0500
> 
> > 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.

This seems to be the mistake.  If you pass nil instead of `md' (as in
the patch below), then there's no more problem.

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 038f58f..38be657 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -395,7 +395,7 @@ icomplete-completions
                 ;; If the `comps' are 0-based, the result should be
                 ;; the same with `comps'.
                 (completion-try-completion
-                 name comps nil (length name) md)))
+                 name comps nil (length name) nil)))
 	     (most (if (consp most-try) (car most-try)
                      (if most-try (car comps) "")))
              ;; Compare name and most, so we can determine if name is

Alternatively, this part of `completion--nth-completion' could be
updated to respond to `completio--unquote-requote' in the completion
metadata when `table' is not a function:

         (when (completion-metadata-get metadata 'completion--unquote-requote)
           (cl-assert (functionp table))
           (let ((new (funcall table string point 'completion--unquote)))

(No idea if that would make sense.)

I was using this recipe for testing:

> Date: Fri, 30 Jan 2015 14:25:04 +0000
> From: Jeremy Moore <[email-masked]>
> 
> Hi folks,
> 
> I get a similar error by following this sequence in 24.4.1:
> 1. emacs -Q
> 2. M-x icomplete-mode
> 3. M-x set-variable icomplete-show-matches-on-no-input t
> 4. C-x C-f C-a C-k
> 
> Version and settings are below.
> 
> Regards,
> Jeremy
> 
> In GNU Emacs 24.4.1 (i686-pc-mingw32)
> of 2014-10-24 on LEG570
> Windowing system distributor `Microsoft Corp.', version 6.1.7601
> Configured using:
> `configure --prefix=/c/usr'