all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 35231@debbugs.gnu.org
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)	[thread overview]
Message-ID: <85ddecd9-7a66-4fbc-8297-b4419e45db05@default> (raw)

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 = 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=t and PREDICATE=`commandp'.

3. Because even with REQUIRE-MATCH=t 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= "" 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=x86_64-w64-mingw32
 --without-compress-install 'CFLAGS=-O2 -static -g3''





             reply	other threads:[~2019-04-11 15:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 15:10 Drew Adams [this message]
2019-07-09 15:39 ` bug#35231: 26.1; Redefine `read-command' behavior for empty input and DEFAULT not a command name Lars Ingebrigtsen
2019-07-09 16:17   ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85ddecd9-7a66-4fbc-8297-b4419e45db05@default \
    --to=drew.adams@oracle.com \
    --cc=35231@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.