GNU bug report logs - #31696
27.0.50; dotimes-with-progress-reporter: Polimorphic 2nd argument

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Sun, 3 Jun 2018 13:17:02 UTC

Severity: wishlist

Found in version 27.0.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 31696 in the body.
You can then email your comments to 31696 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#31696; Package emacs. (Sun, 03 Jun 2018 13:17:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tino Calancha <tino.calancha <at> gmail.com>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Sun, 03 Jun 2018 13:17:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; dotimes-with-progress-reporter: Polimorphic 2nd argument
Date: Sun, 03 Jun 2018 22:15:56 +0900
Severity: Wishlist
X-Debbugs-Cc: Stefan Monnier <monnier <at> 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 <at> 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 <at> dots{}
+@defmac dotimes-with-progress-reporter (var count [result]) reporter-or-message body <at> 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))))
 
 
 ;;;; 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31696; Package emacs. (Sun, 03 Jun 2018 13:41:01 GMT) Full text and rfc822 format available.

Message #8 received at 31696 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 31696 <at> debbugs.gnu.org, stefan monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#31696: 27.0.50;
 dotimes-with-progress-reporter: Polimorphic 2nd argument
Date: Sun, 03 Jun 2018 09:40:37 -0400
Tino Calancha <tino.calancha <at> gmail.com> writes:

>     dotimes-with-progress-reporter: Polimorphic 2nd argument

Polymorphic with a "y".

