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, 3 Jun 2018 23:09:18 +0900 (JST) Message-ID: References: <874lik57ub.fsf@gmail.com> <87vab07zu2.fsf@gmail.com> <87y3fw3rmh.fsf@gmail.com> <87sh647ysx.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1528034893 14615 195.159.176.226 (3 Jun 2018 14:08:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 3 Jun 2018 14:08:13 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: 31696@debbugs.gnu.org, stefan monnier , Tino Calancha To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 03 16:08:09 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 1fPTfy-0003eg-8x for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 16:08:06 +0200 Original-Received: from localhost ([::1]:35441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPTi3-0003Uv-7r for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 10:10:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPThu-0003Uq-Uk for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 10:10:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPThq-0000b1-Ri for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 10:10:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52522) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPThq-0000at-Nf for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 10:10:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fPThq-0006lB-90 for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 10:10:02 -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 14:10:02 +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.152803496925941 (code B ref 31696); Sun, 03 Jun 2018 14:10:02 +0000 Original-Received: (at 31696) by debbugs.gnu.org; 3 Jun 2018 14:09:29 +0000 Original-Received: from localhost ([127.0.0.1]:60419 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPThJ-0006kL-0o for submit@debbugs.gnu.org; Sun, 03 Jun 2018 10:09:29 -0400 Original-Received: from mail-pf0-f179.google.com ([209.85.192.179]:35986) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPThH-0006k8-CJ for 31696@debbugs.gnu.org; Sun, 03 Jun 2018 10:09:27 -0400 Original-Received: by mail-pf0-f179.google.com with SMTP id a12-v6so1068774pfi.3 for <31696@debbugs.gnu.org>; Sun, 03 Jun 2018 07:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=yWmihMqfsSf9BAfab3RhAePc4yFFVM+q8/40vWOWekE=; b=Bo4VhV8yys/7g7xaCupg63kPB2dY3z9R74BVu22bDiuFKnYUHjtJ/8uvEQLrIKO2Sk i3+8hQSPQZp1yOhVKHXXXlLnYx07+i1LqyNrPCoxuPKqR242nETSKPXISQ6kf7uK7RzR bb68swH04yHY22JXmT9brIottcEAyTcmewpiMZOMMcI66eS4FyLFr4J6Vb3DhOqEZOiC G84UKAsEk1YVuyuGvG40nuONrLjm3omc5X6JCM3FwjWTDVA937GVJTGvMTNvR/bYqo5r 3C8fSJGZhExrM7JFueCD3gFciCkLr5OSAmcX/IIMt6KtMfny6tTG6e1umWW1JCYsrHTL NwiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=yWmihMqfsSf9BAfab3RhAePc4yFFVM+q8/40vWOWekE=; b=l5lb6ZQ5TFy3Z/3OSYoNLHn864dU9xZXX9OXcWA5kBfZaJxGzHN8kwhweZB096nMcb Ek+5tIlit4quSpByVkUqh7gHDd8UvwwNrFCUyaNANsEPs0XoC5O+Ye52sEzF6p8hB/W5 54smCRZoSrjhwQR2CG63TuO/ml6ANjKRpSfcM1Mk+6xYfrf0gyxU1IBqL4LxhFFTHwFs 2ZxNzF8YnD00M237ERJwAHc/KMhW+oO31NhT0aTIyucLUs/w06AKw2KBxuq8pY4uHMnB LySjzUe/Cdx9PTpFrcOq9MLkkZX4cWUFfS9hAT4GP0op2B1yRq78Dgt5pmlWY0bsQYJD 3TLg== X-Gm-Message-State: ALKqPwdsp0eDrgr9Z+g9mTmyQgaGfEFMDE/86u1nPup1ckRqE8DCgLQm c70jRj6oRVm7Q4LEAjt7ulY= X-Google-Smtp-Source: ADUXVKI/I+44I/2EyKzF10OBP7ZsVM9JYr3LMyODrVfKrdAbhIHoLd6Hq2N2+FuhPsMzyoZRZRJDpQ== X-Received: by 2002:a62:418b:: with SMTP id g11-v6mr17809511pfd.51.1528034961624; Sun, 03 Jun 2018 07:09:21 -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 k24-v6sm84353022pfi.37.2018.06.03.07.09.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jun 2018 07:09:21 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <87sh647ysx.fsf@gmail.com> 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:146906 Archived-At: On Sun, 3 Jun 2018, Noam Postavsky wrote: > Tino Calancha 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 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@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..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