diff options
| author | Kim F. Storm | 2006-05-05 23:35:57 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2006-05-05 23:35:57 +0000 |
| commit | 6b04bd6eec639d158e3dbb4de3d77b2b8dde3e6a (patch) | |
| tree | 0123c432a694dc11bd109634d940827f84310ef9 | |
| parent | d91bd17cb6e8699e64411465b84960e088e1cd10 (diff) | |
| download | emacs-6b04bd6eec639d158e3dbb4de3d77b2b8dde3e6a.tar.gz emacs-6b04bd6eec639d158e3dbb4de3d77b2b8dde3e6a.zip | |
(add-to-history): New function.
| -rw-r--r-- | lisp/subr.el | 26 |
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. | ||
| 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 | ||