diff --git a/src/minibuf.c b/src/minibuf.c index 58adde1bf66..a1cbf4747f5 100644 --- 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 = SSDATA (prompt); - len = SBYTES (prompt); - if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ') - len = len - 2; - else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' ')) - len--; - - prompt = make_specified_string (s, -1, len, - STRING_MULTIBYTE (prompt)); - } + if (STRINGP (prompt)) + { + s = SSDATA (prompt); + len = SBYTES (prompt); + if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ') + len = len - 2; + else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' ')) + len--; + + prompt = make_specified_string (s, -1, len, + STRING_MULTIBYTE (prompt)); + } - prompt = CALLN (Ffuncall, intern("format-prompt"), - prompt, - CONSP (def) ? XCAR (def) : def); - } + prompt = CALLN (Ffuncall, intern("format-prompt"), + prompt, + CONSP (def) ? XCAR (def) : def); + if (NILP (Vread_buffer_function)) + { result = Fcompleting_read (prompt, intern ("internal-complete-buffer"), predicate, require_match, Qnil, Qbuffer_name_history, def, Qnil);