Allow pre-fetching images asynchronously.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Sun, 29 Aug 2010 02:40:49 +0000 (04:40 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Sun, 29 Aug 2010 02:40:49 +0000 (04:40 +0200)
lisp/gnus-async.el
lisp/gnus-html.el

index 432990e..a39821c 100644 (file)
@@ -71,6 +71,13 @@ It should return non-nil if the article is to be prefetched."
   :group 'gnus-asynchronous
   :type 'function)
 
+(defcustom gnus-async-post-fetch-function nil
+  "Function called after an article has been prefetched.
+The function will be called narrowed to the region of the article
+that was fetched."
+  :group 'gnus-asynchronous
+  :type 'function)
+
 ;;; Internal variables.
 
 (defvar gnus-async-prefetch-article-buffer " *Async Prefetch Article*")
@@ -227,6 +234,11 @@ It should return non-nil if the article is to be prefetched."
     (setq gnus-async-current-prefetch-article nil)
     (when arg
       (gnus-async-set-buffer)
+      (when gnus-async-post-fetch-function
+       (save-excursion
+         (save-restriction
+           (narrow-to-region mark (point-max))
+           (funcall gnus-async-post-fetch-function))))
       (gnus-async-with-semaphore
        (setq
         gnus-async-article-alist
index abf50d6..2492545 100644 (file)
          (decf total-size (cadr file))
          (delete-file (nth 2 file)))))))
 
+(defun gnus-html-prefetch-images ()
+  (save-match-data
+    (let (urls)
+      (while (re-search-forward "<img.*src=\"\\([^\"]+\\)" nil t)
+       (let ((url (match-string 1)))
+         (when (or (null mm-w3m-safe-url-regexp)
+                   (string-match mm-w3m-safe-url-regexp url))
+           (unless (file-exists-p (gnus-html-image-id url))
+             (push url urls)
+             (push (gnus-html-image-id url) urls)
+             (push "-o" urls)))))
+      (apply 'start-process 
+            "images" nil "curl"
+            "-s" "--create-dirs"
+            urls))))
+
 ;;; gnus-html.el ends here