a-c-d-w · 2022-02-25 15:48
A lot of built-in functions will message "Doing xxx..." when they start, then "Doing xxx...done." when they're done, and if no message has appeared between the two they'll appear on the same line in Emacs' message buffer. When writing my own functions, I've been doing two message calls, but sometimes those messages will appear one after the other even if nothing has appeared between them.
Is there a function, macro, or some other pattern to keep in mind to copy the behavior with several built-in Emacs functions? Or is it some built-in magic that I'm not going to really be privvy to?
mickeyp · 2022-02-25 16:36
There's `make-progress-reporter` and friends.
a-c-d-w · 2022-02-25 17:07
Thanks so much, that gave me the info I needed to make this macro (which seems to work :D):
(defmacro with-progress (pr-args &rest body)
"Perform BODY wrapped in a progress reporter.
PR-ARGS is the list of arguments to pass to
`make-progress-reporter'; it can be a single string for the
message, as well. If you want to use a formatted string, wrap
the `format' call in a list."
(declare (indent 1))
(let ((reporter (gensym))
(pr-args (if (listp pr-args) pr-args (list pr-args))))
`(let ((,reporter (make-progress-reporter ,@pr-args)))
(prog1 (progn ,@body)
(progress-reporter-done ,reporter)))))
mickeyp · 2022-02-25 17:14
No problem. Seems like a useful macro!