| | 1125 | |
|---|
| | 1126 | (defun add-to-history (history-var newelt &optional maxelt) |
|---|
| | 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 | (unless maxelt |
|---|
| | 1135 | (setq maxelt (or (get history-var 'history-length) |
|---|
| | 1136 | history-length))) |
|---|
| | 1137 | (let ((history (symbol-value history-var)) |
|---|
| | 1138 | tail) |
|---|
| | 1139 | (if history-delete-duplicates |
|---|
| | 1140 | (setq history (delete newelt history))) |
|---|
| | 1141 | (setq history (cons newelt history)) |
|---|
| | 1142 | (when (integerp maxelt) |
|---|
| | 1143 | (if (= 0 maxelt) |
|---|
| | 1144 | (setq history nil) |
|---|
| | 1145 | (setq tail (nthcdr (1- maxelt) history)) |
|---|
| | 1146 | (when (consp tail) |
|---|
| | 1147 | (setcdr tail nil)))) |
|---|
| | 1148 | (set history-var history))) |
|---|
| | 1149 | |
|---|