From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Juri Linkov <juri@linkov.net>
Newsgroups: gmane.emacs.devel
Subject: Re: Turning completion table lambdas into symbols
Date: Wed, 29 Nov 2023 09:18:46 +0200
Organization: LINKOV.NET
Message-ID: <865y1lt5hh.fsf@mail.linkov.net>
References: <87bkd3z9bi.fsf@catern.com> <86y1esuajx.fsf@mail.linkov.net>
 <ierleas4fcr.fsf@janestreet.com> <86v89ws5t3.fsf@mail.linkov.net>
 <iercyw445tu.fsf@janestreet.com> <86v89vzf1o.fsf@mail.linkov.net>
 <87pm03jn3w.fsf@catern.com> <861qcjw3ch.fsf@mail.linkov.net>
 <ier1qcin8db.fsf@janestreet.com> <86r0ki2on3.fsf@mail.linkov.net>
 <ierttpdlqe4.fsf@janestreet.com> <86leao519y.fsf@mail.linkov.net>
 <87fs0wk5oq.fsf@catern.com> <86edgfin4v.fsf@mail.linkov.net>
 <87o7fhixzv.fsf@catern.com> <86o7fhy9ae.fsf@mail.linkov.net>
 <87v89ohc6f.fsf@catern.com> <86il5nhdvh.fsf@mail.linkov.net>
 <87plzuuend.fsf@catern.com> <86wmu1j2hh.fsf@mail.linkov.net>
 <87a5qxv4bh.fsf@catern.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="31440"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)
Cc: Spencer Baugh <sbaugh@janestreet.com>,  emacs-devel@gnu.org
To: Spencer Baugh <sbaugh@catern.com>
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 29 08:22:03 2023
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
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 <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1r8EtW-00082A-QD
	for ged-emacs-devel@m.gmane-mx.org; Wed, 29 Nov 2023 08:22:02 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-devel-bounces@gnu.org>)
	id 1r8EsY-0002nr-VG; Wed, 29 Nov 2023 02:21:03 -0500
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 <juri@linkov.net>) id 1r8EsW-0002nZ-FR
 for emacs-devel@gnu.org; Wed, 29 Nov 2023 02:21:00 -0500
Original-Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@linkov.net>) id 1r8EsQ-0001qw-HH
 for emacs-devel@gnu.org; Wed, 29 Nov 2023 02:21:00 -0500
Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 3C34720009;
 Wed, 29 Nov 2023 07:20:50 +0000 (UTC)
In-Reply-To: <87a5qxv4bh.fsf@catern.com> (Spencer Baugh's message of "Tue, 28
 Nov 2023 23:36:44 +0000 (UTC)")
X-GND-Sasl: juri@linkov.net
Received-SPF: pass client-ip=2001:4b98:dc4:8::227;
 envelope-from=juri@linkov.net; helo=relay7-d.mail.gandi.net
X-Spam_score_int: -25
X-Spam_score: -2.6
X-Spam_bar: --
X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7,
 SPF_HELO_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01,
 T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-devel>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.devel:313352
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/313352>

>>>> display-buffer has a similar problem, but the difference is that
>>>> it's possible to identify a buffer by its name and use a regexp
>>>> to match buffer names.  Whereas for completing-read it's not easy
>>>> to identify a completion table.  A category matches a set of
>>>> completion tables, so maybe we need another identification
>>>> for individual tables?
>>>
>>> True, that would help.  Maybe the function symbol for the completion
>>> table?  Tables are usually lambdas today, but maybe we could make it
>>> easy to use a defun'd function instead, which would be very good for
>>> comprehensibility in general IMO.
>>
>> Turning lambdas into symbols looks good, this is like the existing
>> 'help--symbol-completion-table'.
>
> Like 'help--symbol-completion-table' in what way?

Just an example where minibuffer-completion-table is a symbol.

> One thing that requires a lambda is when the table is over some custom
> data.  But that can sometimes be avoided by moving the logic into the
> table, like this for example:
>
> +(defun project--project-dir-completion-table (string pred action)
> +  (cond
> +   ((eq action 'metadata)
> +    '(metadata . ((category . project-dir))))
> +   (t
> +    (complete-with-action action (cons "... (choose a dir)" project--list) string pred))))
> ...
> -              (completing-read "Select project: " choices nil t nil 'project--dir-history))))
> +              (completing-read "Select project: " #'project--project-dir-completion-table
> +                               nil t nil 'project--dir-history))))

> If there was a canonical way for a completion table to maintain some
> state which *doesn't* require the completion table to be a lambda, I
> think most completion tables could become defuns instead of lambdas.
> (And then they could be customized based on the function symbol)

Or they could be customized based on a new symbol for table identification
without turning lambdas into defuns:

  (completing-read "Select project: "
                   (lambda (string pred action)
                     (cond
                      ((eq action 'metadata)
                       '(metadata
                         . ((category . project-dir)
                            (table . project-dir-completion-table))))
                      (t
                       (complete-with-action action choices string pred))))
                   nil t nil 'project--dir-history)