# HG changeset patch # User Kim F. Storm # Date 1100532074 0 # Node ID 6c9552cf734a5e68c4d924d341ee87c30284f613 # Parent 920e7325f52c0d8536e28f447e75162090eb7acc (Fsafe_plist_get): New defun. (syms_of_fns): Defsubr it. diff -r 920e7325f52c -r 6c9552cf734a src/fns.c --- a/src/fns.c Mon Nov 15 15:20:57 2004 +0000 +++ b/src/fns.c Mon Nov 15 15:21:14 2004 +0000 @@ -1997,6 +1997,35 @@ return Qnil; } +DEFUN ("safe-plist-get", Fsafe_plist_get, Ssafe_plist_get, 2, 2, 0, + doc: /* Extract a value from a property list. +PLIST is a property list, which is a list of the form +\(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value +corresponding to the given PROP, or nil if PROP is not +one of the properties on the list. +This function never signals an error. */) + (plist, prop) + Lisp_Object plist; + Lisp_Object prop; +{ + Lisp_Object tail, halftail; + + /* halftail is used to detect circular lists. */ + tail = halftail = plist; + while (CONSP (tail) && CONSP (XCDR (tail))) + { + if (EQ (prop, XCAR (tail))) + return XCAR (XCDR (tail)); + + tail = XCDR (XCDR (tail)); + halftail = XCDR (halftail); + if (EQ (tail, halftail)) + break; + } + + return Qnil; +} + DEFUN ("get", Fget, Sget, 2, 2, 0, doc: /* Return the value of SYMBOL's PROPNAME property. This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */) @@ -5734,6 +5763,7 @@ defsubr (&Sreverse); defsubr (&Ssort); defsubr (&Splist_get); + defsubr (&Ssafe_plist_get); defsubr (&Sget); defsubr (&Splist_put); defsubr (&Sput);