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

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 05 Apr 2025 08:36:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
77054: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77054
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#77054: Completion highlighting applied outside completion-lazy-hilit-fn
From: Eli Zaretskii <[email-masked]>
To: João Távora <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Sat, 05 Apr 2025 11:35:22 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: João Távora <[email-masked]>
> Date: Fri, 21 Mar 2025 12:41:55 +0000
> Cc: Dmitry Gutov <[email-masked]>, Eli Zaretskii <[email-masked]>, [email-masked]
> 
> On Fri, Mar 21, 2025, 11:10 João Guerra <[email-masked]> wrote:
> 
>  . Having the completion style
>  remove all prior fontification sounds a bit extreme for an interface.
>  For me, it makes more sense to be additive, but I don't know what
>  Emacs' vision is on this topic.
> 
> It's up to the style. If you like it additive keep it additive, else do what Eli suggests.
> 
>  `completion--twq-all` is doing fontification. This function doesn't
>  look like it's part of the completion frontend nor of the completion
>  style. Why is it doing fontification? Should it be doing
>  fontification?
> 
> It's part of the table. It does what it has done probably for many years. If you want to change that behavior for
> everyone, go ahead, but IME you'll eventually bother lots of people using simpler setups. If your style is
> bothered by it, remove it there just like Eli suggests. In lazy and in non-lazy situations. IOW the lazy
> optimization has nothing to do with this. 
> 
> And if for some reason you're worrying about performance, don't. The lazy optimization is largely about
> avoiding premature upfront string allocations, not propertization. And it more than likely doesn't matter for file
> tables anyway which are small compared to symbol obarrays, for instance.

No further comments within 2 weeks, so I presume the problem is
solved, and I'm closing this bug.

Subject: Completion highlighting applied outside completion-lazy-hilit-fn
From: João Guerra <[email-masked]>
To: [email-masked]
Date: Sun, 16 Mar 2025 16:27:00 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

TL;DR: Emacs applies additional completion highlighting even when
completion-lazy-hilit-fn is set, leading to incorrect behaviour with
alternative completion styles and frontends.

I'm implementing a custom fuzzy completion style and encountering an
issue where Emacs highlights parts of completions that it shouldn't.

For example, given the following directory structure:

```
<dir>/
  ...
  set-editing.el
  ...
```

and the input pattern `set`, my completion style produces three
possible matches for `set-editing.el`:

```
1 set-editing.el
  ^^^
2 set-editing.el
  ^^     ^
3 set-editing.el
  ^   ^  ^
```

Each match has a different score. In this case, match #3 has the
highest score and should be the one being highlighted.

Completion styles can bind completion-lazy-hilit-fn to control
highlighting. However, Emacs is still applying additional highlighting
outside completion-lazy-hilit-fn, resulting in the following
highlights:

```
set-editing.el
^^^ ^   ^
```

When completing files and buffers, but not commands, Emacs is
highlighting prefixes in
[completion--twq-all](https://github.com/emacs-mirror/emacs/blob/8ac894e2246f25d2a2a97d866b10e6e0b0fede5a/lisp/minibuffer.el#L677).
This becomes more evident if I make my completion-lazy-hilit-fn not do
any highlighting: completions are still highlighted when they
shouldn't at all.

Expected behavior: when lazy highlighting is enabled, Emacs shouldn't
apply any additional highlighting. While the current behavior works
for the default completion style (i.e. completions buffer), it easily
break as soon as users employ alternative styles or frontends.

Steps to reproduce (Emacs 30.1):
- emacs -Q
- Load:
    - https://github.com/minad/vertico/
    - https://github.com/lewang/flx/
    - https://gist.github.com/joca-bt/356ba1201c4fe842144e19ee1c723c28/
- Eval:
   - (vertico-mode t)
   - (setopt completion-styles '(flx))