aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2006-05-05 23:35:57 +0000
committerKim F. Storm2006-05-05 23:35:57 +0000
commit6b04bd6eec639d158e3dbb4de3d77b2b8dde3e6a (patch)
tree0123c432a694dc11bd109634d940827f84310ef9
parentd91bd17cb6e8699e64411465b84960e088e1cd10 (diff)
downloademacs-6b04bd6eec639d158e3dbb4de3d77b2b8dde3e6a.tar.gz
emacs-6b04bd6eec639d158e3dbb4de3d77b2b8dde3e6a.zip
(add-to-history): New function.
-rw-r--r--lisp/subr.el26
1 files changed, 26 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 8b8416375b1..82d60a34d5f 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1122,6 +1122,32 @@ The return value is the new value of LIST-VAR."
1122 (if (and oa ob) 1122 (if (and oa ob)
1123 (< oa ob) 1123 (< oa ob)
1124 oa))))))) 1124 oa)))))))
1125
1126(defun add-to-history (history-var newelt &optional maxelt keep-dups)
1127 "Add NEWELT to the history list stored in the variable HISTORY-VAR.
1128Return the new history list.
1129If MAXELT is non-nil, it specifies the maximum length of the history.
1130Otherwise, the maximum history length is the value of the `history-length'
1131property on symbol HISTORY-VAR, if set, or the value of the `history-length'
1132variable.
1133Remove duplicates of NEWELT unless `history-delete-duplicates' is nil
1134or KEEP-DUPS is non-nil."
1135 (unless maxelt
1136 (setq maxelt (or (get history-var 'history-length)
1137 history-length)))
1138 (let ((history (symbol-value history-var))
1139 tail)
1140 (if (and history-delete-duplicates (not keep-dups))
1141 (setq history (delete newelt history)))
1142 (setq history (cons newelt history))
1143 (when (integerp maxelt)
1144 (if (= 0 maxelt)
1145 (setq history nil)
1146 (setq tail (nthcdr (1- maxelt) history))
1147 (when (consp tail)
1148 (setcdr tail nil))))
1149 (set history-var history)))
1150
1125 1151
1126;;;; Mode hooks. 1152;;;; Mode hooks.
1127 1153