(Qforeground_color, Qbackground_color): Declare.
[bpt/emacs.git] / src / minibuf.c
index 03cddcc..91230e6 100644 (file)
@@ -1,5 +1,6 @@
 /* Minibuffer input and completion.
-   Copyright (C) 1985, 1986, 93, 94, 95, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998
+         Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -85,6 +86,9 @@ Lisp_Object Qread_file_name_internal;
 Lisp_Object Qminibuffer_setup_hook, Vminibuffer_setup_hook;
 Lisp_Object Qminibuffer_exit_hook, Vminibuffer_exit_hook;
 
+/* Function to call to read a buffer name.  */
+Lisp_Object Vread_buffer_function; 
+
 /* Nonzero means completion ignores case.  */
 
 int completion_ignore_case;
@@ -179,12 +183,15 @@ without invoking the usual minibuffer commands.")
 \f
 /* Actual minibuffer invocation. */
 
-static void read_minibuf_unwind ();
-Lisp_Object get_minibuffer ();
-static Lisp_Object read_minibuf ();
+static Lisp_Object read_minibuf_unwind P_ ((Lisp_Object));
+static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object,
+                                    Lisp_Object, Lisp_Object,
+                                    int, Lisp_Object,
+                                    Lisp_Object, Lisp_Object,
+                                    int, int));
 
 /* Read from the minibuffer using keymap MAP, initial contents INITIAL
-   (a string), putting point minus BACKUP_N chars from the end of INITIAL,
+   (a string), putting point minus BACKUP_N bytes from the end of INITIAL,
    prompting with PROMPT (a string), using history list HISTVAR
    with initial position HISTPOS.  (BACKUP_N should be <= 0.)
 
@@ -212,6 +219,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
      Lisp_Object histvar;
      Lisp_Object histpos;
      Lisp_Object defalt;
+     int allow_props;
      int inherit_input_method;
 {
   Lisp_Object val;
@@ -365,8 +373,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   if (!NILP (initial))
     {
       Finsert (1, &initial);
-      if (!NILP (backup_n) && INTEGERP (backup_n))
-       Fgoto_char (make_number (PT + XFASTINT (backup_n)));
+      if (INTEGERP (backup_n))
+       Fforward_char (backup_n);
     }
 
   echo_area_glyphs = 0;
@@ -376,7 +384,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   current_buffer->keymap = map;
 
   /* Turn on an input method stored in INPUT_METHOD if any.  */
-  if (STRINGP (input_method) && Ffboundp (Qactivate_input_method))
+  if (STRINGP (input_method) && !NILP (Ffboundp (Qactivate_input_method)))
     call1 (Qactivate_input_method, input_method);
 
   /* If appropriate, copy enable-multibyte-characters into the minibuffer.  */
@@ -412,6 +420,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
 #endif
 
   /* VAL is the string of minibuffer text.  */
+
   last_minibuf_string = val;
 
   /* Add the value to the appropriate history list unless it is empty.  */
@@ -458,12 +467,26 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
     {
       Lisp_Object expr_and_pos;
       unsigned char *p;
+      int pos;
+
+      if (STRINGP (val) && XSTRING (val)->size == 0
+         && STRINGP (defalt))
+       val = defalt;
 
       expr_and_pos = Fread_from_string (val, Qnil, Qnil);
-      /* Ignore trailing whitespace; any other trailing junk is an error.  */
-      for (p = XSTRING (val)->data + XINT (Fcdr (expr_and_pos)); *p; p++)
-       if (*p != ' ' && *p != '\t' && *p != '\n')
-         error ("Trailing garbage following expression");
+      pos = XINT (Fcdr (expr_and_pos));
+      if (pos != XSTRING (val)->size)
+       {
+         /* Ignore trailing whitespace; any other trailing junk is an error.  */
+         int i;
+         pos = string_char_to_byte (val, pos);
+         for (i = pos; i < STRING_BYTES (XSTRING (val)); i++)
+           {
+             int c = XSTRING (val)->data[i];
+             if (c != ' ' && c != '\t' && c != '\n')
+               error ("Trailing garbage following expression");
+           }
+       }
       val = Fcar (expr_and_pos);
     }
 
@@ -520,7 +543,7 @@ get_minibuffer (depth)
 /* This function is called on exiting minibuffer, whether normally or not,
  and it restores the current window, buffer, etc. */
 
