unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ryan Thompson <rct@thompsonclan.org>
To: Drew Adams <drew.adams@oracle.com>,
	Dmitry Gutov <dgutov@yandex.ru>,
	27158@debbugs.gnu.org
Subject: bug#27158: 25.2; Eliminating old usage of completing-read from built-in files
Date: Wed, 31 May 2017 15:44:15 +0000	[thread overview]
Message-ID: <CAHCt_abn99xFvEZdp5xQmQMx-VxoWd87OkX2EBC8u5mZwdTi_g@mail.gmail.com> (raw)
In-Reply-To: <3d3bc85b-31d3-4701-8acd-45591d075253@default>

[-- Attachment #1: Type: text/plain, Size: 2286 bytes --]

>
> 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 ... <whatever floats your boat>.
>

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.

[-- Attachment #2: Type: text/html, Size: 4779 bytes --]

  reply	other threads:[~2017-05-31 15:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31  4:41 bug#27158: 25.2; Eliminating old usage of completing-read from built-in files Ryan
2017-05-31  5:52 ` Drew Adams
2017-05-31 11:45   ` Ryan Thompson
2017-05-31 14:51     ` Drew Adams
2017-05-31 12:23   ` Dmitry Gutov
2017-05-31 14:51     ` Drew Adams
2017-05-31 14:59       ` Dmitry Gutov
2017-05-31 15:19         ` Drew Adams
2017-05-31 15:44           ` Ryan Thompson [this message]
2017-05-31 22:41             ` Dmitry Gutov
2017-05-31 23:16               ` Drew Adams
2017-05-31 23:54                 ` Dmitry Gutov
2017-06-01  2:23                   ` Drew Adams
2017-06-01  9:27                     ` Dmitry Gutov
2017-06-01 14:57                       ` Drew Adams
2017-06-01 20:53                         ` Dmitry Gutov
2017-06-01 21:04                           ` Ryan Thompson
2017-06-05 23:01                             ` Dmitry Gutov
2017-06-06  0:06                               ` Ryan Thompson
2017-06-06  0:09                                 ` Dmitry Gutov
2017-05-31 21:20           ` Dmitry Gutov
2020-08-24 14:58 ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=CAHCt_abn99xFvEZdp5xQmQMx-VxoWd87OkX2EBC8u5mZwdTi_g@mail.gmail.com \
    --to=rct@thompsonclan.org \
    --cc=27158@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=drew.adams@oracle.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).