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

From: Stefan Monnier <[email-masked]>
Date: Mon, 06 Nov 2017 23:06:26 -0500

>> Ping!  I hope to fix this for emacs-26 if it's possible.  It also
>> solves Bug#28898.
> Stefan, any objections for pushing this to the emacs-26 branch?

Yes, using nil instead of `md` has other undesirable side-effects.
E.g. it loses the `category` metadata so it will cause the wrong
completion-styles to be used e.g. in C-x b.

Does the patch below work around the problem?

BTW, thanks Charles for the recipe,

        Stefan

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index f13f1fa798..54a6afeca9 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -896,8 +896,15 @@ completion--nth-completion
   ;; than from completion-extra-properties) because it may apply only to some
   ;; part of the string (e.g. substitute-in-file-name).
   (let ((requote
-         (when (completion-metadata-get metadata 'completion--unquote-requote)
-           (cl-assert (functionp table))
+         (when (and
+                (completion-metadata-get metadata 'completion--unquote-requote)
+                ;; Sometimes a table's metadata is used on another
+                ;; table (typically that other table is just a list taken
+                ;; from the output of `all-completions' or something equivalent,
+                ;; for progressive refinement).
+                ;; FIXME: Rather than do nothing, we should somehow call
+                ;; the original table, in that case!
+                (functionp table))
            (let ((new (funcall table string point 'completion--unquote)))
              (setq string (pop new))
              (setq table (pop new))