unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Chris Roberts via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 72511@debbugs.gnu.org
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	[thread overview]
Message-ID: <20240807135305.189c2c3e@cdr> (raw)

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





             reply	other threads:[~2024-08-07 11:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 11:53 Chris Roberts via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-08-07 14:20 ` bug#72511: 30.0.50; prefix-completions is always nil in help--symbol-completion-table Eli Zaretskii
2024-08-14 15:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-17  9:35   ` Eli Zaretskii
2024-08-20 12:13     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240807135305.189c2c3e@cdr \
    --to=bug-gnu-emacs@gnu.org \
    --cc=72511@debbugs.gnu.org \
    --cc=frayedultrasonicaligator@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).