diff options
| -rw-r--r-- | lisp/subr.el | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index ee6c468d711..956fcef64f4 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1123,28 +1123,36 @@ The return value is the new value of LIST-VAR." | |||
| 1123 | (< oa ob) | 1123 | (< oa ob) |
| 1124 | oa))))))) | 1124 | oa))))))) |
| 1125 | 1125 | ||
| 1126 | (defun add-to-history (history-var newelt &optional maxelt) | 1126 | (defun add-to-history (history-var newelt &optional maxelt keep-all) |
| 1127 | "Add NEWELT to the history list stored in the variable HISTORY-VAR. | 1127 | "Add NEWELT to the history list stored in the variable HISTORY-VAR. |
| 1128 | Return the new history list. | 1128 | Return the new history list. |
| 1129 | If MAXELT is non-nil, it specifies the maximum length of the history. | 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' | 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' | 1131 | property on symbol HISTORY-VAR, if set, or the value of the `history-length' |
| 1132 | variable. | 1132 | variable. |
| 1133 | Remove duplicates of NEWELT unless `history-delete-duplicates' is nil." | 1133 | Remove duplicates of NEWELT if `history-delete-duplicates' is non-nil. |
| 1134 | If optional fourth arg KEEP-ALL is non-nil, add NEWELT to history even | ||
| 1135 | if it is empty or a duplicate." | ||
| 1134 | (unless maxelt | 1136 | (unless maxelt |
| 1135 | (setq maxelt (or (get history-var 'history-length) | 1137 | (setq maxelt (or (get history-var 'history-length) |
| 1136 | history-length))) | 1138 | history-length))) |
| 1137 | (let ((history (symbol-value history-var)) | 1139 | (let ((history (symbol-value history-var)) |
| 1138 | tail) | 1140 | tail) |
| 1139 | (if history-delete-duplicates | 1141 | (when (and (listp history) |
| 1140 | (setq history (delete newelt history))) | 1142 | (or keep-all |
| 1141 | (setq history (cons newelt history)) | 1143 | (not (stringp newelt)) |
| 1142 | (when (integerp maxelt) | 1144 | (> (length newelt) 0)) |
| 1143 | (if (= 0 maxelt) | 1145 | (or keep-all |
| 1144 | (setq history nil) | 1146 | (not (equal (car history) newelt)))) |
| 1145 | (setq tail (nthcdr (1- maxelt) history)) | 1147 | (if history-delete-duplicates |
| 1146 | (when (consp tail) | 1148 | (delete newelt history)) |
| 1147 | (setcdr tail nil)))) | 1149 | (setq history (cons newelt history)) |
| 1150 | (when (integerp maxelt) | ||
| 1151 | (if (= 0 maxelt) | ||
| 1152 | (setq history nil) | ||
| 1153 | (setq tail (nthcdr (1- maxelt) history)) | ||
| 1154 | (when (consp tail) | ||
| 1155 | (setcdr tail nil))))) | ||
| 1148 | (set history-var history))) | 1156 | (set history-var history))) |
| 1149 | 1157 | ||
| 1150 | 1158 | ||