* w32fns.c (hourglass_timer, hourglass_hwnd): New variables.
[bpt/emacs.git] / src / minibuf.c
index c2654d0..724de3f 100644 (file)
@@ -1,13 +1,13 @@
 /* Minibuffer input and completion.
    Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
                  2001, 2002, 2003, 2004, 2005,
-                 2006, 2007 Free Software Foundation, Inc.
+                 2006, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -27,7 +27,7 @@ Boston, MA 02110-1301, USA.  */
 #include "lisp.h"
 #include "commands.h"
 #include "buffer.h"
-#include "charset.h"
+#include "character.h"
 #include "dispextern.h"
 #include "keyboard.h"
 #include "frame.h"
@@ -35,6 +35,7 @@ Boston, MA 02110-1301, USA.  */
 #include "syntax.h"
 #include "intervals.h"
 #include "keymap.h"
+#include "termhooks.h"
 
 extern int quit_char;
 
@@ -117,6 +118,7 @@ Lisp_Object Vread_buffer_function;
 /* Nonzero means completion ignores case.  */
 
 int completion_ignore_case;
+Lisp_Object Qcompletion_ignore_case;
 
 /* List of regexps that should restrict possible completions.  */
 
@@ -255,9 +257,13 @@ string_to_object (val, defalt)
 
   GCPRO2 (val, defalt);
 
-  if (STRINGP (val) && SCHARS (val) == 0
-      && STRINGP (defalt))
-    val = defalt;
+  if (STRINGP (val) && SCHARS (val) == 0)
+    {
+      if (STRINGP (defalt))
+       val = defalt;
+      else if (CONSP (defalt) && STRINGP (XCAR (defalt)))
+       val = XCAR (defalt);
+    }
 
   expr_and_pos = Fread_from_string (val, Qnil, Qnil);
   pos = XINT (Fcdr (expr_and_pos));
@@ -335,7 +341,7 @@ read_minibuf_noninteractive (map, initial, prompt, backup_n, expflag,
 
   /* If Lisp form desired instead of string, parse it. */
   if (expflag)
-    val = string_to_object (val, defalt);
+    val = string_to_object (val, CONSP (defalt) ? XCAR (defalt) : defalt);
 
   return val;
 }
@@ -491,8 +497,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   if (EQ (Vminibuffer_completing_file_name, Qlambda))
     Vminibuffer_completing_file_name = Qnil;
 
-  single_kboard_state ();
-#ifdef HAVE_X_WINDOWS
+#ifdef HAVE_WINDOW_SYSTEM
   if (display_hourglass_p)
     cancel_hourglass ();
 #endif
@@ -575,6 +580,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
   if (minibuffer_auto_raise)
     Fraise_frame (mini_frame);
 
+  temporarily_switch_to_single_kboard (XFRAME (mini_frame));
+
   /* We have to do this after saving the window configuration
      since that is what restores the current buffer.  */
 
@@ -758,8 +765,12 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
       XWINDOW (minibuf_window)->cursor.x = 0;
       XWINDOW (minibuf_window)->must_be_updated_p = 1;
       update_frame (XFRAME (selected_frame), 1, 1);
-      if (rif && rif->flush_display)
-       rif->flush_display (XFRAME (XWINDOW (minibuf_window)->frame));
+      {
+        struct frame *f = XFRAME (XWINDOW (minibuf_window)->frame);
+        struct redisplay_interface *rif = FRAME_RIF (f);
+        if (rif && rif->flush_display)
+          rif->flush_display (f);
+      }
     }
 
   /* Make minibuffer contents into a string.  */
@@ -778,6 +789,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
     histstring = val;
   else if (STRINGP (defalt))
     histstring = defalt;
+  else if (CONSP (defalt) && STRINGP (XCAR (defalt)))
+    histstring = XCAR (defalt);
   else
     histstring = Qnil;
 
