GNU bug report logs - #77054
Completion highlighting applied outside completion-lazy-hilit-fn

Previous Next

Package: emacs;

Reported by: João Guerra <joca.bt <at> gmail.com>

Date: Sun, 16 Mar 2025 15:28:01 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: João Guerra <joca.bt <at> gmail.com>
Subject: bug#77054: closed (Re: bug#77054: Completion highlighting applied
 outside completion-lazy-hilit-fn)
Date: Sat, 05 Apr 2025 08:36:02 +0000
[Message part 1 (text/plain, inline)]
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 77054 <at> debbugs.gnu.org.

-- 
77054: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77054
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
To: João Távora <joaotavora <at> gmail.com>
Cc: dmitry <at> gutov.dev, joca.bt <at> gmail.com, 77054-done <at> debbugs.gnu.org
Subject: Re: bug#77054: Completion highlighting applied outside
 completion-lazy-hilit-fn
Date: Sat, 05 Apr 2025 11:35:22 +0300
> From: João Távora <joaotavora <at> gmail.com>
> Date: Fri, 21 Mar 2025 12:41:55 +0000
> Cc: Dmitry Gutov <dmitry <at> gutov.dev>, Eli Zaretskii <eliz <at> gnu.org>, 77054 <at> debbugs.gnu.org
> 
> On Fri, Mar 21, 2025, 11:10 João Guerra <joca.bt <at> gmail.com> 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.

[Message part 3 (message/rfc822, inline)]
From: João Guerra <joca.bt <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Completion highlighting applied outside completion-lazy-hilit-fn
Date: Sun, 16 Mar 2025 16:27:00 +0100
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))



This bug report was last modified 104 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.