From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#31696: 27.0.50; dotimes-with-progress-reporter: Polimorphic 2nd argument Date: Sun, 03 Jun 2018 22:51:34 +0900 Message-ID: <87y3fw3rmh.fsf@gmail.com> References: <874lik57ub.fsf@gmail.com> <87vab07zu2.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1528033811 6653 195.159.176.226 (3 Jun 2018 13:50:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 3 Jun 2018 13:50:11 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 31696@debbugs.gnu.org, stefan monnier To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 03 15:50:06 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPTOX-0001cr-Vt for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 15:50:06 +0200 Original-Received: from localhost ([::1]:35403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPTQf-00016K-2R for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 09:52:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPTQV-00015I-9B for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:52:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPTQQ-0002su-9o for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:52:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51997) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPTQQ-0002sm-5E for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fPTQP-0006Do-OH for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Jun 2018 13:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31696 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31696-submit@debbugs.gnu.org id=B31696.152803390723893 (code B ref 31696); Sun, 03 Jun 2018 13:52:01 +0000 Original-Received: (at 31696) by debbugs.gnu.org; 3 Jun 2018 13:51:47 +0000 Original-Received: from localhost ([127.0.0.1]:59894 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPTQA-0006DI-Mw for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:51:46 -0400 Original-Received: from mail-pl0-f49.google.com ([209.85.160.49]:42790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPTQ8-0006D5-4Q for 31696@debbugs.gnu.org; Sun, 03 Jun 2018 09:51:44 -0400 Original-Received: by mail-pl0-f49.google.com with SMTP id w17-v6so2178228pll.9 for <31696@debbugs.gnu.org>; Sun, 03 Jun 2018 06:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=8EzLqtu/ON88Zom482XGaOBPmnSrN8QroGa8TbIaqZA=; b=odWMg/iF+nZnD9mdsvsNp+n0hrXA3WG6Pq/W04eZAnBBftoLGwPB/+Np6ZVDSYBC1Q YDfV6MwfuJBqjH1+pn2cVnaGtaQFPvvjugHk+IV4fNCUH+b5j0EMyLVsTn1ElRy8OvgL upV8VMoJ6neNmFVImPF6hbeacpjVbo1kBe4WLK7egsG6LRFnKQhHkN+W1Z18wx0wRCWw GxQNRkiT/JyIIybAPp19dfpUCn3nSgsG+J27pHXkwXcTd7X7tOGwS27P6h7yYBFNTEqy r9GWSaw+Vt7ktmC4/1fFha5RaZB52QfcnWAWwL2eQlP8l6NdUbQNMoMK+s251PJZX6Pn xzSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=8EzLqtu/ON88Zom482XGaOBPmnSrN8QroGa8TbIaqZA=; b=NGimZLi65tBOUB8CtAPvYxwtZW2cW0It/8LjdW4nW6ynftlgFxSFAU7t7SPLW4rhcK hN+3ZefJjHgsRe8yFmU3BJNngkbgat8Vh2Rr40f4ERAziPUHMF2cBmM4TV0pItQdLcLr 35ibBcOcWxpuotvIS047fL10+r0A5kXHWFkXidDio0soxJdfGiNzeoVquLItUSOikvZa eBxN3FAJUbmKnhpN1Z1st8/c8pePSI7QAjMIKrEJOZQt5G5XgHshMxvKWwFohfoU+BkH fDKw6Bt7GNz5cGIjib6hPQjAV+hPLadIT0ZI1pi/SOoVSrP/4y7q9TAdD+2x6oCv1otY Favg== X-Gm-Message-State: ALKqPwd9g3znysnouv7Erq+YWuVz1OsKIDl4yWqcjxRYNTw38jWTO1DZ d7uyxQg+m98rqS65CBNLGao= X-Google-Smtp-Source: ADUXVKLbpkCw/cGCOdkuEXS16AaWZhw0eqpOVSD+rFM6kWJmVBkkUxXaG76Z+tOnas50anwppOOE9Q== X-Received: by 2002:a17:902:52ee:: with SMTP id a101-v6mr18221548pli.131.1528033898232; Sun, 03 Jun 2018 06:51:38 -0700 (PDT) Original-Received: from calancha-pc (228.225.128.101.dy.bbexcite.jp. [101.128.225.228]) by smtp.gmail.com with ESMTPSA id a10-v6sm28258126pfg.107.2018.06.03.06.51.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Jun 2018 06:51:37 -0700 (PDT) In-Reply-To: <87vab07zu2.fsf@gmail.com> (Noam Postavsky's message of "Sun, 03 Jun 2018 09:40:37 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:146903 Archived-At: Noam Postavsky writes: > Tino Calancha 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 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@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..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---