changeset 15967:b791ab74ff30

(Vhistory_length, Qhistory_length): New variables. (syms_of_minibuf): Register and initialise these. (read_minibuf): Truncate history list if needed.
author Richard M. Stallman <rms@gnu.org>
date Thu, 29 Aug 1996 04:35:38 +0000
parents ceb8d03a04f6
children 231e14e38946
files src/minibuf.c
diffstat 1 files changed, 35 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/minibuf.c	Thu Aug 29 03:50:02 1996 +0000
+++ b/src/minibuf.c	Thu Aug 29 04:35:38 1996 +0000
@@ -46,9 +46,12 @@
 /* Depth in minibuffer invocations.  */
 int minibuf_level;
 
-/* Nonzero means display completion help for invalid input */
+/* Nonzero means display completion help for invalid input.  */
 int auto_help;
 
+/* The maximum length of a minibuffer history.  */
+Lisp_Object Qhistory_length, Vhistory_length;
+
 /* Fread_minibuffer leaves the input here as a string. */
 Lisp_Object last_minibuf_string;
 
@@ -356,8 +359,27 @@
       if (NILP (histval)
 	  || (CONSP (histval)
 	      && NILP (Fequal (last_minibuf_string, Fcar (histval)))))
-	Fset (Vminibuffer_history_variable,
-	      Fcons (last_minibuf_string, histval));
+	{
+	  Lisp_Object length;
+
+	  histval = Fcons (last_minibuf_string, histval);
+	  Fset (Vminibuffer_history_variable, histval);
+
+	  /* Truncate if requested.  */
+	  length = Fget (Vminibuffer_history_variable, Qhistory_length);
+	  if (NILP (length)) length = Vhistory_length;
+	  if (INTEGERP (length)) {
+	    if (XINT (length) <= 0)
+	      Fset (Vminibuffer_history_variable, Qnil);
+	    else
+	      {
+		Lisp_Object temp;
+
+		temp = Fnthcdr (Fsub1 (length), histval);
+		if (CONSP (temp)) Fsetcdr (temp, Qnil);
+	      }
+	  }
+	}
     }
 
   /* If Lisp form desired instead of string, parse it. */
@@ -1794,6 +1816,9 @@
   Qminibuffer_exit_hook = intern ("minibuffer-exit-hook");
   staticpro (&Qminibuffer_exit_hook);
 
+  Qhistory_length = intern ("history-length");
+  staticpro (&Qhistory_length);
+
   DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook, 
     "Normal hook run just after entry to minibuffer.");
   Vminibuffer_setup_hook = Qnil;
@@ -1802,6 +1827,13 @@
     "Normal hook run just after exit from minibuffer.");
   Vminibuffer_exit_hook = Qnil;
 
+  DEFVAR_LISP ("history-length", &Vhistory_length,
+    "*Maximum length for history lists before truncation takes place.\n\
+A number means that length; t means infinite.  Truncation takes place\n\
+just after a new element is inserted.  Setting the history-length\n\
+property of a history variable overrides this default.");
+  XSETFASTINT (Vhistory_length, 30);
+
   DEFVAR_BOOL ("completion-auto-help", &auto_help,
     "*Non-nil means automatically provide help for invalid completion input.");
   auto_help = 1;