emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/subr.el


From: Kim F. Storm
Subject: [Emacs-diffs] Changes to emacs/lisp/subr.el
Date: Fri, 05 May 2006 23:35:57 +0000

Index: emacs/lisp/subr.el
diff -u emacs/lisp/subr.el:1.505 emacs/lisp/subr.el:1.506
--- emacs/lisp/subr.el:1.505    Sat Apr 29 13:56:19 2006
+++ emacs/lisp/subr.el  Fri May  5 23:35:57 2006
@@ -1122,6 +1122,32 @@
                            (if (and oa ob)
                                (< oa ob)
                              oa)))))))
+
+(defun add-to-history (history-var newelt &optional maxelt keep-dups)
+  "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
+or KEEP-DUPS is non-nil."
+  (unless maxelt
+    (setq maxelt (or (get history-var 'history-length)
+                    history-length)))
+  (let ((history (symbol-value history-var))
+       tail)
+    (if (and history-delete-duplicates (not keep-dups))
+       (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))))
+    (set history-var history)))
+
 
 ;;;; Mode hooks.
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]