(read_minibuf_unwind): Clear last_overlay_modified field.
[bpt/emacs.git] / src / fns.c
index 62050ef..46a9bbe 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -41,6 +41,7 @@ extern Lisp_Object Flookup_key ();
 
 Lisp_Object Qstring_lessp, Qprovide, Qrequire;
 Lisp_Object Qyes_or_no_p_history;
+Lisp_Object Qcursor_in_echo_area;
 
 static int internal_equal ();
 \f
@@ -508,31 +509,49 @@ Elements of ALIST that are not conses are also shared.")
 DEFUN ("substring", Fsubstring, Ssubstring, 2, 3, 0,
   "Return a substring of STRING, starting at index FROM and ending before TO.\n\
 TO may be nil or omitted; then the substring runs to the end of STRING.\n\
-If FROM or TO is negative, it counts from the end.")
+If FROM or TO is negative, it counts from the end.\n\
+\n\
+This function allows vectors as well as strings.")
   (string, from, to)
      Lisp_Object string;
      register Lisp_Object from, to;
 {
   Lisp_Object res;
+  int size;
+
+  if (! (STRINGP (string) || VECTORP (string)))
+    wrong_type_argument (Qarrayp, string);
 
-  CHECK_STRING (string, 0);
   CHECK_NUMBER (from, 1);
+
+  if (STRINGP (string))
+    size = XSTRING (string)->size;
+  else
+    size = XVECTOR (string)->size;
+
   if (NILP (to))
-    to = Flength (string);
+    to = size;
   else
     CHECK_NUMBER (to, 2);
 
   if (XINT (from) < 0)
-    XSETINT (from, XINT (from) + XSTRING (string)->size);
+    XSETINT (from, XINT (from) + size);
   if (XINT (to) < 0)
-    XSETINT (to, XINT (to) + XSTRING (string)->size);
+    XSETINT (to, XINT (to) + size);
   if (!(0 <= XINT (from) && XINT (from) <= XINT (to)
-        && XINT (to) <= XSTRING (string)->size))
+        && XINT (to) <= size))
     args_out_of_range_3 (string, from, to);
 
-  res = make_string (XSTRING (string)->data + XINT (from),
-                    XINT (to) - XINT (from));
-  copy_text_properties (from, to, string, make_number (0), res, Qnil);
+  if (STRINGP (string))
+    {
+      res = make_string (XSTRING (string)->data + XINT (from),
+                        XINT (to) - XINT (from));
+      copy_text_properties (from, to, string, make_number (0), res, Qnil);
+    }
+  else
+    res = Fvector (XINT (to) - XINT (from),
+                  XVECTOR (string)->contents + XINT (from));
+                  
   return res;
 }
 \f
@@ -1330,7 +1349,8 @@ or a character code.")
 
 void
 map_char_table (c_function, function, chartable, depth, indices)
-     Lisp_Object (*c_function) (), function, chartable, depth, *indices;
+     Lisp_Object (*c_function) (), function, chartable, *indices;
+     int depth;
 {
   int i;
   int size = CHAR_TABLE_ORDINARY_SLOTS;
@@ -1350,7 +1370,7 @@ map_char_table (c_function, function, chartable, depth, indices)
       indices[depth] = i;
       elt = XCHAR_TABLE (chartable)->contents[i];
       if (CHAR_TABLE_P (elt))
-       map_char_table (chartable, c_function, function, depth + 1, indices);
+       map_char_table (c_function, function, chartable, depth + 1, indices);
       else if (c_function)
        (*c_function) (depth + 1, indices, elt);
       /* Here we should handle all cases where the range is a single character
@@ -1558,8 +1578,10 @@ Also accepts Space to mean yes, or Delete to mean no.")
   register int answer;
   Lisp_Object xprompt;
   Lisp_Object args[2];
-  int ocech = cursor_in_echo_area;
   struct gcpro gcpro1, gcpro2;
+  int count = specpdl_ptr - specpdl;
+
+  specbind (Qcursor_in_echo_area, Qt);
 
   map = Fsymbol_value (intern ("query-replace-map"));
 
@@ -1569,6 +1591,8 @@ Also accepts Space to mean yes, or Delete to mean no.")
 
   while (1)
     {
+      
+
 #ifdef HAVE_MENUS
       if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
          && have_menus_p ())
@@ -1585,6 +1609,7 @@ Also accepts Space to mean yes, or Delete to mean no.")
        }
 #endif /* HAVE_MENUS */
       cursor_in_echo_area = 1;
+      choose_minibuf_frame ();
       message_nolog ("%s(y or n) ", XSTRING (xprompt)->data);
 
       obj = read_filtered_event (1, 0, 0);
@@ -1593,7 +1618,7 @@ Also accepts Space to mean yes, or Delete to mean no.")
       QUIT;
 
       key = Fmake_vector (make_number (1), obj);
-      def = Flookup_key (map, key);
+      def = Flookup_key (map, key, Qt);
       answer_string = Fsingle_key_description (obj);
 
       if (EQ (def, intern ("skip")))
@@ -1641,9 +1666,9 @@ Also accepts Space to mean yes, or Delete to mean no.")
       cursor_in_echo_area = -1;
       message_nolog ("%s(y or n) %c",
                     XSTRING (xprompt)->data, answer ? 'y' : 'n');
-      cursor_in_echo_area = ocech;
     }
 
+  unbind_to (count, Qnil);
   return answer ? Qt : Qnil;
 }
 \f
@@ -1822,6 +1847,10 @@ syms_of_fns ()
   staticpro (&Qrequire);
   Qyes_or_no_p_history = intern ("yes-or-no-p-history");
   staticpro (&Qyes_or_no_p_history);
+  Qcursor_in_echo_area = intern ("cursor-in-echo-area");
+  staticpro (&Qcursor_in_echo_area);
+
+  Fset (Qyes_or_no_p_history, Qnil);
 
   DEFVAR_LISP ("features", &Vfeatures,
     "A list of symbols which are the features of the executing emacs.\n\