diff options
author | Tino Calancha <tino.calancha@gmail.com> | 2018-06-17 18:28:34 +0900 |
---|---|---|
committer | Tino Calancha <tino.calancha@gmail.com> | 2018-06-17 18:28:34 +0900 |
commit | edb1f85a27817a3fac38bb85752671414819203b (patch) | |
tree | 8da1b7145ad7959199b2150c9337cd2f308bbb8c /lisp/subr.el | |
parent | 5099b3abb2b623ce949b8efc37bee8c41d5ad754 (diff) | |
download | emacs-edb1f85a27817a3fac38bb85752671414819203b.tar.gz |
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.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index d4383f862af..dc946bd90b0 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5068,6 +5068,34 @@ This macro is a convenience wrapper around `make-progress-reporter' and friends. (progress-reporter-done ,prep) (or ,@(cdr (cdr spec)) nil)))) +(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--")) + (list (make-symbol "--dolist-list--"))) + `(let ((,prep ,reporter-or-message) + (,count 0) + (,list ,(cadr spec))) + (when (stringp ,prep) + (setq ,prep (make-progress-reporter ,prep 0 (1- (length ,list))))) + (dolist (,(car spec) ,list) + ,@body + (progress-reporter-update ,prep (setq ,count (1+ ,count)))) + (progress-reporter-done ,prep) + (or ,@(cdr (cdr spec)) nil)))) + ;;;; Comparing version strings. |