From: Philip Kaludercic <philipk@posteo.net>
To: Mariano Montone <marianomontone@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: [ELPA] New package: progress-bar
Date: Tue, 29 Oct 2024 15:03:35 +0000 [thread overview]
Message-ID: <87h68v3q9k.fsf@posteo.net> (raw)
In-Reply-To: <f775c8e0-435e-4cdb-9a7e-3ce4ebf6f8c8@gmail.com> (Mariano Montone's message of "Tue, 29 Oct 2024 10:42:28 -0300")
[-- Attachment #1: Type: text/plain, Size: 211 bytes --]
Mariano Montone <marianomontone@gmail.com> writes:
> Hello,
Hi,
> I would like to propose adding this package to ELPA:
> https://github.com/mmontone/emacs-progress-bar/
Here are a few comments on the code:
[-- Attachment #2: Type: text/plain, Size: 9601 bytes --]
diff --git a/progress-bar.el b/progress-bar.el
index ab49ca9..f385f5a 100644
--- a/progress-bar.el
+++ b/progress-bar.el
@@ -24,15 +24,17 @@
;; A progress bar in the echo area.
;;
-;; This package contains the basic implementation. For integration of progress-bar
-;; into common Emacs commands and behaviors, install progress-bar-integrations package.
+;; This package contains the basic implementation. For integration of
+;; progress-bar into common Emacs commands and behaviors, install
+;; progress-bar-integrations package.
;;
-;; Usage:
+;;;; Usage:
;;
-;; The preferred method for using a progress-bar is via the utility functions:
-;; `dolist-with-progress-bar', `dotimes-with-progress-bar' and `mapc-with-progress-bar'.
+;; The preferred method for using a progress-bar is via the utility
+;; functions: `dolist-with-progress-bar', `dotimes-with-progress-bar'
+;; and `mapc-with-progress-bar'.
;;
-;; Example:
+;;;; Example:
;;
;; (dolist-with-progress-bar (x (cl-loop for i from 1 to 10 collect i)
;; :status-message (list "Started ..."
@@ -40,11 +42,15 @@
;; (format "Processing %s..." (progress-bar-data pb)))
;; "Completed!"))
;; (sit-for (seq-random-elt '(0.3 0.4 0.5))))
-;;
-;; TODO:
-;; - Consider putting event notification in call-with-progress-bar instead of in the utilities.
-;; - Consider implementing progress-bars with no total-steps specified.
-;; - Consider an option for hiding the progress-bar display after N seconds after completion.
+
+;;; TODO:
+
+;; - Consider putting event notification in call-with-progress-bar
+;; instead of in the utilities.
+;; - Consider implementing progress-bars with no total-steps
+;; specified.
+;; - Consider an option for hiding the progress-bar display after N
+;; seconds after completion.
;;; Code:
@@ -57,48 +63,41 @@
;; Chosen from https://en.wikipedia.org/wiki/Block_Elements and inserted using `insert-char' command:
-(defcustom progress-bar-char ?▓
+(defcustom progress-bar-char
+ (eval-when-compile (char-from-name "DARK SHADE")) ;as a suggetion
"Character for drawing progress bars."
- :type 'character
- :group 'progress-bar)
+ :type 'character) ;not necessary, :group default to the last `defgroup'
(defcustom progress-bar-background-char ?░
"Character for drawing progress bars background."
- :type 'character
- :group 'progress-bar)
+ :type 'character)
(defcustom progress-bar-width 35
"Standard width for progress bars."
- :type 'integer
- :group 'progress-bar)
+ :type 'natnum)
(defcustom progress-bar-min-steps 0
"Minimum number of steps for progress bars to be displayed."
- :type 'integer
- :group 'progress-bar)
+ :type 'natnum)
(defcustom progress-bar-display-after-seconds 0
"Display progress bars only after this number of seconds have passed."
- :type 'float
- :group 'progress-bar)
+ :type 'number) ;this was a type mismatch, 0 is not a flonum
-(defcustom progress-bar-format-string " [%d of %d](%d%%%%)"
+(defcustom progress-bar-format-string " [%d of %d](%d%%%%)" ;how about using `format-spec'?
"String for formatting the progress bar.
Arguments passed are current-step, total-steps and completed percentage.
Consider using field number arguments for more flexibility.
See `format' documentation."
- :type 'string
- :group 'progress-bar)
+ :type 'string)
(defcustom progress-bar-min-time 0.2
"The minimum time interval between progress bar displays."
- :type 'float
- :group 'progress-bar)
+ :type 'number)
(defcustom progress-bar-min-change 1
"The minimum percentage change required between progress bar displays."
- :type 'integer
- :group 'progress-bar)
+ :type 'number)
(defcustom progress-bar-message-display-layout
'concatenate
@@ -109,15 +108,14 @@ If `dynamic', the message is either concatenated or inserted after a new line
depending on its length."
:type '(choice (const concatenate)
(const newline)
- (const dynamic))
- :group 'progress-bar)
+ (const dynamic)))
(defvar progress-bar-update-functions '()
"An abnormal hook for getting notified of progress bar updates.
Functions get called with a progress bar event, and a progress-bar instance.
Progress bar events can be either `started', `updated' or `completed'")
-(cl-defstruct progress-bar
+(cl-defstruct progress-bar ;please address the `checkdoc' messages!
(status-message nil
:documentation "The status-message can be either a status-formatter or a list of three status-formatters, the first applied when the progress-bar starts, the second applied for each element processed, the third when the progress-bar completes.
A status-formatter is either a string or a function that takes a progress-bar instance and returns a string.")
@@ -159,7 +157,7 @@ See `progress-bar-update-functions' hook."
ARGS is a property-list of slot-name and value.
Example:
-(progress-bar-update pg 'current-step 2 'data 'foo)"
+\(progress-bar-update pg \\='current-step 2 \\='data \\='foo)"
(cl-loop for (slot value) on args by 'cddr
do (setf (slot-value progress-bar slot) value))
(progress-bar--display progress-bar)
@@ -168,11 +166,12 @@ Example:
(progress-bar-notify 'updated progress-bar)))
(defun progress-bar-incf (progress-bar &optional increment display)
- "Increment step in PROGRESS-BAR."
+ "Increment step by STEP in PROGRESS-BAR.
+If DISPLAY is non-nil, ..."
(let ((inc (or increment 1)))
(with-slots (current-step total-steps) progress-bar
(when (and total-steps (> (+ current-step inc) total-steps))
- (error "current-step > total-steps"))
+ (error "current-step > total-steps")) ;please rephrase this error message to be understandable on its own
(cl-incf current-step inc)
(when display
(progress-bar--display progress-bar))
@@ -185,7 +184,7 @@ Example:
(if (progress-bar-completed-p progress-bar)
100
(with-slots (current-step total-steps) progress-bar
- (truncate (* (/ current-step (float total-steps)) 100)))))
+ (truncate (* current-step 100.0) total-steps))))
(defun progress-bar--display (progress-bar)
"Display PROGRESS-BAR in echo-area."
@@ -207,7 +206,7 @@ Example:
(defun progress-bar--format-status-message (progress-bar message)
(cl-etypecase message
- ((or symbol function)
+ (function ;; you don't need to check symbols separately: (cl-typep 'insert 'function) ;=> t
(funcall message progress-bar))
(string message)))
@@ -256,7 +255,7 @@ evaluating FUNC, so that messages are displayed together with the progress bar."
(funcall func progress-bar)
;; Replace the implementation of `message' temporarily, so that
;; messages sent by FUNC are shown together with the progress bar.
- (let ((emacs-message (symbol-function 'message)))
+ (let ((emacs-message (symbol-function #'message)))
(cl-flet ((pb-message (msg &rest args)
;; This is only for logging. Can we log the message
;; without calling `message' ?
@@ -286,10 +285,10 @@ evaluating FUNC, so that messages are displayed together with the progress bar."
(defmacro with-progress-bar (spec &rest body)
"Create a PROGRESS-BAR binding SPEC in BODY scope.
-SPEC has either the form (VAR PROGRESS-BAR-INSTANCE) or (VAR &rest INITARGS), with
-INITARGS used for creating a `progress-bar'.
-This macros sets up special treatment for calls to MESSAGE that may ocurr in BODY,
-so that messages are displayed together with the progress bar."
+SPEC has either the form (VAR PROGRESS-BAR-INSTANCE) or (VAR &rest
+INITARGS), with INITARGS used for creating a `progress-bar'. This
+macros sets up special treatment for calls to MESSAGE that may ocurr in
+BODY, so that messages are displayed together with the progress bar."
(declare (indent 2))
(cl-destructuring-bind (var &rest initargs) spec
(if (= (length initargs) 1)
@@ -298,9 +297,9 @@ so that messages are displayed together with the progress bar."
`(let ((,var (make-progress-bar ,@initargs)))
(call-with-progress-bar ,var (lambda (,var) ,@body))))))
-;; Utilities
+;;;; Utilities
-(defun mapc-with-progress-bar (func sequence &rest args)
+(defun progress-bar-mapc (func sequence &rest args)
"Like `mapc' but using a progress-bar."
(let ((progress-bar (if (= (length args) 1)
(car args)
@@ -318,7 +317,7 @@ so that messages are displayed together with the progress bar."
(progress-bar--display progress-bar)
(progress-bar-notify 'completed progress-bar))))
-(defmacro dolist-with-progress-bar (spec &rest body)
+(defmacro progress-bar-dolist- (spec &rest body)
"Like DOLIST but displaying a progress-bar as items in the list are processed.
ARGS are arguments for `make-progress-bar'.
@@ -334,7 +333,7 @@ Example:
(cl-destructuring-bind (var list &rest args) spec
`(mapc-with-progress-bar (lambda (,var) ,@body) ,list ,@args)))
-(defmacro dotimes-with-progress-bar (spec &rest body)
+(defmacro progress-bar-dotimes (spec &rest body)
"Like `dotimes' but with a progress bar."
(declare (indent 2))
(let ((progress-bar (gensym "progress-bar-")))
[-- Attachment #3: Type: text/plain, Size: 713 bytes --]
> progress-bar is a progress bar that is displayed in the echo area.
>
> Please let me know if you accept, and what would be the next steps.
My main question, which I realised too late when reading the code, is if
you could rework this to integrate into existing instances of
`make-progress-reporter', just replacing the UI. It seems like it would
be more effective and consistent, and avoid hard dependencies of
programs that want to use `dotimes-with-progress-bar' (or as I renamed
it `progress-bar-dotimes' to avoid namespace clashes), when
`dotimes-with-progress-reporter' already exists and is being used.
> Thank you,
>
> Mariano
>
>
>
--
Philip Kaludercic on siskin
next prev parent reply other threads:[~2024-10-29 15:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 13:42 [ELPA] New package: progress-bar Mariano Montone
2024-10-29 14:47 ` Mariano Montone
2024-10-29 14:50 ` Mariano Montone
2024-10-29 14:49 ` Eli Zaretskii
2024-10-29 14:53 ` Mariano Montone
2024-10-29 15:03 ` Philip Kaludercic [this message]
2024-10-29 15:06 ` Mariano Montone
2024-10-29 15:24 ` Philip Kaludercic
2024-10-29 15:48 ` Mariano Montone
2024-10-29 16:19 ` Mariano Montone
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h68v3q9k.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=emacs-devel@gnu.org \
--cc=marianomontone@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).