-static void
+static Lisp_Object
 read_minibuf_unwind (data)
      Lisp_Object data;
 {
@@ -579,6 +602,8 @@ read_minibuf_unwind (data)
   windows_or_buffers_changed++;
   XSETFASTINT (XWINDOW (window)->last_modified, 0);
   XSETFASTINT (XWINDOW (window)->last_overlay_modified, 0);
+
+  return Qnil;
 }
 \f
 
@@ -605,12 +630,12 @@ Fifth arg HIST, if non-nil, specifies a history list\n\
   and HISTPOS is the initial position (the position in the list\n\
   which INITIAL-CONTENTS corresponds to).\n\
   Positions are counted starting from 1 at the beginning of the list.\n\
-Sixth arg DEFAULT-VALUE is the default value.  If non-nil, it is used\n\
- for history commands, and as the value to return if the user enters\n\
- the empty string.\n\
-Seventh arg INHERIT-INPUT-METHOD non-nil means the minibuffer inherits\n\
- the current input method.\n\
-If the variable `minibuffer-allow-text-properties is non-nil,\n\
+Sixth arg DEFAULT-VALUE is the default value.  If non-nil, it is available\n\
+ for history commands; but `read-from-minibuffer' does NOT return DEFAULT-VALUE\n\
if the user enters empty input!  It returns the empty string.\n\
+Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
+ the current input method and the setting of enable-multibyte-characters.\n\
+If the variable `minibuffer-allow-text-properties' is non-nil,\n\
  then the string which is returned includes whatever text properties\n\
  were present in the minibuffer.  Otherwise the value has no text properties.")
   (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method)
@@ -675,8 +700,6 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1,
                      histvar, histpos, default_value,
                      minibuffer_allow_text_properties,
                      !NILP (inherit_input_method));
-  if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (default_value))
-    val = default_value;
   UNGCPRO;
   return val;
 }
@@ -714,30 +737,37 @@ If non-nil, second arg INITIAL-INPUT is a string to insert before reading.\n\
 The third arg HISTORY, if non-nil, specifies a history list\n\
   and optionally the initial position in the list.\n\
 See `read-from-minibuffer' for details of HISTORY argument.\n\
-The forth arg INHERIT-INPUT-METHOD non-nil means the minibuffer inherits\n\
-  the current input method.")
+Fourth arg DEFAULT-VALUE is the default value.  If non-nil, it is used\n\
+ for history commands, and as the value to return if the user enters\n\
+ the empty string.\n\
+Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
+ the current input method and the setting of enable-multibyte-characters.")
   (prompt, initial_input, history, default_value, inherit_input_method)
      Lisp_Object prompt, initial_input, history, default_value;
      Lisp_Object inherit_input_method;
 {
-  return Fread_from_minibuffer (prompt, initial_input, Qnil,
-                               Qnil, history, default_value,
-                               inherit_input_method);
+  Lisp_Object val;
+  val = Fread_from_minibuffer (prompt, initial_input, Qnil,
+                              Qnil, history, default_value,
+                              inherit_input_method);
+  if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (default_value))
+    val = default_value;
+  return val;
 }
 
 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0,
-  "Args PROMPT and INIT, strings.  Read a string from the terminal, not allowing blanks.\n\
-Prompt with PROMPT, and provide INIT as an initial value of the input string.\n\
-The third optional arg INHERIT-INPUT-METHOD non-nil means the minibuffer\n\
-  inherits the current input method.")
-  (prompt, init, inherit_input_method)
-     Lisp_Object prompt, init, inherit_input_method;
+  "Read a string from the terminal, not allowing blanks.\n\
+Prompt with PROMPT, and provide INITIAL as an initial value of the input string.\n\
+Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits\n\
+the current input method and the setting of enable-multibyte-characters.")
+  (prompt, initial, inherit_input_method)
+     Lisp_Object prompt, initial, inherit_input_method;
 {
   CHECK_STRING (prompt, 0);
-  if (! NILP (init))
-    CHECK_STRING (init, 1);
+  if (! NILP (initial))
+    CHECK_STRING (initial, 1);
 
-  return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil,
+  return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil,
                       0, Qminibuffer_history, make_number (0), Qnil, 0,
                       !NILP (inherit_input_method));
 }
