diff --git a/src/minibuf.c b/src/minibuf.c index 58adde1bf66..4318cab04cb 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -1343,10 +1343,34 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer, (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 = 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 (default_value) ? XCAR (default_value) : default_value); + if (NILP (keymap)) keymap = Vminibuffer_local_map; else @@ -1473,8 +1497,7 @@ DEFUN ("read-variable", Fread_variable, Sread_variable, 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 space. -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 = 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 = 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); - } - - result = Fcompleting_read (prompt, intern ("internal-complete-buffer"), - predicate, require_match, Qnil, - Qbuffer_name_history, def, Qnil); - } + result = Fcompleting_read (prompt, intern ("internal-complete-buffer"), + predicate, require_match, Qnil, + Qbuffer_name_history, def, Qnil); else result = (NILP (predicate) /* Partial backward compatibility for older read_buffer_functions @@ -1978,7 +1971,7 @@ DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0, 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 space. +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.