use dynwind_begin and dynwind_end
[bpt/emacs.git] / src / minibuf.c
index 03d6104..e257ac2 100644 (file)
@@ -205,7 +205,7 @@ string_to_object (Lisp_Object val, Lisp_Object defalt)
     }
 
   val = Fcar (expr_and_pos);
-  RETURN_UNGCPRO (val);
+  return val;
 }
 
 
@@ -231,7 +231,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
   val = Qnil;
   size = 100;
   len = 0;
-  line = xmalloc (size);
+  line = xmalloc_atomic (size);
 
   while ((c = getchar ()) != '\n')
     {
@@ -377,13 +377,14 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
              bool allow_props, bool inherit_input_method)
 {
   Lisp_Object val;
-  ptrdiff_t count = SPECPDL_INDEX ();
+  dynwind_begin ();
   Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
   Lisp_Object enable_multibyte;
   EMACS_INT pos = 0;
   /* String to add to the history.  */
   Lisp_Object histstring;
+  Lisp_Object histval;
 
   Lisp_Object empty_minibuf;
   Lisp_Object dummy, frame;
@@ -395,7 +396,8 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
      in previous recursive minibuffer, but was not set explicitly
      to t for this invocation, so set it to nil in this minibuffer.
      Save the old value now, before we change it.  */
-  specbind (intern ("minibuffer-completing-file-name"), Vminibuffer_completing_file_name);
+  specbind (intern ("minibuffer-completing-file-name"),
+           Vminibuffer_completing_file_name);
   if (EQ (Vminibuffer_completing_file_name, Qlambda))
     Vminibuffer_completing_file_name = Qnil;
 
@@ -460,7 +462,8 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
                                         expflag, histvar, histpos, defalt,
                                         allow_props, inherit_input_method);
       UNGCPRO;
-      return unbind_to (count, val);
+      dynwind_end ();
+      return val;
     }
 
   /* Choose the minibuffer window and frame, and take action on them.  */
@@ -536,11 +539,12 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
     Vminibuffer_completing_file_name = Qlambda;
 
   /* If variable is unbound, make it nil.  */
-  Lisp_Object histval = find_symbol_value (Vminibuffer_history_variable);
-  if (EQ (histval, Qunbound)) {
-    Fset (Vminibuffer_history_variable, Qnil);
-    histval = Qnil;
-  }
+  histval = find_symbol_value (Vminibuffer_history_variable);
+  if (EQ (histval, Qunbound))
+    {
+      Fset (Vminibuffer_history_variable, Qnil);
+      histval = Qnil;
+    }
 
   if (inherit_input_method)
     {
@@ -622,7 +626,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
 
   /* Erase the buffer.  */
   {
-    ptrdiff_t count1 = SPECPDL_INDEX ();
+    dynwind_begin ();
     specbind (Qinhibit_read_only, Qt);
     specbind (Qinhibit_modification_hooks, Qt);
     Ferase_buffer ();
@@ -644,7 +648,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
        Fadd_text_properties (make_number (BEG), make_number (PT),
                              Vminibuffer_prompt_properties, Qnil);
       }
-    unbind_to (count1, Qnil);
+    dynwind_end ();
   }
 
   minibuf_prompt_width = current_column ();
@@ -750,7 +754,8 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
   /* The appropriate frame will get selected
      in set-window-configuration.  */
   UNGCPRO;
-  return unbind_to (count, val);
+  dynwind_end ();
+  return val;
 }
 
 /* Return a buffer to be used as the minibuffer at depth `depth'.
@@ -784,7 +789,7 @@ get_minibuffer (EMACS_INT depth)
     }
   else
     {
-      ptrdiff_t count = SPECPDL_INDEX ();
+      dynwind_begin ();
       /* We have to empty both overlay lists.  Otherwise we end
         up with overlays that think they belong to this buffer
         while the buffer doesn't know about them any more.  */
@@ -796,7 +801,7 @@ get_minibuffer (EMACS_INT depth)
        call0 (intern ("minibuffer-inactive-mode"));
       else
         Fkill_all_local_variables ();
-      unbind_to (count, Qnil);
+      dynwind_end ();
     }
 
   return buf;
