"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
- (cond
- (gmm-image-load-path) ; user setting exists
- ((let (gmm-library-name) ; try relative setting
- ;; First, find gmm-e in the load-path.
- (setq gmm-library-name (locate-library "gmm-e"))
- (if (not gmm-library-name)
- (error "Can not find GMM-E in load-path"))
- ;; And then set gmm-image-load-path relative to that.
- (setq gmm-image-load-path
- (expand-file-name (concat
- (file-name-directory gmm-library-name)
- "../../etc/images")))
- (file-exists-p (expand-file-name "gmm-logo.xpm" gmm-image-load-path))))
- ((gmm-image-search-load-path "gmm-logo.xpm")
- ;; Images in image-load-path.
- (setq gmm-image-load-path
- (file-name-directory (gmm-image-search-load-path "gmm-logo.xpm"))))
- ((locate-library "gmm-logo.xpm")
- ;; Images in load-path.
- (setq gmm-image-load-path
- (file-name-directory (locate-library "gmm-logo.xpm")))))
-
- (if (not (file-exists-p gmm-image-load-path))
- (error "Directory %s in gmm-image-load-path does not exist"
- gmm-image-load-path))
- (if (not (file-exists-p
- (expand-file-name "gmm-logo.xpm" gmm-image-load-path)))
- (error "Directory %s in gmm-image-load-path does not contain GMM-E images"
- gmm-image-load-path))
- (if (boundp 'image-load-path)
- (add-to-list 'image-load-path gmm-image-load-path)
- (add-to-list 'load-path gmm-image-load-path))
-
- (setq gmm-image-load-path-called-flag t)))
+(defun gmm-image-load-path (library image &optional path)
+ "Return a suitable search path for images of LIBRARY.
+
+Images for LIBRARY are found in \"../../etc/images\" relative to
+the files in \"lisp/LIBRARY\", in `image-load-path', or in
+`load-path'.
+
+This function returns value of `load-path' augmented with the
+path to IMAGE. If PATH is given, it is used instead of
+`load-path'."
+ (unless library (error "No library specified."))
+ (unless image (error "No image specified."))
+ (cond (gmm-image-load-path) ;; User setting exists.
+ ((let (gmm-library-name) ;; Try relative setting
+ ;; First, find library in the load-path.
+ (setq gmm-library-name (locate-library library))
+ (if (not gmm-library-name)
+ (error "Cannot find library `%s' in load-path" library))
+ ;; And then set gmm-image-load-path relative to that.
+ (setq gmm-image-load-path
+ (expand-file-name (concat
+ (file-name-directory gmm-library-name)
+ "../../etc/images")))
+ (file-exists-p (expand-file-name image gmm-image-load-path))))
+ ((gmm-image-search-load-path image)
+ ;; Images in image-load-path.
+ (setq gmm-image-load-path
+ (file-name-directory (gmm-image-search-load-path image))))
+ ((locate-library image)
+ ;; Images in load-path.
+ (setq gmm-image-load-path
+ (file-name-directory (locate-library image)))))
+ ;;
+ (unless (file-exists-p gmm-image-load-path)
+ (error "Directory `%s' in gmm-image-load-path does not exist"
+ gmm-image-load-path))
+ (unless (file-exists-p (expand-file-name image gmm-image-load-path))
+ (error "Directory `%s' in gmm-image-load-path does not contain image `%s'."
+ gmm-image-load-path image))
+ ;; Return augmented `image-load-path' or `load-path'.
+ (cond ((and path (symbolp path))
+ (nconc (list gmm-image-load-path)
+ (delete gmm-image-load-path (if (boundp path)
+ (symbol-value path)
+ nil))))
+ (t
+ (nconc (list gmm-image-load-path)
+ (delete gmm-image-load-path load-path)))))
(provide 'gmm-utils)