diff src/minibuf.c @ 65758:028c8f536edb

(High-Level Completion): Explain that the prompt given to `read-buffer' should end with a colon and a space. Update usage examples.
author Romain Francoise <romain@orebokech.com>
date Fri, 30 Sep 2005 18:30:10 +0000
parents da27b91068ae
children 13abee3a9bc6 2a679c81f552 aa89c814f853
line wrap: on
line diff
--- a/src/minibuf.c	Fri Sep 30 18:29:18 2005 +0000
+++ b/src/minibuf.c	Fri Sep 30 18:30:10 2005 +0000
@@ -1132,11 +1132,14 @@
 Prompt with PROMPT.
 Optional second arg DEF is value to return if user enters an empty line.
 If optional third arg REQUIRE-MATCH is non-nil,
- only existing buffer names are allowed.  */)
+ only existing buffer names are allowed.
+The argument PROMPT should be a string ending with a colon and a space.  */)
      (prompt, def, require_match)
      Lisp_Object prompt, def, require_match;
 {
   Lisp_Object args[4];
+  unsigned char *s;
+  int len;
 
   if (BUFFERP (def))
     def = XBUFFER (def)->name;
@@ -1145,7 +1148,26 @@
     {
       if (!NILP (def))
 	{
-	  args[0] = build_string ("%s(default %s) ");
+	  /* 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 = SDATA (prompt);
+	      len = strlen (s);
+	      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));
+	    }
+
+	  args[0] = build_string ("%s (default %s): ");
 	  args[1] = prompt;
 	  args[2] = def;
 	  prompt = Fformat (3, args);