From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Mendler Newsgroups: gmane.emacs.devel Subject: Re: [elpa] externals/vertico a962a8b 2/3: Implement deferred highlighting for all completion styles Date: Sun, 11 Apr 2021 19:34:17 +0200 Message-ID: <6e7ec568-0e4f-76da-8b2b-45d5c5726f69@daniel-mendler.de> References: <20210411131733.8572.37775@vcs0.savannah.gnu.org> <20210411131739.DAF2320AE6@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15236"; mail-complaints-to="usenet@ciao.gmane.io" To: Stefan Monnier , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 11 19:35:22 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVdzW-0003sf-7E for ged-emacs-devel@m.gmane-mx.org; Sun, 11 Apr 2021 19:35:22 +0200 Original-Received: from localhost ([::1]:39892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVdzV-0003Tt-9b for ged-emacs-devel@m.gmane-mx.org; Sun, 11 Apr 2021 13:35:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVdyc-00034F-N4 for emacs-devel@gnu.org; Sun, 11 Apr 2021 13:34:26 -0400 Original-Received: from server.qxqx.de ([2a01:4f8:121:346::180]:55489 helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVdya-0006Pg-9S for emacs-devel@gnu.org; Sun, 11 Apr 2021 13:34:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:To:Subject:Sender:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=NycpmVVFVGX/noJlU8DP8koByfwmJNwzjvXDbH6u3Cs=; b=U+77Z/+xrYtVcx29uIM+Pijs7e PSdMau8/chziz62Bz6p5Pt54CFTsURuqy4NqB+kJC3yHSVDtbv+iHenOXmAY9+7ya2NCq0wwSYqfW I2v9WZXKTrp3EW0J3chbsUm6rXv4MpqKksYu3edxbDC3r5dBBFZc8oiI/NHNPHWyGwdc=; In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2a01:4f8:121:346::180; envelope-from=mail@daniel-mendler.de; helo=mail.qxqx.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:267906 Archived-At: 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