[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: pages with many images slow



Katsumi Yamaoka <yamaoka@xxxxxxx> writes:

>>>>>> In [emacs-w3m : No.10631] Naohiro Aota <naota@xxxxxxxxx> wrote:
>> BTW I wrote a patch to delay the process invoking. Could you try
>> this? I hope you like it :)
>
> I like it very much!  But there are three problems.  One is that
> the `gnus-summary-w3m-safe-toggle-inline-images' command which
> is mentioned in (info "(emacs-w3m)Gnus") does not work with cid
> images in shimbun articles. 

It seems I forgot to change buffer before calling
`w3m-create-image'. Could you try the new patch?

> Two is that there seems to be no way
> to stop retrieving images immediately (`T' doesn't toggle it).

It might fix this problem to add new function
`w3m-idle-images-show-unqueue' and call it at the same place where
`w3m-process-stop' is called in `w3m-toggle-inline-images'. Also changed
in the new patch.

> And three is that the change has been installed in CVS without
> the ChangeLog entry (accident? ;-).

Oh, I'm so sorry. I completely forgot about this change and committed
the "x-pdf"'s change. :( Reverted.

Regards,
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1413
diff -u -r1.1413 w3m.el
--- w3m.el	26 Jan 2009 07:42:40 -0000	1.1413
+++ w3m.el	26 Jan 2009 08:12:41 -0000
@@ -3618,6 +3618,69 @@
 						    'help-echo help
 						    'balloon-help balloon)))))))))
 
+(defvar w3m-idle-images-show-timer nil)
+(defvar w3m-idle-images-show-list nil)
+(defvar w3m-idle-images-show-interval 1)
+(defun w3m-idle-images-show ()
+  (let ((repeat t))
+    (while (and repeat w3m-idle-images-show-list)
+      (setq w3m-idle-images-show-list (nreverse w3m-idle-images-show-list))
+      (let* ((item (car w3m-idle-images-show-list))
+	     (start    (nth 0 item))
+	     (end      (nth 1 item))
+	     (iurl     (nth 2 item))
+	     (url      (nth 3 item))
+	     (no-cache (nth 4 item))
+	     (size     (nth 5 item)))
+	(when (buffer-live-p (marker-buffer start))
+	  (with-current-buffer (marker-buffer start)
+	    (w3m-process-with-null-handler
+	      (lexical-let ((start start)
+			    (end end)
+			    (iurl iurl)
+			    (url url))
+		(w3m-process-do
+		    (image (let ((w3m-current-buffer (current-buffer)))
+			     (w3m-create-image
+			      iurl no-cache
+			      url
+			      size handler)))
+		  (when (buffer-live-p (marker-buffer start))
+		    (with-current-buffer (marker-buffer start)
+		      (if image
+			  (when (equal url w3m-current-url)
+			    (let (buffer-read-only)
+			      (w3m-insert-image start end image iurl))
+			    ;; Redisplay
+			    (when w3m-force-redisplay
+			      (sit-for 0)))
+			(let (buffer-read-only)
+			  (w3m-add-text-properties
+			   start end '(w3m-image-status off))))
+		      (set-buffer-modified-p nil))
+		    (set-marker start nil)
+		    (set-marker end nil))))))))
+      (setq w3m-idle-images-show-list
+	    (nreverse (cdr w3m-idle-images-show-list)))
+      (setq repeat (sit-for 0.1 nil)))
+    (unless w3m-idle-images-show-list
+      (cancel-timer w3m-idle-images-show-timer)
+      (setq w3m-idle-images-show-timer nil))))
+
+(defun w3m-idle-images-show-unqueue (buffer)
+  (when w3m-idle-images-show-timer
+    (cancel-timer w3m-idle-images-show-timer)
+    (setq w3m-idle-images-show-list
+	  (delq nil
+		(mapcar (lambda (x)
+			  (and (not (eq buffer (marker-buffer (nth 0 x))))
+			       x))
+			w3m-idle-images-show-list)))
+    (when w3m-idle-images-show-list
+      (run-with-idle-timer w3m-idle-images-show-interval
+			   t
+			   'w3m-idle-images-show))))
+
 (defsubst w3m-toggle-inline-images-internal (status
 					     &optional no-cache url
 					     begin-pos end-pos)
@@ -3675,32 +3738,19 @@
 You are retrieving non-secure image(s).  Continue? ")
 				      (message nil))
 				    (setq allow-non-secure-images t))))
-		  (w3m-process-with-null-handler
-		    (lexical-let ((start (set-marker (make-marker) start))
-				  (end (set-marker (make-marker) end))
-				  (iurl (w3m-url-transfer-encode-string iurl))
-				  (url w3m-current-url))
-		      (w3m-process-do
-			  (image (let ((w3m-current-buffer (current-buffer)))
-				   (w3m-create-image
-				    iurl no-cache
+		  (setq w3m-idle-images-show-list
+			(cons (list (set-marker (make-marker) start)
+				    (set-marker (make-marker) end)
+				    (w3m-url-transfer-encode-string iurl)
 				    w3m-current-url
-				    size handler)))
-			(when (buffer-live-p (marker-buffer start))
-			  (with-current-buffer (marker-buffer start)
-			    (if image
-				(when (equal url w3m-current-url)
-				  (let (buffer-read-only)
-				    (w3m-insert-image start end image iurl))
-				  ;; Redisplay
-				  (when w3m-force-redisplay
-				    (sit-for 0)))
-			      (let (buffer-read-only)
-				(w3m-add-text-properties
-				 start end '(w3m-image-status off))))
-			    (set-buffer-modified-p nil))
-			  (set-marker start nil)
-			  (set-marker end nil)))))))))
+				    no-cache
+				    size)
+			      w3m-idle-images-show-list))
+		  (unless w3m-idle-images-show-timer
+		    (setq w3m-idle-images-show-timer
+			  (run-with-idle-timer w3m-idle-images-show-interval
+					       t
+					       'w3m-idle-images-show)))))))
 	;; Remove.
 	(while (< (setq start (if (w3m-image end)
 				  end
@@ -3851,7 +3901,9 @@
 	      (w3m-toggle-inline-images-internal (if status 'on 'off)
 						 no-cache nil beg end)
 	    (setq w3m-display-inline-images (not status))
-	    (when status (w3m-process-stop (current-buffer)))
+	    (when status 
+	      (w3m-process-stop (current-buffer))
+	      (w3m-idle-images-show-unqueue (current-buffer)))
 	    (force-mode-line-update)))
       (w3m-message "There are some images considered unsafe;\
  use the prefix arg to force display"))))