+ val = Qnil;
+ size = 100;
+ len = 0;
+ line = (char *) xmalloc (size * sizeof *line);
+ while ((s = fgets (line + len, size - len, stdin)) != NULL
+ && (len = strlen (line),
+ len == size - 1 && line[len - 1] != '\n'))
+ {
+ size *= 2;
+ line = (char *) xrealloc (line, size);
+ }
+
+ if (s)
+ {
+ len = strlen (line);
+
+ if (len > 0 && line[len - 1] == '\n')
+ line[--len] = '\0';
+
+ val = build_string (line);
+ xfree (line);
+ }
+ else
+ {
+ xfree (line);
+ error ("Error reading from stdin");
+ }
+
+ /* If Lisp form desired instead of string, parse it. */
+ if (expflag)
+ val = string_to_object (val, defalt);
+
+ return val;
+}
+\f
+DEFUN ("minibufferp", Fminibufferp,
+ Sminibufferp, 0, 1, 0,
+ doc: /* Return t if BUFFER is a minibuffer.
+No argument or nil as argument means use current buffer as BUFFER.
+BUFFER can be a buffer or a buffer name. */)
+ (buffer)
+ Lisp_Object buffer;
+{
+ Lisp_Object tem;
+
+ if (NILP (buffer))
+ buffer = Fcurrent_buffer ();
+ else if (STRINGP (buffer))
+ buffer = Fget_buffer (buffer);
+ else
+ CHECK_BUFFER (buffer);
+
+ tem = Fmemq (buffer, Vminibuffer_list);
+ return ! NILP (tem) ? Qt : Qnil;
+}
+
+DEFUN ("minibuffer-prompt-end", Fminibuffer_prompt_end,
+ Sminibuffer_prompt_end, 0, 0, 0,
+ doc: /* Return the buffer position of the end of the minibuffer prompt.
+Return (point-min) if current buffer is not a minibuffer. */)
+ ()
+{
+ /* This function is written to be most efficient when there's a prompt. */
+ Lisp_Object beg, end, tem;
+ beg = make_number (BEGV);
+
+ tem = Fmemq (Fcurrent_buffer (), Vminibuffer_list);
+ if (NILP (tem))
+ return beg;
+
+ end = Ffield_end (beg, Qnil, Qnil);
+
+ if (XINT (end) == ZV && NILP (Fget_char_property (beg, Qfield, Qnil)))
+ return beg;
+ else
+ return end;
+}
+
+DEFUN ("minibuffer-contents", Fminibuffer_contents,
+ Sminibuffer_contents, 0, 0, 0,
+ doc: /* Return the user input in a minibuffer as a string.
+The current buffer must be a minibuffer. */)
+ ()
+{
+ int prompt_end = XINT (Fminibuffer_prompt_end ());
+ return make_buffer_string (prompt_end, ZV, 1);
+}
+
+DEFUN ("minibuffer-contents-no-properties", Fminibuffer_contents_no_properties,
+ Sminibuffer_contents_no_properties, 0, 0, 0,
+ doc: /* Return the user input in a minibuffer as a string, without text-properties.
+The current buffer must be a minibuffer. */)
+ ()
+{
+ int prompt_end = XINT (Fminibuffer_prompt_end ());
+ return make_buffer_string (prompt_end, ZV, 0);
+}
+
+DEFUN ("delete-minibuffer-contents", Fdelete_minibuffer_contents,
+ Sdelete_minibuffer_contents, 0, 0, 0,
+ doc: /* Delete all user input in a minibuffer.
+The current buffer must be a minibuffer. */)
+ ()
+{
+ int prompt_end = XINT (Fminibuffer_prompt_end ());
+ if (prompt_end < ZV)
+ del_range (prompt_end, ZV);
+ return Qnil;
+}
+
+/* Get the text in the minibuffer before point.
+ That is what completion commands operate on. */
+
+Lisp_Object
+minibuffer_completion_contents ()
+{
+ int prompt_end = XINT (Fminibuffer_prompt_end ());
+ if (PT < prompt_end)
+ error ("Cannot do completion in the prompt");
+ return make_buffer_string (prompt_end, PT, 1);
+}
+\f
+/* Read from the minibuffer using keymap MAP and initial contents INITIAL,
+ putting point minus BACKUP_N bytes from the end of INITIAL,