@@ -748,9 +778,20 @@ Prompts with PROMPT.  By default, return DEFAULT-VALUE.")
   (prompt, default_value)
      Lisp_Object prompt, default_value;
 {
-  return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt,
-                                   Qnil, Qnil, default_value, Qnil),
-                 Qnil);
+  Lisp_Object name, default_string;
+
+  if (NILP (default_value))
+    default_string = Qnil;
+  else if (SYMBOLP (default_value))
+    XSETSTRING (default_string, XSYMBOL (default_value)->name);
+  else
+    default_string = default_value;
+    
+  name = Fcompleting_read (prompt, Vobarray, Qcommandp, Qt,
+                          Qnil, Qnil, default_string, Qnil);
+  if (NILP (name))
+    return name;
+  return Fintern (name, Qnil);
 }
 
 #ifdef NOTDEF
@@ -772,10 +813,21 @@ A user variable is one whose documentation starts with a `*' character.")
   (prompt, default_value)
      Lisp_Object prompt, default_value;
 {
-  return Fintern (Fcompleting_read (prompt, Vobarray,
-                                   Quser_variable_p, Qt,
-                                   Qnil, Qnil, default_value, Qnil),
-                 Qnil);
+  Lisp_Object name, default_string;
+
+  if (NILP (default_value))
+    default_string = Qnil;
+  else if (SYMBOLP (default_value))
+    XSETSTRING (default_string, XSYMBOL (default_value)->name);
+  else
+    default_string = default_value;
+    
+  name = Fcompleting_read (prompt, Vobarray,
+                          Quser_variable_p, Qt,
+                          Qnil, Qnil, default_string, Qnil);
+  if (NILP (name))
+    return name;
+  return Fintern (name, Qnil);
 }
 
 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0,
@@ -787,19 +839,32 @@ If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are a
      Lisp_Object prompt, def, require_match;
 {
   Lisp_Object tem;
-  Lisp_Object args[3];
-
+  Lisp_Object args[4];
+  
   if (BUFFERP (def))
     def = XBUFFER (def)->name;
-  if (!NILP (def))
+
+  if (NILP (Vread_buffer_function))
+    {
+      if (!NILP (def))
+       {
+         args[0] = build_string ("%s(default %s) ");
+         args[1] = prompt;
+         args[2] = def;
+         prompt = Fformat (3, args);
+       }
+
+      return Fcompleting_read (prompt, Vbuffer_alist, Qnil,
+                              require_match, Qnil, Qnil, def, Qnil);
+    }
+  else
     {
-      args[0] = build_string ("%s(default %s) ");
+      args[0] = Vread_buffer_function;
       args[1] = prompt;
       args[2] = def;
-      prompt = Fformat (3, args);
+      args[3] = require_match;
+      return Ffuncall(4, args);
     }
-  return Fcompleting_read (prompt, Vbuffer_alist, Qnil,
-                          require_match, Qnil, Qnil, def, Qnil);
 }
 \f
 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
@@ -826,7 +891,9 @@ or the symbol from the obarray.")
      Lisp_Object string, alist, predicate;
 {
   Lisp_Object bestmatch, tail, elt, eltstring;
+  /* Size in bytes of BESTMATCH.  */
   int bestmatchsize;
+  /* These are in bytes, too.  */
   int compare, matchsize;
   int list = CONSP (alist) || NILP (alist);
   int index, obsize;
@@ -887,9 +954,9 @@ or the symbol from the obarray.")
       /* Is this element a possible completion? */
 
       if (STRINGP (eltstring)
-         && XSTRING (string)->size <= XSTRING (eltstring)->size
+         && STRING_BYTES (XSTRING (string)) <= STRING_BYTES (XSTRING (eltstring))
          && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
-                      XSTRING (string)->size))
+                      STRING_BYTES (XSTRING (string))))
        {
          /* Yes. */
          Lisp_Object regexps;
@@ -927,10 +994,13 @@ or the symbol from the obarray.")
 
          matchcount++;
          if (NILP (bestmatch))
-           bestmatch = eltstring, bestmatchsize = XSTRING (eltstring)->size;
+           {
+             bestmatch = eltstring;
+             bestmatchsize = STRING_BYTES (XSTRING (eltstring));
+           }
          else
            {
-             compare = min (bestmatchsize, XSTRING (eltstring)->size);
+             compare = min (bestmatchsize, STRING_BYTES (XSTRING (eltstring)));
              matchsize = scmp (XSTRING (bestmatch)->data,
                                XSTRING (eltstring)->data,
                                compare);
@@ -942,8 +1012,8 @@ or the symbol from the obarray.")
                     use it as the best match rather than one that is not an
                     exact match.  This way, we get the case pattern
                     of the actual match.  */
-                 if ((matchsize == XSTRING (eltstring)->size
-                      && matchsize < XSTRING (bestmatch)->size)
+                 if ((matchsize == STRING_BYTES (XSTRING (eltstring))
+                      && matchsize < STRING_BYTES (XSTRING (bestmatch)))
                      ||
                      /* If there is more than one exact match ignoring case,
                         and one of them is exact including case,
@@ -951,13 +1021,15 @@ or the symbol from the obarray.")
                      /* If there is no exact match ignoring case,
                         prefer a match that does not change the case
                         of the input.  */
-                     ((matchsize == XSTRING (eltstring)->size)
+                     ((matchsize == STRING_BYTES (XSTRING (eltstring)))
                       ==
-                      (matchsize == XSTRING (bestmatch)->size)
+                      (matchsize == STRING_BYTES (XSTRING (bestmatch)))
                       && !bcmp (XSTRING (eltstring)->data,
-                                XSTRING (string)->data, XSTRING (string)->size)
+                                XSTRING (string)->data,
+                                STRING_BYTES (XSTRING (string)))
                       && bcmp (XSTRING (bestmatch)->data,
-                               XSTRING (string)->data, XSTRING (string)->size)))
+                               XSTRING (string)->data,
+                               STRING_BYTES (XSTRING (string)))))
                    bestmatch = eltstring;
                }
              bestmatchsize = matchsize;
@@ -970,17 +1042,19 @@ or the symbol from the obarray.")
   /* If we are ignoring case, and there is no exact match,
      and no additional text was supplied,
      don't change the case of what the user typed.  */
-  if (completion_ignore_case && bestmatchsize == XSTRING (string)->size
-      && XSTRING (bestmatch)->size > bestmatchsize)
+  if (completion_ignore_case && bestmatchsize == STRING_BYTES (XSTRING (string))
+      && STRING_BYTES (XSTRING (bestmatch)) > bestmatchsize)
     return string;
 
   /* Return t if the supplied string is an exact match (counting case);
      it does not require any change to be made.  */
-  if (matchcount == 1 && bestmatchsize == XSTRING (string)->size
+  if (matchcount == 1 && bestmatchsize == STRING_BYTES (XSTRING (string))
       && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data,
                bestmatchsize))
     return Qt;
 
+  bestmatchsize = string_byte_to_char (bestmatch, bestmatchsize);
+
   XSETFASTINT (zero, 0);               /* Else extract the part in which */
   XSETFASTINT (end, bestmatchsize);    /* all completions agree */
   return Fsubstring (bestmatch, zero, end);
@@ -1108,14 +1182,15 @@ are ignored unless STRING itself starts with a space.")
       /* Is this element a possible completion? */
 
       if (STRINGP (eltstring)
-         && XSTRING (string)->size <= XSTRING (eltstring)->size
+         && STRING_BYTES (XSTRING (string)) <= STRING_BYTES (XSTRING (eltstring))
          /* If HIDE_SPACES, reject alternatives that start with space
             unless the input starts with space.  */
-         && ((XSTRING (string)->size > 0 && XSTRING (string)->data[0] == ' ')
+         && ((STRING_BYTES (XSTRING (string)) > 0
+              && XSTRING (string)->data[0] == ' ')
              || XSTRING (eltstring)->data[0] != ' '
              || NILP (hide_spaces))
          && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
-                      XSTRING (string)->size))
+                      STRING_BYTES (XSTRING (string))))
        {
          /* Yes. */
          Lisp_Object regexps;
@@ -1187,12 +1262,12 @@ HIST, if non-nil, specifies a history list\n\
   or it can be a cons cell (HISTVAR . HISTPOS).\n\
   In that case, HISTVAR is the history list variable to use,\n\
   and HISTPOS is the initial position (the position in the list\n\
-  which INITIAL-CONTENTS corresponds to).\n\
+  which INITIAL-INPUT corresponds to).\n\
   Positions are counted starting from 1 at the beginning of the list.\n\
 DEF, if non-nil, is the default value.\n\
 \n\
 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits\n\
-  the current input method.\n\
+  the current input method and the setting of enable-multibyte-characters.\n\
 \n\
 Completion ignores case if the ambient value of\n\
   `completion-ignore-case' is non-nil."
