1132 |
Prompt with PROMPT. |
Prompt with PROMPT. |
1133 |
Optional second arg DEF is value to return if user enters an empty line. |
Optional second arg DEF is value to return if user enters an empty line. |
1134 |
If optional third arg REQUIRE-MATCH is non-nil, |
If optional third arg REQUIRE-MATCH is non-nil, |
1135 |
only existing buffer names are allowed. */) |
only existing buffer names are allowed. |
1136 |
|
The argument PROMPT should be a string ending with a colon and a space. */) |
1137 |
(prompt, def, require_match) |
(prompt, def, require_match) |
1138 |
Lisp_Object prompt, def, require_match; |
Lisp_Object prompt, def, require_match; |
1139 |
{ |
{ |
1140 |
Lisp_Object args[4]; |
Lisp_Object args[4]; |
1141 |
|
unsigned char *s; |
1142 |
|
int len; |
1143 |
|
|
1144 |
if (BUFFERP (def)) |
if (BUFFERP (def)) |
1145 |
def = XBUFFER (def)->name; |
def = XBUFFER (def)->name; |
1148 |
{ |
{ |
1149 |
if (!NILP (def)) |
if (!NILP (def)) |
1150 |
{ |
{ |
1151 |
args[0] = build_string ("%s(default %s) "); |
/* 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): "); |
1171 |
args[1] = prompt; |
args[1] = prompt; |
1172 |
args[2] = def; |
args[2] = def; |
1173 |
prompt = Fformat (3, args); |
prompt = Fformat (3, args); |