Subject: Re: bug#77054: Completion highlighting applied outside completion-lazy-hilit-fn

From: João Távora <[email-masked]>
Date: Wed, 19 Mar 2025 20:41:32 +0000

Forgot to CC the bug tracker.  So just wanted to say again I'm sorry
to disappoint, and to clarify a possible misunderstanding.  "lazy" has
nothing to do with "what" is highlighted but merely "when". As far
as I can tell,that part is working fine,so whatever your problem is
And again, lazy highlighting only concerns a collaboration between
style and frontend.

toodle-oo!
João

On Wed, Mar 19, 2025 at 3:14 PM João Távora <[email-masked]> wrote:
>
> So, sorry to disappoint you João, and best of luck!
>
> João
>
> On Wed, Mar 19, 2025, 15:12 João Guerra <[email-masked]> wrote:
>>
>> > AFAIK this feature has been in Emacs at least for a full major version cycle (29) and had it failed in its basic mission we would have heard about it. I also remember testing it thoroughly.
>>
>> It feels a bit disappointing when the answer to a possible bug report
>> is something like "nobody has reported it so it must be working fine"
>> or "it worked on my machine".
>>
>> Anyway, here's a way to reproduce it in a less "complex" setup, only
>> using Emacs builtins.
>>
>> The flex style sets `completion-lazy-hilit-fn` in the middle of
>> `completion-pcm--hilit-commonality` to `completion--hilit-from-re`.
>> Let's override that just for demonstration purposes in a *hacky way*.
>>
>> ```
>> (setopt completion-styles '(flex)
>>         file-name-shadow-properties `(invisible t
>> ,@file-name-shadow-properties))
>> (setq completion-lazy-hilit t)
>> (defun completion--hilit-from-re (string regexp &optional point-idx)
>>   "Bogus fontification that only fontifies the last character of STRING."
>>   (message "lazy %s" completion-lazy-hilit)
>>   (let ((last (1- (length string))))
>>     (add-face-text-property last (1+ last) 'completions-common-part t string))
>>   string)
>> (icomplete-mode t)
>> ```
>>
>> See the attached picture for the outcome (if that doesn't work here's
>> an alternative url
>> https://drive.proton.me/urls/ZMMW1D9S2R#EXEwlTnWeCHy). You'll notice
>> that my fontification function has run, fontifying the last character.
>> However, additional characters are fontified, meaning there's
>> fontification happening elsewhere (the culprit indicated in the
>> original bug report). It could be the case that the frontend decided
>> to do additional fontification, but that's not the case (except for
>> the first candidate).
>>
>> My expectation as a user or package maintainer is that no
>> fontification will be performed by Emacs if I am using lazy
>> highlighting. However, that's not the case in *specific* situations as
>> I am trying to show in this bug report.
>>
>> > At least according to the docstrings I wrote at the time, and which I suggest reading.
>>
>> Neither docstring directly discusses whether additional fontification
>> can be performed by Emacs when using lazy highlighting, so my
>> assumption would be no.
>>
>> If it helps, I can reframe this bug report as: if lazy highlighting is
>> enabled, can Emacs perform additional fontification (outside the
>> completion frontend and style)?
>>
>> If the answer is yes, can we consider changing that behaviour? As I
>> believe it constraints what packages can do.

--
João Távora