@@ -850,14 +855,14 @@ read_minibuf_unwind (void)
 
   /* Erase the minibuffer we were using at this level.  */
   {
-    ptrdiff_t count = SPECPDL_INDEX ();
+    dynwind_begin ();
     /* Prevent error in erase-buffer.  */
     specbind (Qinhibit_read_only, Qt);
     specbind (Qinhibit_modification_hooks, Qt);
     old_deactivate_mark = Vdeactivate_mark;
     Ferase_buffer ();
     Vdeactivate_mark = old_deactivate_mark;
-    unbind_to (count, Qnil);
+    dynwind_end ();
   }
 
   /* When we get to the outmost level, make sure we resize the
@@ -980,7 +985,7 @@ Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
   (Lisp_Object prompt, Lisp_Object initial_input, Lisp_Object history, Lisp_Object default_value, Lisp_Object inherit_input_method)
 {
   Lisp_Object val;
-  ptrdiff_t count = SPECPDL_INDEX ();
+  dynwind_begin ();
 
   /* Just in case we're in a recursive minibuffer, make it clear that the
      previous minibuffer's completion table does not apply to the new
@@ -993,7 +998,8 @@ Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
                               inherit_input_method);
   if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value))
     val = CONSP (default_value) ? XCAR (default_value) : default_value;
-  return unbind_to (count, val);
+  dynwind_end ();
+  return val;
 }
 
 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0,
@@ -1090,7 +1096,7 @@ function, instead of the usual behavior.  */)
   Lisp_Object args[4], result;
   char *s;
   ptrdiff_t len;
-  ptrdiff_t count = SPECPDL_INDEX ();
+  dynwind_begin ();
 
   if (BUFFERP (def))
     def = BVAR (XBUFFER (def), name);
@@ -1139,7 +1145,8 @@ function, instead of the usual behavior.  */)
       args[3] = require_match;
       result = Ffuncall (4, args);
     }
-  return unbind_to (count, result);
+  dynwind_end ();
+  return result;
 }
 \f
 static Lisp_Object
@@ -1200,7 +1207,6 @@ is used to further constrain the set of candidates.  */)
               ? list_table : function_table));
   ptrdiff_t idx = 0, obsize = 0;
   int matchcount = 0;
-  ptrdiff_t bindcount = -1;
   Lisp_Object bucket, zero, end, tem;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
@@ -1285,18 +1291,17 @@ is used to further constrain the set of candidates.  */)
 
          /* Ignore this element if it fails to match all the regexps.  */
          {
+            dynwind_begin ();
+            specbind (Qcase_fold_search,
+                      completion_ignore_case ? Qt : Qnil);
            for (regexps = Vcompletion_regexp_list; CONSP (regexps);
                 regexps = XCDR (regexps))
              {
-               if (bindcount < 0) {
-                 bindcount = SPECPDL_INDEX ();
-                 specbind (Qcase_fold_search,
-                           completion_ignore_case ? Qt : Qnil);
-               }
                tem = Fstring_match (XCAR (regexps), eltstring, zero);
                if (NILP (tem))
                  break;
              }
+            dynwind_end ();
            if (CONSP (regexps))
              continue;
          }
@@ -1310,11 +1315,6 @@ is used to further constrain the set of candidates.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
-                 if (bindcount >= 0)
-                   {
-                     unbind_to (bindcount, Qnil);
-                     bindcount = -1;
-                   }
                  GCPRO4 (tail, string, eltstring, bestmatch);
                  tem = (type == hash_table
                         ? call2 (predicate, elt,
@@ -1393,11 +1393,6 @@ is used to further constrain the set of candidates.  */)
        }
     }
 
-  if (bindcount >= 0) {
-    unbind_to (bindcount, Qnil);
-    bindcount = -1;
-  }
-
   if (NILP (bestmatch))
     return Qnil;               /* No completions found.  */
   /* If we are ignoring case, and there is no exact match,
@@ -1457,7 +1452,6 @@ with a space are ignored unless STRING itself starts with a space.  */)
     : VECTORP (collection) ? 2
     : NILP (collection) || (CONSP (collection) && !FUNCTIONP (collection));
   ptrdiff_t idx = 0, obsize = 0;
-  ptrdiff_t bindcount = -1;
   Lisp_Object bucket, tem, zero;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
 
