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:15:56 +0900 Message-ID: <874lik57ub.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1528031721 29380 195.159.176.226 (3 Jun 2018 13:15:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 3 Jun 2018 13:15:21 +0000 (UTC) Cc: stefan monnier To: 31696@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 03 15:15:17 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 1fPSqk-0007RH-O9 for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 15:15:10 +0200 Original-Received: from localhost ([::1]:35183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPSsp-0000qQ-LV for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 09:17:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPSsc-0000qE-Vb for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:17:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPSsY-0003rH-T8 for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:17:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51982) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPSsY-0003qx-Nv for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fPSsY-0005LM-FT; Sun, 03 Jun 2018 09:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Jun 2018 13:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 31696 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: stefan monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.152803178120467 (code B ref -1); Sun, 03 Jun 2018 13:17:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Jun 2018 13:16:21 +0000 Original-Received: from localhost ([127.0.0.1]:59876 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPSrt-0005K2-1h for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:21 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49780) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPSrr-0005Jm-9A for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPSrk-0003Ep-Qj for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:13 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:36600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fPSrk-0003El-My for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPSrh-0000bf-Sd for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:16:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPSrd-0003Df-TR for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:16:09 -0400 Original-Received: from mail-pg0-x22d.google.com ([2607:f8b0:400e:c05::22d]:36976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPSrd-0003DO-Lg for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:16:05 -0400 Original-Received: by mail-pg0-x22d.google.com with SMTP id a13-v6so13239660pgu.4 for ; Sun, 03 Jun 2018 06:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=+8IIT13MmBaO7qqSc9CE9Xk097uTI2Ah97WGjDaSlR8=; b=AVeaSrGNj1/vim47XzxmJYcrqGGePzETMkS0hOkc4Edf1I/8z3r6oGuI+qZUAxs8Bh pMoHMIZsYOAtb/zUhX+Z6gaS/oiHwmFdHLul7htWyhRIIcoYH8Xc75m5CVUk2I8pA2ru B0TxlxamXd1HHGhNdlyJODl4Te42p+rUX14AVoCTenwQVCOKECKlan1z4WspmqiBjq9E qrAfvnP3Sdi9zl06C21Q0d/pKZYlRU2iL08o+UnDTntf/htJYhxp+/JZwV9hChMKHwVz c+bjUyv44j/edP5UmwHr+LPRwYqNcs19Vj4ZnZ4p7qVENCDaEKb5GqEcq5Kzx4D1pgQD KkKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=+8IIT13MmBaO7qqSc9CE9Xk097uTI2Ah97WGjDaSlR8=; b=etE6t0C5zgY2oixus++9JwtEjT3dgszLOqeFXwj467R1lYV6XgtPT7Z3C0pRDc+DLD da4IBT7I2V+j8ghqEX86AfhgCm62iA7c1w2OHyhohSZy8TLsafLiJdr8fyNG6D07Qsxa QnwezBn2NYpMLIOEdhwISI2MVzvY78BXF5oA9/mnajHFxpNlPpjjcTYWMHEOUukP40yq E+pgbWX7fCHdQsR52fo4XQW4kvVvYrlOyZpwVlYkRfG8CCpyaih0fF+BZRukU8P1uhoP VS6/suxJF9EmRECZREtm43nzT7wN4AQ+NrwHxXiqsxlqPkI/j68lAb8tAuT1yGHdOT1y R7Yg== X-Gm-Message-State: ALKqPwdCFBguFOX38Sr1W0h3eVg4n8AHt1CZGxrvzkX2iYeaSRTavQ+y hggxtOj+5AkerIBSl5nIjr4T7g== X-Google-Smtp-Source: ADUXVKIqI2ABYlTAcGqSeHEUQ0i6iva8OjDoa+S6CnLxBKgE5d/pbMSid+uisVAZadgp1qparlIZxw== X-Received: by 2002:a62:ea1a:: with SMTP id t26-v6mr17756803pfh.117.1528031764274; Sun, 03 Jun 2018 06:16:04 -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 z129-v6sm70711534pfb.108.2018.06.03.06.16.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Jun 2018 06:16:03 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:146900 Archived-At: Severity: Wishlist X-Debbugs-Cc: Stefan Monnier 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 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)))) ;;;; 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