-;; From MH-E with modifications:
-
-(defvar gmm-image-load-path nil
- "Directory where images are found.
-See the function `gmm-image-load-path'.")
-
-(defun gmm-image-load-path ()
- "Ensure that the GMM-E images are accessible by `find-image'.
-
-Images for GMM-E are found in \"../../etc/images\" relative to the
-files in \"lisp/gmm-e\", in `image-load-path', or in `load-path'.
-This function saves the actual location found in the variable
-`gmm-image-load-path'. If the images on your system are actually
-located elsewhere, then set the variable `gmm-image-load-path'
-before starting GMM-E.
-
-If `image-load-path' exists (since Emacs 22), then the contents
-of the variable `gmm-image-load-path' is added to it if isn't
-already there. Otherwise, the contents of the variable
-`gmm-image-load-path' is added to the `load-path' if it isn't
-already there.
-
-See also variable `gmm-image-load-path-called-flag'."
- (unless gmm-image-load-path-called-flag
+;; Cf. `mh-image-load-path-for-library' in `mh-compat.el'.
+
+(defun-gmm gmm-image-load-path-for-library
+ image-load-path-for-library (library image &optional path no-error)
+ "Return a suitable search path for images used by LIBRARY.
+
+It searches for IMAGE in `image-load-path' (excluding
+\"`data-directory'/images\") and `load-path', followed by a path
+suitable for LIBRARY, which includes \"../../etc/images\" and
+\"../etc/images\" relative to the library file itself, and then
+in \"`data-directory'/images\".
+
+Then this function returns a list of directories which contains
+first the directory in which IMAGE was found, followed by the
+value of `load-path'. If PATH is given, it is used instead of
+`load-path'.
+
+If NO-ERROR is non-nil and a suitable path can't be found, don't
+signal an error. Instead, return a list of directories as before,
+except that nil appears in place of the image directory.
+
+Here is an example that uses a common idiom to provide
+compatibility with versions of Emacs that lack the variable
+`image-load-path':
+
+ ;; Shush compiler.
+ (defvar image-load-path)
+
+ (let* ((load-path (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\"))
+ (image-load-path (cons (car load-path)
+ (when (boundp 'image-load-path)
+ image-load-path))))
+ (mh-tool-bar-folder-buttons-init))"
+ (unless library (error "No library specified"))
+ (unless image (error "No image specified"))
+ (let (image-directory image-directory-load-path)
+ ;; Check for images in image-load-path or load-path.
+ (let ((img image)
+ (dir (or
+ ;; Images in image-load-path.
+ (gmm-image-search-load-path image) ;; "gmm-" prefix!
+ ;; Images in load-path.
+ (locate-library image)))
+ parent)
+ ;; Since the image might be in a nested directory (for
+ ;; example, mail/attach.pbm), adjust `image-directory'
+ ;; accordingly.
+ (when dir
+ (setq dir (file-name-directory dir))
+ (while (setq parent (file-name-directory img))
+ (setq img (directory-file-name parent)
+ dir (expand-file-name "../" dir))))
+ (setq image-directory-load-path dir))
+
+ ;; If `image-directory-load-path' isn't Emacs' image directory,
+ ;; it's probably a user preference, so use it. Then use a
+ ;; relative setting if possible; otherwise, use
+ ;; `image-directory-load-path'.