From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ryan Thompson Newsgroups: gmane.emacs.bugs Subject: bug#27158: 25.2; Eliminating old usage of completing-read from built-in files Date: Wed, 31 May 2017 15:44:15 +0000 Message-ID: References: <24f4a025-ad7b-06e5-10ee-f122bef32402@thompsonclan.org> <0276a0cd-874b-47ee-a2dc-fe8ca08ece9d@default> <21029018-5890-e545-8b50-ee856bc2caec@yandex.ru> <562784bd-e22b-411d-8230-4f95fe2fa7db@default> <4dfcd02b-53bc-c430-89db-f93ad6b283c2@yandex.ru> <3d3bc85b-31d3-4701-8acd-45591d075253@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a114a91f6837f7b0550d3cb5d" X-Trace: blaine.gmane.org 1496245522 29811 195.159.176.226 (31 May 2017 15:45:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 31 May 2017 15:45:22 +0000 (UTC) To: Drew Adams , Dmitry Gutov , 27158@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 31 17:45:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1dG5o8-0007HA-Tb for geb-bug-gnu-emacs@m.gmane.org; Wed, 31 May 2017 17:45:13 +0200 Original-Received: from localhost ([::1]:60454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG5oE-0001eE-98 for geb-bug-gnu-emacs@m.gmane.org; Wed, 31 May 2017 11:45:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG5o5-0001aA-7p for bug-gnu-emacs@gnu.org; Wed, 31 May 2017 11:45:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG5ny-0001s7-PM for bug-gnu-emacs@gnu.org; Wed, 31 May 2017 11:45:09 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44956) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG5ny-0001ro-K1 for bug-gnu-emacs@gnu.org; Wed, 31 May 2017 11:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dG5ny-0004PV-ER for bug-gnu-emacs@gnu.org; Wed, 31 May 2017 11:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ryan Thompson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 31 May 2017 15:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27158 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27158-submit@debbugs.gnu.org id=B27158.149624547416899 (code B ref 27158); Wed, 31 May 2017 15:45:02 +0000 Original-Received: (at 27158) by debbugs.gnu.org; 31 May 2017 15:44:34 +0000 Original-Received: from localhost ([127.0.0.1]:47632 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dG5nW-0004OV-6J for submit@debbugs.gnu.org; Wed, 31 May 2017 11:44:34 -0400 Original-Received: from mail-it0-f52.google.com ([209.85.214.52]:37930) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dG5nU-0004OH-0t for 27158@debbugs.gnu.org; Wed, 31 May 2017 11:44:32 -0400 Original-Received: by mail-it0-f52.google.com with SMTP id r63so13889627itc.1 for <27158@debbugs.gnu.org>; Wed, 31 May 2017 08:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thompsonclan-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=EESIRukJ6xS7tntLQHdvrvAG5f60waFnNE4fH1lOWcU=; b=Ufc737Txt3ykQUgbmHvotI1e8XWtvauXwNlt1WruHAcCvVmq0+EakEulAdAH/Pcm+S vREvIay9LK5VGf8e44g8nwdiI//PIg22q4JysVBFvOVGD1pv2a+GpxCOSyFRY1B8m8wU uzQRhlFYiRL+Kf/WO2Tzlbb0ur7e5MWsHM/GffakcSm791sB4Fg7QGUQZ4dPvU8aZc8Y x2Ps+Dj7BzpeDCcS6tM6twYwNDXugrRNRhHKARtIB9LKt6PjdC04qBKVhni09Yv1yt4N Gw5XzHl2gbVTfahcSdCS+1jNlim2qhNi+vmsHB9eJK9FIvc3mXjwdZEz3pRm8ZY6lNwX 5h+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=EESIRukJ6xS7tntLQHdvrvAG5f60waFnNE4fH1lOWcU=; b=Cu2GkbiLa/euxfjsFRSfKpvlqXuWfZsiv5rW7LSBC+EXHDiKQNUyouWIQsq+DoLpo5 VkzAnTTRnj187KgYOlCfzPPPGYAsiSY18EDWcqvEjy1ze4hCvVqK37gkiTbIMx0xvPQ5 ztgqw4msecyioB+ee9gE77rh12jX7HtuQG4LchQNi6Hu9ggKUtfRwYBv7aWqOFewToAj mDTA3TSPPPfeHUyqRx0fwd60oQeefa/aLsTpLoqrQNRb5qCnNWlpV/slTHz2XnGL5zgO EtInZFkMQTMn4sah/2zJ7c8JPJ8EGmYbTf0fjYCJPYq58xR/0uBNotNBvOLRwTecaZHN CrCw== X-Gm-Message-State: AODbwcAFuT0aRfscAf+F6s6ZUBrw3RtcbT53w36xDOEa/5eKdkBSPWvM 3mdA6P48lk4/ZticSIo0jX/QIkgeo086 X-Received: by 10.36.53.79 with SMTP id k76mr7507181ita.71.1496245466244; Wed, 31 May 2017 08:44:26 -0700 (PDT) In-Reply-To: <3d3bc85b-31d3-4701-8acd-45591d075253@default> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:133092 Archived-At: --001a114a91f6837f7b0550d3cb5d Content-Type: text/plain; charset="UTF-8" > > But if an explicit DEFAULT arg is the solution then your > completion system need only set arg DEFAULT to "" when > it is nil, no? Or set it to the first completion candidate > when it is nil or "". Or ... . > The problem is that there is no one solution that floats everyone's boat. Whatever you choose, someone sinks (i.e. has broken completion). The only way to float everyone's boat is for the completion function to check which function called it and then change its behavior based on prior knowledge of what each caller expects. Consider the following two functions: (defun pick-a-fruit () (interactive) (let* ((default "banana") (prompt (format "Pick a fruit (default %s): " default)) (collection '("apple" "banana" "cherry")) (selection (completing-read prompt collection nil t))) (when (string= selection "") (setq selection default)) (message "You selected %s" selection))) (defun pick-a-tool () (interactive) (let* ((prompt "Pick a tool: ") (collection '("hammer" "screwdriver" "drill")) (selection (completing-read prompt collection nil t))) (message "You selected %S" selection))) The fruit function expects completing-read to return an empty string to indicate that the default should be used, while the tool function expects completing-read to always return an element from the collection no matter what. Technically, the tool function is wrong, because completing-read is documented to return an empty string even when REQUIRE-MATCH is non-nil. But there are plenty of functions that use this pattern and expect it to work, because they don't know about this edge case, and it would be nice to be able to support them in a custom completion system without breaking the functions that use the former pattern. As it is, you have to choose one or the other to break, or else imeplement caller-dependent behavior to give everyone what they expect, which is messy. As I said, though, treating DEF = nil as equivalent to DEF = "" might form the basis for an acceptable compromise. It will still break the pick-a-tool case, but it will be clearer why it's breaking, since the empty string will be presented explicitly as the first completion option. I'll test it out. --001a114a91f6837f7b0550d3cb5d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
= But if an explicit DEFAULT arg is the solution then your
completion system need only set arg DEFAULT to "" when
it is nil, no?=C2=A0 Or set it to the first completion candidate
when it is nil or "".=C2=A0 Or ... <whatever floats your boat&= gt;.

