diff lisp/subr.el @ 90399:a5812696f7bf unicode-pre-font-backend

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 274-284) - Update from CVS - Update etc/MORE.STUFF. - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 101) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-62
author Miles Bader <miles@gnu.org>
date Wed, 17 May 2006 07:46:49 +0000
parents 146cd8369025 a561e5346aa8
children a8190f7e546e
line wrap: on
line diff
--- a/lisp/subr.el	Mon May 15 03:48:50 2006 +0000
+++ b/lisp/subr.el	Wed May 17 07:46:49 2006 +0000
@@ -1123,28 +1123,36 @@
 				(< oa ob)
 			      oa)))))))
 
-(defun add-to-history (history-var newelt &optional maxelt)
+(defun add-to-history (history-var newelt &optional maxelt keep-all)
   "Add NEWELT to the history list stored in the variable HISTORY-VAR.
 Return the new history list.
 If MAXELT is non-nil, it specifies the maximum length of the history.
 Otherwise, the maximum history length is the value of the `history-length'
 property on symbol HISTORY-VAR, if set, or the value of the `history-length'
 variable.
-Remove duplicates of NEWELT unless `history-delete-duplicates' is nil."
+Remove duplicates of NEWELT if `history-delete-duplicates' is non-nil.
+If optional fourth arg KEEP-ALL is non-nil, add NEWELT to history even
+if it is empty or a duplicate."
   (unless maxelt
     (setq maxelt (or (get history-var 'history-length)
 		     history-length)))
   (let ((history (symbol-value history-var))
 	tail)
-    (if history-delete-duplicates
-	(setq history (delete newelt history)))
-    (setq history (cons newelt history))
-    (when (integerp maxelt)
-      (if (= 0 maxelt)
-	  (setq history nil)
-	(setq tail (nthcdr (1- maxelt) history))
-	(when (consp tail)
-	  (setcdr tail nil))))
+    (when (and (listp history)
+	       (or keep-all
+		   (not (stringp newelt))
+		   (> (length newelt) 0))
+	       (or keep-all
+		   (not (equal (car history) newelt))))
+      (if history-delete-duplicates
+	  (delete newelt history))
+      (setq history (cons newelt history))
+      (when (integerp maxelt)
+	(if (= 0 maxelt)
+	    (setq history nil)
+	  (setq tail (nthcdr (1- maxelt) history))
+	  (when (consp tail)
+	    (setcdr tail nil)))))
     (set history-var history)))