comparison 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
comparison
equal deleted inserted replaced
65757:ee26002f84d8 65758:028c8f536edb
1130 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0, 1130 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0,
1131 doc: /* Read the name of a buffer and return as a string. 1131 doc: /* Read the name of a buffer and return as a string.
1132 Prompt with PROMPT. 1132 Prompt with PROMPT.
1133 Optional second arg DEF is value to return if user enters an empty line. 1133 Optional second arg DEF is value to return if user enters an empty line.
1134 If optional third arg REQUIRE-MATCH is non-nil, 1134 If optional third arg REQUIRE-MATCH is non-nil,
1135 only existing buffer names are allowed. */) 1135 only existing buffer names are allowed.
1136 The argument PROMPT should be a string ending with a colon and a space. */)
1136 (prompt, def, require_match) 1137 (prompt, def, require_match)
1137 Lisp_Object prompt, def, require_match; 1138 Lisp_Object prompt, def, require_match;
1138 { 1139 {
1139 Lisp_Object args[4]; 1140 Lisp_Object args[4];
1141 unsigned char *s;
1142 int len;
1140 1143
1141 if (BUFFERP (def)) 1144 if (BUFFERP (def))
1142 def = XBUFFER (def)->name; 1145 def = XBUFFER (def)->name;
1143 1146
1144 if (NILP (Vread_buffer_function)) 1147 if (NILP (Vread_buffer_function))
1145 { 1148 {
1146 if (!NILP (def)) 1149 if (!NILP (def))
1147 { 1150 {
1148 args[0] = build_string ("%s(default %s) "); 1151 /* A default value was provided: we must change PROMPT,
1152 editing the default value in before the colon. To achieve
1153 this, we replace PROMPT with a substring that doesn't
1154 contain the terminal space and colon (if present). They
1155 are then added back using Fformat. */
1156
1157 if (STRINGP (prompt))
1158 {
1159 s = SDATA (prompt);
1160 len = strlen (s);
1161 if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ')
1162 len = len - 2;
1163 else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' '))
1164 len--;
1165
1166 prompt = make_specified_string (s, -1, len,
1167 STRING_MULTIBYTE (prompt));
1168 }
1169
1170 args[0] = build_string ("%s (default %s): ");
1149 args[1] = prompt; 1171 args[1] = prompt;
1150 args[2] = def; 1172 args[2] = def;
1151 prompt = Fformat (3, args); 1173 prompt = Fformat (3, args);
1152 } 1174 }
1153 1175