From 91f10af059ab03d50da990a332995b93aa4fcfbc Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Wed, 30 Sep 2009 22:02:57 -0700 Subject: [PATCH] Add pulsing progress reporter functionality. --- lisp/subr.el | 41 ++++++++++++++++++++++++++++++----------- 1 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index a7d3fcd..e26783f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3415,9 +3415,8 @@ you call it." (when (>= value (car reporter)) (progress-reporter-do-update reporter value))) -(defun make-progress-reporter (message min-value max-value - &optional current-value - min-change min-time) +(defun make-progress-reporter (message &optional min-value max-value + current-value min-change min-time) "Return progress reporter object to be used with `progress-reporter-update'. MESSAGE is shown in the echo area. When at least 1% of operation @@ -3426,20 +3425,23 @@ MESSAGE. When you call `progress-reporter-done', word \"done\" is printed after the MESSAGE. You can change MESSAGE of an existing progress reporter with `progress-reporter-force-update'. -MIN-VALUE and MAX-VALUE designate starting (0% complete) and -final (100% complete) states of operation. The latter should be -larger; if this is not the case, then simply negate all values. -Optional CURRENT-VALUE specifies the progress by the moment you -call this function. You should omit it or set it to nil in most -cases since it defaults to MIN-VALUE. +If provided, MIN-VALUE and MAX-VALUE designate starting (0% +complete) and final (100% complete) states of operation. The +latter should be larger; if this is not the case, then simply +negate all values. Optional CURRENT-VALUE specifies the progress +by the moment you call this function. You should omit it or set +it to nil in most cases since it defaults to MIN-VALUE. Optional MIN-CHANGE determines the minimal change in percents to report (default is 1%.) Optional MIN-TIME specifies the minimal time before echo area updates (default is 0.2 seconds.) If `float-time' function is not present, then time is not tracked at all. If OS is not capable of measuring fractions of seconds, -then this parameter is effectively rounded up." +then this parameter is effectively rounded up. +If MIN-VALUE and MAX-VALUE are unknown, they may be omitted to +return a \"pulsing\" progress reporter. This should be updated +using the `progress-reporter-pulse' function instead." (unless min-time (setq min-time 0.2)) (let ((reporter @@ -3447,7 +3449,7 @@ then this parameter is effectively rounded up." (vector (if (and (fboundp 'float-time) (>= min-time 0.02)) (float-time) nil) - min-value + (or min-value 0) max-value message (if min-change (max (min min-change 50) 1) 1) @@ -3505,6 +3507,23 @@ change the displayed message." (message "%s%d%%" (aref parameters 3) percentage) (message "%s" (aref parameters 3)))))) +(defvar progress-pulse-values ["-" "\\" "|" "/"] + "Characters to use for pulsing progress reporters.") + +(defun progress-reporter-pulse (reporter &optional new-message) + "Advance pulsing indicator of REPORTER. Display NEW-MESSAGE if given." + (let* ((parameters (cdr reporter)) + (message (or new-message + (aref parameters 3))) + (index (aref parameters 1)) + (new-index (mod (+ index 1) 4))) + (aset parameters 1 new-index) + (aset parameters 3 message) + (let ((message-log-max nil)) ; No logging + (message "%s %s" + (aref progress-pulse-values new-index) + message)))) + (defun progress-reporter-done (reporter) "Print reporter's message followed by word \"done\" in echo area." (message "%sdone" (aref (cdr reporter) 3))) -- 1.6.0.4