From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#47711: bug#48841: bug#47711: bug#48841: bug#47711: [PATCH VERSION 2] Add new `completion-filter-completions` API and deferred highlighting Date: Wed, 25 Oct 2023 16:50:29 -0400 Message-ID: References: <3d3f894f-a6fa-53ae-5d50-c3aa9bffc73e@daniel-mendler.de> <56ab18b1-4348-9b2c-85bb-af9b76cd429a@daniel-mendler.de> <328f87eb-6474-1442-e1ca-9ae8deb2a84a@yandex.ru> <83fsvcbio7.fsf@gnu.org> <9f432d18-e70f-54c1-0173-1899fb66d176@gutov.dev> <877cnafv39.fsf@gmail.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24526"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Dmitry Gutov , Eli Zaretskii , 47711@debbugs.gnu.org, Daniel Mendler To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 25 22:53:49 2023 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 1qvksu-000629-HP for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 25 Oct 2023 22:53:48 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvksf-0004Ws-Pg; Wed, 25 Oct 2023 16:53:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvkse-0004Wg-H9 for bug-gnu-emacs@gnu.org; Wed, 25 Oct 2023 16:53:32 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvkse-0005Sg-9S for bug-gnu-emacs@gnu.org; Wed, 25 Oct 2023 16:53:32 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qvkt8-0003RU-90 for bug-gnu-emacs@gnu.org; Wed, 25 Oct 2023 16:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Oct 2023 20:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47711 X-GNU-PR-Package: emacs Original-Received: via spool by 47711-submit@debbugs.gnu.org id=B47711.169826720413180 (code B ref 47711); Wed, 25 Oct 2023 20:54:02 +0000 Original-Received: (at 47711) by debbugs.gnu.org; 25 Oct 2023 20:53:24 +0000 Original-Received: from localhost ([127.0.0.1]:60082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qvksV-0003QV-U5 for submit@debbugs.gnu.org; Wed, 25 Oct 2023 16:53:24 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:22403) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qvksR-0003QD-Lw for 47711@debbugs.gnu.org; Wed, 25 Oct 2023 16:53:21 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id E000D807D7; Wed, 25 Oct 2023 16:52:43 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1698267163; bh=7jfyvYecg45dKiMOO9dMhSmhBvK337JaISVMh9levfA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=dIfTjaUuyl/J91ukl5HWcD7CNJQAiovNyu8JyEWMDZVgw2RaaT1M7MMFTpEFdNUWJ L4btcqrgYTvmd5vAxeaq9sM1+KYKohVPMqjdcQllYPKgfJ4twnJbOI3MAOmE1cxQ9u 2K35nwRKUW0ga360s63EGMHQxr3w4An/Bt1yIK3Vvw/AiES5yuXRM6OXKE7nZUw7mr KvIylc9GsEZyDzeJlayXplKsyMdkGUDjfh/btMQnSN36ut5iJakGMf1fcHfwZNPJNN XFvKjHZ9Sif5DpOeEeRCNsJazok2Rq3hVevMdiuA/8Mtmw40m40ay4Q05qNh4wird2 Qj5zYTAMm+RoA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 0F24480409; Wed, 25 Oct 2023 16:52:43 -0400 (EDT) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id ED26C120446; Wed, 25 Oct 2023 16:52:42 -0400 (EDT) In-Reply-To: <877cnafv39.fsf@gmail.com> ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Wed, 25 Oct 2023 18:52:26 +0100") 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273212 Archived-At: This sounds fairly reasonable: the worst-case breakage seems to be that we may occasionally lose highlighting because the var was non-nil at the wrong time. Sidenote: since the hash-table uses `eq` we don't need to use `gensym`, we can use something like `cons` instead, which is cheaper and doesn't risk making its way into the `obarray`. > +(defun completion-lazy-hilit (str) > + "Return a copy of completion STR that is `face'-propertized. > +See documentation for variable `completion-lazy-hilit' for more > +details." > + (completion--hilit-from-re > + (copy-sequence str) > + (gethash completion-lazy-hilit completion--lazy-hilit-table))) Hmm... in order to get the right result you need to call `completion-lazy-hilit` sometime after calling `completion-all-completions` and before the next call to `completion-all-completions` done with the same value of `completion-lazy-hilit`, right? So how important is it to use a hash-table rather than a variable holding just "the info about the last call to `completion-all-completions`"? > + last-md > + (score (lambda (str) > + (unless (string-match re str) > + (error "Internal error: %s does not match %s" re str)) > + (let* ((match-end (match-end 0)) > + (md (cddr (setq last-md (match-data t last-md))))) > + (completion--flex-score-1 md match-end (length str)))))) > + (cond (completion-lazy-hilit > + (puthash completion-lazy-hilit re completion--lazy-hilit-table) > + (mapc (lambda (str) > + (put-text-property 0 1 'completion-score (funcall score str) str)) > + completions)) > + (t > + (mapcar > + (lambda (str) > + (setq str (copy-sequence str)) > + (put-text-property 0 1 'completion-score (funcall score str) str) > + (completion--hilit-from-re str re) > + str) > + completions))))) How much more expensive is it to replace the (mapc (lambda (str) (put-text-property 0 1 'completion-score (funcall score str) str)) completions)) with something like (let ((tail `(completion-lazy-hilit (completion--hilit-from-re ,re)))) (mapc (lambda (str) (add-text-properties 0 1 `(completion-score ,(funcall score str) ,@tail) str)) completions)) and then get rid of the hash-table altogether? Stefan