The problem is that there is no on= e solution that floats everyone's boat. Whatever you choose, someone si= nks (i.e. has broken completion). The only way to float everyone's boat= is for the completion function to check which function called it and then = change its behavior based on prior knowledge of what each caller expects. C= onsider the following two functions:
(defun pick-a-fruit<=
/span> ()
  (interactive)
  (let* ((default "banana")
         (prompt (format "Pic=
k a fruit (default %s): " default))
         (collection '("apple&q=
uot; "banana" "cherry"))
         (selection (completing-read prompt collection nil t)))
    (when (string=3D selection "")
      (setq selection default))
    (message "You selected %s"=
 selection)))
(def=
un pick-a-tool ()
  (interactive)
  (let* ((prompt "Pick a tool:=
 ")
         (collection '("hammer&=
quot; "screwdriver&qu=
ot; "drill"))
         (selection (completing-read prompt collection nil t)))
    (message "You selected %S"=
 selection)))
The fruit function expects completing-read to return a=
n empty string to indicate that the default should be used, while the tool =
function expects completing-read to always return an element from the colle=
ction no matter what. Technically, the tool function is wrong, because comp=
leting-read is documented to return an empty string even when REQUIRE-MATCH=
 is non-nil. But there are plenty of functions that use this pattern and ex=
pect it to work, because they don't know about this edge case, and it w=
ould be nice to be able to support them in a custom completion system witho=
ut breaking the functions that use the former pattern. As it is, you have t=
o choose one or the other to break, or else imeplement caller-dependent beh=
avior to give everyone what they expect, which is messy.
<=
span style=3D"font-family:sans-serif;white-space:normal">As I said, though,=
 treating DEF =3D nil as equivalent to DEF =3D "" might form the =
basis for an acceptable compromise. It will still break the pick-a-tool cas=
e, but it will be clearer why it's breaking, since the empty string wil=
l be presented explicitly as the first completion option. I'll test it =
out.
--001a114a91f6837f7b0550d3cb5d--