Mercurial > emacs
changeset 22860:349fa4ee1f27
(assoc-default): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 31 Jul 1998 10:53:30 +0000 |
parents | 16dcade0dd4a |
children | 49e731d1ddb6 |
files | lisp/subr.el |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/subr.el Fri Jul 31 10:24:41 1998 +0000 +++ b/lisp/subr.el Fri Jul 31 10:53:30 1998 +0000 @@ -93,6 +93,18 @@ (while (cdr x) (setq x (cdr x))) x)) + +(defun assoc-default (el alist test default) + "Find object EL in a pseudo-alist ALIST. +ALIST is a list of conses or objects. Each element (or the element's +car, if it. is a cons) is compared with EL by calling TEST. +If TEST returns non-nil, the element matches; +then `assoc-default' returns the cdr of the element (if it is a cons), +or DEFAULT if the element is not a cons. +If no element matches, the value is nil." + (dolist (rr alist) + (when (funcall test el (if (consp rr) (car rr) rr)) + (return (if (consp rr) (cdr rr) default))))) ;;;; Keymap support.