unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: 31696@debbugs.gnu.org
Cc: stefan monnier <monnier@iro.umontreal.ca>
Subject: bug#31696: 27.0.50; dotimes-with-progress-reporter: Polimorphic 2nd argument
Date: Sun, 03 Jun 2018 22:15:56 +0900	[thread overview]
Message-ID: <874lik57ub.fsf@gmail.com> (raw)


Severity: Wishlist
X-Debbugs-Cc: Stefan Monnier <monnier@iro.umontreal.ca>

The second arg might be a string or a progress reporter object; the
latter is useful if the programmer wish to specify the optional
parameters of the reporter.

--8<-----------------------------cut here---------------start------------->8---
commit d4d07b0d9a444cc925d0c1c6fbcc155f9709fbe9
Author: Tino Calancha <tino.calancha@gmail.com>
Date:   Sun Jun 3 22:06:01 2018 +0900

    dotimes-with-progress-reporter: Polimorphic 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.

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index ce7ec3ac10..8591fa8cef 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -469,7 +469,7 @@ Progress
 Secondly, @samp{done} is more explicit.
 @end defun
 
-@defmac dotimes-with-progress-reporter (var count [result]) message body@dots{}
+@defmac dotimes-with-progress-reporter (var count [result]) reporter-or-message body@dots{}
 This is a convenience macro that works the same way as @code{dotimes}
 does, but also reports loop progress using the functions described
 above.  It allows you to save some typing.
@@ -483,6 +483,18 @@ Progress
     "Collecting some mana for Emacs..."
   (sit-for 0.01))
 @end example
+
+
+The second argument @code{reporter-or-message} might be a progress
+reporter object.  This is useful if you want to specify the optional
+arguments in @code{make-progress-reporter}.
+For instance, you can write previous example as follows:
+@example
+(dotimes-with-progress-reporter
+    (k 500)
+    (make-progress-reporter "Collecting some mana for Emacs..." 0 500 0 1 1.5)
+  (sit-for 0.01))
+@end example
 @end defmac
 
 @node Logging Messages
diff --git a/lisp/subr.el b/lisp/subr.el
index 914112ccef..a1b2556239 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5013,32 +5013,32 @@ progress-reporter-done
   "Print reporter's message followed by word \"done\" in echo area."
   (message "%sdone" (aref (cdr reporter) 3)))
 
-(defmacro dotimes-with-progress-reporter (spec message &rest body)
+(defmacro dotimes-with-progress-reporter (spec reporter-or-message &rest body)
   "Loop a certain number of times and report progress in the echo area.
 Evaluate BODY with VAR bound to successive integers running from
 0, inclusive, to COUNT, exclusive.  Then evaluate RESULT to get
 the return value (nil if RESULT is omitted).
 
-At each iteration MESSAGE followed by progress percentage is
-printed in the echo area.  After the loop is finished, MESSAGE
-followed by word \"done\" is printed.  This macro is a
-convenience wrapper around `make-progress-reporter' and friends.
+REPORTER-OR-MESSAGE is a progress reporter object or a string.  In the latter
+case, use this string to create a progress reporter.
+
+At each iteration, print the reporter message followed by progress
+percentage in the echo area.  After the loop is finished,
+print the reporter message followed by word \"done\".
+
+This macro is a convenience wrapper around `make-progress-reporter' and friends.
 
 \(fn (VAR COUNT [RESULT]) MESSAGE BODY...)"
   (declare (indent 2) (debug ((symbolp form &optional form) form body)))
-  (let ((temp (make-symbol "--dotimes-temp--"))
-	(temp2 (make-symbol "--dotimes-temp2--"))
-	(start 0)
-	(end (nth 1 spec)))
-    `(let ((,temp ,end)
-	   (,(car spec) ,start)
-	   (,temp2 (make-progress-reporter ,message ,start ,end)))
-       (while (< ,(car spec) ,temp)
-	 ,@body
-	 (progress-reporter-update ,temp2
-				   (setq ,(car spec) (1+ ,(car spec)))))
-       (progress-reporter-done ,temp2)
-       nil ,@(cdr (cdr spec)))))
+  (let ((prep (make-symbol "--dotimes-prep--")))
+    `(let ((,prep ,reporter-or-message))
+       (when (stringp ,prep)
+         (setq ,prep (make-progress-reporter ,prep 0 ,(cadr spec))))
+       (dotimes ,spec
+         ,@body
+         (progress-reporter-update ,prep (1+ ,(car spec))))
+       (progress-reporter-done ,prep)
+       (or ,@(cdr (cdr spec)) nil))))
 
 \f
 ;;;; Comparing version strings.

--8<-----------------------------cut here---------------end--------------->8---

In GNU Emacs 27.0.50 (build 78, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2018-06-03 built on calancha-pc
Repository revision: e75c57f10ee9418599398361b0676f48d265fb12





             reply	other threads:[~2018-06-03 13:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-03 13:15 Tino Calancha [this message]
2018-06-03 13:40 ` bug#31696: 27.0.50; dotimes-with-progress-reporter: Polimorphic 2nd argument Noam Postavsky
2018-06-03 13:51   ` Tino Calancha
2018-06-03 14:02     ` Noam Postavsky
2018-06-03 14:09       ` Tino Calancha
2018-06-17  9:36         ` Tino Calancha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874lik57ub.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=31696@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).