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: Improvement proposals for `completing-read' Date: Thu, 8 Apr 2021 10:37:59 +0200 Message-ID: References: <09b67fc5-f8fd-c48a-8b0b-ad47c88761f1@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2239"; mail-complaints-to="usenet@ciao.gmane.io" To: Dmitry Gutov , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 08 10:39:12 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 1lUQC0-0000TR-2d for ged-emacs-devel@m.gmane-mx.org; Thu, 08 Apr 2021 10:39:12 +0200 Original-Received: from localhost ([::1]:33570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUQBz-0008D2-3k for ged-emacs-devel@m.gmane-mx.org; Thu, 08 Apr 2021 04:39:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUQAw-0007fa-U3 for emacs-devel@gnu.org; Thu, 08 Apr 2021 04:38:06 -0400 Original-Received: from server.qxqx.de ([2a01:4f8:121:346::180]:45055 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 1lUQAt-0003Wu-R5 for emacs-devel@gnu.org; Thu, 08 Apr 2021 04:38:06 -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=l3AwBLsHYCqInNOrta8XxF252nP8DXQNQMYksK4hRl0=; b=Ed2pz3AWUjfqbn/WHPBL50knaE vN67bbFxHwrsCnfbQ01MaXiyVD3Ed4jk70gUBXHsvxtP4w/Ru4GlYdy2QDQ2QNxSXB3GkLsvfsO+t GWEBX7NmVq6q6szBnjuuOKfwl+s0iW2BRzgpFiUsUH56abEpKi0izxtkWun+x3kZIQHg=; In-Reply-To: <09b67fc5-f8fd-c48a-8b0b-ad47c88761f1@yandex.ru> 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:267599 Archived-At: On 4/8/21 12:16 AM, Dmitry Gutov wrote: > On 07.04.2021 14:16, Daniel Mendler wrote: >>    .. Proposal 1: Disabling the history >>    .. Proposal 2: More efficient sorting >>    .. Proposal 3: Sort file names by history >>    .. Proposal 4: Add support for `group-function' >>    .. Proposal 5: Forbid the null completions for `REQUIRE-MATCH=t' >>    .. Proposal 6: Return text properties from `completing-read' >>    .. Proposal 7: Allow duplicates and retain object identity >>    .. Proposal 8: Completion style optimization of filtering and >> highlighting > 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. > 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. 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 :) > 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. 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. (There are also a few more arguments which are accepted 'flush and one can potentially extend this and compose the closure functions. But this is a detail.) 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. 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. But since this proposal is much more complicated than the ones I didn't add something like this here. Small steps first. Daniel Mendler