aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2005-01-19 23:44:48 +0000
committerStefan Monnier2005-01-19 23:44:48 +0000
commitaa56124af51e80c65bfc143326aedaa96ec0e028 (patch)
treecdb036100c03e32abf85473893feac1f6814566c
parent8fd7aa51de09980366ad249ef80081ef0763d3ef (diff)
downloademacs-aa56124af51e80c65bfc143326aedaa96ec0e028.tar.gz
emacs-aa56124af51e80c65bfc143326aedaa96ec0e028.zip
(dotimes-with-progress-reporter): New macro.
-rw-r--r--lisp/subr.el31
1 files changed, 29 insertions, 2 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 5e4e321d909..f338e47ea56 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1,7 +1,7 @@
1;;; subr.el --- basic lisp subroutines for Emacs 1;;; subr.el --- basic lisp subroutines for Emacs
2 2
3;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1999, 2000, 2001, 2002, 2003, 3;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1999, 2000, 2001, 2002, 2003,
4;; 2004 Free Software Foundation, Inc. 4;; 2004, 2005 Free Software Foundation, Inc.
5 5
6;; Maintainer: FSF 6;; Maintainer: FSF
7;; Keywords: internal 7;; Keywords: internal
@@ -2711,7 +2711,7 @@ you call it."
2711(defun make-progress-reporter (message min-value max-value 2711(defun make-progress-reporter (message min-value max-value
2712 &optional current-value 2712 &optional current-value
2713 min-change min-time) 2713 min-change min-time)
2714 "Return progress reporter object usage with `progress-reporter-update'. 2714 "Return progress reporter object to be used with `progress-reporter-update'.
2715 2715
2716MESSAGE is shown in the echo area. When at least 1% of operation 2716MESSAGE is shown in the echo area. When at least 1% of operation
2717is complete, the exact percentage will be appended to the 2717is complete, the exact percentage will be appended to the
@@ -2800,5 +2800,32 @@ change the displayed message."
2800 "Print reporter's message followed by word \"done\" in echo area." 2800 "Print reporter's message followed by word \"done\" in echo area."
2801 (message "%sdone" (aref (cdr reporter) 3))) 2801 (message "%sdone" (aref (cdr reporter) 3)))
2802 2802
2803(defmacro dotimes-with-progress-reporter (spec message &rest body)
2804 "Loop a certain number of times and report progress in the echo area.
2805Evaluate BODY with VAR bound to successive integers running from
28060, inclusive, to COUNT, exclusive. Then evaluate RESULT to get
2807the return value (nil if RESULT is omitted).
2808
2809At each iteration MESSAGE followed by progress percentage is
2810printed in the echo area. After the loop is finished, MESSAGE
2811followed by word \"done\" is printed. This macro is a
2812convenience wrapper around `make-progress-reporter' and friends.
2813
2814\(fn (VAR COUNT [RESULT]) MESSAGE BODY...)"
2815 (declare (indent 2) (debug ((symbolp form &optional form) form body)))
2816 (let ((temp (make-symbol "--dotimes-temp--"))
2817 (temp2 (make-symbol "--dotimes-temp2--"))
2818 (start 0)
2819 (end (nth 1 spec)))
2820 `(let ((,temp ,end)
2821 (,(car spec) ,start)
2822 (,temp2 (make-progress-reporter ,message ,start ,end)))
2823 (while (< ,(car spec) ,temp)
2824 ,@body
2825 (progress-reporter-update ,temp2
2826 (setq ,(car spec) (1+ ,(car spec)))))
2827 (progress-reporter-done ,temp2)
2828 nil ,@(cdr (cdr spec)))))
2829
2803;; arch-tag: f7e0e6e5-70aa-4897-ae72-7a3511ec40bc 2830;; arch-tag: f7e0e6e5-70aa-4897-ae72-7a3511ec40bc
2804;;; subr.el ends here 2831;;; subr.el ends here