From: Daniel Mendler <mail@daniel-mendler.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: [elpa] externals/vertico a962a8b 2/3: Implement deferred highlighting for all completion styles
Date: Sun, 11 Apr 2021 19:34:17 +0200 [thread overview]
Message-ID: <6e7ec568-0e4f-76da-8b2b-45d5c5726f69@daniel-mendler.de> (raw)
In-Reply-To: <jwvy2dog4om.fsf-monnier+emacs@gnu.org>
Hi Stefan!
On 4/11/21 6:37 PM, Stefan Monnier wrote:
>> +(declare-function orderless-highlight-matches "ext:orderless")
>> +(defun vertico--all-completions (&rest args)
>> + "Compute all completions for ARGS with deferred highlighting."
>> + (cl-letf* ((orig-pcm (symbol-function #'completion-pcm--hilit-commonality))
>> + (orig-flex (symbol-function #'completion-flex-all-completions))
>> + ((symbol-function #'completion-flex-all-completions)
>> + (lambda (&rest args)
>> + ;; Unfortunately for flex we have to undo the deferred highlighting, since flex uses
>> + ;; the completion-score for sorting, which is applied during highlighting.
>> + (cl-letf (((symbol-function #'completion-pcm--hilit-commonality) orig-pcm))
>> + (apply orig-flex args))))
>> + ;; Defer the following highlighting functions
>> + (hl #'identity)
>> + ((symbol-function #'completion-hilit-commonality)
>> + (lambda (cands prefix &optional base)
>> + (setq hl (lambda (x) (nconc (completion-hilit-commonality x prefix base) nil)))
>> + (and cands (nconc cands base))))
>> + ((symbol-function #'completion-pcm--hilit-commonality)
>> + (lambda (pattern cands)
>> + (setq hl (lambda (x) (completion-pcm--hilit-commonality pattern x)))
>> + cands))
>> + ((symbol-function #'orderless-highlight-matches)
>> + (lambda (pattern cands)
>> + (setq hl (lambda (x) (orderless-highlight-matches pattern x)))
>> + cands)))
>> + (cons (apply #'completion-all-completions args) hl)))
>
> Yuck!
> I think this should have a bug#NNN attached to make sure it's only used
> on a temporary basis (i.e. until Emacs's minibuffer.el provides the
> corresponding functionality).
I wasn't aware that you are monitoring this so closely. This is
basically the prototype of how the deferred highlighting could look
like, instead of my proposal 8, `completion-skip-highlighting`, which
can hardly be generalized. It works well for Orderless
(`orderless-skip-highlighting`), but that's about it.
One can introduce a function
`completion-all-completions-deferred-highlighting` or alternatively add
an optional argument to `completion-all-completions`, which signals that
the function should return the list of completions and the deferred
highlighting function/highlighting data. (One may also consider
returning the base directly or is there a particular reason to put it
into the last cdr?)
The function `completion-all-completions-deferred-highlighting` can
return a special highlighting function, registered in
`completion-styles-alist`.
Daniel
prev parent reply other threads:[~2021-04-11 17:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210411131733.8572.37775@vcs0.savannah.gnu.org>
[not found] ` <20210411131739.DAF2320AE6@vcs0.savannah.gnu.org>
2021-04-11 16:37 ` [elpa] externals/vertico a962a8b 2/3: Implement deferred highlighting for all completion styles Stefan Monnier
2021-04-11 17:34 ` Daniel Mendler [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6e7ec568-0e4f-76da-8b2b-45d5c5726f69@daniel-mendler.de \
--to=mail@daniel-mendler.de \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.