From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#65736: 30.0.50; Extending the use of format-prompt Date: Mon, 04 Sep 2023 18:31:23 +0200 Message-ID: <87jzt599yc.fsf@gmx.net> 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="14794"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 65736@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 04 18:32:38 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qdCVC-0003f6-4B for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Sep 2023 18:32:38 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdCUx-0008Aw-Ad; Mon, 04 Sep 2023 12:32:23 -0400 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 1qdCUi-00081w-3U for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2023 12:32:13 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qdCUc-0003D3-6D for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2023 12:32:07 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qdCUb-0007Pm-UH for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2023 12:32:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 Sep 2023 16:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65736 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169384510228469 (code B ref -1); Mon, 04 Sep 2023 16:32:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Sep 2023 16:31:42 +0000 Original-Received: from localhost ([127.0.0.1]:52417 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qdCUH-0007P6-E6 for submit@debbugs.gnu.org; Mon, 04 Sep 2023 12:31:42 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:44372) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qdCUB-0007Op-CZ for submit@debbugs.gnu.org; Mon, 04 Sep 2023 12:31:39 -0400 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 1qdCU6-0007pP-0T for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2023 12:31:30 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdCU2-00037Z-Vv for bug-gnu-emacs@gnu.org; Mon, 04 Sep 2023 12:31:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1693845084; x=1694449884; i=stephen.berman@gmx.net; bh=RRfq8xAqfOJVDXDL0/eypltsZFtOho9IPmI7VDW/Akw=; h=X-UI-Sender-Class:From:To:Subject:Date; b=oh9o1Nnu7Sxuenb1jjgNYO8QsO2XFO6ONNJ1+N2zhhQQgH7XOAYSu129WFecZplBwUTPk5D 88vVjcqKQd6OAUQwXnaUg/1JzvTLsEjT/lAi1cPRXYJrhi+MmFSFiIddY3vUCRGS7x9S//ckf WWb+3KaOlgHzYIBmYH/Nd5NfFz5uTFuLZkf8GFMvHVJf7r8f8lR76qFA5Gep0hvdCKUFponMc Ixc5mF1ArmviivIxnTjke5F6sgu0aUS4SyRRXf7+ZmBJcp70Tcn7+EDUxJUXTzAw17OweZhuy NrVnFOc4Iqtv6tRd2Z6T22rif9FL5rqgIqNV9T5vLWzfoTfLyJAg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfssd ([94.134.196.62]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mn2aN-1ptzmF0SsZ-00k4Ua for ; Mon, 04 Sep 2023 18:31:24 +0200 X-Provags-ID: V03:K1:up5I1hfnKR4uF2j1XayZdwvB6JhfyfRgIVuTPRJQniacMmMHyan /gz9pFfXlivQzdtXdZz199mETokNw06PARMxsOl6IqYihIhjX0YMmxm/6hL2iPCH1RdXc23 NtxFSNwxUcWKUIssO21/Uxyy/763VMM91Clx/9m6sqKS0yOe/dFEUuNavtYST3dxjrSDSRM eix/mbrxzKugU9i1F9vsg== UI-OutboundReport: notjunk:1;M01:P0:+T76QsfvqQQ=;bu7WDe4JITVI3Sv3S38+96Sz3vm dGinps+8VghIS6oDHU3XxTvHXaDmWSBIDsBv6kwsKMQhxEdsd6Pt1d+rabS9XWWPQi30qn9b9 4S81CcbrswwlmDzRFeWi+vrFkPdsa4nlOzt3qPdEoutQ90UwX16nND3gCi3f+P7a8dNQlmWIr VXmI+oHPEQ2I4UvunQFdLZrbjNdjq9zhZldirLXdH4+/GrRrU0h839NHU3HN1wDLB19Oo7/BB gWSy2mSmISF1QMC6v7AJ6W4jN3snEprUUb+FbOJT6nxPsmZNOSOWBdPztEx3+eOLjFXM5pnWs CeTfd2tXBGjL0c5K8BPWvLSvX1O5Sum0jHn4TNVxgeeM9TMVIN3z5qab0/7ekmBkTJT8tT9o3 xLAOOfp5ZngriBGDpcAZ2WCUEGku5uubx6FPbema72tmeUZPxexb+fqw2FUS3jIlWIyqEW4QO N9gTa9SOo9hh5dY2e+STH41dbVvwXn0AJJu9EQn7XNwFv2aK9BFN3rvgdhCF8lcdOfE07a5QH qQ/w3z1nDrD/niYJUBkZSPODZUIBCb5GO7XW6ivns7yRVDnjq1wnK5BcRwsE8/6IUmd5GmKwP iJOWFBf2ctZJPFXhFdTswiLlyUmfeJjQH21GDzQBayOhsnKYGF9l7YQuf3+9A32QHePLZgmLL CoE1gc2SRK2g/bCrxO08ljYo5GgOtpUCyLxKsZEJjESvrPracA+RZHeX03UXuuefZZ6diStfj zwYEnCIg+U5Np7HL+qnTk9QoxmshFafONEbkkEkJPZfsLvQyVsVvXi35HVhm0nn/Ec+3J9Ct Received-SPF: pass client-ip=212.227.17.20; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:269261 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 0. emacs -Q 1. Invoke read-buffer with a prompt containg grave-style quoting and with no default buffer argument, e.g.: M-: (read-buffer "Enter `buffer': ") =3D> This displays the prompt in the minibuffer with grave-style quoting, i.e. as it appears in the invocation. 2. Repeat step 1 but add a default buffer argument, e.g.: M-: (read-buffer "Enter `buffer': " "*scratch*") =3D> This displays the prompt in the minibuffer with curve-style quoting: Enter =E2=80=98buffer=E2=80=99 (default *scratch*):=20=20 The different appearances of the prompt with and without the presence of a default argument is due to commit 50512e36c7, which passes the prompt string to format-prompt when read-buffer has a non-nil default argument DEF, but not when DEF is nil. (The purpose of that commit was to replace occurrences of prompts containing the string "(default %s)" by invocations of the then recently introduced function format-prompt; the fact that this function also calls substitute-command-keys was not a concern for that commit and its effect was presumably for that reason overlooked.) I think the simplest fix is to pass PROMPT to format-prompt regardless of the presence of a default argument of read-buffer, as in the first attached patch. But having substitute-command-keys always apply to the prompt string of read-buffer raises the question whether it should apply more generally to prompt strings. In fact, commit 50512e36c7 did change numerous mostly mode-specific prompts in several Lisp libraries to pass the prompt to format-prompt, but in almost all cases those prompts are fixed strings where applying substitute-command-keys makes no difference. But with read-buffer the prompt string is provided by the caller, so its appearance could be affected by substitute-command-keys. By default, read-buffer calls (in C) completing-read, which by default calls read-from-minibuffer, and indeed most, if not all, other functions that prompt for minibuffer input end up calling read-from-minibuffer. So passing the prompt string to format-prompt in read-from-minibuffer, as in the second attached patch (which should be applied instead of the first patch), would achieve a higher degree of consistency and simplicity in Emacs in the handling of prompts for minibuffer input, at least by default. (With functions that accept a user-defined function, like read-buffer-function with read-buffer, it would be up to the user to decide whether or not to use format-prompt, if the function does not invoke read-from-minibuffer.) If this change (the second patch) is accepted, it will probably require adjustments in the Emacs code base, e.g. to avoid double invocations of format-prompt. This would partly undo the changes made in 50512e36c7. I'd be willing to make the needed adjustments in Emacs. Steve Berman --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Description: read-buffer patch Content-Transfer-Encoding: quoted-printable diff --git a/src/minibuf.c b/src/minibuf.c index 58adde1bf66..a1cbf4747f5 100644 =2D-- a/src/minibuf.c +++ b/src/minibuf.c @@ -1502,34 +1502,30 @@ DEFUN ("read-buffer", Fread_buffer, Sread_buffer, = 1, 4, 0, specbind (Qcompletion_ignore_case, read_buffer_completion_ignore_case ? Qt : Qnil); - if (NILP (Vread_buffer_function)) - { - if (!NILP (def)) - { - /* A default value was provided: we must change PROMPT, - editing the default value in before the colon. To achieve - this, we replace PROMPT with a substring that doesn't - contain the terminal space and colon (if present). They - are then added back using Fformat. */ + /* For backward compatibility we accept prompt strings ending with a + colon and a space, but we have to delete them, if present, before + passing PROMPT to `format-prompt', which automatically appends + these characters to PROMPT. */ - if (STRINGP (prompt)) - { - s =3D SSDATA (prompt); - len =3D SBYTES (prompt); - if (len >=3D 2 && s[len - 2] =3D=3D ':' && s[len - 1] =3D=3D ' ') - len =3D len - 2; - else if (len >=3D 1 && (s[len - 1] =3D=3D ':' || s[len - 1] =3D=3D= ' ')) - len--; - - prompt =3D make_specified_string (s, -1, len, - STRING_MULTIBYTE (prompt)); - } + if (STRINGP (prompt)) + { + s =3D SSDATA (prompt); + len =3D SBYTES (prompt); + if (len >=3D 2 && s[len - 2] =3D=3D ':' && s[len - 1] =3D=3D ' ') + len =3D len - 2; + else if (len >=3D 1 && (s[len - 1] =3D=3D ':' || s[len - 1] =3D=3D = ' ')) + len--; + + prompt =3D make_specified_string (s, -1, len, + STRING_MULTIBYTE (prompt)); + } - prompt =3D CALLN (Ffuncall, intern("format-prompt"), - prompt, - CONSP (def) ? XCAR (def) : def); - } + prompt =3D CALLN (Ffuncall, intern("format-prompt"), + prompt, + CONSP (def) ? XCAR (def) : def); + if (NILP (Vread_buffer_function)) + { result =3D Fcompleting_read (prompt, intern ("internal-complete-buf= fer"), predicate, require_match, Qnil, Qbuffer_name_history, def, Qnil); --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Description: read-from-minibuffer patch Content-Transfer-Encoding: quoted-printable diff --git a/src/minibuf.c b/src/minibuf.c index 58adde1bf66..4318cab04cb 100644 =2D-- a/src/minibuf.c +++ b/src/minibuf.c @@ -1343,10 +1343,34 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuff= er, (Lisp_Object prompt, Lisp_Object initial_contents, Lisp_Object keymap, = Lisp_Object read, Lisp_Object hist, Lisp_Object default_value, Lisp_Object= inherit_input_method) { Lisp_Object histvar, histpos, val; + char *s; + ptrdiff_t len; barf_if_interaction_inhibited (); CHECK_STRING (prompt); + + /* For backward compatibility we accept prompt strings ending with a + colon and a space, but we have to delete them, if present, before + passing PROMPT to `format-prompt', which automatically appends + these characters to PROMPT. */ + + if (STRINGP (prompt)) + { + s =3D SSDATA (prompt); + len =3D SBYTES (prompt); + if (len >=3D 2 && s[len - 2] =3D=3D ':' && s[len - 1] =3D=3D ' ') + len =3D len - 2; + else if (len >=3D 1 && (s[len - 1] =3D=3D ':' || s[len - 1] =3D=3D = ' ')) + len--; + + prompt =3D make_specified_string (s, -1, len, + STRING_MULTIBYTE (prompt)); + } + + prompt =3D CALLN (Ffuncall, intern("format-prompt"), prompt, + CONSP (default_value) ? XCAR (default_value) : default_value); + if (NILP (keymap)) keymap =3D Vminibuffer_local_map; else @@ -1473,8 +1497,7 @@ DEFUN ("read-variable", Fread_variable, Sread_variab= le, 1, 2, 0, DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 4, 0, doc: /* Read the name of a buffer and return it as a string. -Prompt with PROMPT, which should be a string ending with a colon and a sp= ace. -Provides completion on buffer names the user types. +Prompt with string PROMPT. Provides completion on buffer names the user = types. Optional second arg DEF is value to return if user enters an empty line, instead of that empty string. If DEF is a list of default values, return its first element. @@ -1492,8 +1515,6 @@ DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1,= 4, 0, Lisp_Object predicate) { Lisp_Object result; - char *s; - ptrdiff_t len; specpdl_ref count =3D SPECPDL_INDEX (); if (BUFFERP (def)) @@ -1503,37 +1524,9 @@ DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1= , 4, 0, read_buffer_completion_ignore_case ? Qt : Qnil); if (NILP (Vread_buffer_function)) - { - if (!NILP (def)) - { - /* A default value was provided: we must change PROMPT, - editing the default value in before the colon. To achieve - this, we replace PROMPT with a substring that doesn't - contain the terminal space and colon (if present). They - are then added back using Fformat. */ - - if (STRINGP (prompt)) - { - s =3D SSDATA (prompt); - len =3D SBYTES (prompt); - if (len >=3D 2 && s[len - 2] =3D=3D ':' && s[len - 1] =3D=3D ' ') - len =3D len - 2; - else if (len >=3D 1 && (s[len - 1] =3D=3D ':' || s[len - 1] =3D=3D= ' ')) - len--; - - prompt =3D make_specified_string (s, -1, len, - STRING_MULTIBYTE (prompt)); - } - - prompt =3D CALLN (Ffuncall, intern("format-prompt"), - prompt, - CONSP (def) ? XCAR (def) : def); - } - - result =3D Fcompleting_read (prompt, intern ("internal-complete-buf= fer"), - predicate, require_match, Qnil, - Qbuffer_name_history, def, Qnil); - } + result =3D Fcompleting_read (prompt, intern ("internal-complete-buffe= r"), + predicate, require_match, Qnil, + Qbuffer_name_history, def, Qnil); else result =3D (NILP (predicate) /* Partial backward compatibility for older read_buffer_functions @@ -1978,7 +1971,7 @@ DEFUN ("all-completions", Fall_completions, Sall_com= pletions, 2, 4, 0, =0C DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, doc: /* Read a string in the minibuffer, with completion. -PROMPT is a string to prompt with; normally it ends in a colon and a spac= e. +PROMPT is a string to prompt with. COLLECTION can be a list of strings, an alist, an obarray or a hash table= . COLLECTION can also be a function to do the completion itself. PREDICATE limits completion to a subset of COLLECTION. --=-=-=--