@@ -1045,8 +1058,8 @@ DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0,
        doc: /* Return a Lisp object read using the minibuffer, unevaluated.
 Prompt with PROMPT.  If non-nil, optional second arg INITIAL-CONTENTS
 is a string to insert in the minibuffer before reading.
-\(INITIAL-CONTENTS can also be a cons of a string and an integer.  Such
-arguments are used as in `read-from-minibuffer'.)  */)
+\(INITIAL-CONTENTS can also be a cons of a string and an integer.
+Such arguments are used as in `read-from-minibuffer'.)  */)
      (prompt, initial_contents)
      Lisp_Object prompt, initial_contents;
 {
@@ -1060,8 +1073,8 @@ DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0,
        doc: /* Return value of Lisp expression read using the minibuffer.
 Prompt with PROMPT.  If non-nil, optional second arg INITIAL-CONTENTS
 is a string to insert in the minibuffer before reading.
-\(INITIAL-CONTENTS can also be a cons of a string and an integer.  Such
-arguments are used as in `read-from-minibuffer'.)  */)
+\(INITIAL-CONTENTS can also be a cons of a string and an integer.
+Such arguments are used as in `read-from-minibuffer'.)  */)
      (prompt, initial_contents)
      Lisp_Object prompt, initial_contents;
 {
@@ -1095,7 +1108,7 @@ Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
                               Qnil, history, default_value,
                               inherit_input_method);
   if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value))
-    val = default_value;
+    val = CONSP (default_value) ? XCAR (default_value) : default_value;
   return val;
 }
 
@@ -1218,7 +1231,7 @@ The argument PROMPT should be a string ending with a colon and a space.  */)
 
          args[0] = build_string ("%s (default %s): ");
          args[1] = prompt;
-         args[2] = def;
+         args[2] = CONSP (def) ? XCAR (def) : def;
          prompt = Fformat (3, args);
        }
 
@@ -1288,11 +1301,14 @@ is used to further constrain the set of candidates.  */)
   int bestmatchsize = 0;
   /* These are in bytes, too.  */
   int compare, matchsize;
-  int type = (HASH_TABLE_P (collection) ? 3
-             : VECTORP (collection) ? 2
-             : NILP (collection) || (CONSP (collection)
-                                     && (!SYMBOLP (XCAR (collection))
-                                         || NILP (XCAR (collection)))));
+  enum { function_table, list_table, obarray_table, hash_table}
+    type = (HASH_TABLE_P (collection) ? hash_table
+           : VECTORP (collection) ? obarray_table
+           : ((NILP (collection)
+               || (CONSP (collection)
+                   && (!SYMBOLP (XCAR (collection))
+                       || NILP (XCAR (collection)))))
+              ? list_table : function_table));
   int index = 0, obsize = 0;
   int matchcount = 0;
   int bindcount = -1;
@@ -1300,7 +1316,7 @@ is used to further constrain the set of candidates.  */)
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
   CHECK_STRING (string);
-  if (type == 0)
+  if (type == function_table)
     return call3 (collection, string, predicate, Qnil);
 
   bestmatch = bucket = Qnil;
@@ -1308,7 +1324,7 @@ is used to further constrain the set of candidates.  */)
 
   /* If COLLECTION is not a list, set TAIL just for gc pro.  */
   tail = collection;
-  if (type == 2)
+  if (type == obarray_table)
     {
       collection = check_obarray (collection);
       obsize = XVECTOR (collection)->size;
@@ -1322,7 +1338,7 @@ is used to further constrain the set of candidates.  */)
       /* elt gets the alist element or symbol.
         eltstring gets the name to check as a completion. */
 
-      if (type == 1)
+      if (type == list_table)
        {
          if (!CONSP (tail))
            break;
@@ -1330,7 +1346,7 @@ is used to further constrain the set of candidates.  */)
          eltstring = CONSP (elt) ? XCAR (elt) : elt;
          tail = XCDR (tail);
        }
-      else if (type == 2)
+      else if (type == obarray_table)
        {
          if (!EQ (bucket, zero))
            {
@@ -1351,7 +1367,7 @@ is used to further constrain the set of candidates.  */)
              continue;
            }
        }
-      else /* if (type == 3) */
+      else /* if (type == hash_table) */
        {
          while (index < HASH_TABLE_SIZE (XHASH_TABLE (collection))
                 && NILP (HASH_HASH (XHASH_TABLE (collection), index)))
@@ -1405,15 +1421,17 @@ is used to further constrain the set of candidates.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
-                 if (bindcount >= 0) {
-                   unbind_to (bindcount, Qnil);
-                   bindcount = -1;
-                 }
+                 if (bindcount >= 0)
+                   {
+                     unbind_to (bindcount, Qnil);
+                     bindcount = -1;
+                   }
                  GCPRO4 (tail, string, eltstring, bestmatch);
-                 tem = type == 3
-                   ? call2 (predicate, elt,
-                            HASH_VALUE (XHASH_TABLE (collection), index - 1))
-                   : call1 (predicate, elt);
+                 tem = (type == hash_table
+                        ? call2 (predicate, elt,
+                                 HASH_VALUE (XHASH_TABLE (collection),
+                                             index - 1))
+                        : call1 (predicate, elt));
                  UNGCPRO;
                }
              if (NILP (tem)) continue;
@@ -1823,7 +1841,7 @@ Completion ignores case if the ambient value of
                      !NILP (inherit_input_method));
 
   if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def))
-    val = def;
+    val = CONSP (def) ? XCAR (def) : def;
 
   RETURN_UNGCPRO (unbind_to (count, val));
 }
@@ -2098,10 +2116,10 @@ string rather than a cons cell whose car is a string.  */)
   if (SYMBOLP (key))
     key = Fsymbol_name (key);
 
-  for (tail = list; !NILP (tail); tail = Fcdr (tail))
+  for (tail = list; CONSP (tail); tail = XCDR (tail))
     {
       register Lisp_Object elt, tem, thiscar;
-      elt = Fcar (tail);
+      elt = XCAR (tail);
       thiscar = CONSP (elt) ? XCAR (elt) : elt;
       if (SYMBOLP (thiscar))
        thiscar = Fsymbol_name (thiscar);
@@ -2414,23 +2432,14 @@ Return nil if there is no valid completion, else t.  */)
 
   /* Now find first word-break in the stuff found by completion.
      i gets index in string of where to stop completing.  */
-  {
-    int len, c;
-    int bytes = SBYTES (completion);
-    register const unsigned char *completion_string = SDATA (completion);
-    for (; i_byte < SBYTES (completion); i_byte += len, i++)
-      {
-       c = STRING_CHAR_AND_LENGTH (completion_string + i_byte,
-                                   bytes - i_byte,
-                                   len);
-       if (SYNTAX (c) != Sword)
-         {
-           i_byte += len;
-           i++;
-           break;
-         }
-      }
-  }
+  while (i_byte < SBYTES (completion))
+    {
+      int c;
+
+      FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, completion, i, i_byte);
+      if (SYNTAX (c) != Sword)
+       break;
+    }
 
   /* If got no characters, print help for user.  */
 
@@ -2710,7 +2719,7 @@ DEFUN ("self-insert-and-exit", Fself_insert_and_exit, Sself_insert_and_exit, 0,
        doc: /* Terminate minibuffer input.  */)
      ()
 {
-  if (INTEGERP (last_command_char))
+  if (CHARACTERP (last_command_char))
     internal_self_insert (XINT (last_command_char), 0);
   else
     bitch_at_user ();
@@ -2820,6 +2829,9 @@ syms_of_minibuf ()
   minibuf_save_list = Qnil;
   staticpro (&minibuf_save_list);
 
+  Qcompletion_ignore_case = intern ("completion-ignore-case");
+  staticpro (&Qcompletion_ignore_case);
+
   Qread_file_name_internal = intern ("read-file-name-internal");
   staticpro (&Qread_file_name_internal);