aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/image.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/image.el')
-rw-r--r--lisp/image.el80
1 files changed, 49 insertions, 31 deletions
diff --git a/lisp/image.el b/lisp/image.el
index 6938dba05cb..2212b0fb471 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -79,12 +79,13 @@ value is used as a list of directories to search.")
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 used by LIBRARY.
83 83
84First it searches for IMAGE in a path suitable for LIBRARY, which 84It searches for IMAGE in `image-load-path' (excluding
85includes \"../../etc/images\" and \"../etc/images\" relative to 85\"`data-directory'/images\") and `load-path', followed by a path
86the library file itself, followed by `image-load-path' and 86suitable for LIBRARY, which includes \"../../etc/images\" and
87`load-path'. 87\"../etc/images\" relative to the library file itself, and then
88in \"`data-directory'/images\".
88 89
89Then this function returns a list of directories which contains 90Then this function returns a list of directories which contains
90first the directory in which IMAGE was found, followed by the 91first the directory in which IMAGE was found, followed by the
@@ -99,16 +100,46 @@ Here is an example that uses a common idiom to provide
99compatibility with versions of Emacs that lack the variable 100compatibility with versions of Emacs that lack the variable
100`image-load-path': 101`image-load-path':
101 102
102 ;; Avoid errors on Emacsen without `image-load-path'. 103 ;; Shush compiler.
103 (if (not (boundp 'image-load-path)) (defvar image-load-path nil)) 104 (defvar image-load-path)
104 105
105 (let* ((load-path (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\")) 106 (let* ((load-path (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\"))
106 (image-load-path (cons (car load-path) image-load-path))) 107 (image-load-path (cons (car load-path)
108 (when (boundp 'image-load-path)
109 image-load-path))))
107 (mh-tool-bar-folder-buttons-init))" 110 (mh-tool-bar-folder-buttons-init))"
108 (unless library (error "No library specified")) 111 (unless library (error "No library specified"))
109 (unless image (error "No image specified")) 112 (unless image (error "No image specified"))
110 (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'.
111 (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))
112 ;; Try relative setting. 143 ;; Try relative setting.
113 ((let (library-name d1ei d2ei) 144 ((let (library-name d1ei d2ei)
114 ;; First, find library in the load-path. 145 ;; First, find library in the load-path.
@@ -118,33 +149,20 @@ compatibility with versions of Emacs that lack the variable
118 ;; And then set image-directory relative to that. 149 ;; And then set image-directory relative to that.
119 (setq 150 (setq
120 ;; Go down 2 levels. 151 ;; Go down 2 levels.
121 d2ei (expand-file-name 152 d2ei (file-name-as-directory
122 (concat (file-name-directory library-name) "../../etc/images")) 153 (expand-file-name
154 (concat (file-name-directory library-name) "../../etc/images")))
123 ;; Go down 1 level. 155 ;; Go down 1 level.
124 d1ei (expand-file-name 156 d1ei (file-name-as-directory
125 (concat (file-name-directory library-name) "../etc/images"))) 157 (expand-file-name
158 (concat (file-name-directory library-name) "../etc/images"))))
126 (setq image-directory 159 (setq image-directory
127 ;; Set it to nil if image is not found. 160 ;; Set it to nil if image is not found.
128 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei) 161 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei)
129 ((file-exists-p (expand-file-name image d1ei)) d1ei))))) 162 ((file-exists-p (expand-file-name image d1ei)) d1ei)))))
130 ;; Check for images in image-load-path or load-path. 163 ;; Use Emacs' image directory.
131 ((let ((img image) 164 (image-directory-load-path
132 (dir (or 165 (setq image-directory image-directory-load-path))
133 ;; Images in image-load-path.
134 (image-search-load-path image)
135 ;; Images in load-path.
136 (locate-library image)))
137 parent)
138 ;; Since the image might be in a nested directory (for
139 ;; example, mail/attach.pbm), adjust `image-directory'
140 ;; accordingly.
141 (and dir
142 (setq dir (file-name-directory dir))
143 (progn
144 (while (setq parent (file-name-directory img))
145 (setq img (directory-file-name parent)
146 dir (expand-file-name "../" dir)))
147 (setq image-directory dir)))))
148 (no-error 166 (no-error
149 (message "Could not find image %s for library %s" image library)) 167 (message "Could not find image %s for library %s" image library))
150 (t 168 (t