@@ -1255,16 +1330,15 @@ DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
                      init, prompt, make_number (pos), 0,
                      histvar, histpos, def, 0,
                      !NILP (inherit_input_method));
+
   if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (def))
     val = def;
+
   RETURN_UNGCPRO (unbind_to (count, val));
 }
 \f
 Lisp_Object Fminibuffer_completion_help ();
 Lisp_Object assoc_for_completion ();
-/* A subroutine of Fintern_soft.  */
-extern Lisp_Object oblookup ();
-
 
 /* Test whether TXT is an exact completion.  */
 Lisp_Object
@@ -1280,7 +1354,9 @@ test_completion (txt)
     {
       /* Bypass intern-soft as that loses for nil */
       tem = oblookup (Vminibuffer_completion_table,
-                     XSTRING (txt)->data, XSTRING (txt)->size);
+                     XSTRING (txt)->data,
+                     XSTRING (txt)->size,
+                     STRING_BYTES (XSTRING (txt)));
       if (!SYMBOLP (tem))
        return Qnil;
       else if (!NILP (Vminibuffer_completion_predicate))
@@ -1529,7 +1605,7 @@ Return nil if there is no valid completion, else t.")
   ()
 {
   Lisp_Object completion, tem;
-  register int i;
+  register int i, i_byte;
   register unsigned char *completion_string;
   struct gcpro gcpro1, gcpro2;
 
@@ -1566,7 +1642,7 @@ Return nil if there is no valid completion, else t.")
 #else /* Rewritten code */
   {
     register unsigned char *buffer_string;
-    int buffer_length, completion_length;
+    int buffer_nbytes, completion_nbytes;
 
     CHECK_STRING (completion, 0);
     tem = Fbuffer_string ();
@@ -1581,30 +1657,31 @@ Return nil if there is no valid completion, else t.")
          {
            tem = substituted;
            Ferase_buffer ();
-           insert_from_string (tem, 0, XSTRING (tem)->size, 0);
+           insert_from_string (tem, 0, 0, XSTRING (tem)->size,
+                               STRING_BYTES (XSTRING (tem)), 0);
          }
       }
     buffer_string = XSTRING (tem)->data;
     completion_string = XSTRING (completion)->data;
-    buffer_length = XSTRING (tem)->size; /* ie ZV - BEGV */
-    completion_length = XSTRING (completion)->size;
-    i = buffer_length - completion_length;
-    /* Mly: I don't understand what this is supposed to do AT ALL */
-    if (i > 0 ||
-       0 <= scmp (buffer_string, completion_string, buffer_length))
+    buffer_nbytes = STRING_BYTES (XSTRING (tem)); /* ie ZV_BYTE - BEGV_BYTE */
+    completion_nbytes = STRING_BYTES (XSTRING (completion));
+    i_byte = buffer_nbytes - completion_nbytes;
+    if (i_byte > 0 ||
+       0 <= scmp (buffer_string, completion_string, buffer_nbytes))
       {
        /* Set buffer to longest match of buffer tail and completion head. */
-       if (i <= 0) i = 1;
-       buffer_string += i;
-       buffer_length -= i;
-       while (0 <= scmp (buffer_string++, completion_string, buffer_length--))
-         i++;
-       del_range (1, i + 1);
-       SET_PT (ZV);
+       if (i_byte <= 0) i_byte = 1;
+       buffer_string += i_byte;
+       buffer_nbytes -= i_byte;
+       while (0 <= scmp (buffer_string++, completion_string, buffer_nbytes--))
+         i_byte++;
+       del_range_byte (1, i_byte + 1, 1);
+       SET_PT_BOTH (ZV, ZV_BYTE);
       }
     UNGCPRO;
   }
 #endif /* Rewritten code */
