(calendar-mode-map): Rename `holidays' menu to `Holidays'.
[bpt/emacs.git] / src / minibuf.c
index 83c35ac..2e89c61 100644 (file)
@@ -77,7 +77,7 @@ Lisp_Object Vminibuffer_history_variable;
 
 Lisp_Object Vminibuffer_history_position;
 
-Lisp_Object Qminibuffer_history;
+Lisp_Object Qminibuffer_history, Qbuffer_name_history;
 
 Lisp_Object Qread_file_name_internal;
 
@@ -391,6 +391,10 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   if (inherit_input_method)
     current_buffer->enable_multibyte_characters = enable_multibyte;
 
+  if (!NILP (current_buffer->enable_multibyte_characters)
+      && ! STRING_MULTIBYTE (minibuf_prompt))
+    minibuf_prompt = Fstring_make_multibyte (minibuf_prompt);
+
   /* Run our hook, but not if it is empty.
      (run-hooks would do nothing if it is empty,
      but it's important to save time here in the usual case).  */
@@ -398,7 +402,6 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
       && !NILP (Vrun_hooks))
     call1 (Vrun_hooks, Qminibuffer_setup_hook);
 
-/* ??? MCC did redraw_screen here if switching screens.  */
   recursive_edit_1 ();
 
   /* If cursor is on the minibuffer line,
@@ -415,9 +418,6 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   /* Make minibuffer contents into a string.  */
   Fset_buffer (minibuffer);
   val = make_buffer_string (1, Z, allow_props);
-#if 0  /* make_buffer_string should handle the gap.  */
-  bcopy (GAP_END_ADDR, XSTRING (val)->data + GPT - BEG, Z - GPT);
-#endif
 
   /* VAL is the string of minibuffer text.  */
 
@@ -855,7 +855,8 @@ If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are a
        }
 
       return Fcompleting_read (prompt, Vbuffer_alist, Qnil,
-                              require_match, Qnil, Qnil, def, Qnil);
+                              require_match, Qnil, Qbuffer_name_history,
+                              def, Qnil);
     }
   else
     {
@@ -867,6 +868,19 @@ If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are a
     }
 }
 \f
+static Lisp_Object
+minibuf_conform_representation (string, basis)
+     Lisp_Object string, basis;
+{
+  if (STRING_MULTIBYTE (string) == STRING_MULTIBYTE (basis))
+    return string;
+
+  if (STRING_MULTIBYTE (string))
+    return Fstring_make_unibyte (string);
+  else
+    return Fstring_make_multibyte (string);
+}
+
 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
   "Return common substring of all completions of STRING in ALIST.\n\
 Each car of each element of ALIST is tested to see if it begins with STRING.\n\
@@ -1062,7 +1076,7 @@ or the symbol from the obarray.")
      don't change the case of what the user typed.  */
   if (completion_ignore_case && bestmatchsize == XSTRING (string)->size
       && XSTRING (bestmatch)->size > bestmatchsize)
-    return string;
+    return minibuf_conform_representation (string, bestmatch);
 
   /* Return t if the supplied string is an exact match (counting case);
      it does not require any change to be made.  */
@@ -1382,8 +1396,20 @@ test_completion (txt)
                      XSTRING (txt)->size,
                      STRING_BYTES (XSTRING (txt)));
       if (!SYMBOLP (tem))
-       return Qnil;
-      else if (!NILP (Vminibuffer_completion_predicate))
+       {
+         if (STRING_MULTIBYTE (txt))
+           txt = Fstring_make_unibyte (txt);
+         else
+           txt = Fstring_make_multibyte (txt);
+
+         tem = oblookup (Vminibuffer_completion_table,
+                         XSTRING (txt)->data,
+                         XSTRING (txt)->size,
+                         STRING_BYTES (XSTRING (txt)));
+         if (!SYMBOLP (tem))
+           return Qnil;
+       }
+      if (!NILP (Vminibuffer_completion_predicate))
        return call1 (Vminibuffer_completion_predicate, tem);
       else
        return Qt;
@@ -1480,9 +1506,6 @@ assoc_for_completion (key, list)
 {
   register Lisp_Object tail;
 
-  if (completion_ignore_case)
-    key = Fupcase (key);
-
   for (tail = list; !NILP (tail); tail = Fcdr (tail))
     {
       register Lisp_Object elt, tem, thiscar;
@@ -1491,10 +1514,11 @@ assoc_for_completion (key, list)
       thiscar = Fcar (elt);
       if (!STRINGP (thiscar))
        continue;
-      if (completion_ignore_case)
-       thiscar = Fupcase (thiscar);
-      tem = Fequal (thiscar, key);
-      if (!NILP (tem)) return elt;
+      tem = Fcompare_strings (thiscar, make_number (0), Qnil,
+                             key, make_number (0), Qnil,
+                             completion_ignore_case ? Qt : Qnil);
+      if (EQ (tem, Qt))
+       return elt;
       QUIT;
     }
   return Qnil;
@@ -1821,7 +1845,7 @@ It can find the completion buffer in `standard-output'.")
       write_string ("Possible completions are:", -1);
       for (tail = completions, i = 0; !NILP (tail); tail = Fcdr (tail), i++)
        {
-         Lisp_Object tem;
+         Lisp_Object tem, string;
          int length;
          Lisp_Object startpos, endpos;
 
@@ -1887,15 +1911,25 @@ It can find the completion buffer in `standard-output'.")
                                    Qnil, Vstandard_output);
            }
 
-         /* Output this element and update COLUMN.  */
+         /* Output this element.
+            If necessary, convert it to unibyte or to multibyte first.  */
          if (CONSP (elt))
-           {
-             Fprinc (Fcar (elt), Qnil);
-             Fprinc (Fcar (Fcdr (elt)), Qnil);
-           }
+           string = Fcar (elt);
          else
-           Fprinc (elt, Qnil);
+           string = elt;
+         if (NILP (current_buffer->enable_multibyte_characters)
+             && STRING_MULTIBYTE (string))
+           string = Fstring_make_unibyte (string);
+         else if (!NILP (current_buffer->enable_multibyte_characters)
+                  && !STRING_MULTIBYTE (string))
+           string = Fstring_make_multibyte (string);
+         Fprinc (string, Qnil);
+
+         /* Output the annotation for this element.  */
+         if (CONSP (elt))
+           Fprinc (Fcar (Fcdr (elt)), Qnil);
 
+         /* Update COLUMN for what we have output.  */
          column += length;
 
          /* If output is to a buffer, recompute COLUMN in a way
@@ -2083,6 +2117,9 @@ syms_of_minibuf ()
   Qminibuffer_history = intern ("minibuffer-history");
   staticpro (&Qminibuffer_history);
 
+  Qbuffer_name_history = intern ("buffer-name-history");
+  staticpro (&Qbuffer_name_history);
+
   Qminibuffer_setup_hook = intern ("minibuffer-setup-hook");
   staticpro (&Qminibuffer_setup_hook);