Subject: bug#62300: 29.0.60; No hyperlinks for some symbols in *Help* buffers

From: Stefan Monnier <[email-masked]>
Date: Mon, 20 Mar 2023 17:55:40 -0400

>>   emacs -Q
>>   C-h f global-text-scale-adjust RET
>> 
>> Observe that in the *Help* buffer the variable
>> global-text-scale-adjust-resizes-frames does not have the link
>> appearance.  This is because:
>> 
>>   (boundp 'global-text-scale-adjust-resizes-frames) => nil

`help-definition-prefixes` and friends
(`help-enable-completion-autoload`, ...) are the result of a tradeoff:
we offer to autoload files "on demand" but the "demand" is often
vague/implicit, so we have to judge when the demand is clear enough to
justify loading a file and when it's not.

If we're too trigger happy, we can end up auto-loading all the .el files
in sight, making Emacs unnecessarily bigger&slower (and increasing the
risk that we bump into a file that breaks the convention, such as
`c-ts-mode`).

In this case, `global-text-scale-adjust` has an explicit autoload in
`loaddefs.el` so we already have the docstring needed to display
`C-h f global-text-scale-adjust RET` without having to load
`face-remap.el`, so `help-enable-completion-autoload` doesn't load
`face-remap.el`.

>> By contrast, if you try
>> 
>>   C-h f text-scale-adjust RET
>> 
>> then the variable text-scale-mode-step in the *Help* buffer does get
>> the link appearance, and boundp returns non-nil for that variable.

Among the prefixes registered for `face-remap.el` there is `text-scale-`
because there are various other functions beside `text-scale-adjust`
which start with `text-scale-`.  I'm not completely sure why we end up
loading `face-remap.el` here (it doesn't seem necessary since the
function is also autoloaded), but this difference in the
definition-prefixes is probably the reason for the difference
in behavior (apparently completion gets involved somewhere even tho
it's not needed).

>>  (radix-tree-prefixes (help-definition-prefixes) "global-text-scale-adjust")
>> 
>> This returns nil, whereas if you do the same with "text-scale-adjust",
>> you get:
>> 
>>   (("text-scale-" "face-remap") ("tex" "flyspell"))
>> 
>> Interestingly, just appending a dash to global-text-scale-adjust, i.e.
>> 
>>  (radix-tree-prefixes (help-definition-prefixes) "global-text-scale-adjust-")

Yup: in `face-remap.el`, all the definitions that aren't known before
the file is loaded (i.e. not autoloaded) and whose name starts with
"global-text-" also start  with "global-text-scale-adjust-", so the
definition-prefixes data registers this longer prefix, which is more
precise.

BTW, this is also related to the part of `C-h f` which loads autoloaded
functions when it sees something like \\< or \\[ (this is controlled by
`help-enable-autoload`).  We could change it so it does it also when it
sees `...' in the docstring.

        Stefan