Mercurial > emacs
comparison src/minibuf.c @ 26320:d3926d907840
(string_to_object): New.
(read_minibuf_noninteractive): New.
(read_minibuf): Call read_minibuf_noninteractive if
noninteractive. Use string_to_object.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Wed, 03 Nov 1999 12:40:41 +0000 |
parents | d39ec0a27081 |
children | 10cb17dccd20 |
comparison
equal
deleted
inserted
replaced
26319:de1bf433d5f0 | 26320:d3926d907840 |
---|---|
208 static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object, | 208 static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object, |
209 Lisp_Object, Lisp_Object, | 209 Lisp_Object, Lisp_Object, |
210 int, Lisp_Object, | 210 int, Lisp_Object, |
211 Lisp_Object, Lisp_Object, | 211 Lisp_Object, Lisp_Object, |
212 int, int)); | 212 int, int)); |
213 static Lisp_Object read_minibuf_noninteractive P_ ((Lisp_Object, Lisp_Object, | |
214 Lisp_Object, Lisp_Object, | |
215 int, Lisp_Object, | |
216 Lisp_Object, Lisp_Object, | |
217 int, int)); | |
218 static Lisp_Object string_to_object P_ ((Lisp_Object, Lisp_Object)); | |
219 | |
220 | |
221 /* Read a Lisp object from VAL and return it. If VAL is an empty | |
222 string, and DEFALT is a string, read from DEFALT instead of VAL. */ | |
223 | |
224 static Lisp_Object | |
225 string_to_object (val, defalt) | |
226 Lisp_Object val, defalt; | |
227 { | |
228 struct gcpro gcpro1, gcpro2; | |
229 Lisp_Object expr_and_pos; | |
230 int pos; | |
231 | |
232 GCPRO2 (val, defalt); | |
233 | |
234 if (STRINGP (val) && XSTRING (val)->size == 0 | |
235 && STRINGP (defalt)) | |
236 val = defalt; | |
237 | |
238 expr_and_pos = Fread_from_string (val, Qnil, Qnil); | |
239 pos = XINT (Fcdr (expr_and_pos)); | |
240 if (pos != XSTRING (val)->size) | |
241 { | |
242 /* Ignore trailing whitespace; any other trailing junk | |
243 is an error. */ | |
244 int i; | |
245 pos = string_char_to_byte (val, pos); | |
246 for (i = pos; i < STRING_BYTES (XSTRING (val)); i++) | |
247 { | |
248 int c = XSTRING (val)->data[i]; | |
249 if (c != ' ' && c != '\t' && c != '\n') | |
250 error ("Trailing garbage following expression"); | |
251 } | |
252 } | |
253 | |
254 val = Fcar (expr_and_pos); | |
255 RETURN_UNGCPRO (val); | |
256 } | |
257 | |
258 | |
259 /* Like read_minibuf but reading from stdin. This function is called | |
260 from read_minibuf to do the job if noninteractive. */ | |
261 | |
262 static Lisp_Object | |
263 read_minibuf_noninteractive (map, initial, prompt, backup_n, expflag, | |
264 histvar, histpos, defalt, allow_props, | |
265 inherit_input_method) | |
266 Lisp_Object map; | |
267 Lisp_Object initial; | |
268 Lisp_Object prompt; | |
269 Lisp_Object backup_n; | |
270 int expflag; | |
271 Lisp_Object histvar; | |
272 Lisp_Object histpos; | |
273 Lisp_Object defalt; | |
274 int allow_props; | |
275 int inherit_input_method; | |
276 { | |
277 int size, len; | |
278 char *line, *s; | |
279 struct gcpro gcpro1, gcpro2; | |
280 Lisp_Object val; | |
281 | |
282 fprintf (stdout, "%s", XSTRING (prompt)->data); | |
283 fflush (stdout); | |
284 | |
285 size = 100; | |
286 len = 0; | |
287 line = (char *) xmalloc (size * sizeof *line); | |
288 while ((s = fgets (line + len, size - len, stdin)) != NULL | |
289 && (len = strlen (line), | |
290 len == size - 1 && line[len - 1] != '\n')) | |
291 { | |
292 size *= 2; | |
293 line = (char *) xrealloc (line, size); | |
294 } | |
295 | |
296 if (s) | |
297 { | |
298 len = strlen (line); | |
299 | |
300 if (len > 0 && line[len - 1] == '\n') | |
301 line[--len] = '\0'; | |
302 | |
303 val = build_string (line); | |
304 xfree (line); | |
305 } | |
306 else | |
307 { | |
308 xfree (line); | |
309 error ("Error reading from stdin"); | |
310 } | |
311 | |
312 /* If Lisp form desired instead of string, parse it. */ | |
313 if (expflag) | |
314 val = string_to_object (val, defalt); | |
315 | |
316 return val; | |
317 } | |
318 | |
213 | 319 |
214 /* Read from the minibuffer using keymap MAP, initial contents INITIAL | 320 /* Read from the minibuffer using keymap MAP, initial contents INITIAL |
215 (a string), putting point minus BACKUP_N bytes from the end of INITIAL, | 321 (a string), putting point minus BACKUP_N bytes from the end of INITIAL, |
216 prompting with PROMPT (a string), using history list HISTVAR | 322 prompting with PROMPT (a string), using history list HISTVAR |
217 with initial position HISTPOS. (BACKUP_N should be <= 0.) | 323 with initial position HISTPOS. (BACKUP_N should be <= 0.) |
276 else | 382 else |
277 /* If we're in another window, cancel the minibuffer that's active. */ | 383 /* If we're in another window, cancel the minibuffer that's active. */ |
278 Fthrow (Qexit, | 384 Fthrow (Qexit, |
279 build_string ("Command attempted to use minibuffer while in minibuffer")); | 385 build_string ("Command attempted to use minibuffer while in minibuffer")); |
280 } | 386 } |
387 | |
388 if (noninteractive) | |
389 return read_minibuf_noninteractive (map, initial, prompt, backup_n, | |
390 expflag, histvar, histpos, defalt, | |
391 allow_props, inherit_input_method); | |
281 | 392 |
282 /* Choose the minibuffer window and frame, and take action on them. */ | 393 /* Choose the minibuffer window and frame, and take action on them. */ |
283 | 394 |
284 choose_minibuf_frame (); | 395 choose_minibuf_frame (); |
285 | 396 |
504 } | 615 } |
505 } | 616 } |
506 | 617 |
507 /* If Lisp form desired instead of string, parse it. */ | 618 /* If Lisp form desired instead of string, parse it. */ |
508 if (expflag) | 619 if (expflag) |
509 { | 620 val = string_to_object (val, defalt); |
510 Lisp_Object expr_and_pos; | |
511 int pos; | |
512 | |
513 if (STRINGP (val) && XSTRING (val)->size == 0 | |
514 && STRINGP (defalt)) | |
515 val = defalt; | |
516 | |
517 expr_and_pos = Fread_from_string (val, Qnil, Qnil); | |
518 pos = XINT (Fcdr (expr_and_pos)); | |
519 if (pos != XSTRING (val)->size) | |
520 { | |
521 /* Ignore trailing whitespace; any other trailing junk is an error. */ | |
522 int i; | |
523 pos = string_char_to_byte (val, pos); | |
524 for (i = pos; i < STRING_BYTES (XSTRING (val)); i++) | |
525 { | |
526 int c = XSTRING (val)->data[i]; | |
527 if (c != ' ' && c != '\t' && c != '\n') | |
528 error ("Trailing garbage following expression"); | |
529 } | |
530 } | |
531 val = Fcar (expr_and_pos); | |
532 } | |
533 | 621 |
534 /* The appropriate frame will get selected | 622 /* The appropriate frame will get selected |
535 in set-window-configuration. */ | 623 in set-window-configuration. */ |
536 RETURN_UNGCPRO (unbind_to (count, val)); | 624 RETURN_UNGCPRO (unbind_to (count, val)); |
537 } | 625 } |