From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Chris Roberts via "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#72511: 30.0.50;
 prefix-completions is always nil in help--symbol-completion-table
Date: Wed, 7 Aug 2024 13:53:05 +0200
Message-ID: <20240807135305.189c2c3e@cdr>
Reply-To: Chris Roberts <frayedultrasonicaligator@disroot.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="1655"; mail-complaints-to="usenet@ciao.gmane.io"
To: 72511@debbugs.gnu.org
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 07 14:42:51 2024
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1sbg08-0000Gm-D1
	for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Aug 2024 14:42:48 +0200
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1sbg00-0006Rr-Hm; Wed, 07 Aug 2024 08:42:40 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1sbfzy-0006JW-4g
 for bug-gnu-emacs@gnu.org; Wed, 07 Aug 2024 08:42:38 -0400
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1sbfzx-0005Kg-S8
 for bug-gnu-emacs@gnu.org; Wed, 07 Aug 2024 08:42:37 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
 d=debbugs.gnu.org; s=debbugs-gnu-org; 
 h=MIME-Version:From:Date:To:Subject;
 bh=5tRGCMGP7pvPP4EuibNsAWDZ4KlnoqHW88DkD4Er3EU=; 
 b=iVs6YV1yuMOpvHZ6J+yH/iTjyaC9uMhkb9cw4HYqUEK42nhmgKChnEy65oUf24/k6f4DaU4Azw/LYcJ2B6fZ0iSnAIBXGS2A3xgw2gkin6a4hzSFlM987NmlV/cvZ0LNO4mb0OLbV7SUMj2K9CCx1bcgbouae8G1p4GoujpAZLMh5CMyzxcxTosjsSbdHTJVE+pvvhu7ZihLcScVQlXqdJPDpCQNF8FUOgFKcssdlWfe+dzNnT85u7vRhOYLDSMfuyV90eGFhSHfrdChwM9lbd862iuDq4f3vUqE7BoTuqeEPCK6xXI11e3i72N94I8mdJ1WdNcDAU4ceMJf05Z15A==;
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1sbg0M-0004V5-0e
 for bug-gnu-emacs@gnu.org; Wed, 07 Aug 2024 08:43:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Chris Roberts <frayedultrasonicaligator@disroot.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Wed, 07 Aug 2024 12:43:01 +0000
Resent-Message-ID: <handler.72511.B.172303452917220@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 72511
X-GNU-PR-Package: emacs
X-Debbugs-Original-To: bug-gnu-emacs@gnu.org
Original-Received: via spool by submit@debbugs.gnu.org id=B.172303452917220
 (code B ref -1); Wed, 07 Aug 2024 12:43:01 +0000
Original-Received: (at submit) by debbugs.gnu.org; 7 Aug 2024 12:42:09 +0000
Original-Received: from localhost ([127.0.0.1]:33924 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1sbfzS-0004Tc-W0
 for submit@debbugs.gnu.org; Wed, 07 Aug 2024 08:42:09 -0400
Original-Received: from lists.gnu.org ([209.51.188.17]:34354)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <frayedultrasonicaligator@disroot.org>)
 id 1sbfEb-0002yw-Bz
 for submit@debbugs.gnu.org; Wed, 07 Aug 2024 07:53:41 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <frayedultrasonicaligator@disroot.org>)
 id 1sbfEB-0003pg-CG
 for bug-gnu-emacs@gnu.org; Wed, 07 Aug 2024 07:53:15 -0400
Original-Received: from layka.disroot.org ([178.21.23.139])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <frayedultrasonicaligator@disroot.org>)
 id 1sbfE7-000588-Ay
 for bug-gnu-emacs@gnu.org; Wed, 07 Aug 2024 07:53:14 -0400
Original-Received: from localhost (localhost [127.0.0.1])
 by disroot.org (Postfix) with ESMTP id 93C17417AC
 for <bug-gnu-emacs@gnu.org>; Wed,  7 Aug 2024 13:53:07 +0200 (CEST)
