(require 'wl-highlight)
(require 'elmo)
(require 'elmo-mime)
+(require 'timer)
(eval-when-compile
(require 'wl-mime)
wl-message-buffer-prefetch-folder-list))
(t wl-message-buffer-prefetch-folder-list))))
-(defun wl-message-buffer-prefetch-next (folder number count &optional
- summary charset)
+(defun wl-message-buffer-prefetch-next (folder number &optional
+ count summary charset)
(if (wl-message-buffer-prefetch-p folder)
- (with-current-buffer (or summary (get-buffer wl-summary-buffer-name))
- (let* ((next (funcall wl-message-buffer-prefetch-get-next-function
- number)))
- (when (and next (wl-message-buffer-prefetch-p folder next))
- (if (not (fboundp 'run-with-idle-timer))
- (when (sit-for wl-message-buffer-prefetch-idle-time)
- (wl-message-buffer-prefetch
- folder next count summary charset))
- (unless wl-message-buffer-prefetch-timer
- (setq wl-message-buffer-prefetch-timer
- (run-with-idle-timer
- wl-message-buffer-prefetch-idle-time
- nil
- 'wl-message-buffer-prefetch
- folder next count summary charset)))))))))
-
-(defun wl-message-buffer-prefetch (folder number count summary charset)
- (setq wl-message-buffer-prefetch-timer nil)
- (if (and (numberp count)
- (>= (setq count (- count 1)) 0))
- (if (buffer-live-p summary)
- (save-excursion
- (set-buffer summary)
- (if (string= (elmo-folder-name-internal folder)
- (wl-summary-buffer-folder-name))
- (let* ((message-id (elmo-message-field folder number 'message-id))
- (wl-mime-charset charset)
+ (if (not (fboundp 'run-with-idle-timer))
+ (when (sit-for wl-message-buffer-prefetch-idle-time)
+ (wl-message-buffer-prefetch-subr
+ folder number (or count 1) summary charset))
+;;; cannot use for the bug of fsf-compat package (1.09).
+;;; (cancel-function-timers 'wl-message-buffer-prefetch-subr)
+ (run-with-idle-timer
+ wl-message-buffer-prefetch-idle-time
+ nil
+ 'wl-message-buffer-prefetch-subr
+ folder number (or count 1) summary charset))))
+
+(defun wl-message-buffer-prefetch-subr (folder number count summary charset)
+ (if (buffer-live-p summary)
+ (with-current-buffer summary
+ ;(set-buffer summary)
+ (let ((next (funcall wl-message-buffer-prefetch-get-next-function
+ number)))
+ (if (and next (not (wl-message-buffer-prefetch-p folder next)))
+ ;; for Multi folder
+ (wl-message-buffer-prefetch-subr folder next count summary charset)
+ (if (and next
+ (numberp count)
+ (>= (setq count (- count 1)) 0)
+ (string= (elmo-folder-name-internal folder)
+ (wl-summary-buffer-folder-name)))
+ (let* ((wl-mime-charset charset)
(default-mime-charset charset)
+ (message-id (elmo-message-field folder next 'message-id))
(key (list (elmo-folder-name-internal folder)
- number message-id))
- (hit (wl-message-buffer-cache-hit key))
- result time1 time2 sec micro)
+ next message-id))
+ (hit (wl-message-buffer-cache-hit key)))
+ (when wl-message-buffer-prefetch-debug
+ (message "%S: count %S, hit %S" next count hit))
(if (and hit (buffer-live-p hit))
- (wl-message-buffer-cache-sort
- (wl-message-buffer-cache-entry-make key hit))
- (let* ((size (elmo-message-field folder number 'size)))
- (when (or (elmo-message-file-p folder number)
- (not
- (and (integerp size)
- elmo-message-fetch-threshold
- (>= size
- elmo-message-fetch-threshold))))
- ;;(not (elmo-file-cache-exists-p message-id)))))
+ (progn
+ (wl-message-buffer-cache-sort
+ (wl-message-buffer-cache-entry-make key hit))
+ (wl-message-buffer-prefetch-subr folder next count summary charset))
+ (let* ((size (elmo-message-field folder next 'size))
+ result time1 time2 sec micro)
+ (when (or (elmo-message-file-p folder next)
+ (not (and (integerp size)
+ elmo-message-fetch-threshold
+ (>= size
+ elmo-message-fetch-threshold))))
(when wl-message-buffer-prefetch-debug
(setq time1 (current-time))
- (message "Prefetching %d..." number))
- (setq result (wl-message-buffer-display folder number
+ (message "Prefetching %d..." next))
+ (setq result (wl-message-buffer-display folder next
'mime nil 'unread))
(when wl-message-buffer-prefetch-debug
(setq time2 (current-time))
(setq micro (- (nth 2 time2)(nth 2 time1)))
(setq micro (+ micro (* 1000000 sec)))
(message "Prefetching %d...done(%f msec)."
- number
- (/ micro 1000.0))))))
- (wl-message-buffer-prefetch-next
- folder number count summary charset)))))
- (when wl-message-buffer-prefetch-debug
- (message "Buffer Cached Messages %S"
- (mapcar '(lambda (cache)
- (nth 1 (car cache)))
- wl-message-buffer-cache)))))
+ next
+ (/ micro 1000.0))
+ (sit-for 0))
+ ;; set next prefetch
+ (wl-message-buffer-prefetch-next
+ folder next count summary charset)
+ (sit-for 0)
+ ;; success prefetch
+ ))))))
+ ;; finish prefetch
+ (when wl-message-buffer-prefetch-debug
+ (message "Buffer Cached Messages %S"
+ (mapcar '(lambda (cache)
+ (nth 1 (car cache)))
+ wl-message-buffer-cache))) ))))
(defvar wl-message-button-map (make-sparse-keymap))