Subject: bug#73473: 31.0.50; Minibuffer completions include nonsense prefix candidates

From: Eshel Yaron <[email-masked]>
Date: Thu, 26 Sep 2024 08:21:20 +0200

Eli Zaretskii <[email-masked]> writes:

> merge 73473 72787
> thanks
>
>> Date: Wed, 25 Sep 2024 19:54:59 +0900
>> From:  Jordan Ellis Coppard via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
[...]
>> 1. Open Emacs.
>> 2. C-h o foo TAB
>> 
>> Observe that completion candidate `footnote-` is listed and that there 
>> are 80 completion candidates.
[...]
> Thanks, this is a known bug#72787.  I hope someone will be able to
> look into it soon.

FWIW, I've been using a change along the following lines:
(I don't completely understand why the existing code does what it does,
so I'm not sure that this fix is the right thing to do, but it makes
sense to me and it seems to solve this issue.)

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index e1daa8977f0..d2539e6074c 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -209,13 +209,9 @@ help--symbol-completion-table
     (when help-enable-completion-autoload
       (let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
         (help--load-prefixes prefixes)))
-    (let ((prefix-completions
-           (and help-enable-completion-autoload
-                (mapcar #'intern (all-completions string definition-prefixes)))))
-      (complete-with-action action obarray string
-                            (if pred (lambda (sym)
-                                       (or (funcall pred sym)
-                                           (memq sym prefix-completions))))))))
+    (when help-enable-completion-autoload
+      (mapc #'intern (all-completions string definition-prefixes)))
+    (complete-with-action action obarray string pred)))
 
 (defvar describe-function-orig-buffer nil
   "Buffer that was current when `describe-function' was invoked.