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

From: Jim Porter <[email-masked]>
Date: Thu, 18 May 2023 00:11:09 -0700

On 5/17/2023 2:20 PM, Stefan Monnier via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
> 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`?).

Yeah, that's what my patch does.

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

Hmm, yeah. That would be pretty tricky to get working 100% reliably. 
Like Daniel mentions, I think this doesn't come up (often?) for the 
specific case in this bug, but a fully-robust solution would be ideal. 
Maybe the 'metadata' operation[1] would be usable for this with some 
extra work. I'll have to think about this...

... since getting a 100% reliable solution here might take quite a bit 
more work than I thought, how about a not-quite-100% hack? Instead of 
propertizing the first character of each candidate, propertize the 
*last* character (or the entire string?). That won't get thrown out 
quite so easily.

[1] 
https://www.gnu.org/software/emacs/manual/html_node/elisp/Programmed-Completion.html