From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: Improvement proposals for `completing-read' Date: Thu, 8 Apr 2021 23:44:57 +0300 Message-ID: <292a9f63-5a41-7b32-66f2-67d06f138a09@yandex.ru> References: <09b67fc5-f8fd-c48a-8b0b-ad47c88761f1@yandex.ru> 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="31922"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 To: Daniel Mendler , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 08 22:46:57 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 1lUbYH-00089z-Ox for ged-emacs-devel@m.gmane-mx.org; Thu, 08 Apr 2021 22:46:57 +0200 Original-Received: from localhost ([::1]:34608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUbYG-0003jQ-Oz for ged-emacs-devel@m.gmane-mx.org; Thu, 08 Apr 2021 16:46:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUbWR-0002j7-SL for emacs-devel@gnu.org; Thu, 08 Apr 2021 16:45:03 -0400 Original-Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:42810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUbWP-0001zo-Gp for emacs-devel@gnu.org; Thu, 08 Apr 2021 16:45:03 -0400 Original-Received: by mail-wm1-x32d.google.com with SMTP id 5-20020a05600c0245b029011a8273f85eso1886918wmj.1 for ; Thu, 08 Apr 2021 13:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=R4Vv/yYXvrDWbZ9vIhMVviBZn7qP2W5Jcakmc/n0wnQ=; b=nAXZdEd2J50sCG+HpQVitM67f1//jNK2Vcs53Y5xt5rA3gmQaP+WKY7+8kx3BvJgsU Cwm+c0RmViapDDBGL1bMbZ7AYhNDqRDirqfAeQQ/qB+fL2VyengXLVduQz1wLYHJkgUi Y26wHuQQucfyENjl7HBQMMSmHzOU9xNhoBm4txT05q4crz1Fn0jTDtgl5IRq0UoLjt8d w6IpHY30/DqnJ8lF/zkFBEGbhB3eSOirbz9McUwXrK8NT1jJlXQA2oQJWQak0qQ1bNyX ZgUSJXjF/JjTGoGTUCill5mdapXTjYZk7l5LDbTsK0sLT/iQ+DJ98cUZcD6x1nx4tIiz cEkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=R4Vv/yYXvrDWbZ9vIhMVviBZn7qP2W5Jcakmc/n0wnQ=; b=Aqt28sz3GuC3zRyVmCcxo8k7gHdf/Nipwz6NCeRQXBWOAd9Px9R62LwNbvmgjAXzw+ CSjFns8Z9czdORVrHnq5O1nmFpFdemor+MigO4wko1vQdL+24Ohqv5ytlDd4yHPjYBXQ 8JnrrButKkjo6vFFg6QF12cxJZsNrD3rZ/zFHLriyT3RLSBEwp5mEsySbuzjA77/EoJC guZVSJnovNRi8xFH+GCa5oj3E1223ZPpXMZuJt0TUAxj8D/cEdHLHOaXTVL8UczVkNQM s4kHhHlwnwFCisCnTLsXiFU+oui4c3aqeIM0QO4V/swOpljKUb9T7NX2gnFfEmOFFtUw KBPA== X-Gm-Message-State: AOAM531j9H6u701CCFECQ3WHqJgeq5eGRC20+zkYsGvoK8UEmTY0BeES Kpdm8lkqMRg5ZlbuHCE9vmdJbHfUSvo= X-Google-Smtp-Source: ABdhPJw3VYIgq+IDdEydVPLInCyMsbA9AzayCyOx9Xl2JYQulL5uPp3AOrMv4vrBB2UMqrS9lVYC+g== X-Received: by 2002:a7b:c5c8:: with SMTP id n8mr10792983wmk.63.1617914700187; Thu, 08 Apr 2021 13:45:00 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id p5sm530108wme.23.2021.04.08.13.44.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Apr 2021 13:44:59 -0700 (PDT) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=raaahh@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:267666 Archived-At: On 08.04.2021 11:37, Daniel Mendler wrote: >> 6. would indeed make sense, and I'm not sure why we wouldn't want to >> have it in the non-selection case. Whatever come makes use of the >> completed value, could do the stripping of properties. >> >> Often, completing-read's caller can ensure the properties are there, >> by using something like (assoc-default completed-string collection) at >> the end. But that only works if the caller is also the provider of the >> completion table (otherwise it's an "opaque" data structure). > > Yes, you can use an alist and this is also what I use in my Consult > package when I want to obtain the associated data. But allowing > text-properties could simplify some scenarios and it would be more > natural when you are doing selection. If you consider proposal 7 > (identity/deduplication), retaining the text properties is an automatic > outcome. Perhaps. We might disable deduplication only optionally, though, OTOH retaining text properties seems to be always useful (even if caller wouldn't be able to always rely on it). >> 9. completion tables need to be able to delegate all matching logic to >> an external process, both filtering and sorting. That's an important >> case for code completion, where we can take advantage of existing code >> and its "fuzzy matching" implementations. > > This would be neat, but it requires a lot of restructuring of the > completion logic. For this reason I am not fond of this idea. But you > can achieve something like this with your proposal 10. See what I > describe there, regarding Consult async. AFAIK, being able to do this is essential to reach best performance in a number of important use cases. > I tried to integrate `fzf` once with Consult async, like generating a > list outside Emacs, pushing it through `fzf` for fuzzy-filtering and > presenting it to the user via completion. But it turned out that most of > the external implementations are not good enough for this use case. They > don't have an option to open a pipe to update the filtering input for > example. I could write my own fuzzy matcher external backend which would > work perfectly with async completion. However then I can also just wait > for gccemacs :) I was thinking more about interactions over network, with HTTP requests sent and received asynchronously. Mainly the cases where one uses the LSP protocol or similar. >> 10. support for delayed/asynchronous fetching of completions which >> doesn't interrupt user's typing (it would generally abort the request >> if user input is detected, but there might be other approaches to >> that). Again, that's helpful when completions are produces by an >> external process. > > You may want to take a look at my Consult package, specifically the > async functionality. I believe that this functionality can easily be > provided on top of the current infrastructure, and actually in a nice way. You can check out Company's asynchronous convention for backends: https://github.com/company-mode/company-mode/blob/f3aacd77d0135c09227400fef45c54b717d33f2e/company.el#L456-L467 It's a very simple lambda-based future-like value. It can be updated to use a named type, and with other features too. I think it's a clean and simple base to build on, though. > In Consult I am using closures which hold the asynchronously acquired > data. The closure function must accept a single argument, it can either > be a string (the new input) or it can be a list of newly obtained > candidates. I'm not sure where to look, sorry. > If it is a list the closure function must append the new candidates to > the already existing ones and return the full list of candidates. The > completion table then calls the async closure with either the input or > nil when doing all-completions. I'm not 100% clear, but it sounds like chunked iteration. Which is a good feature to have. Though perhaps not always applicable to every UI (blinking with new results in a completion popup might be not user-friendly). > Now a single problem remains - if new data is incoming the async data > source must somehow inform completion that new candidates are available. > In order to do this the async source must trigger the UI for example via > icomplete-exhibit/selectrum-exhibit and so on. It would be good to have > a common "completion-refresh" entry point for that. In Consult I have to > write a tiny bit of integration code for each supported completion system. See my link, perhaps. Or in general, a Future/Promise API has a way to subscribe to the value's update(s) (and the completion frontend can do that). Having to use a global variable seems pretty inelegant in comparison. > But since this proposal is much more complicated than the ones I didn't > add something like this here. Small steps first. No hurry at all. Sometimes, though, a big feature like that can inform the whole design from the outset.