From 1205de9ab5cdf9d8305bcfa5e0ae85afe36c0a65 Mon Sep 17 00:00:00 2001 From: hmurata Date: Tue, 7 Nov 2006 14:18:53 +0000 Subject: [PATCH] * elmo-util.el (elmo-progress-start): Accept nil for `total'. Set `elmo-progress-counter' as t when a query callback returns nil. (elmo-progress-clear): New function. (elmo-progress-done): Split into `elmo-progress-clear'. (elmo-progress-notify): Update a total slot when it is nil. (elmo-with-progress-display): Call `elmo-progress-clear' in unwind-protect and move calling `elmo-progress-done' to outside. * elmo-imap4.el (elmo-imap4-find-next-line): Call `elmo-progress-notify' with :total parameter instead of `elmo-progress-counter-set-total'. --- elmo/ChangeLog | 14 ++++++++++++ elmo/elmo-imap4.el | 15 +++++------- elmo/elmo-util.el | 64 ++++++++++++++++++++++++++++++++-------------------- 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/elmo/ChangeLog b/elmo/ChangeLog index a612605..e52bb40 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,3 +1,17 @@ +2006-11-07 Hiroya Murata + + * elmo-util.el (elmo-progress-start): Accept nil for `total'. Set + `elmo-progress-counter' as t when a query callback returns nil. + (elmo-progress-clear): New function. + (elmo-progress-done): Split into `elmo-progress-clear'. + (elmo-progress-notify): Update a total slot when it is nil. + (elmo-with-progress-display): Call `elmo-progress-clear' in + unwind-protect and move calling `elmo-progress-done' to outside. + + * elmo-imap4.el (elmo-imap4-find-next-line): Call + `elmo-progress-notify' with :total parameter instead of + `elmo-progress-counter-set-total'. + 2006-11-07 Tetsurou Okazaki * elmo-util.el (elmo-cache-expire-by-age): Add docstring. diff --git a/elmo/elmo-imap4.el b/elmo/elmo-imap4.el index 5f1d5e2..d22da97 100644 --- a/elmo/elmo-imap4.el +++ b/elmo/elmo-imap4.el @@ -1246,13 +1246,11 @@ Return nil if no complete line has arrived." (if (match-string 1) (if (< (point-max) (+ (point) (string-to-number (match-string 1)))) (progn - (when (elmo-progress-counter-label - elmo-imap4-literal-progress-reporter) - (elmo-progress-counter-set-total - elmo-imap4-literal-progress-reporter - (string-to-number (match-string 1))) - (elmo-progress-notify 'elmo-retrieve-message - :set (- (point-max) (point)))) + (when elmo-imap4-literal-progress-reporter + (elmo-progress-notify + 'elmo-retrieve-message + :set (- (point-max) (point)) + :total (string-to-number (match-string 1)))) nil) (goto-char (+ (point) (string-to-number (match-string 1)))) (elmo-imap4-find-next-line)) @@ -2694,8 +2692,7 @@ If optional argument REMOVE is non-nil, remove FLAG." (setq elmo-imap4-fetch-callback nil) (setq elmo-imap4-fetch-callback-data nil)) (elmo-with-progress-display (elmo-retrieve-message - (or (elmo-message-field folder number :size) - 0) + (elmo-message-field folder number :size) elmo-imap4-literal-progress-reporter) "Retrieving" (setq response diff --git a/elmo/elmo-util.el b/elmo/elmo-util.el index 9f4910b..c744ff3 100644 --- a/elmo/elmo-util.el +++ b/elmo/elmo-util.el @@ -1189,40 +1189,53 @@ If optional DELETE-FUNCTION is speficied, it is used as delete procedure." (elmo-progress-counter-total counter)))) (defun elmo-progress-start (label total action) - (when (and (> total 0) - (null elmo-progress-counter)) + (when (and (null elmo-progress-counter) + (or (null total) + (> total 0))) (let ((counter (cons label (vector 0 total action)))) (elmo-progress-call-callback counter 'start) - (when (elmo-progress-call-callback counter 'query) - (elmo-progress-call-callback counter) - (setq elmo-progress-counter counter)) + (setq elmo-progress-counter + (cond ((null total) + counter) + ((elmo-progress-call-callback counter 'query) + (elmo-progress-call-callback counter) + counter) + (t + t))) counter))) -(defun elmo-progress-done (counter) +(defun elmo-progress-clear (counter) (when counter - (when (elmo-progress-counter-label counter) - (when (< (elmo-progress-counter-value counter) - (elmo-progress-counter-total counter)) - (elmo-progress-call-callback counter 100)) - (elmo-progress-call-callback counter 'done)) - (when (eq counter elmo-progress-counter) - (setq elmo-progress-counter nil)))) + (when (and (elmo-progress-counter-label elmo-progress-counter) + (elmo-progress-counter-total elmo-progress-counter)) + (elmo-progress-call-callback elmo-progress-counter 100)) + (setq elmo-progress-counter nil))) + +(defun elmo-progress-done (counter) + (when (elmo-progress-counter-label counter) + (elmo-progress-call-callback counter 'done))) (defun elmo-progress-notify (label &rest params) - (when (and elmo-progress-counter - (eq (elmo-progress-counter-label elmo-progress-counter) label)) + (when (eq label (elmo-progress-counter-label elmo-progress-counter)) (let ((counter elmo-progress-counter)) - (elmo-progress-counter-set-value - counter - (or (plist-get params :set) - (+ (elmo-progress-counter-value counter) - (or (plist-get params :inc) - (car params) - 1)))) - (elmo-progress-call-callback counter)))) + (if (or (elmo-progress-counter-total counter) + (and (elmo-progress-counter-set-total + counter + (plist-get params :total)) + (elmo-progress-call-callback counter 'query))) + (progn + (elmo-progress-counter-set-value + counter + (or (plist-get params :set) + (+ (elmo-progress-counter-value counter) + (or (plist-get params :inc) + (car params) + 1)))) + (elmo-progress-call-callback counter)) + (setq elmo-progress-counter t))))) (defmacro elmo-with-progress-display (spec message &rest body) - "Evaluate BODY with progress gauge if CONDITION is non-nil. + "Evaluate BODY with progress message. SPEC is a list as followed (LABEL TOTAL [VAR])." (let ((label (nth 0 spec)) (total (nth 1 spec)) @@ -1231,7 +1244,8 @@ SPEC is a list as followed (LABEL TOTAL [VAR])." (unwind-protect (progn ,@body) - (elmo-progress-done ,var))))) + (elmo-progress-clear ,var)) + (elmo-progress-done ,var)))) (put 'elmo-with-progress-display 'lisp-indent-function '2) (def-edebug-spec elmo-with-progress-display -- 1.7.10.4