* Re: [elpa] externals/vertico a962a8b 2/3: Implement deferred highlighting for all completion styles
[not found] ` <20210411131739.DAF2320AE6@vcs0.savannah.gnu.org>
@ 2021-04-11 16:37 ` Stefan Monnier
2021-04-11 17:34 ` Daniel Mendler
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Monnier @ 2021-04-11 16:37 UTC (permalink / raw)
To: emacs-devel; +Cc: Daniel Mendler
> +(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).
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [elpa] externals/vertico a962a8b 2/3: Implement deferred highlighting for all completion styles
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
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Mendler @ 2021-04-11 17:34 UTC (permalink / raw)
To: Stefan Monnier, emacs-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-11 17:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
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.