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#31697: 27.0.50; Add new macro dolist-with-progress-reporter Date: Sun, 03 Jun 2018 22:16:09 +0900 Message-ID: <8736y457ty.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1528031735 30253 195.159.176.226 (3 Jun 2018 13:15:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 3 Jun 2018 13:15:35 +0000 (UTC) Cc: stefan monnier To: 31697@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 03 15:15:30 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 1fPSr3-0007l3-A4 for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 15:15:29 +0200 Original-Received: from localhost ([::1]:35187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPStA-00011p-Do for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jun 2018 09:17:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPSsc-0000qF-Vc 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 1fPSsZ-0003s6-GL for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:17:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51986) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPSsZ-0003ro-BI for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:17:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fPSsZ-0005Lc-57; Sun, 03 Jun 2018 09:17:03 -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:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 31697 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.152803178920486 (code B ref -1); Sun, 03 Jun 2018 13:17:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Jun 2018 13:16:29 +0000 Original-Received: from localhost ([127.0.0.1]:59879 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPSs0-0005KM-EA for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49831) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPSry-0005KA-OZ for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPSrs-0003GK-A1 for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:21 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:55883) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fPSrs-0003GF-6B for submit@debbugs.gnu.org; Sun, 03 Jun 2018 09:16:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPSrn-0000dk-Ti for bug-gnu-emacs@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 1fPSrm-0003F6-Fi for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:16:15 -0400 Original-Received: from mail-pg0-x233.google.com ([2607:f8b0:400e:c05::233]:47100) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPSrm-0003Et-7F for bug-gnu-emacs@gnu.org; Sun, 03 Jun 2018 09:16:14 -0400 Original-Received: by mail-pg0-x233.google.com with SMTP id d2-v6so2631482pga.13 for ; Sun, 03 Jun 2018 06:16:14 -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=xJAKsE6VFhQJB+wKN+OTpIQ9mpNfHAjZkyRbxSVenBc=; b=WM9VckpWs6s/FQVA1QEbqkBy/etixqIxuaD0ytL7LUlDchSdJS7kJ7GA6zm5NJxY2R JbE2OZ4XwAvDgO4dvqzPA2EjxQT+yf1jExPwf3JbSsSXDjiMFP/ZifmhCtLXG/u6zFvF hw6vqBxKORDrCjyapOK6gkXMptr3GxsczaX4vM2TkxIdV41GWxaeSKNe1NwhQmH36dlK DVFHrV0boypfkmfu0vL1ud86ar8+PC5PvSMiP5Ynq0DZpA9JlammoEewp9WLg1YCYu6H g2meSMdeuPnkm/igSsaQLGN9cZag6/ZUOgphC3irVG4pFycLG18yOa61YKSkaoYZ7h9e R93Q== 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=xJAKsE6VFhQJB+wKN+OTpIQ9mpNfHAjZkyRbxSVenBc=; b=e8Zbqon8lXHVyOzrFBHltyXU5YS1qbjji80KSHmo5mppVlNwdXLTfxEM6UgkEEml5u URu0AJ/GcXE+N3oVNAkFpnI8BLpiZxAZkSMdVS9nOUZHfSzP7GfrZ2jS9zdVZ2Y8g/Ke biqd/ylEyc7Tfb/QQqRUjS49GkrkYoYdHtSMxAgkM/qIxuar80n7da22nA+eglaOvnn5 9Enbx9i/GF5fUudlzFMtkY6ZBNNbJSyiovkJOfl4SdAhQw22ABeYJmHsxkShz3Wo6PP2 z1/qoV2K6h4bQe3bmIGRPs6o1j2BXsKPdtH/ynjcH/wJV82pevyuGgTm7OyZ8tHkH8An ZVvA== X-Gm-Message-State: ALKqPwf4aAk6XaVWyOkTDN5G2TrDQLrFj1DvHf2W4qumjDmHBcrLyKvd LC7uGqDrb6HeQrwlxUIhaIy0jw== X-Google-Smtp-Source: ADUXVKLSES+BQprIVlrUapTLux8xUj20Ogzt8UWnBeh+NBWYY5lM5xxFyaGttiqhU4E1BTyIn2UDQA== X-Received: by 2002:aa7:8345:: with SMTP id z5-v6mr9837128pfm.251.1528031773187; Sun, 03 Jun 2018 06:16:13 -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 68-v6sm76772214pff.35.2018.06.03.06.16.11 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Jun 2018 06:16:12 -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:146901 Archived-At: Severity: Wishlist X-Debbugs-Cc: Stefan Monnier It might have sense to have also this macro: sister of `dotimes-with-progress-reporter'. --8<-----------------------------cut here---------------start------------->8--- commit cfe50e187acb0cc4341869cc35acac83d82826d4 Author: Tino Calancha Date: Sun Jun 3 22:06:12 2018 +0900 Add new macro dolist-with-progress-reporter * lisp/subr.el (dolist-with-progress-reporter): New macro (Bug#31697). * lisp/cus-edit.el (custom-group-value-create): Use it. * lisp/dabbrev.el (dabbrev--progress-reporter): Delete variable. (dabbrev--find-expansion): Use dotimes-with-progress-reporter. * doc/lispref/display.texi: Document the macro ; * etc/NEWS: Announce it. diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index ce7ec3ac10..dd1d1e80e9 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -485,6 +485,12 @@ Progress @end example @end defmac +@defmac dolist-with-progress-reporter (var count [result]) reporter-or-message body@dots{} +This is another convenience macro that works the same way as @code{dolist} +does, but also reports loop progress using the functions described +above. +@end defmac + @node Logging Messages @subsection Logging Messages in @file{*Messages*} @cindex logging echo-area messages diff --git a/etc/NEWS b/etc/NEWS index 1b324986d9..16e2d6d752 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -562,6 +562,8 @@ manual for more details. * Lisp Changes in Emacs 27.1 +++ +** New macro dolist-with-progress-reporter. ++++ ** New function assoc-delete-all. +++ diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index a12897e799..c227bb0a26 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -4221,19 +4221,14 @@ custom-group-value-create custom-buffer-order-groups)) (prefixes (widget-get widget :custom-prefixes)) (custom-prefix-list (custom-prefix-add symbol prefixes)) - (len (length members)) - (count 0) - (reporter (make-progress-reporter - "Creating group entries..." 0 len)) (have-subtitle (and (not (eq symbol 'emacs)) (eq custom-buffer-order-groups 'last))) prev-type children) - (dolist (entry members) + (dolist-with-progress-reporter (entry members) "Creating group entries..." (unless (eq prev-type 'custom-group) (widget-insert "\n")) - (progress-reporter-update reporter (setq count (1+ count))) (let ((sym (nth 0 entry)) (type (nth 1 entry))) (when (and have-subtitle (eq type 'custom-group)) @@ -4255,8 +4250,7 @@ custom-group-value-create (setq children (nreverse children)) (mapc 'custom-magic-reset children) (widget-put widget :children children) - (custom-group-state-update widget) - (progress-reporter-done reporter)) + (custom-group-state-update widget)) ;; End line (let ((p (1+ (point)))) (insert "\n\n") diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 57ee9a526a..4af22e6140 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el @@ -327,9 +327,6 @@ dabbrev--check-other-buffers ;; The regexp for recognizing a character in an abbreviation. (defvar dabbrev--abbrev-char-regexp nil) -;; The progress reporter for buffer-scanning progress. -(defvar dabbrev--progress-reporter nil) - ;;---------------------------------------------------------------- ;; Macros ;;---------------------------------------------------------------- @@ -739,21 +736,19 @@ dabbrev--find-expansion ;; Put that list in dabbrev--friend-buffer-list. (unless dabbrev--friend-buffer-list (setq dabbrev--friend-buffer-list - (dabbrev--make-friend-buffer-list)) - (setq dabbrev--progress-reporter - (make-progress-reporter - "Scanning for dabbrevs..." - (- (length dabbrev--friend-buffer-list)) 0 0 1 1.5)))) + (dabbrev--make-friend-buffer-list)))) ;; Walk through the buffers till we find a match. (let (expansion) - (while (and (not expansion) dabbrev--friend-buffer-list) + (dolist-with-progress-reporter + (_ dabbrev--friend-buffer-list) + (make-progress-reporter + "Scanning for dabbrevs..." + 0 (length dabbrev--friend-buffer-list) 0 1 1.5) (setq dabbrev--last-buffer (pop dabbrev--friend-buffer-list)) (set-buffer dabbrev--last-buffer) - (progress-reporter-update dabbrev--progress-reporter - (- (length dabbrev--friend-buffer-list))) (setq dabbrev--last-expansion-location (point-min)) - (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case))) - (progress-reporter-done dabbrev--progress-reporter) + (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case)) + (unless expansion (setq dabbrev--friend-buffer-list '()))) expansion))))) ;; Compute the list of buffers to scan. diff --git a/lisp/subr.el b/lisp/subr.el index 914112ccef..7eabc3e12a 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5039,6 +5039,31 @@ dotimes-with-progress-reporter (setq ,(car spec) (1+ ,(car spec))))) (progress-reporter-done ,temp2) nil ,@(cdr (cdr spec))))) +(defmacro dolist-with-progress-reporter (spec reporter-or-message &rest body) + "Loop over a list and report progress in the echo area. +Evaluate BODY with VAR bound to each car from LIST, in turn. +Then evaluate RESULT to get return value, default nil. + +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\". + +\(fn (VAR LIST [RESULT]) MESSAGE BODY...)" + (declare (indent 2) (debug ((symbolp form &optional form) form body))) + (let ((prep (make-symbol "--dolist-progress-reporter--")) + (count (make-symbol "--dolist-count--"))) + `(let ((,prep ,reporter-or-message) + (,count 0)) + (when (stringp ,prep) + (setq ,prep (make-progress-reporter ,prep 0 (1- (length ,(cadr spec)))))) + (dolist ,spec + ,@body + (progress-reporter-update ,prep (setq ,count (1+ ,count)))) + (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