From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#35231: 26.1; Redefine `read-command' behavior for empty input and DEFAULT not a command name Date: Thu, 11 Apr 2019 08:10:59 -0700 (PDT) Message-ID: <85ddecd9-7a66-4fbc-8297-b4419e45db05@default> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="141176"; mail-complaints-to="usenet@blaine.gmane.org" To: 35231@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Apr 11 17:12:25 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEbNF-000aYO-Kh for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Apr 2019 17:12:21 +0200 Original-Received: from localhost ([127.0.0.1]:50514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEbNE-0001m5-Ma for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Apr 2019 11:12:20 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEbN7-0001lk-4r for bug-gnu-emacs@gnu.org; Thu, 11 Apr 2019 11:12:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEbN5-0005eW-5x for bug-gnu-emacs@gnu.org; Thu, 11 Apr 2019 11:12:13 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41488) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hEbMw-0005ai-Sm for bug-gnu-emacs@gnu.org; Thu, 11 Apr 2019 11:12:07 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hEbMw-00059I-IJ for bug-gnu-emacs@gnu.org; Thu, 11 Apr 2019 11:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Apr 2019 15:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 35231 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.155499547819740 (code B ref -1); Thu, 11 Apr 2019 15:12:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Apr 2019 15:11:18 +0000 Original-Received: from localhost ([127.0.0.1]:55032 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hEbME-00058K-26 for submit@debbugs.gnu.org; Thu, 11 Apr 2019 11:11:18 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58296) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hEbMC-000587-46 for submit@debbugs.gnu.org; Thu, 11 Apr 2019 11:11:17 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:58330) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEbM6-0004h8-UO for submit@debbugs.gnu.org; Thu, 11 Apr 2019 11:11:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEbM4-0001Fc-7q for bug-gnu-emacs@gnu.org; Thu, 11 Apr 2019 11:11:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEbM3-0004eb-7z for bug-gnu-emacs@gnu.org; Thu, 11 Apr 2019 11:11:08 -0400 Original-Received: from userp2130.oracle.com ([156.151.31.86]:48258) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEbM2-0004dX-TV for bug-gnu-emacs@gnu.org; Thu, 11 Apr 2019 11:11:07 -0400 Original-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3BF4ZpT107274 for ; Thu, 11 Apr 2019 15:11:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=oBgr8gcL0K8oVXdPHizIvR8mtVu4MDlHHKfc+s2wfpI=; b=FJisjChbDzaccrLFxZU3AoYs3VZiH1AoBPFUCtjNt0E/TW10kq/gpkIQTxiYUchf7sie X9afPaMPbmK0+IyoW1WNIAMoz6REDC5dMm5BH/1H1KQEPmWH9HLydQmTGh7Ey5fBigYl PQoAfGKgITOiyjnvB2NEYjZJR0771PcQTZzmDdJ4/AUc14YpVJMK5f4u4Hlvcamix6fc Px4i5gBQqbu7mfBCUTCex7Z92reME2TZ/AG/mccJHWgEFZN10w3hTG1ErPHFDD8ykZYx NvGJ/HMS0YQHxU8/qE3xOOUhuByFWdQxFfhcXMNf4N0sqVmULFCxrUxlu3rQasYpPJH1 LQ== Original-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2rpkht9n2r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2019 15:11:02 +0000 Original-Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3BFAXuH125542 for ; Thu, 11 Apr 2019 15:11:01 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2rph7tssn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2019 15:11:01 +0000 Original-Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3BFB00q009799 for ; Thu, 11 Apr 2019 15:11:00 GMT X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4834.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9224 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904110103 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9224 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904110103 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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: 209.51.188.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:157503 Archived-At: This is a followup to bug #35222 (and thanks for fixing that doc bug). As discussed in #35222, the current C-code definition of `read-command' seems not so desirable, when it comes to DEFAULT =3D nil or "". The behavior in that case is to return an uninterned symbol whose name is empty, which has the read/print syntax `##'. This is _not_ a symbol whose function definition is `commandp'. There is nothing about this symbol that qualifies for consideration as a command. It seems wrong (a bug) for `read-command' to ever return a symbol whose function definition is `commandp'. Function `read-command' is old, and it has always had this odd behavior. One question is whether there is code out there that depends on this odd null DEFAULT behavior. Another question is whether this behavior is good. I don't think so (see above), but perhaps there is an argument supporting it? Supposing that there is no sufficient argument supporting it, can we fix it, adjust any deliverable calling code as needed, and record in NEWS the change in this corner-case behavior? If so, what's the right fix? Here's one suggestion: 1. Define it in Lisp, not C (why should it ever have been in C?). 2. Use `completing-read' with REQUIRE-MATCH=3Dt and PREDICATE=3D`commandp'. 3. Because even with REQUIRE-MATCH=3Dt you can exit `completing-read' with empty input that does not satisfy PREDICATE, loop until the input is nonempty and satisfies PREDICATE. Something like this, for example: (defun read-command (prompt &optional default) "Read the name of a command and return a symbol with that name. \(A command is anything that satisfies predicate `commandp'.) Prompt with PROMPT. By default, return the command named DEFAULT (or its first element if DEFAULT is a list). (If DEFAULT does not name a command then it is ignored.)" (let ((name (completing-read prompt obarray #'commandp t nil 'extended-command-history default))) (while (string=3D "" name) (setq name (completing-read prompt obarray #'commandp t nil 'extended-command-history default))) (intern name))) In GNU Emacs 26.1 (build 1, x86_64-w64-mingw32) of 2018-05-30 Repository revision: 07f8f9bc5a51f5aa94eb099f3e15fbe0c20ea1ea Windowing system distributor `Microsoft Corp.', version 10.0.17134 Configured using: `configure --without-dbus --host=3Dx86_64-w64-mingw32 --without-compress-install 'CFLAGS=3D-O2 -static -g3''