Mercurial > emacs
comparison lisp/image.el @ 69516:e419733d5cf6
(image-load-path-for-library): Prefer user's images in
image-load-path.
author | Bill Wohler <wohler@newt.com> |
---|---|
date | Thu, 16 Mar 2006 16:55:26 +0000 |
parents | 4f9233243d97 |
children | 3feef8dfbff5 |
comparison
equal
deleted
inserted
replaced
69515:9fba91bc5b5d | 69516:e419733d5cf6 |
---|---|
79 | 79 |
80 | 80 |
81 (defun image-load-path-for-library (library image &optional path no-error) | 81 (defun image-load-path-for-library (library image &optional path no-error) |
82 "Return a suitable search path for images relative to LIBRARY. | 82 "Return a suitable search path for images relative to LIBRARY. |
83 | 83 |
84 First it searches for IMAGE in a path suitable for LIBRARY, which | 84 First it searches for IMAGE in `image-load-path' (excluding |
85 includes \"../../etc/images\" and \"../etc/images\" relative to | 85 \"`data-directory'/images\") and `load-path', followed by a path |
86 the library file itself, followed by `image-load-path' and | 86 suitable for LIBRARY, which includes \"../../etc/images\" and |
87 `load-path'. | 87 \"../etc/images\" relative to the library file itself, and then |
88 in \"`data-directory'/images\". | |
88 | 89 |
89 Then this function returns a list of directories which contains | 90 Then this function returns a list of directories which contains |
90 first the directory in which IMAGE was found, followed by the | 91 first the directory in which IMAGE was found, followed by the |
91 value of `load-path'. If PATH is given, it is used instead of | 92 value of `load-path'. If PATH is given, it is used instead of |
92 `load-path'. | 93 `load-path'. |
107 (when (boundp 'image-load-path) | 108 (when (boundp 'image-load-path) |
108 image-load-path)))) | 109 image-load-path)))) |
109 (mh-tool-bar-folder-buttons-init))" | 110 (mh-tool-bar-folder-buttons-init))" |
110 (unless library (error "No library specified")) | 111 (unless library (error "No library specified")) |
111 (unless image (error "No image specified")) | 112 (unless image (error "No image specified")) |
112 (let ((image-directory)) | 113 (let (image-directory image-directory-load-path) |
114 ;; Check for images in image-load-path or load-path. | |
115 (let ((img image) | |
116 (dir (or | |
117 ;; Images in image-load-path. | |
118 (image-search-load-path image) | |
119 ;; Images in load-path. | |
120 (locate-library image))) | |
121 parent) | |
122 ;; Since the image might be in a nested directory (for | |
123 ;; example, mail/attach.pbm), adjust `image-directory' | |
124 ;; accordingly. | |
125 (when dir | |
126 (setq dir (file-name-directory dir)) | |
127 (while (setq parent (file-name-directory img)) | |
128 (setq img (directory-file-name parent) | |
129 dir (expand-file-name "../" dir)))) | |
130 (setq image-directory-load-path dir)) | |
131 | |
132 ;; If `image-directory-load-path' isn't Emacs' image directory, | |
133 ;; it's probably a user preference, so use it. Then use a | |
134 ;; relative setting if possible; otherwise, use | |
135 ;; `image-directory-load-path'. | |
113 (cond | 136 (cond |
137 ;; User-modified image-load-path? | |
138 ((and image-directory-load-path | |
139 (not (equal image-directory-load-path | |
140 (file-name-as-directory | |
141 (expand-file-name "images" data-directory))))) | |
142 (setq image-directory image-directory-load-path)) | |
114 ;; Try relative setting. | 143 ;; Try relative setting. |
115 ((let (library-name d1ei d2ei) | 144 ((let (library-name d1ei d2ei) |
116 ;; First, find library in the load-path. | 145 ;; First, find library in the load-path. |
117 (setq library-name (locate-library library)) | 146 (setq library-name (locate-library library)) |
118 (if (not library-name) | 147 (if (not library-name) |
119 (error "Cannot find library %s in load-path" library)) | 148 (error "Cannot find library %s in load-path" library)) |
120 ;; And then set image-directory relative to that. | 149 ;; And then set image-directory relative to that. |
121 (setq | 150 (setq |
122 ;; Go down 2 levels. | 151 ;; Go down 2 levels. |
123 d2ei (expand-file-name | 152 d2ei (file-name-as-directory |
124 (concat (file-name-directory library-name) "../../etc/images")) | 153 (expand-file-name |
154 (concat (file-name-directory library-name) "../../etc/images"))) | |
125 ;; Go down 1 level. | 155 ;; Go down 1 level. |
126 d1ei (expand-file-name | 156 d1ei (file-name-as-directory |
127 (concat (file-name-directory library-name) "../etc/images"))) | 157 (expand-file-name |
158 (concat (file-name-directory library-name) "../etc/images")))) | |
128 (setq image-directory | 159 (setq image-directory |
129 ;; Set it to nil if image is not found. | 160 ;; Set it to nil if image is not found. |
130 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei) | 161 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei) |
131 ((file-exists-p (expand-file-name image d1ei)) d1ei))))) | 162 ((file-exists-p (expand-file-name image d1ei)) d1ei))))) |
132 ;; Check for images in image-load-path or load-path. | 163 ;; Use Emacs' image directory. |
133 ((let ((img image) | 164 (image-directory-load-path |
134 (dir (or | 165 (setq image-directory image-directory-load-path)) |
135 ;; Images in image-load-path. | |
136 (image-search-load-path image) | |
137 ;; Images in load-path. | |
138 (locate-library image))) | |
139 parent) | |
140 ;; Since the image might be in a nested directory (for | |
141 ;; example, mail/attach.pbm), adjust `image-directory' | |
142 ;; accordingly. | |
143 (and dir | |
144 (setq dir (file-name-directory dir)) | |
145 (progn | |
146 (while (setq parent (file-name-directory img)) | |
147 (setq img (directory-file-name parent) | |
148 dir (expand-file-name "../" dir))) | |
149 (setq image-directory dir))))) | |
150 (no-error | 166 (no-error |
151 (message "Could not find image %s for library %s" image library)) | 167 (message "Could not find image %s for library %s" image library)) |
152 (t | 168 (t |
153 (error "Could not find image %s for library %s" image library))) | 169 (error "Could not find image %s for library %s" image library))) |
154 | 170 |