emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unexpected behavior of format-number with format-prompt


From: Joseph Turner
Subject: Re: Unexpected behavior of format-number with format-prompt
Date: Sat, 09 Nov 2024 11:02:58 -0800

Stephen Berman <stephen.berman@gmx.net> writes:

> On Thu, 07 Nov 2024 16:47:40 +0200 Eli Zaretskii <eliz@gnu.org> wrote:
>
>>> From: Stephen Berman <stephen.berman@gmx.net>
>>> Cc: Joseph Turner <joseph@breatheoutbreathe.in>,  emacs-devel@gnu.org
>>> Date: Thu, 07 Nov 2024 14:50:27 +0100
>>>
>>> > More to the point: we cannot possibly change the behavior of
>>> > read-number in such a backward-incompatible way.  Especially since
>>> > this behavior is old, and explicitly called out in the doc string.  It
>>> > is perhaps unfortunate that read-number behaves differently in this
>>> > manner, but I'm afraid we will have to live with this.
>>>
>>> Maybe something like the attached patch is acceptable?  With it,
>>> evaluating each of the following prompts with "Enter (default 42): "
>>>
>>> (read-number "Enter: " 42)
>>> (read-number (format-prompt "Enter" 42))
>>> (read-number (format-prompt "Enter" 42) 42)
>>
>> This assumes that using the same format as
>> minibuffer-default-prompt-format necessarily means that format-prompt
>> is being used.  I'm not sure we can rely on that, it's too ad-hoc.
>
> The patch itself does not assume format-prompt but only checks whether
> the prompt uses minibuffer-default-prompt-format (which format-prompt
> does); the following also prompt with "Enter (default 42): ":
>
> (read-number (concat "Enter"
>                      (format minibuffer-default-prompt-format 42)
>                      ": "))
>
> (read-number (concat "Enter:"
>                      (format minibuffer-default-prompt-format 42)
>                      ": ")
>              42)
>
> So the reference to format-prompt in the comment I added is misleading
> and should be either removed or revised, e.g.: "If PROMPT uses
> `minibuffer-default-prompt-format' (as e.g. with `format-prompt'), don't
> duplicate DEFAULT in the prompt string."

I like your idea, but the DEFAULT argument passed to `format-prompt' may
be different from the DEFAULT argument passed to `read-number', so the
regex may not match.  For example,

(read-number (format-prompt "Read number" "three") 3)

would still prompt with

Read number (default three) (default 3):

[ Also /s/string-match/string-match-p ]

I think we're better off documenting the idiosyncrasy in the
`read-number' docstring as Eli suggested.

Thanks!

Joseph



reply via email to

[Prev in Thread] Current Thread [Next in Thread]