(gmm-image-load-path): Added arguments LIBRARY, IMAGE and PATH. Don't modify
authorReiner Steib <Reiner.Steib@gmx.de>
Tue, 21 Feb 2006 21:17:33 +0000 (21:17 +0000)
committerReiner Steib <Reiner.Steib@gmx.de>
Tue, 21 Feb 2006 21:17:33 +0000 (21:17 +0000)
paths.  Don't use *-image-load-path-called-flag.

lisp/ChangeLog
lisp/gmm-utils.el

index 5d43408..8dd6c63 100644 (file)
@@ -3,7 +3,9 @@
        * gmm-utils.el (gmm-defun-compat, gmm-image-search-load-path): New
        functions from MH-E.
        (gmm-image-load-path): New variable from MH-E.
-       (gmm-image-load-path): New function from MH-E.
+       (gmm-image-load-path): New function from MH-E.  Added arguments
+       LIBRARY, IMAGE and PATH.  Don't modify paths.  Don't use
+       *-image-load-path-called-flag.
 
 2006-02-21  Arne J\e,Ax\e(Brgensen <arne@arnested.dk>
 
index c8a2b8f..592da16 100644 (file)
@@ -258,58 +258,54 @@ This function returns nil on those systems."
   "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)