Subject: Re: bug#61283: 29.0.60; pcomplete-completions-at-point loses text properties, breaking pcomplete-from-help annotations

From: Stefan Monnier <[email-masked]>
Date: Wed, 17 May 2023 17:20:52 -0400

[ BTW, I just noticed that Augusto (original author of that code) was
  not in the Cc.  Augusto, you may want to go and read the other
  messages in bug#61283.  ]

>> This is obviously a pretty invasive change and would require changing
>> a number of internal assumptions in Pcomplete (though I don't think it would
>> break the public API). If this sounds even remotely like a reasonable way to
>> go forward, I'll try to clean up my patch a bit more and post it for
>> feedback; it's currently a bit of a mess, I'm afraid...
>
> It sounds like a sane approach, so yes, I'd be happy to look at
> the patch.

Augusto's code relies on storing the info as text properties on the
first char of completion candidates and then making sure it's properly
preserved/propagated, and this is indeed generally risky (not dangerous,
but it's an information that's easily lost).

I think the crux of the problem is in:

                :annotation-function
                (lambda (cand)
                  (when (stringp cand)
                    (get-text-property 0 'pcomplete-annotation cand)))
                :company-docsig
                (lambda (cand)
                  (when (stringp cand)
                    (get-text-property 0 'pcomplete-help cand)))

Rather than fetch the info directly from `cand`, we should maybe
lookup the info from elsewhere (maybe `completions`?).  Then again, I'm
not sure how much `cand` can differ from the matching entry in
`completions`: it's affected by `completion-table-subvert` and
`completion-table-with-quoting` so in general it can be non-trivial to
figure out which entry of `completions` corresponds to the `cand` we
got :-(

        Stefan