comparison lisp/mh-e/mh-compat.el @ 69518:2f7238ff01ad

(mh-image-load-path-for-library): Prefer user's images.
author Bill Wohler <wohler@newt.com>
date Thu, 16 Mar 2006 17:00:02 +0000
parents 6afc0d1f682b
children 052139add0ff
comparison
equal deleted inserted replaced
69517:a1a937e48976 69518:2f7238ff01ad
117 117
118 (mh-defun-compat mh-image-load-path-for-library 118 (mh-defun-compat mh-image-load-path-for-library
119 image-load-path-for-library (library image &optional path no-error) 119 image-load-path-for-library (library image &optional path no-error)
120 "Return a suitable search path for images relative to LIBRARY. 120 "Return a suitable search path for images relative to LIBRARY.
121 121
122 First it searches for IMAGE in a path suitable for LIBRARY, which 122 First it searches for IMAGE in `image-load-path' (excluding
123 includes \"../../etc/images\" and \"../etc/images\" relative to 123 \"`data-directory'/images\") and `load-path', followed by a path
124 the library file itself, followed by `image-load-path' and 124 suitable for LIBRARY, which includes \"../../etc/images\" and
125 `load-path'. 125 \"../etc/images\" relative to the library file itself, and then
126 in \"`data-directory'/images\".
126 127
127 Then this function returns a list of directories which contains 128 Then this function returns a list of directories which contains
128 first the directory in which IMAGE was found, followed by the 129 first the directory in which IMAGE was found, followed by the
129 value of `load-path'. If PATH is given, it is used instead of 130 value of `load-path'. If PATH is given, it is used instead of
130 `load-path'. 131 `load-path'.
145 (when (boundp 'image-load-path) 146 (when (boundp 'image-load-path)
146 image-load-path)))) 147 image-load-path))))
147 (mh-tool-bar-folder-buttons-init))" 148 (mh-tool-bar-folder-buttons-init))"
148 (unless library (error "No library specified")) 149 (unless library (error "No library specified"))
149 (unless image (error "No image specified")) 150 (unless image (error "No image specified"))
150 (let ((image-directory)) 151 (let (image-directory image-directory-load-path)
152 ;; Check for images in image-load-path or load-path.
153 (let ((img image)
154 (dir (or
155 ;; Images in image-load-path.
156 (mh-image-search-load-path image)
157 ;; Images in load-path.
158 (locate-library image)))
159 parent)
160 ;; Since the image might be in a nested directory (for
161 ;; example, mail/attach.pbm), adjust `image-directory'
162 ;; accordingly.
163 (when dir
164 (setq dir (file-name-directory dir))
165 (while (setq parent (file-name-directory img))
166 (setq img (directory-file-name parent)
167 dir (expand-file-name "../" dir))))
168 (setq image-directory-load-path dir))
169
170 ;; If `image-directory-load-path' isn't Emacs' image directory,
171 ;; it's probably a user preference, so use it. Then use a
172 ;; relative setting if possible; otherwise, use
173 ;; `image-directory-load-path'.
151 (cond 174 (cond
175 ;; User-modified image-load-path?
176 ((and image-directory-load-path
177 (not (equal image-directory-load-path
178 (file-name-as-directory
179 (expand-file-name "images" data-directory)))))
180 (setq image-directory image-directory-load-path))
152 ;; Try relative setting. 181 ;; Try relative setting.
153 ((let (library-name d1ei d2ei) 182 ((let (library-name d1ei d2ei)
154 ;; First, find library in the load-path. 183 ;; First, find library in the load-path.
155 (setq library-name (locate-library library)) 184 (setq library-name (locate-library library))
156 (if (not library-name) 185 (if (not library-name)
157 (error "Cannot find library %s in load-path" library)) 186 (error "Cannot find library %s in load-path" library))
158 ;; And then set image-directory relative to that. 187 ;; And then set image-directory relative to that.
159 (setq 188 (setq
160 ;; Go down 2 levels. 189 ;; Go down 2 levels.
161 d2ei (expand-file-name 190 d2ei (file-name-as-directory
162 (concat (file-name-directory library-name) "../../etc/images")) 191 (expand-file-name
192 (concat (file-name-directory library-name) "../../etc/images")))
163 ;; Go down 1 level. 193 ;; Go down 1 level.
164 d1ei (expand-file-name 194 d1ei (file-name-as-directory
165 (concat (file-name-directory library-name) "../etc/images"))) 195 (expand-file-name
196 (concat (file-name-directory library-name) "../etc/images"))))
166 (setq image-directory 197 (setq image-directory
167 ;; Set it to nil if image is not found. 198 ;; Set it to nil if image is not found.
168 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei) 199 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei)
169 ((file-exists-p (expand-file-name image d1ei)) d1ei))))) 200 ((file-exists-p (expand-file-name image d1ei)) d1ei)))))
170 ;; Check for images in image-load-path or load-path. 201 ;; Use Emacs' image directory.
171 ((let ((img image) 202 (image-directory-load-path
172 (dir (or 203 (setq image-directory image-directory-load-path))
173 ;; Images in image-load-path.
174 (mh-image-search-load-path image)
175 ;; Images in load-path.
176 (locate-library image)))
177 parent)
178 ;; Since the image might be in a nested directory (for
179 ;; example, mail/attach.pbm), adjust `image-directory'
180 ;; accordingly.
181 (and dir
182 (setq dir (file-name-directory dir))
183 (progn
184 (while (setq parent (file-name-directory img))
185 (setq img (directory-file-name parent)
186 dir (expand-file-name "../" dir)))
187 (setq image-directory dir)))))
188 (no-error 204 (no-error
189 (message "Could not find image %s for library %s" image library)) 205 (message "Could not find image %s for library %s" image library))
190 (t 206 (t
191 (error "Could not find image %s for library %s" image library))) 207 (error "Could not find image %s for library %s" image library)))
192 208