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.bugs Subject: bug#47711: 27.1; Deferred highlighting support in `completion-all-completions', `vertico--all-completions` Date: Sun, 11 Apr 2021 22:51:14 +0200 Message-ID: <3cc8aae8-58fc-abce-728c-090595281da2@daniel-mendler.de> 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="3033"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier To: 47711@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 11 22:52:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1lVh3y-0000fV-Pz for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Apr 2021 22:52:10 +0200 Original-Received: from localhost ([::1]:50912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVh3x-0000N0-A8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Apr 2021 16:52:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVh3q-0000Mm-9y for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 16:52:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lVh3q-0001PA-2K for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 16:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lVh3q-0000iN-0p for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 16:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Apr 2021 20:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47711 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16181742862702 (code B ref -1); Sun, 11 Apr 2021 20:52:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Apr 2021 20:51:26 +0000 Original-Received: from localhost ([127.0.0.1]:55936 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVh3F-0000hW-O7 for submit@debbugs.gnu.org; Sun, 11 Apr 2021 16:51:26 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:52524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVh3D-0000hO-VM for submit@debbugs.gnu.org; Sun, 11 Apr 2021 16:51:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVh3D-0000MJ-NK for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 16:51:23 -0400 Original-Received: from server.qxqx.de ([2a01:4f8:121:346::180]:36941 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 1lVh3B-0000s7-0p for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 16:51:23 -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:MIME-Version:Date: Message-ID:Subject:From:Cc:To:Sender:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=phweBwQ12UjBVQH3aBBq3QC32jFVbUVJO67bDBnsOG4=; b=zW5FvyGZ5fSOyOBNNxuk8MRqDS tWjdWfWuC1C5+wVxXulc6UsLs0wFuD3gpOCVGMJAlLkL9sYpG5zBpNe7EBMl4WZO77YjKBJ8WKXe0 1VI1j2goeMO6fl0i6FYYo9LR85K2sUaWc1YfefNiDNrIBzYUKYy9EhrI5tcFG4ZzYEKo=; 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: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:203864 Archived-At: Emacs is lacking a possibility to defer the completion highlighting when computing completions via `completion-all-completions'. This feature is important for the performance of completion UIs when the set of all completions is much larger than the set of completions which are displayed. The Vertico package defers highlighting by modifying the `completion*-hilit-*' function with advices. (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))) This function `vertico--all-completions` returns the list of completions and a highlighting function which can then be used to highlight the completions on the fly. It is a prototype of how some improved functionality in Emacs could look like. (completion-all-completions STRING TABLE PRED POINT &optional METADATA DEFER-HL) or (completion-all-completions-defer-hl STRING TABLE PRED POINT &optional METADATA) If DEFER-HL=t, then the function returns the completions and a highlighting function. One may consider returning a triple of base, completions and highlighting functions. Internally the completion styles should be adapted such that they support the deferred highlighting. It could be that this feature becomes less needed with the introduction of gccemacs in the future.