comparison lisp/image.el @ 29470:7bde123bed95

(find-image): Doc fix. Return nil if image not found. (put-image, insert-image): Make STRING arg optional.
author Dave Love <fx@gnu.org>
date Tue, 06 Jun 2000 14:27:42 +0000
parents 56c76b64f321
children 42d156d8d8eb
comparison
equal deleted inserted replaced
29469:f9b5fe053f7c 29470:7bde123bed95
109 (append (list 'image :type type (if data-p :data :file) file-or-data) 109 (append (list 'image :type type (if data-p :data :file) file-or-data)
110 props))) 110 props)))
111 111
112 112
113 ;;;###autoload 113 ;;;###autoload
114 (defun put-image (image pos string &optional area) 114 (defun put-image (image pos &optional string area)
115 "Put image IMAGE in front of POS in the current buffer. 115 "Put image IMAGE in front of POS in the current buffer.
116 IMAGE must be an image created with `create-image' or `defimage'. 116 IMAGE must be an image created with `create-image' or `defimage'.
117 IMAGE is displayed by putting an overlay into the current buffer with a 117 IMAGE is displayed by putting an overlay into the current buffer with a
118 `before-string' STRING that has a `display' property whose value is the 118 `before-string' STRING that has a `display' property whose value is the
119 image. 119 image. STRING is defaulted if you omit it.
120 POS may be an integer or marker. 120 POS may be an integer or marker.
121 AREA is where to display the image. AREA nil or omitted means 121 AREA is where to display the image. AREA nil or omitted means
122 display it in the text area, a value of `left-margin' means 122 display it in the text area, a value of `left-margin' means
123 display it in the left marginal area, a value of `right-margin' 123 display it in the left marginal area, a value of `right-margin'
124 means display it in the right marginal area." 124 means display it in the right marginal area."
125 (unless string (setq string "x"))
125 (let ((buffer (current-buffer))) 126 (let ((buffer (current-buffer)))
126 (unless (eq (car image) 'image) 127 (unless (eq (car-safe image) 'image)
127 (error "Not an image: %s" image)) 128 (error "Not an image: %s" image))
128 (unless (or (null area) (memq area '(left-margin right-margin))) 129 (unless (or (null area) (memq area '(left-margin right-margin)))
129 (error "Invalid area %s" area)) 130 (error "Invalid area %s" area))
130 (setq string (copy-sequence string)) 131 (setq string (copy-sequence string))
131 (let ((overlay (make-overlay pos pos buffer)) 132 (let ((overlay (make-overlay pos pos buffer))
134 (overlay-put overlay 'put-image t) 135 (overlay-put overlay 'put-image t)
135 (overlay-put overlay 'before-string string)))) 136 (overlay-put overlay 'before-string string))))
136 137
137 138
138 ;;;###autoload 139 ;;;###autoload
139 (defun insert-image (image string &optional area) 140 (defun insert-image (image &optional string area)
140 "Insert IMAGE into current buffer at point. 141 "Insert IMAGE into current buffer at point.
141 IMAGE is displayed by inserting STRING into the current buffer 142 IMAGE is displayed by inserting STRING into the current buffer
142 with a `display' property whose value is the image. 143 with a `display' property whose value is the image. STRING is
144 defaulted if you omit it.
143 AREA is where to display the image. AREA nil or omitted means 145 AREA is where to display the image. AREA nil or omitted means
144 display it in the text area, a value of `left-margin' means 146 display it in the text area, a value of `left-margin' means
145 display it in the left marginal area, a value of `right-margin' 147 display it in the left marginal area, a value of `right-margin'
146 means display it in the right marginal area." 148 means display it in the right marginal area."
147 (unless (eq (car image) 'image) 149 (unless string (setq string "x"))
150 (unless (eq (car-safe image) 'image)
148 (error "Not an image: %s" image)) 151 (error "Not an image: %s" image))
149 (unless (or (null area) (memq area '(left-margin right-margin))) 152 (unless (or (null area) (memq area '(left-margin right-margin)))
150 (error "Invalid area %s" area)) 153 (error "Invalid area %s" area))
151 (when area 154 (when area
152 (setq image (list (list 'margin area) image))) 155 (setq image (list (list 'margin area) image)))
177 180
178 ;;;###autoload 181 ;;;###autoload
179 (defun find-image (specs) 182 (defun find-image (specs)
180 "Find an image, choosing one of a list of image specifications. 183 "Find an image, choosing one of a list of image specifications.
181 184
182 SPECS is a list of image specifications. DOC is an optional 185 SPECS is a list of image specifications.
183 documentation string.
184 186
185 Each image specification in SPECS is a property list. The contents of 187 Each image specification in SPECS is a property list. The contents of
186 a specification are image type dependent. All specifications must at 188 a specification are image type dependent. All specifications must at
187 least contain the properties `:type TYPE' and either `:file FILE' or 189 least contain the properties `:type TYPE' and either `:file FILE' or
188 `:data DATA', where TYPE is a symbol specifying the image type, 190 `:data DATA', where TYPE is a symbol specifying the image type,
189 e.g. `xbm', FILE is the file to load the image from, and DATA is a 191 e.g. `xbm', FILE is the file to load the image from, and DATA is a
190 string containing the actual image data. The first image 192 string containing the actual image data. The specification whose TYPE
191 specification whose TYPE is supported, and FILE exists, is used to 193 is supported, and FILE exists, is used to construct the image
192 define SYMBOL." 194 specification to be returned. Return nil if no specification is
195 satisfied.
196
197 The image is looked for first on `load-path' and then in `data-directory'."
193 (let (image) 198 (let (image)
194 (while (and specs (null image)) 199 (while (and specs (null image))
195 (let* ((spec (car specs)) 200 (let* ((spec (car specs))
196 (type (plist-get spec :type)) 201 (type (plist-get spec :type))
197 (data (plist-get spec :data)) 202 (data (plist-get spec :data))
204 (let ((try-file (expand-file-name file (car path)))) 209 (let ((try-file (expand-file-name file (car path))))
205 (when (file-readable-p try-file) 210 (when (file-readable-p try-file)
206 (setq found try-file))) 211 (setq found try-file)))
207 (setq path (cdr path))) 212 (setq path (cdr path)))
208 (unless found 213 (unless found
209 (setq found (expand-file-name file data-directory))) 214 (let ((try-file (expand-file-name file data-directory)))
210 (setq image (cons 'image (plist-put spec :file found))))) 215 (if (file-readable-p try-file)
216 (setq found try-file))))
217 (if found
218 (setq image
219 (cons 'image (plist-put spec :file found))))))
211 ((not (null data)) 220 ((not (null data))
212 (setq image (cons 'image spec))))) 221 (setq image (cons 'image spec)))))
213 (setq specs (cdr specs)))) 222 (setq specs (cdr specs))))
214 image)) 223 image))
215 224