aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Calancha2018-06-17 18:28:34 +0900
committerTino Calancha2018-06-17 18:28:34 +0900
commit5099b3abb2b623ce949b8efc37bee8c41d5ad754 (patch)
treeb596f9ed994b5ffab0be9eddf8154dd3912489af
parent39ccbacf9c42b2fed08c47ed7314e4c067de21b9 (diff)
downloademacs-5099b3abb2b623ce949b8efc37bee8c41d5ad754.tar.gz
emacs-5099b3abb2b623ce949b8efc37bee8c41d5ad754.zip
dotimes-with-progress-reporter: Polymorphic 2nd argument
* lisp/subr.el (dotimes-with-progress-reporter): Allow 2nd arg to be a string or a progress reporter (Bug#31696). * doc/lispref/display.texi (node Progress): Update manual.
-rw-r--r--doc/lispref/display.texi14
-rw-r--r--lisp/subr.el38
2 files changed, 33 insertions, 19 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 0ba7f0fd586..12c36bb08ff 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -469,7 +469,7 @@ never print it, there are many good reasons for this not to happen.
469Secondly, @samp{done} is more explicit. 469Secondly, @samp{done} is more explicit.
470@end defun 470@end defun
471 471
472@defmac dotimes-with-progress-reporter (var count [result]) message body@dots{} 472@defmac dotimes-with-progress-reporter (var count [result]) reporter-or-message body@dots{}
473This is a convenience macro that works the same way as @code{dotimes} 473This is a convenience macro that works the same way as @code{dotimes}
474does, but also reports loop progress using the functions described 474does, but also reports loop progress using the functions described
475above. It allows you to save some typing. 475above. It allows you to save some typing.
@@ -483,6 +483,18 @@ this macro this way:
483 "Collecting some mana for Emacs..." 483 "Collecting some mana for Emacs..."
484 (sit-for 0.01)) 484 (sit-for 0.01))
485@end example 485@end example
486
487
488The second argument @code{reporter-or-message} might be a progress
489reporter object. This is useful if you want to specify the optional
490arguments in @code{make-progress-reporter}.
491For instance, you can write previous example as follows:
492@example
493(dotimes-with-progress-reporter
494 (k 500)
495 (make-progress-reporter "Collecting some mana for Emacs..." 0 500 0 1 1.5)
496 (sit-for 0.01))
497@end example
486@end defmac 498@end defmac
487 499
488@node Logging Messages 500@node Logging Messages
diff --git a/lisp/subr.el b/lisp/subr.el
index 8123e60f62a..d4383f862af 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5039,32 +5039,34 @@ NEW-MESSAGE, if non-nil, sets a new message for the reporter."
5039 "Print reporter's message followed by word \"done\" in echo area." 5039 "Print reporter's message followed by word \"done\" in echo area."
5040 (message "%sdone" (aref (cdr reporter) 3))) 5040 (message "%sdone" (aref (cdr reporter) 3)))
5041 5041
5042(defmacro dotimes-with-progress-reporter (spec message &rest body) 5042(defmacro dotimes-with-progress-reporter (spec reporter-or-message &rest body)
5043 "Loop a certain number of times and report progress in the echo area. 5043 "Loop a certain number of times and report progress in the echo area.
5044Evaluate BODY with VAR bound to successive integers running from 5044Evaluate BODY with VAR bound to successive integers running from
50450, inclusive, to COUNT, exclusive. Then evaluate RESULT to get 50450, inclusive, to COUNT, exclusive. Then evaluate RESULT to get
5046the return value (nil if RESULT is omitted). 5046the return value (nil if RESULT is omitted).
5047 5047
5048At each iteration MESSAGE followed by progress percentage is 5048REPORTER-OR-MESSAGE is a progress reporter object or a string. In the latter
5049printed in the echo area. After the loop is finished, MESSAGE 5049case, use this string to create a progress reporter.
5050followed by word \"done\" is printed. This macro is a 5050
5051convenience wrapper around `make-progress-reporter' and friends. 5051At each iteration, print the reporter message followed by progress
5052percentage in the echo area. After the loop is finished,
5053print the reporter message followed by word \"done\".
5054
5055This macro is a convenience wrapper around `make-progress-reporter' and friends.
5052 5056
5053\(fn (VAR COUNT [RESULT]) MESSAGE BODY...)" 5057\(fn (VAR COUNT [RESULT]) MESSAGE BODY...)"
5054 (declare (indent 2) (debug ((symbolp form &optional form) form body))) 5058 (declare (indent 2) (debug ((symbolp form &optional form) form body)))
5055 (let ((temp (make-symbol "--dotimes-temp--")) 5059 (let ((prep (make-symbol "--dotimes-prep--"))
5056 (temp2 (make-symbol "--dotimes-temp2--")) 5060 (end (make-symbol "--dotimes-end--")))
5057 (start 0) 5061 `(let ((,prep ,reporter-or-message)
5058 (end (nth 1 spec))) 5062 (,end ,(cadr spec)))
5059 `(let ((,temp ,end) 5063 (when (stringp ,prep)
5060 (,(car spec) ,start) 5064 (setq ,prep (make-progress-reporter ,prep 0 ,end)))
5061 (,temp2 (make-progress-reporter ,message ,start ,end))) 5065 (dotimes (,(car spec) ,end)
5062 (while (< ,(car spec) ,temp) 5066 ,@body
5063 ,@body 5067 (progress-reporter-update ,prep (1+ ,(car spec))))
5064 (progress-reporter-update ,temp2 5068 (progress-reporter-done ,prep)
5065 (setq ,(car spec) (1+ ,(car spec))))) 5069 (or ,@(cdr (cdr spec)) nil))))
5066 (progress-reporter-done ,temp2)
5067 nil ,@(cdr (cdr spec)))))
5068 5070
5069 5071
5070;;;; Comparing version strings. 5072;;;; Comparing version strings.