unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gabriel <gabriel376@hotmail.com>
To: 47286@debbugs.gnu.org
Subject: bug#47286: 28.0.50; [PATCH] Replace "(default %s)" with 'format-prompt'
Date: Sun, 21 Mar 2021 21:03:15 -0300	[thread overview]
Message-ID: <CH2PR01MB58794A7BA6ED2E9EB0B27DD88B659@CH2PR01MB5879.prod.exchangelabs.com> (raw)
In-Reply-To: <2454249f-5987-8f04-a58e-0596f572bb0e@yandex.ru> (Dmitry Gutov's message of "Sun, 21 Mar 2021 20:57:04 +0200")

Dmitry Gutov <dgutov@yandex.ru> writes:
> Also note that project--completing-read-strict includes as (string-equal default
> "") check added in 2be537e64.
>
> Perhaps format-prompt could use it as well.

Do you mean to add a new check to 'format-prompt' to consider an empty
DEFAULT as nil, e.g., to not show it on minibuffer prompt in case the
value of the DEFAULT argument is an empty string ?

Also, maybe another useful check for 'format-prompt' would remove the
": " suffix from the PROMPT argument, to avoid displaying something like
"prompt: : ", which could avoid regressions when migrating existing
code.

Example of the new 'format-prompt':

(defun format-prompt (prompt default &rest format-args)
  "Format PROMPT with DEFAULT according to `minibuffer-default-prompt-format'.
If FORMAT-ARGS is nil, PROMPT is used as a plain string.  If
FORMAT-ARGS is non-nil, PROMPT is used as a format control
string, and FORMAT-ARGS are the arguments to be substituted into
it.  See `format' for details.

If DEFAULT is a list, the first element is used as the default.
If not, the element is used as is.

If DEFAULT is nil or an empty string, no \"default value\" string
is included in the return value."
  (let* ((suffix ": ")
         (prompt (if (string-suffix-p suffix prompt)
                     (substring prompt 0 (* -1 (length suffix)))
                   prompt))
         (default (if (equal "" default)
                      nil
                    default))
         (formatted-prompt (if (null format-args)
                               prompt
                             (apply #'format prompt format-args)))
         (formatted-default (and default
                                 (format minibuffer-default-prompt-format
                                         (if (consp default)
                                             (car default)
                                           default)))))
    (concat formatted-prompt
            formatted-default
            suffix)))





  reply	other threads:[~2021-03-22  0:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-20 22:22 bug#47286: 28.0.50; [PATCH] Replace "(default %s)" with 'format-prompt' Gabriel
2021-03-21  6:07 ` Eli Zaretskii
2021-03-21 18:22   ` Gabriel
2021-03-21 15:53 ` Kévin Le Gouguec
2021-03-21 18:31   ` Gabriel
2021-03-21 18:57     ` Dmitry Gutov
2021-03-22  0:03       ` Gabriel [this message]
2021-03-22  0:48         ` Dmitry Gutov
2021-03-22 19:06     ` Lars Ingebrigtsen
2021-03-23  3:47       ` Gabriel
2021-03-24  9:32         ` 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=CH2PR01MB58794A7BA6ED2E9EB0B27DD88B659@CH2PR01MB5879.prod.exchangelabs.com \
    --to=gabriel376@hotmail.com \
    --cc=47286@debbugs.gnu.org \
    /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).