From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner Newsgroups: gmane.emacs.devel Subject: Unexpected behavior of format-number with format-prompt Date: Wed, 06 Nov 2024 12:06:02 -0800 Message-ID: <875xp0b00l.fsf@breatheoutbreathe.in> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24179"; mail-complaints-to="usenet@ciao.gmane.io" To: Emacs Devel Mailing List Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 07 06:31:48 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t8v7U-000679-0z for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Nov 2024 06:31:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8v6j-0004b0-G1; Thu, 07 Nov 2024 00:31:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8mIG-0002zt-GJ for emacs-devel@gnu.org; Wed, 06 Nov 2024 15:06:20 -0500 Original-Received: from out-170.mta1.migadu.com ([2001:41d0:203:375::aa]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8mIA-0007n9-N7 for emacs-devel@gnu.org; Wed, 06 Nov 2024 15:06:18 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1730923568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=xwqYZ8s3zjM+79NrFtYoSgWnUcP4iqAOF8eZZB506TQ=; b=PfWPwwcS2kMH2NRq2yWMBiMkfzt++qZw9yZ30fN1cgDIPYLyCNmSAIKKJA2KMf+SumLy81 48mHLASfw1jNUgTviC3dlN/WUhxdjECNTMeOvzEr1XU0jAV6UgxobKlBRD1LTuP+eDBYpm Zk3kCgf7RRB0Sc5nUCTlIo+PwVoi59I= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:203:375::aa; envelope-from=joseph@breatheoutbreathe.in; helo=out-170.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 07 Nov 2024 00:30:54 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325202 Archived-At: --=-=-= Content-Type: text/plain 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Don-t-insert-DEFAULT-value-into-prompt.patch >From f42643852249a07acf9181aca37af351ff52bb5b Mon Sep 17 00:00:00 2001 From: Joseph Turner 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 --=-=-= Content-Type: text/plain 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': --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Document-behavior-of-format-prompt-with-read-number.patch >From 0f3c690650e30201c725186bff3b91ef8fa4ee19 Mon Sep 17 00:00:00 2001 From: Joseph Turner 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 --=-=-= Content-Type: text/plain Thanks! Joseph --=-=-=--