(setq path (cdr path)))
(if found filename)))
+(defvar find-image--cache (make-hash-table :test #'equal))
+
;;;###autoload
-(defun find-image (specs)
+(defun find-image (specs &optional cache)
"Find an image, choosing one of a list of image specifications.
SPECS is a list of image specifications.
specification to be returned. Return nil if no specification is
satisfied.
+If CACHE is non-nil, results are cached and returned on subsequent calls.
+
The image is looked for in `image-load-path'.
Image files should not be larger than specified by `max-image-size'."
- (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)
- (if (setq found (image-search-load-path file))
- (setq image
- (cons 'image (plist-put (copy-sequence spec)
- :file found)))))
- ((not (null data))
- (setq image (cons 'image spec)))))
- (setq specs (cdr specs))))
- image))
+ (or (and cache
+ (gethash specs find-image--cache))
+ (let ((orig-specs specs)
+ 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)
+ (if (setq found (image-search-load-path file))
+ (setq image
+ (cons 'image (plist-put (copy-sequence spec)
+ :file found)))))
+ ((not (null data))
+ (setq image (cons 'image spec)))))
+ (setq specs (cdr specs))))
+ (when cache
+ (setf (gethash orig-specs find-image--cache) image))
+ image)))
;;;###autoload
((< (display-color-cells) 256)
',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec))
(t
- ',(list xpm-spec pbm-spec xbm-spec))))))
+ ',(list xpm-spec pbm-spec xbm-spec)))
+ t)))
;;;###autoload
(defun tool-bar-local-item (icon def key map &rest props)