+  i_byte = ZV_BYTE - BEGV_BYTE;
   i = ZV - BEGV;
 
   /* If completion finds next char not unique,
@@ -1639,14 +1716,15 @@ Return nil if there is no valid completion, else t.")
     int len, c;
 
     completion_string = XSTRING (completion)->data;
-    for (; i < XSTRING (completion)->size; i += len)
+    for (; i_byte < STRING_BYTES (XSTRING (completion)); i_byte += len, i++)
       {
-       c = STRING_CHAR_AND_LENGTH (completion_string + i,
-                                   XSTRING (completion)->size - i,
+       c = STRING_CHAR_AND_LENGTH (completion_string + i_byte,
+                                   XSTRING (completion)->size - i_byte,
                                    len);
        if (SYNTAX (c) != Sword)
          {
-           i += len;
+           i_byte += len;
+           i++;
            break;
          }
       }
@@ -1654,7 +1732,7 @@ Return nil if there is no valid completion, else t.")
 
   /* If got no characters, print help for user.  */
 
-  if (i == ZV - BEGV)
+  if (i_byte == ZV_BYTE - BEGV_BYTE)
     {
       if (auto_help)
        Fminibuffer_completion_help ();
@@ -1664,7 +1742,7 @@ Return nil if there is no valid completion, else t.")
   /* Otherwise insert in minibuffer the chars we got */
 
   Ferase_buffer ();
-  insert_from_string (completion, 0, i, 1);
+  insert_from_string (completion, 0, 0, i, i_byte, 1);
   return Qt;
 }
 \f
