comparison lisp/subr.el @ 70415:72f273a616c1

(add-to-history): New function.
author Kim F. Storm <storm@cua.dk>
date Fri, 05 May 2006 23:35:57 +0000
parents a2c45c9f7e1f
children 7bc1bc4d2381
comparison
equal deleted inserted replaced
70414:b835c65a2dc0 70415:72f273a616c1
1120 (let ((oa (gethash a ordering)) 1120 (let ((oa (gethash a ordering))
1121 (ob (gethash b ordering))) 1121 (ob (gethash b ordering)))
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.
1128 Return the new history list.
1129 If MAXELT is non-nil, it specifies the maximum length of the history.
1130 Otherwise, the maximum history length is the value of the `history-length'
1131 property on symbol HISTORY-VAR, if set, or the value of the `history-length'
1132 variable.
1133 Remove duplicates of NEWELT unless `history-delete-duplicates' is nil
1134 or 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
1128 (defvar delay-mode-hooks nil 1154 (defvar delay-mode-hooks nil
1129 "If non-nil, `run-mode-hooks' should delay running the hooks.") 1155 "If non-nil, `run-mode-hooks' should delay running the hooks.")