aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2010-09-08 23:59:52 +0000
committerKatsumi Yamaoka2010-09-08 23:59:52 +0000
commit99fcd180127e80565002271cdc125cd5c02559d6 (patch)
treeeafa135b1ac0f2c6067d573307f4f4d3975d07eb
parent724d30bea033ed39739e757651692bcf27eb3e6e (diff)
downloademacs-99fcd180127e80565002271cdc125cd5c02559d6.tar.gz
emacs-99fcd180127e80565002271cdc125cd5c02559d6.zip
gnus-html.el: Allow showing the ALT text of images and to browse the images themselves.
-rw-r--r--lisp/gnus/ChangeLog5
-rw-r--r--lisp/gnus/gnus-html.el37
2 files changed, 36 insertions, 6 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index a3e4fe99510..29e17b99e64 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,5 +1,10 @@
12010-09-08 Lars Magne Ingebrigtsen <larsi@gnus.org> 12010-09-08 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 2
3 * gnus-html.el (gnus-html-show-alt-text): New command.
4 (gnus-html-browse-image): Ditto.
5 (gnus-html-wash-tags): Add the data to allow showing the ALT text and
6 to browse the image directly.
7
3 * gnus-async.el (gnus-async-article-callback): Call 8 * gnus-async.el (gnus-async-article-callback): Call
4 `gnus-html-prefetch-images' unconditionally. 9 `gnus-html-prefetch-images' unconditionally.
5 10
diff --git a/lisp/gnus/gnus-html.el b/lisp/gnus/gnus-html.el
index 9cd49a06598..fc672197467 100644
--- a/lisp/gnus/gnus-html.el
+++ b/lisp/gnus/gnus-html.el
@@ -72,6 +72,12 @@ fit these criteria."
72 (define-key map "i" 'gnus-html-insert-image) 72 (define-key map "i" 'gnus-html-insert-image)
73 map)) 73 map))
74 74
75(defvar gnus-html-displayed-image-map
76 (let ((map (make-sparse-keymap)))
77 (define-key map "a" 'gnus-html-show-alt-text)
78 (define-key map "i" 'gnus-html-browse-image)
79 map))
80
75;;;###autoload 81;;;###autoload
76(defun gnus-article-html (&optional handle) 82(defun gnus-article-html (&optional handle)
77 (let ((article-buffer (current-buffer))) 83 (let ((article-buffer (current-buffer)))
@@ -176,11 +182,14 @@ fit these criteria."
176 start end 182 start end
177 'gnus-image spec))) 183 'gnus-image spec)))
178 (let ((file (gnus-html-image-id url)) 184 (let ((file (gnus-html-image-id url))
179 width height) 185 width height alt-text)
180 (when (string-match "height=\"?\\([0-9]+\\)" parameters) 186 (when (string-match "height=\"?\\([0-9]+\\)" parameters)
181 (setq height (string-to-number (match-string 1 parameters)))) 187 (setq height (string-to-number (match-string 1 parameters))))
182 (when (string-match "width=\"?\\([0-9]+\\)" parameters) 188 (when (string-match "width=\"?\\([0-9]+\\)" parameters)
183 (setq width (string-to-number (match-string 1 parameters)))) 189 (setq width (string-to-number (match-string 1 parameters))))
190 (when (string-match "\\(alt\\|title\\)=\"\\([^\"]+\\)"
191 parameters)
192 (setq alt-text (match-string 2 parameters)))
184 ;; Don't fetch images that are really small. They're 193 ;; Don't fetch images that are really small. They're
185 ;; probably tracking pictures. 194 ;; probably tracking pictures.
186 (when (and (or (null height) 195 (when (and (or (null height)
@@ -190,9 +199,9 @@ fit these criteria."
190 (if (file-exists-p file) 199 (if (file-exists-p file)
191 ;; It's already cached, so just insert it. 200 ;; It's already cached, so just insert it.
192 (let ((string (buffer-substring start end))) 201 (let ((string (buffer-substring start end)))
193 ;; Delete the ALT text. 202 ;; Delete the IMG text.
194 (delete-region start end) 203 (delete-region start end)
195 (gnus-html-put-image file (point) string)) 204 (gnus-html-put-image file (point) string url alt-text))
196 ;; We don't have it, so schedule it for fetching 205 ;; We don't have it, so schedule it for fetching
197 ;; asynchronously. 206 ;; asynchronously.
198 (push (list url 207 (push (list url
@@ -237,6 +246,16 @@ fit these criteria."
237 (gnus-html-schedule-image-fetching 246 (gnus-html-schedule-image-fetching
238 (current-buffer) (list (get-text-property (point) 'gnus-image)))) 247 (current-buffer) (list (get-text-property (point) 'gnus-image))))
239 248
249(defun gnus-html-show-alt-text ()
250 "Show the ALT text of the image under point."
251 (interactive)
252 (message "%s" (get-text-property (point) 'gnus-alt-text)))
253
254(defun gnus-html-browse-image ()
255 "Browse the image under point."
256 (interactive)
257 (browse-url (get-text-property (point) 'gnus-image)))
258
240(defun gnus-html-schedule-image-fetching (buffer images) 259(defun gnus-html-schedule-image-fetching (buffer images)
241 (gnus-message 8 "gnus-html-schedule-image-fetching: buffer %s, images %s" 260 (gnus-message 8 "gnus-html-schedule-image-fetching: buffer %s, images %s"
242 buffer images) 261 buffer images)
@@ -276,7 +295,7 @@ fit these criteria."
276 (when images 295 (when images
277 (gnus-html-schedule-image-fetching buffer images))))) 296 (gnus-html-schedule-image-fetching buffer images)))))
278 297
279(defun gnus-html-put-image (file point string) 298(defun gnus-html-put-image (file point string &optional url alt-text)
280 (when (gnus-graphic-display-p) 299 (when (gnus-graphic-display-p)
281 (let* ((image (ignore-errors 300 (let* ((image (ignore-errors
282 (gnus-create-image file))) 301 (gnus-create-image file)))
@@ -301,11 +320,17 @@ fit these criteria."
301 'gif) 320 'gif)
302 (= (car size) 30) 321 (= (car size) 30)
303 (= (cdr size) 30)))) 322 (= (cdr size) 30))))
304 (progn 323 (let ((start (point)))
305 (setq image (gnus-html-rescale-image image file size)) 324 (setq image (gnus-html-rescale-image image file size))
306 (gnus-put-image image 325 (gnus-put-image image
307 (gnus-string-or string "*") 326 (gnus-string-or string "*")
308 'external) 327 'external)
328 (let ((overlay (gnus-make-overlay start (point))))
329 (gnus-overlay-put overlay 'local-map
330 gnus-html-displayed-image-map)
331 (gnus-put-text-property start (point) 'gnus-alt-text alt-text)
332 (when url
333 (gnus-put-text-property start (point) 'gnus-image url)))
309 (gnus-add-image 'external image) 334 (gnus-add-image 'external image)
310 t) 335 t)
311 (insert string) 336 (insert string)
@@ -360,7 +385,7 @@ fit these criteria."
360 (delete-file (nth 2 file))))))) 385 (delete-file (nth 2 file)))))))
361 386
362(defun gnus-html-image-url-blocked-p (url blocked-images) 387(defun gnus-html-image-url-blocked-p (url blocked-images)
363"Find out if URL is blocked by BLOCKED-IMAGES." 388 "Find out if URL is blocked by BLOCKED-IMAGES."
364 (let ((ret (and blocked-images 389 (let ((ret (and blocked-images
365 (string-match blocked-images url)))) 390 (string-match blocked-images url))))
366 (if ret 391 (if ret