aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Wohler2006-03-10 22:52:26 +0000
committerBill Wohler2006-03-10 22:52:26 +0000
commit7c565097d15d61cef15fe7474da44a2bc9e87725 (patch)
tree7ce0e30b0890be673c925f35af6492fcf37a3983
parenta2c7d24fafbfb091fc9f74afa1e1c77d51047768 (diff)
downloademacs-7c565097d15d61cef15fe7474da44a2bc9e87725.tar.gz
emacs-7c565097d15d61cef15fe7474da44a2bc9e87725.zip
(image-load-path-for-library): Merge at least three functions from
Gnus and MH-E into this one function that can now be shared.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/image.el74
2 files changed, 80 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 000011e2de3..7892a9b6d22 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12006-03-10 Bill Wohler <wohler@newt.com>
2
3 * image.el (image-load-path-for-library): Merge at least three
4 functions from Gnus and MH-E into this one function that can now
5 be shared.
6
12006-03-11 Nick Roberts <nickrob@snap.net.nz> 72006-03-11 Nick Roberts <nickrob@snap.net.nz>
2 8
3 * progmodes/gdb-ui.el (gdb-remove-text-properties): Rename from 9 * progmodes/gdb-ui.el (gdb-remove-text-properties): Rename from
diff --git a/lisp/image.el b/lisp/image.el
index 316896cabce..4acff8d251b 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -77,6 +77,80 @@ value is used as a list of directories to search.")
77 (list (file-name-as-directory (expand-file-name "images" data-directory)) 77 (list (file-name-as-directory (expand-file-name "images" data-directory))
78 'data-directory 'load-path))) 78 'data-directory 'load-path)))
79 79
80(defun image-load-path-for-library (library image &optional path)
81 "Return a suitable search path for images relative to LIBRARY.
82
83Images for LIBRARY are searched for in \"../../etc/images\" and
84\"../etc/images\" relative to the files in \"lisp/LIBRARY\" as
85well as in `image-load-path' and `load-path'.
86
87This function returns the value of `load-path' augmented with the
88path to IMAGE. If PATH is given, it is used instead of
89`load-path'.
90
91Here is an example that uses a common idiom to provide
92compatibility with versions of Emacs that lack the variable
93`image-load-path':
94
95 (let ((load-path
96 (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\"))
97 (image-load-path
98 (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\" 'image-load-path)))
99 (mh-tool-bar-folder-buttons-init))"
100 (unless library (error "No library specified"))
101 (unless image (error "No image specified"))
102 (let ((image-directory))
103 (cond
104 ;; Try relative setting.
105 ((let (library-name d1ei d2ei)
106 ;; First, find library in the load-path.
107 (setq library-name (locate-library library))
108 (if (not library-name)
109 (error "Cannot find library %s in load-path" library))
110 ;; And then set image-directory relative to that.
111 (setq
112 ;; Go down 2 levels.
113 d2ei (expand-file-name
114 (concat (file-name-directory library-name) "../../etc/images"))
115 ;; Go down 1 level.
116 d1ei (expand-file-name
117 (concat (file-name-directory library-name) "../etc/images")))
118 (setq image-directory
119 ;; Set it to nil if image is not found.
120 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei)
121 ((file-exists-p (expand-file-name image d1ei)) d1ei)))))
122 ;; Check for images in image-load-path or load-path.
123 ((let ((img image)
124 (dir (or
125 ;; Images in image-load-path.
126 (image-search-load-path image)
127 ;; Images in load-path.
128 (locate-library image)))
129 parent)
130 ;; Since the image might be in a nested directory (for
131 ;; example, mail/attach.pbm), adjust `image-directory'
132 ;; accordingly.
133 (and dir
134 (setq dir (file-name-directory dir))
135 (progn
136 (while (setq parent (file-name-directory img))
137 (setq img (directory-file-name parent)
138 dir (expand-file-name "../" dir)))
139 (setq image-directory dir)))))
140 (t
141 (error "Could not find image %s for library %s" image library)))
142
143 ;; Return augmented `image-load-path' or `load-path'.
144 (cond ((and path (symbolp path))
145 (nconc (list image-directory)
146 (delete image-directory
147 (if (boundp path)
148 (copy-sequence (symbol-value path))
149 nil))))
150 (t
151 (nconc (list image-directory)
152 (delete image-directory (copy-sequence load-path)))))))
153
80(defun image-jpeg-p (data) 154(defun image-jpeg-p (data)
81 "Value is non-nil if DATA, a string, consists of JFIF image data. 155 "Value is non-nil if DATA, a string, consists of JFIF image data.
82We accept the tag Exif because that is the same format." 156We accept the tag Exif because that is the same format."