> +(defmacro dotimes-with-progress-reporter (spec reporter-or-message &rest body)

> +  (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

The (cadr spec) expression would be evaluated twice.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31696; Package emacs. (Sun, 03 Jun 2018 13:52:01 GMT) Full text and rfc822 format available.

Message #11 received at 31696 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 31696 <at> debbugs.gnu.org, stefan monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#31696: 27.0.50;
 dotimes-with-progress-reporter: Polimorphic 2nd argument
Date: Sun, 03 Jun 2018 22:51:34 +0900
Noam Postavsky <npostavs <at> gmail.com> writes:

> Tino Calancha <tino.calancha <at> gmail.com> writes:
>
>>     dotimes-with-progress-reporter: Polimorphic 2nd argument
>
> Polymorphic with a "y".
Thank you :-)

>> +(defmacro dotimes-with-progress-reporter (spec reporter-or-message &rest body)
>
>> +  (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
>
> The (cadr spec) expression would be evaluated twice.
Ohhh, you are right.  Thank you!
I will add another variable.
Here is the updated patch:
--8<-----------------------------cut here---------------start------------->8---
commit fd7412a31acb16a361cdbda6080954de6241cf0f
Author: Tino Calancha <tino.calancha <at> gmail.com>
Date:   Sun Jun 3 22:47:47 2018 +0900

    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.

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 <at> dots{}
+@defmac dotimes-with-progress-reporter (var count [result]) reporter-or-message body <at> 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..62b9681f34 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5013,32 +5013,34 @@ 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--"))
+        ((end (make-symbol "--dotimes-end--"))))
+    `(let ((,prep ,reporter-or-message)
+           (,end ,(cadr spec)))
+       (when (stringp ,prep)
+         (setq ,prep (make-progress-reporter ,prep 0 ,end)))
+       (dotimes ,spec
+         ,@body
+         (progress-reporter-update ,prep (1+ ,(car spec))))
+       (progress-reporter-done ,prep)
+       (or ,@(cdr (cdr spec)) nil))))
 
 
 ;;;; Comparing version strings.
--8<-----------------------------cut here---------------end--------------->8---




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31696; Package emacs. (Sun, 03 Jun 2018 14:04:02 GMT) Full text and rfc822 format available.

Message #14 received at 31696 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 31696 <at> debbugs.gnu.org, stefan monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#31696: 27.0.50;
 dotimes-with-progress-reporter: Polimorphic 2nd argument
Date: Sun, 03 Jun 2018 10:02:54 -0400
Tino Calancha <tino.calancha <at> gmail.com> writes:

> +(defmacro dotimes-with-progress-reporter (spec reporter-or-message &rest body)

> +  (let ((prep (make-symbol "--dotimes-prep--"))
> +        ((end (make-symbol "--dotimes-end--"))))
> +    `(let ((,prep ,reporter-or-message)
> +           (,end ,(cadr spec)))
> +       (when (stringp ,prep)
> +         (setq ,prep (make-progress-reporter ,prep 0 ,end)))
> +       (dotimes ,spec

That's still going to evaluate (cadr spec) twice.  You need to change
the spec passed to `dotimes' so that it also uses `end'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31696; Package emacs. (Sun, 03 Jun 2018 14:10:02 GMT) Full text and rfc822 format available.

Message #17 received at 31696 <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 31696 <at> debbugs.gnu.org, stefan monnier <monnier <at> iro.umontreal.ca>,
 Tino Calancha <tino.calancha <at> gmail.com>
Subject: Re: bug#31696: 27.0.50; dotimes-with-progress-reporter: Polimorphic
 2nd argument
Date: Sun, 3 Jun 2018 23:09:18 +0900 (JST)

On Sun, 3 Jun 2018, Noam Postavsky wrote:

> Tino Calancha <tino.calancha <at> gmail.com> writes:
>
>> +(defmacro dotimes-with-progress-reporter (spec reporter-or-message &rest body)
>
>> +  (let ((prep (make-symbol "--dotimes-prep--"))
>> +        ((end (make-symbol "--dotimes-end--"))))
>> +    `(let ((,prep ,reporter-or-message)
>> +           (,end ,(cadr spec)))
>> +       (when (stringp ,prep)
>> +         (setq ,prep (make-progress-reporter ,prep 0 ,end)))
>> +       (dotimes ,spec
>
> That's still going to evaluate (cadr spec) twice.  You need to change
> the spec passed to `dotimes' so that it also uses `end'.
Ah! I am stupid, I did it in Bug#31697 but forgot here :-|
Thank you very much for let me know!
I hope it's OK know (I cross my fingers).

--8<-----------------------------cut here---------------start------------->8---
commit 7c088017a8c0c5446d0c09202aec6d60416b0843
Author: Tino Calancha <tino.calancha <at> gmail.com>
Date:   Sun Jun 3 23:07:20 2018 +0900

    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.

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 <at> dots{}
+@defmac dotimes-with-progress-reporter (var count [result]) reporter-or-message body <at> 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..03e64e04c7 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5013,32 +5013,34 @@ 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--"))
+        ((end (make-symbol "--dotimes-end--"))))
+    `(let ((,prep ,reporter-or-message)
+           (,end ,(cadr spec)))
+       (when (stringp ,prep)
+         (setq ,prep (make-progress-reporter ,prep 0 ,end)))
+       (dotimes (,(car spec) ,end)
+         ,@body
+         (progress-reporter-update ,prep (1+ ,(car spec))))
+       (progress-reporter-done ,prep)
+       (or ,@(cdr (cdr spec)) nil))))


 ;;;; Comparing version strings.
--8<-----------------------------cut here---------------end--------------->8---
R




Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Sun, 17 Jun 2018 09:38:01 GMT) Full text and rfc822 format available.

Notification sent to Tino Calancha <tino.calancha <at> gmail.com>:
bug acknowledged by developer. (Sun, 17 Jun 2018 09:38:02 GMT) Full text and rfc822 format available.

Message #22 received at 31696-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 31696-done <at> debbugs.gnu.org
Subject: Re: bug#31696: 27.0.50;
 dotimes-with-progress-reporter: Polimorphic 2nd argument
Date: Sun, 17 Jun 2018 18:36:56 +0900
Tino Calancha <tino.calancha <at> gmail.com> writes:

> On Sun, 3 Jun 2018, Noam Postavsky wrote:
>
>> Tino Calancha <tino.calancha <at> gmail.com> writes:
>>
>>> +(defmacro dotimes-with-progress-reporter (spec reporter-or-message &rest body)
>>
>>> +  (let ((prep (make-symbol "--dotimes-prep--"))
>>> +        ((end (make-symbol "--dotimes-end--"))))
>>> +    `(let ((,prep ,reporter-or-message)
>>> +           (,end ,(cadr spec)))
>>> +       (when (stringp ,prep)
>>> +         (setq ,prep (make-progress-reporter ,prep 0 ,end)))
>>> +       (dotimes ,spec
>>
>> That's still going to evaluate (cadr spec) twice.  You need to change
>> the spec passed to `dotimes' so that it also uses `end'.
> I did it in Bug#31697 but forgot here :-|
> Thank you very much for let me know!
Implemented in master branch as commit
'dotimes-with-progress-reporter: Polymorphic 2nd argument'
(5099b3abb2b623ce949b8efc37bee8c41d5ad754)




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 16 Jul 2018 11:24:11 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 36 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.