@@ -1548,18 +1542,17 @@ with a space are ignored unless STRING itself starts with a space.  */)
 
          /* Ignore this element if it fails to match all the regexps.  */
          {
+            dynwind_begin ();
+            specbind (Qcase_fold_search,
+                      completion_ignore_case ? Qt : Qnil);
            for (regexps = Vcompletion_regexp_list; CONSP (regexps);
                 regexps = XCDR (regexps))
              {
-               if (bindcount < 0) {
-                 bindcount = SPECPDL_INDEX ();
-                 specbind (Qcase_fold_search,
-                           completion_ignore_case ? Qt : Qnil);
-               }
                tem = Fstring_match (XCAR (regexps), eltstring, zero);
                if (NILP (tem))
                  break;
              }
+            dynwind_end ();
            if (CONSP (regexps))
              continue;
          }
@@ -1573,10 +1566,6 @@ with a space are ignored unless STRING itself starts with a space.  */)
                tem = Fcommandp (elt, Qnil);
              else
                {
-                 if (bindcount >= 0) {
-                   unbind_to (bindcount, Qnil);
-                   bindcount = -1;
-                 }
                  GCPRO4 (tail, eltstring, allmatches, string);
                  tem = type == 3
                    ? call2 (predicate, elt,
@@ -1591,11 +1580,6 @@ with a space are ignored unless STRING itself starts with a space.  */)
        }
     }
 
-  if (bindcount >= 0) {
-    unbind_to (bindcount, Qnil);
-    bindcount = -1;
-  }
-
   return Fnreverse (allmatches);
 }
 \f
@@ -1766,17 +1750,20 @@ the values STRING, PREDICATE and `lambda'.  */)
   /* Reject this element if it fails to match all the regexps.  */
   if (CONSP (Vcompletion_regexp_list))
     {
-      ptrdiff_t count = SPECPDL_INDEX ();
+      dynwind_begin ();
       specbind (Qcase_fold_search, completion_ignore_case ? Qt : Qnil);
       for (regexps = Vcompletion_regexp_list; CONSP (regexps);
           regexps = XCDR (regexps))
        {
          if (NILP (Fstring_match (XCAR (regexps),
                                   SYMBOLP (tem) ? string : tem,
-                                  Qnil)))
-           return unbind_to (count, Qnil);
+                                  Qnil))){
+           
+             dynwind_end ();
+           return Qnil;
+           }
        }
-      unbind_to (count, Qnil);
+      dynwind_end ();
     }
 
   /* Finally, check the predicate.  */
@@ -1901,6 +1888,8 @@ init_minibuf_once (void)
 void
 syms_of_minibuf (void)
 {
+#include "minibuf.x"
+
   minibuf_level = 0;
   minibuf_prompt = Qnil;
   staticpro (&minibuf_prompt);
@@ -1967,7 +1956,7 @@ A value of t means no truncation.
 This variable only affects history lists that don't specify their own
 maximum lengths.  Setting the `history-length' property of a history
 variable overrides this default.  */);
-  XSETFASTINT (Vhistory_length, 30);
+  XSETFASTINT (Vhistory_length, 100);
 
   DEFVAR_BOOL ("history-delete-duplicates", history_delete_duplicates,
               doc: /* Non-nil means to delete duplicates in history.
@@ -2075,28 +2064,4 @@ properties.  */);
   /* We use `intern' here instead of Qread_only to avoid
      initialization-order problems.  */
   Vminibuffer_prompt_properties = list2 (intern_c_string ("read-only"), Qt);
-
-  defsubr (&Sactive_minibuffer_window);
-  defsubr (&Sset_minibuffer_window);
-  defsubr (&Sread_from_minibuffer);
-  defsubr (&Sread_string);
-  defsubr (&Sread_command);
-  defsubr (&Sread_variable);
-  defsubr (&Sinternal_complete_buffer);
-  defsubr (&Sread_buffer);
-  defsubr (&Sread_no_blanks_input);
-  defsubr (&Sminibuffer_depth);
-  defsubr (&Sminibuffer_prompt);
-
-  defsubr (&Sminibufferp);
-  defsubr (&Sminibuffer_prompt_end);
-  defsubr (&Sminibuffer_contents);
-  defsubr (&Sminibuffer_contents_no_properties);
-  defsubr (&Sminibuffer_completion_contents);
-
-  defsubr (&Stry_completion);
-  defsubr (&Sall_completions);
-  defsubr (&Stest_completion);
-  defsubr (&Sassoc_string);
-  defsubr (&Scompleting_read);
 }