X-Virus-Scanned: SPAM Filter at disroot.org
Original-Received: from layka.disroot.org ([127.0.0.1])
 by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id o35Ym4JFtZAG for <bug-gnu-emacs@gnu.org>;
 Wed,  7 Aug 2024 13:53:06 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail;
 t=1723031586; bh=Pw+/IVgdWDxCk3jcbFD2oDz2JFqKtX481UYznvluH3w=;
 h=Date:From:To:Subject;
 b=Behm6BRV4NDGMrGklE8knHXIfGN3GcL1yg0p9mexiyOshSE6W3ogiWd0dox182kOx
 lEkc3hWnvQ0IZK/rtQXT3eYmGgDBHpyCutdDSGW08ggwS9p+/Op339weQIKFd2Y0H5
 HytQ7lWWg5qbAU7s5Y/apkw6HHw+IklrLQWEo+fBms1tqS+1ThG39lFt/sQMX+Bew0
 BVwfWDH+L8AaBJUaFtjib2uPnH1BQALvR44aC7cudYt/DOW+cBuvf3WVvdSMQ4G9oq
 uTru6vBdXLUPLwkm5++RFYH+ZsGwV0h+HRENVnpT10nP4OBwzkqlov26UHTwM1p2gv
 B7IyvaDjkammw==
Received-SPF: pass client-ip=178.21.23.139;
 envelope-from=frayedultrasonicaligator@disroot.org; helo=layka.disroot.org
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, 
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Mailman-Approved-At: Wed, 07 Aug 2024 08:42:05 -0400
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:289881
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/289881>

On lines 209-214 inside the function `help--symbol-complete-table' in
help-fns.el there is a following block of code:

(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)))))

By default, `help-enable-completion-autoload' is t, so this code should
normally run. The perceived problem here is that the definition of
`help-definition-prefixes' function is as follows:

(defun help-definition-prefixes ()
  "Return the up-to-date radix-tree form of `definition-prefixes'."
  (when (> (hash-table-count definition-prefixes) 0)
    (maphash (lambda (prefix files)
               (let ((old (radix-tree-lookup help-definition-prefixes prefix)))
                 (setq help-definition-prefixes
                       (radix-tree-insert help-definition-prefixes
                                          prefix (append old files)))))
             definition-prefixes)
    (clrhash definition-prefixes))
  help-definition-prefixes)

Because of the `clrhash', `definition-prefixes' will always be empty
after the function call to `help-definition-prefixes'. So in practice,
`definition-prefixes' will always have zero elements when we're trying
to calculate `prefix-completions', which makes the calls to
`all-completions' and `mapcar' basically no-ops. The end result is that
`prefix-completions' will always be NIL.

This can be verified by evaluating the following code in emacs -Q:

(require 'radix-tree)
(require 'help-fns)

(let ((string "string-remove-prefix"))
  (format "Definition prefixes count before: %d\n%sDefinition prefixes count after: %d\nPrefix completions: %s\n"
          (hash-table-count definition-prefixes)
          (or
           (when help-enable-completion-autoload
             (let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
               (help--load-prefixes prefixes)))
           "")
          (hash-table-count definition-prefixes)
          (let ((prefix-completions
                 (and help-enable-completion-autoload
                      (mapcar #'intern (all-completions string definition-prefixes)))))
            prefix-completions)))

This has been first introduced in commit fd8084a (Automatically find
vars and functions via definition-prefixes)

I'm not sure if this was the intended behavior or not, but it seemed
suspicious to me, so I decided it's better to report it.

It might also be useful to note that `prefix-completion' is used in the
following way:

(complete-with-action action obarray string
                      (if pred (lambda (sym)
                                 (or (funcall pred sym)
                                     (memq sym prefix-completions)))))

I'm not sure what `pred' will be in this context, or what impact
`prefix-completions' being always NIL will have, if any. But I believe
that at the very least the code pertaining to `prefix-completions' could
concievably be removed.

Also, was clearing out the entirety of `definition-prefixes' on completion
really the intended behavior? As it stands, just C-h f s <TAB> is enough
to completely truncate it.

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.33, cairo version 1.16.0) of 2024-01-09 built on cdr
Repository revision: 774c8ec74c98d69d56b2511a613145f2b69fb2eb
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version
11.0.12101004 System Description: Linux Mint 21.2

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG
LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND
SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XINPUT2 XPM GTK3
ZLIB