From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: [ELPA] New package: progress-bar Date: Tue, 29 Oct 2024 15:03:35 +0000 Message-ID: <87h68v3q9k.fsf@posteo.net> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39682"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Mariano Montone Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Oct 29 16:05:24 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t5nmd-000A9Q-Ix for ged-emacs-devel@m.gmane-mx.org; Tue, 29 Oct 2024 16:05:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5nm0-0002CS-T1; Tue, 29 Oct 2024 11:04:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5nlG-0001se-33 for emacs-devel@gnu.org; Tue, 29 Oct 2024 11:03:59 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5nlD-0005tr-4Z for emacs-devel@gnu.org; Tue, 29 Oct 2024 11:03:57 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 1CA2B24002A for ; Tue, 29 Oct 2024 16:03:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1730214222; bh=utYdqyagcRP2KIPKIHCP3AjapZhyCc5+sgQoZ0nsvyI=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=Qb11P9NdGM34HcrjX1K8pCf4sXkZdZf9NXxk34bXzP9L+nlW5v4aXnUNKVWs4qMQY 2//D9nOQkK1ibw8quQ8uNmy0mc7+Af+yGZwyQ+CJG2Os5KwJhaon1UVJ/3KcfW5wFf Kb51cRBK4K8+HWQHd5Zi10613FdkD3IyzlQZ0zjWvzdCArpxFwAw00FrkaVFwquRXA p+7FWwYryglrAMyXnFvnUEVC7wgpTEzbSLfCIH7WI4Ov3RRiqb8OrQ48Kn/UBV2ehg Kx1TD48EnjvYptgq+TRHpKL9n4s//0RIBqjum3WoJARF86ttrGJTIpJUmWRhh0VD7b Mgz7mm1iMgkKw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4XdD6J6GDdz6v0G; Tue, 29 Oct 2024 16:03:36 +0100 (CET) In-Reply-To: (Mariano Montone's message of "Tue, 29 Oct 2024 10:42:28 -0300") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=philipk@posteo.net; url="https://keys.openpgp.org/vks/v1/by-email/philipk@posteo.net"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324917 Archived-At: --=-=-= Content-Type: text/plain Mariano Montone 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: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 @@ =20 ;; A progress bar in the echo area. ;; -;; This package contains the basic implementation. For integration of pro= gress-bar -;; into common Emacs commands and behaviors, install progress-bar-integrat= ions package. +;; This package contains the basic implementation. For integration of +;; progress-bar into common Emacs commands and behaviors, install +;; progress-bar-integrations package. ;;=20 -;; Usage: +;;;; Usage: ;; -;; The preferred method for using a progress-bar is via the utility functi= ons: -;; `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 "Processin= g %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 second= s 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. =20 ;;; Code: =20 @@ -57,48 +63,41 @@ =20 ;; Chosen from https://en.wikipedia.org/wiki/Block_Elements and inserted u= sing `insert-char' command: =20 -(defcustom progress-bar-char ?=E2=96=93 +(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' =20 (defcustom progress-bar-background-char ?=E2=96=91 "Character for drawing progress bars background." - :type 'character - :group 'progress-bar) + :type 'character) =20 (defcustom progress-bar-width 35 "Standard width for progress bars." - :type 'integer - :group 'progress-bar) + :type 'natnum) =20 (defcustom progress-bar-min-steps 0 "Minimum number of steps for progress bars to be displayed." - :type 'integer - :group 'progress-bar) + :type 'natnum) =20 (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 =20 -(defcustom progress-bar-format-string " [%d of %d](%d%%%%)" +(defcustom progress-bar-format-string " [%d of %d](%d%%%%)" ;how about usi= ng `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) =20 (defcustom progress-bar-min-time 0.2 "The minimum time interval between progress bar displays." - :type 'float - :group 'progress-bar) + :type 'number) =20 (defcustom progress-bar-min-change 1 "The minimum percentage change required between progress bar displays." - :type 'integer - :group 'progress-bar) + :type 'number) =20 (defcustom progress-bar-message-display-layout 'concatenate @@ -109,15 +108,14 @@ If `dynamic', the message is either concatenated or i= nserted after a new line depending on its length." :type '(choice (const concatenate) (const newline) - (const dynamic)) - :group 'progress-bar) + (const dynamic))) =20 (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 instanc= e. Progress bar events can be either `started', `updated' or `completed'") =20 -(cl-defstruct progress-bar +(cl-defstruct progress-bar ;please address the `checkdoc' messages! (status-message nil :documentation "The status-message can be either a statu= s-formatter or a list of three status-formatters, the first applied when th= e progress-bar starts, the second applied for each element processed, the t= hird 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. =20 Example: -(progress-bar-update pg 'current-step 2 'data 'foo)" +\(progress-bar-update pg \\=3D'current-step 2 \\=3D'data \\=3D'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))) =20 (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)))) =20 (defun progress-bar--display (progress-bar) "Display PROGRESS-BAR in echo-area." @@ -207,7 +206,7 @@ Example: =20 (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 'in= sert 'function) ;=3D> t (funcall message progress-bar)) (string message))) =20 @@ -256,7 +255,7 @@ evaluating FUNC, so that messages are displayed togethe= r 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 toget= her with the progress bar." =20 (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 INITARG= S), 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 (=3D (length initargs) 1) @@ -298,9 +297,9 @@ so that messages are displayed together with the progre= ss bar." `(let ((,var (make-progress-bar ,@initargs))) (call-with-progress-bar ,var (lambda (,var) ,@body)))))) =20 -;; Utilities +;;;; Utilities =20 -(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 (=3D (length args) 1) (car args) @@ -318,7 +317,7 @@ so that messages are displayed together with the progre= ss bar." (progress-bar--display progress-bar) (progress-bar-notify 'completed progress-bar)))) =20 -(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 proc= essed. ARGS are arguments for `make-progress-bar'. =20 @@ -334,7 +333,7 @@ Example: (cl-destructuring-bind (var list &rest args) spec `(mapc-with-progress-bar (lambda (,var) ,@body) ,list ,@args))) =20 -(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-"))) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > 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, > > =C2=A0=C2=A0=C2=A0=C2=A0 Mariano > > > --=20 Philip Kaludercic on siskin --=-=-=--