From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Separating completion candidates and filtering Date: Sat, 19 Aug 2017 18:57:05 -0400 Message-ID: References: <87a82whzqr.fsf@lylat> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1503183510 8832 195.159.176.226 (19 Aug 2017 22:58:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 19 Aug 2017 22:58:30 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 20 00:58:26 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djChE-0001yB-Jn for ged-emacs-devel@m.gmane.org; Sun, 20 Aug 2017 00:58:24 +0200 Original-Received: from localhost ([::1]:45108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djChL-0008L9-6W for ged-emacs-devel@m.gmane.org; Sat, 19 Aug 2017 18:58:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djCgI-0008KZ-VK for emacs-devel@gnu.org; Sat, 19 Aug 2017 18:57:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djCgF-0006It-Sk for emacs-devel@gnu.org; Sat, 19 Aug 2017 18:57:27 -0400 Original-Received: from [195.159.176.226] (port=38321 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1djCgF-0006If-Lq for emacs-devel@gnu.org; Sat, 19 Aug 2017 18:57:23 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1djCg0-0006Dz-Sh for emacs-devel@gnu.org; Sun, 20 Aug 2017 00:57:08 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 54 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:9evUdDejQF+Q4s/9wFQLGlGMDS0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217624 Archived-At: > AFAIU, completion backends such as Helm and Ivy essentially call the > `minibuffer-completion-table' mainly to get the list of candidates, and > then does the filtering on its own. Indeed, this is a problem. E.g. for completion-tables like those that complete file names, that just can't work since the "complete" table is virtually infinite and the completion-table doesn't know how to enumerate this "complete" table, but only how to do "small steps". > One possible solution to this is adding a new value option for `action' > in `complete-with-action' that instructs `completion-table-with-context' > to just return the table. That means adding a new value `identity' for `action' to the API implemented by *all* completion tables. IOW a new method (if you look at completion tables as objects that implement a particular interface). > @@ -164,6 +164,7 @@ complete-with-action > ((functionp table) (funcall table string pred action)) > ((eq (car-safe action) 'boundaries) nil) > ((eq action 'metadata) nil) > + ((eq action 'identity) table) > (t > (funcall > (cond It's not sufficient because when you pass `identity' to a completion-table, you don't know that this table was built with complete-with-action, and since `identity' was not a known possible value, the completion table may do arbitrary things in this case, including returning something that can look like a "table" but isn't what you expected. So you need to do what we did with `boundaries' and with `metadata', i.e. wrap the return value (e.g. with "(cons 'identity table)") such that you can detect with a high probability that the returned value is indeed what you expect. Another issue is to define really what it is that you expect to receive when you call a completion-table with argument `identity' (I strongly suspect that answering this question will lead to changing its name, BTW). BTW, another approach could be to write a function which takes a completion-table and "folds it out". I.e. call `all-completions` on "" to get an initial list of candidates, then check whether those candidates's boundaries are different from 0 and if so call all-candidates on those values, etc... So the first call to (all-completions "" table) might return ("a=" "b=") after which you notice that (completion-boundaries "a=" table) doesn't return 0 so you call (all-completions "a=" table), and same thing for "b=", so in the end the function will have constructed the ("a=foo" "a=bar" "b=hello" "b=world") table. Stefan