Mercurial > hg > xemacs-beta
comparison lisp/subr.el @ 4461:42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
2008-02-25 bpalmer <bpalmer@gmail.com>
* subr.el(add-to-list): add support for `compare-fn' to sync with
emacs.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 14 May 2008 23:47:58 +0200 |
parents | ef9eb714f0e4 |
children | 34b42224a066 |
comparison
equal
deleted
inserted
replaced
4460:04ec3340612e | 4461:42fad34efb3f |
---|---|
388 "Add to the local value of HOOK the one-shot function FUNCTION. | 388 "Add to the local value of HOOK the one-shot function FUNCTION. |
389 You don't need this any more. It's equivalent to specifying the LOCAL | 389 You don't need this any more. It's equivalent to specifying the LOCAL |
390 argument to `add-one-shot-hook'." | 390 argument to `add-one-shot-hook'." |
391 (add-one-shot-hook hook function append t)) | 391 (add-one-shot-hook hook function append t)) |
392 | 392 |
393 (defun add-to-list (list-var element &optional append) | 393 (defun add-to-list (list-var element &optional append compare-fn) |
394 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. | 394 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. |
395 The test for presence of ELEMENT is done with `equal'. | 395 The test for presence of ELEMENT is done with COMPARE-FN; if |
396 If ELEMENT is added, it is added at the beginning of the list, | 396 COMPARE-FN is nil, then it defaults to `equal'. If ELEMENT is added, |
397 unless the optional argument APPEND is non-nil, in which case | 397 it is added at the beginning of the list, unless the optional argument |
398 ELEMENT is added at the end. | 398 APPEND is non-nil, in which case ELEMENT is added at the end. |
399 | 399 |
400 If you want to use `add-to-list' on a variable that is not defined | 400 If you want to use `add-to-list' on a variable that is not defined |
401 until a certain package is loaded, you should put the call to `add-to-list' | 401 until a certain package is loaded, you should put the call to `add-to-list' |
402 into a hook function that will be run only after loading the package. | 402 into a hook function that will be run only after loading the package. |
403 `eval-after-load' provides one way to do this. In some cases | 403 `eval-after-load' provides one way to do this. In some cases |
404 other hooks, such as major mode hooks, can do the job." | 404 other hooks, such as major mode hooks, can do the job." |
405 (if (member element (symbol-value list-var)) | 405 (if (if (not compare-fn) |
406 (member element (symbol-value list-var)) | |
407 (member* element (symbol-value list-var) :test compare-fn)) | |
406 (symbol-value list-var) | 408 (symbol-value list-var) |
407 (set list-var | 409 (set list-var |
408 (if append | 410 (if append |
409 (append (symbol-value list-var) (list element)) | 411 (append (symbol-value list-var) (list element)) |
410 (cons element (symbol-value list-var)))))) | 412 (cons element (symbol-value list-var)))))) |