diff src/minibuf.c @ 4824:eaf67474339b

(Fminibuffer_complete_word): GCPRO1 `completion' during calls to Ftry_completion. (read_minibuf): Rewrite change of Sep 14. Save the return value on the history list provided in the form that the value is returned, iff the value is not equal to the front of the history list. (Fread_no_blanks_input): Change DEFUN to allow 2nd arg to be optional. The code was already written correctly.
author Brian Fox <bfox@gnu.org>
date Tue, 05 Oct 1993 01:46:45 +0000
parents 69eba6f6d5fb
children 47cc31b47402
line wrap: on
line diff
--- a/src/minibuf.c	Tue Oct 05 01:34:06 1993 +0000
+++ b/src/minibuf.c	Tue Oct 05 01:46:45 1993 +0000
@@ -54,7 +54,7 @@
 /* Nonzero means display completion help for invalid input */
 int auto_help;
 
-/* Fread_minibuffer leaves the input, as a string, here */
+/* Fread_minibuffer leaves the input here as a string. */
 Lisp_Object last_minibuf_string;
 
 /* Nonzero means let functions called when within a minibuffer 
@@ -105,7 +105,11 @@
    with initial position HISTPOS.  (BACKUP_N should be <= 0.)
 
    Normally return the result as a string (the text that was read),
-   but if EXPFLAG is non-nil, read it and return the object read.  */
+   but if EXPFLAG is non-nil, read it and return the object read.
+   If HISTVAR is given, save the value read on that history only if it doesn't
+   match the front of that history list exactly.  The value is pushed onto
+   the list as the string that was read, or as the object that resulted iff
+   EXPFLAG is non-nil.  */
 
 Lisp_Object
 read_minibuf (map, initial, prompt, backup_n, expflag, histvar, histpos)
@@ -252,26 +256,33 @@
   val = make_buffer_string (1, Z);
   bcopy (GAP_END_ADDR, XSTRING (val)->data + GPT - BEG, Z - GPT);
 
+  /* VAL is the string of minibuffer text.  */
+  last_minibuf_string = val;
+
+  /* If Lisp form desired instead of string, parse it. */
+  if (expflag)
+    val = Fread (val);
+
   /* Add the value to the appropriate history list.  */
   if (XTYPE (Vminibuffer_history_variable) == Lisp_Symbol
-      && ! EQ (XSYMBOL (Vminibuffer_history_variable)->value, Qunbound)
-      && NILP (Fstring_equal
-	       (val, Fcar (Fsymbol_value (Vminibuffer_history_variable)))))
-    Fset (Vminibuffer_history_variable,
-	  Fcons (val, Fsymbol_value (Vminibuffer_history_variable)));
+      && ! EQ (XSYMBOL (Vminibuffer_history_variable)->value, Qunbound))
+    {
+      /* If the caller wanted to save the value read on a history list,
+	 then do so if the value is not already the front of the list. */
+      Lisp_Object histval = Fsymbol_value (Vminibuffer_history_variable);
+
+      /* The value of the history variable must be a cons or nil.  Other
+	 values are unacceptable.  We silenty ignore these values. */
+      if (NILP (histval)
+	  || (CONSP (histval) && NILP (Fequal (val, Fcar (histval)))))
+	Fset (Vminibuffer_history_variable, Fcons (val, histval));
+    }
 
   unbind_to (count, Qnil);	/* The appropriate frame will get selected
 				   in set-window-configuration.  */
 
   UNGCPRO;
 
-  /* VAL is the string of minibuffer text.  */
-  last_minibuf_string = val;
-
-  /* If Lisp form desired instead of string, parse it */
-  if (expflag)
-    val = Fread (val);
-
   return val;
 }
 
@@ -455,7 +466,7 @@
   return Fread_from_minibuffer (prompt, initial_input, Qnil, Qnil, Qnil);
 }
 
-DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 2, 2, 0,
+DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 2, 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.")
   (prompt, init)
@@ -1142,9 +1153,10 @@
   Lisp_Object completion, tem;
   register int i;
   register unsigned char *completion_string;
-  /* We keep calling Fbuffer_string
-     rather than arrange for GC to hold onto a pointer to
-     one of the strings thus made.  */
+  struct gcpro gcpro1;
+
+  /* We keep calling Fbuffer_string rather than arrange for GC to
+     hold onto a pointer to one of the strings thus made.  */
 
   completion = Ftry_completion (Fbuffer_string (),
 				Vminibuffer_completion_table,
@@ -1158,7 +1170,7 @@
   if (EQ (completion, Qt))
     return Qnil;
 
-#if 0 /* How the below code used to look, for reference */
+#if 0 /* How the below code used to look, for reference. */
   tem = Fbuffer_string ();
   b = XSTRING (tem)->data;
   i = ZV - 1 - XSTRING (completion)->size;
@@ -1215,19 +1227,26 @@
   i = ZV - BEGV;
 
   /* If completion finds next char not unique,
-     consider adding a space or a hyphen */
+     consider adding a space or a hyphen. */
   if (i == XSTRING (completion)->size)
     {
+      GCPRO1 (completion);
       tem = Ftry_completion (concat2 (Fbuffer_string (), build_string (" ")),
 			     Vminibuffer_completion_table,
 			     Vminibuffer_completion_predicate);
+      UNGCPRO;
+
       if (XTYPE (tem) == Lisp_String)
 	completion = tem;
       else
 	{
-	  tem = Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")),
-				 Vminibuffer_completion_table,
-				 Vminibuffer_completion_predicate);
+	  GCPRO1 (completion);
+	  tem =
+	    Ftry_completion (concat2 (Fbuffer_string (), build_string ("-")),
+			     Vminibuffer_completion_table,
+			     Vminibuffer_completion_predicate);
+	  UNGCPRO;
+
 	  if (XTYPE (tem) == Lisp_String)
 	    completion = tem;
 	}
@@ -1235,6 +1254,7 @@
 
   /* Now find first word-break in the stuff found by completion.
      i gets index in string of where to stop completing.  */
+
   completion_string = XSTRING (completion)->data;
 
   for (; i < XSTRING (completion)->size; i++)