From 8041f4b177edbc67296c023e338983b84b6a9123 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Wed, 8 Sep 2010 19:02:06 +0200 Subject: [PATCH] Allow showing the ALT text of images and to browse the images themselves. * gnus-html.el (gnus-html-show-alt-text): New command. (gnus-html-browse-image): Ditto. (gnus-html-wash-tags): Add the data to allow showing the ALT text and to browse the image directly. --- lisp/ChangeLog | 5 +++++ lisp/gnus-html.el | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 107e24c5c..9258e8df9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,10 @@ 2010-09-08 Lars Magne Ingebrigtsen + * gnus-html.el (gnus-html-show-alt-text): New command. + (gnus-html-browse-image): Ditto. + (gnus-html-wash-tags): Add the data to allow showing the ALT text and + to browse the image directly. + * gnus-async.el (gnus-async-article-callback): Call `gnus-html-prefetch-images' unconditionally. diff --git a/lisp/gnus-html.el b/lisp/gnus-html.el index ecab9213e..b411f6c40 100644 --- a/lisp/gnus-html.el +++ b/lisp/gnus-html.el @@ -72,6 +72,12 @@ fit these criteria." (define-key map "i" 'gnus-html-insert-image) map)) +(defvar gnus-html-displayed-image-map + (let ((map (make-sparse-keymap))) + (define-key map "a" 'gnus-html-show-alt-text) + (define-key map "i" 'gnus-html-browse-image) + map)) + ;;;###autoload (defun gnus-article-html (&optional handle) (let ((article-buffer (current-buffer))) @@ -176,11 +182,14 @@ fit these criteria." start end 'gnus-image spec))) (let ((file (gnus-html-image-id url)) - width height) + width height alt-text) (when (string-match "height=\"?\\([0-9]+\\)" parameters) (setq height (string-to-number (match-string 1 parameters)))) (when (string-match "width=\"?\\([0-9]+\\)" parameters) (setq width (string-to-number (match-string 1 parameters)))) + (when (string-match "\\(alt\\|title\\)=\"\\([^\"]+\\)" + parameters) + (setq alt-text (match-string 2 parameters))) ;; Don't fetch images that are really small. They're ;; probably tracking pictures. (when (and (or (null height) @@ -190,9 +199,9 @@ fit these criteria." (if (file-exists-p file) ;; It's already cached, so just insert it. (let ((string (buffer-substring start end))) - ;; Delete the ALT text. + ;; Delete the IMG text. (delete-region start end) - (gnus-html-put-image file (point) string)) + (gnus-html-put-image file (point) string url alt-text)) ;; We don't have it, so schedule it for fetching ;; asynchronously. (push (list url @@ -237,6 +246,16 @@ fit these criteria." (gnus-html-schedule-image-fetching (current-buffer) (list (get-text-property (point) 'gnus-image)))) +(defun gnus-html-show-alt-text () + "Show the ALT text of the image under point." + (interactive) + (message "%s" (get-text-property (point) 'gnus-alt-text))) + +(defun gnus-html-browse-image () + "Browse the image under point." + (interactive) + (browse-url (get-text-property (point) 'gnus-image))) + (defun gnus-html-schedule-image-fetching (buffer images) (gnus-message 8 "gnus-html-schedule-image-fetching: buffer %s, images %s" buffer images) @@ -276,7 +295,7 @@ fit these criteria." (when images (gnus-html-schedule-image-fetching buffer images))))) -(defun gnus-html-put-image (file point string) +(defun gnus-html-put-image (file point string &optional url alt-text) (when (gnus-graphic-display-p) (let* ((image (ignore-errors (gnus-create-image file))) @@ -301,11 +320,17 @@ fit these criteria." 'gif) (= (car size) 30) (= (cdr size) 30)))) - (progn + (let ((start (point))) (setq image (gnus-html-rescale-image image file size)) (gnus-put-image image (gnus-string-or string "*") 'external) + (let ((overlay (gnus-make-overlay start (point)))) + (gnus-overlay-put overlay 'local-map + gnus-html-displayed-image-map) + (gnus-put-text-property start end 'gnus-alt-text alt-text) + (when url + (gnus-put-text-property start end 'gnus-image url))) (gnus-add-image 'external image) t) (insert string) -- 2.25.1