@@ -1835,7 +1913,7 @@ DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0,
   ()
 {
   if (INTEGERP (last_command_char))
-    internal_self_insert (last_command_char, 0);
+    internal_self_insert (XINT (last_command_char), 0);
   else
     bitch_at_user ();
 
@@ -1880,24 +1958,27 @@ DEFUN ("minibuffer-prompt-width", Fminibuffer_prompt_width,
    that has no possible completions, and other quick, unobtrusive
    messages.  */
 
+void
 temp_echo_area_glyphs (m)
      char *m;
 {
   int osize = ZV;
+  int osize_byte = ZV_BYTE;
   int opoint = PT;
+  int opoint_byte = PT_BYTE;
   Lisp_Object oinhibit;
   oinhibit = Vinhibit_quit;
 
   /* Clear out any old echo-area message to make way for our new thing.  */
   message (0);
 
-  SET_PT (osize);
+  SET_PT_BOTH (osize, osize_byte);
   insert_string (m);
-  SET_PT (opoint);
+  SET_PT_BOTH (opoint, opoint_byte);
   Vinhibit_quit = Qt;
   Fsit_for (make_number (2), Qnil, Qnil);
-  del_range (osize, ZV);
-  SET_PT (opoint);
+  del_range_both (osize, osize_byte, ZV, ZV_BYTE, 1);
+  SET_PT_BOTH (opoint, opoint_byte);
   if (!NILP (Vquit_flag))
     {
       Vquit_flag = Qnil;
@@ -1918,12 +1999,14 @@ or until the next input event arrives, whichever comes first.")
   return Qnil;
 }
 \f
+void
 init_minibuf_once ()
 {
   Vminibuffer_list = Qnil;
   staticpro (&Vminibuffer_list);
 }
 
+void
 syms_of_minibuf ()
 {
   minibuf_level = 0;
@@ -1976,6 +2059,10 @@ syms_of_minibuf ()
   Qactivate_input_method = intern ("activate-input-method");
   staticpro (&Qactivate_input_method);
 
+  DEFVAR_LISP ("read-buffer-function", &Vread_buffer_function, 
+    "If this is non-nil, `read-buffer' does its work by calling this function.");
+  Vread_buffer_function = Qnil;
+
   DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook, 
     "Normal hook run just after entry to minibuffer.");
   Vminibuffer_setup_hook = Qnil;
@@ -2001,9 +2088,7 @@ property of a history variable overrides this default.");
 
   DEFVAR_BOOL ("enable-recursive-minibuffers", &enable_recursive_minibuffers,
     "*Non-nil means to allow minibuffer commands while in the minibuffer.\n\
-More precisely, this variable makes a difference when the minibuffer window\n\
-is the selected window.  If you are in some other window, minibuffer commands\n\
-are allowed even if a minibuffer is active.");
+This variable makes a difference whenever the minibuffer window is active.");
   enable_recursive_minibuffers = 0;
 
   DEFVAR_LISP ("minibuffer-completion-table", &Vminibuffer_completion_table,
@@ -2089,6 +2174,7 @@ with completion; they always discard text properties.");
   defsubr (&Sminibuffer_message);
 }
 
+void
 keys_of_minibuf ()
 {
   initial_define_key (Vminibuffer_local_map, Ctl ('g'),