+(defun mm-preferred-alternative (handles &optional preferred)
+ "Say which of HANDLES are preferred."
+ (let ((prec (if preferred (list preferred) mm-alternative-precedence))
+ p h result type handle)
+ (while (setq p (pop prec))
+ (setq h handles)
+ (while h
+ (setq type
+ (if (stringp (caar h))
+ (caar h)
+ (car (mm-handle-type (car h)))))
+ (setq handle (car h))
+ (when (and (equal p type)
+ (mm-automatic-display-p type)
+ (or (stringp (caar h))
+ (not (mm-handle-disposition (car h)))
+ (equal (car (mm-handle-disposition (car h)))
+ "inline")))
+ (setq result (car h)
+ h nil
+ prec nil))
+ (pop h)))
+ result))
+
+(defun mm-get-content-id (id)
+ "Return the handle(s) referred to by ID."
+ (cdr (assoc id mm-content-id-alist)))
+
+(defun mm-get-image (handle)
+ "Return an image instance based on HANDLE."
+ (let ((type (cadr (split-string (car (mm-handle-type handle)) "/")))
+ spec)
+ ;; Allow some common translations.
+ (setq type
+ (cond
+ ((equal type "x-pixmap")
+ "xpm")
+ ((equal type "x-xbitmap")
+ "xbm")
+ (t type)))
+ (or (mm-handle-cache handle)
+ (mm-with-unibyte-buffer
+ (mm-insert-part handle)
+ (prog1
+ (setq spec
+ (make-glyph `[,(intern type) :data ,(buffer-string)]))
+ (mm-handle-set-cache handle spec))))))
+
+(defun mm-image-fit-p (handle)
+ "Say whether the image in HANDLE will fit the current window."
+ (let ((image (mm-get-image handle)))
+ (or mm-all-images-fit
+ (and (< (glyph-width image) (window-pixel-width))
+ (< (glyph-height image) (window-pixel-height))))))
+