+ (delete-overlay overlay)))
+ (setq overlays (cdr overlays)))))
+
+
+;;;###autoload
+(defun find-image (specs)
+ "Find an image, choosing one of a list of image specifications.
+
+SPECS is a list of image specifications.
+
+Each image specification in SPECS is a property list. The contents of
+a specification are image type dependent. All specifications must at
+least contain the properties `:type TYPE' and either `:file FILE' or
+`:data DATA', where TYPE is a symbol specifying the image type,
+e.g. `xbm', FILE is the file to load the image from, and DATA is a
+string containing the actual image data. The specification whose TYPE
+is supported, and FILE exists, is used to construct the image
+specification to be returned. Return nil if no specification is
+satisfied.
+
+The image is looked for first on `load-path' and then in `data-directory'."
+ (let (image)
+ (while (and specs (null image))
+ (let* ((spec (car specs))
+ (type (plist-get spec :type))
+ (data (plist-get spec :data))
+ (file (plist-get spec :file))
+ found)
+ (when (image-type-available-p type)
+ (cond ((stringp file)
+ (let ((path load-path))
+ (while (and (not found) path)
+ (let ((try-file (expand-file-name file (car path))))
+ (when (file-readable-p try-file)
+ (setq found try-file)))
+ (setq path (cdr path)))
+ (unless found
+ (let ((try-file (expand-file-name file data-directory)))
+ (if (file-readable-p try-file)
+ (setq found try-file))))
+ (if found
+ (setq image
+ (cons 'image (plist-put (copy-sequence spec)
+ :file found))))))
+ ((not (null data))
+ (setq image (cons 'image spec)))))
+ (setq specs (cdr specs))))
+ image))