unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Unexpected behavior of format-number with format-prompt
@ 2024-11-06 20:06 Joseph Turner
  2024-11-07  7:36 ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Joseph Turner @ 2024-11-06 20:06 UTC (permalink / raw)
  To: Emacs Devel Mailing List

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

When used with `read-string' (and other read-* functions),
`format-prompt' DTRT:

(let ((default "foo"))
  (read-string (format-prompt "Read" default) default))

The prompt looks like: "Read (default foo): "

However, `read-number' adds its own default argument:

(let ((default 1))
  (read-number (format-prompt "Read" default) default))

Prompt looks like: "Read (default 1) (default 1): "

This patch makes the behavior of `read-number' consistent with other
read-* functions:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Don-t-insert-DEFAULT-value-into-prompt.patch --]
[-- Type: text/x-diff, Size: 1361 bytes --]

From f42643852249a07acf9181aca37af351ff52bb5b Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
Date: Wed, 6 Nov 2024 11:54:31 -0800
Subject: [PATCH] Don't insert DEFAULT value into prompt

* lisp/subr.el (read-number): Don't insert default value into prompt.
---
 lisp/subr.el | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index e630087b68f..aa37066609c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3424,20 +3424,12 @@ read-number-history
 (defun read-number (prompt &optional default hist)
   "Read a numeric value in the minibuffer, prompting with PROMPT.
 DEFAULT specifies a default value to return if the user just types RET.
-The value of DEFAULT is inserted into PROMPT.
 HIST specifies a history list variable.  See `read-from-minibuffer'
 for details of the HIST argument.
 
 This function is used by the `interactive' code letter \"n\"."
   (let ((n nil)
 	(default1 (if (consp default) (car default) default)))
-    (when default1
-      (setq prompt
-	    (if (string-match "\\(\\):[ \t]*\\'" prompt)
-		(replace-match (format minibuffer-default-prompt-format default1) t t prompt 1)
-	      (replace-regexp-in-string "[ \t]*\\'"
-					(format minibuffer-default-prompt-format default1)
-					prompt t t))))
     (while
 	(progn
 	  (let ((str (read-from-minibuffer
-- 
2.46.0


[-- Attachment #3: Type: text/plain, Size: 328 bytes --]


If this patch is acceptable, I'll update NEWS and submit patches to make
`read-number' calls in core to use `format-prompt'.

I understand that such a breaking change may not be acceptable since it
affects external packages as well.  In that case, this patch documents
the collision between `read-number' and `format-prompt':


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-Document-behavior-of-format-prompt-with-read-number.patch --]
[-- Type: text/x-diff, Size: 1066 bytes --]

From 0f3c690650e30201c725186bff3b91ef8fa4ee19 Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
Date: Wed, 6 Nov 2024 11:53:42 -0800
Subject: [PATCH] Document behavior of format-prompt with read-number

* doc/lispref/minibuf.texi (Text from Minibuffer): Update info manual.
---
 doc/lispref/minibuf.texi | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index c5b9176d628..8bb53f6d831 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -491,6 +491,10 @@ Text from Minibuffer
 
 If @var{default} is @code{nil}, there is no default value, and
 therefore no ``default value'' string is included in the result value.
+For historical reasons, @code{read-number} always adds its
+@code{default} argument to its prompt, so the @var{default} argument of
+@code{format-prompt} should be @code{nil} when its return value will be
+passed to @code{read-number}.
 If @var{default} is a non-@code{nil} list, the first element of the
 list is used in the prompt.
 
-- 
2.46.0


[-- Attachment #5: Type: text/plain, Size: 17 bytes --]


Thanks!

Joseph

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-11-16  4:26 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-06 20:06 Unexpected behavior of format-number with format-prompt Joseph Turner
2024-11-07  7:36 ` Eli Zaretskii
2024-11-07  7:44   ` Joseph Turner
2024-11-07  7:57     ` Eli Zaretskii
2024-11-09 19:18       ` Joseph Turner
2024-11-14  8:29         ` Eli Zaretskii
2024-11-14 23:57           ` Joseph Turner
2024-11-15 12:32             ` Eli Zaretskii
2024-11-16  4:26               ` Joseph Turner
2024-11-07 13:50   ` Stephen Berman
2024-11-07 14:47     ` Eli Zaretskii
2024-11-07 15:57       ` Stephen Berman
2024-11-09 19:02         ` Joseph Turner
2024-11-09 21:51           ` Stephen Berman
2024-11-10  3:55             ` Joseph Turner
2024-11-10 10:37               ` Stephen Berman
2024-11-10  5:46             ` Eli Zaretskii
2024-11-10 10:40               ` Stephen Berman

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).