From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: progress reporting again Date: Mon, 15 Nov 2004 18:13:44 +0200 Message-ID: <200411151813.44859.pogonyshev@gmx.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1100535852 30696 80.91.229.6 (15 Nov 2004 16:24:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 15 Nov 2004 16:24:12 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 15 17:24:02 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CTje5-0007du-00 for ; Mon, 15 Nov 2004 17:24:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CTjmn-0007us-Fk for ged-emacs-devel@m.gmane.org; Mon, 15 Nov 2004 11:33:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CTjlg-0007UN-J6 for emacs-devel@gnu.org; Mon, 15 Nov 2004 11:31:52 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CTjlf-0007Tw-CH for emacs-devel@gnu.org; Mon, 15 Nov 2004 11:31:52 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CTjlf-0007Tj-1l for emacs-devel@gnu.org; Mon, 15 Nov 2004 11:31:51 -0500 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.34) id 1CTjco-0001rw-TV for emacs-devel@gnu.org; Mon, 15 Nov 2004 11:22:43 -0500 Original-Received: (qmail 10155 invoked by uid 65534); 15 Nov 2004 16:22:22 -0000 Original-Received: from unknown (EHLO localhost.localdomain) (195.50.12.118) by mail.gmx.net (mp001) with SMTP; 15 Nov 2004 17:22:22 +0100 X-Authenticated: #16844820 Original-To: emacs-devel@gnu.org User-Agent: KMail/1.4.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:29876 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:29876 Can anyone who uses SES mode check if the following patch works fine? I think it is generally a good idea to unify progress reporting as much as possible in Emacs. I didn't touch `ses-time-check' function, since progress messages used with it are non-standard. Paul (for lisp/ChangeLog) 2004-11-15 Paul Pogonyshev =09* subr.el (make-progress-reporter): Doc fix. =09(dotimes-with-progress-reporter): New macro. =09* ses.el (ses-dotimes-msg): Remove macro. =09(ses-relocate-all): Use `dotimes-with-progress-reporter' instead =09of `ses-dotimes-msg'. =09(ses-setup): Likewise. =09(ses-reprint-all): Likewise. =09(ses-reconstruct-all): Likewise. =09(ses-insert-row): Likewise. =09(ses-insert-column): Likewise. =09(ses-delete-column): Likewise. =09(ses-yank-cells): Likewise. (for lispref/ChangeLog) 2004-11-15 Paul Pogonyshev =09* display.texi (Progress): Document new =09`dotimes-with-progress-reporter' macro. Index: etc/NEWS =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/etc/NEWS,v retrieving revision 1.1066 diff -u -p -r1.1066 NEWS --- etc/NEWS=0910 Nov 2004 20:15:00 -0000=091.1066 +++ etc/NEWS=0915 Nov 2004 16:09:10 -0000 @@ -116,8 +116,9 @@ =20 +++ ** New functions `make-progress-reporter', `progress-reporter-update', -`progress-reporter-force-update' and `progress-reporter-done' provide -a simple and efficient way of printing progress messages to the user. +`progress-reporter-force-update' and `progress-reporter-done' and +`dotimes-with-progress-reporter' macro provide a simple and efficient +way of printing progress messages to the user. =20 +++ ** In Enriched mode, `set-left-margin' and `set-right-margin' are now Index: lispref/display.texi =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lispref/display.texi,v retrieving revision 1.132 diff -u -p -r1.132 display.texi --- lispref/display.texi=098 Oct 2004 17:35:47 -0000=091.132 +++ lispref/display.texi=0915 Nov 2004 16:09:40 -0000 @@ -632,6 +632,22 @@ Secondly, ``done'' is more explicit. @end defun =20 +@defmac dotimes-with-progress-reporter (var count [result]) message body= =2E.. +This is a convenience macro that works the same way as @code{dotimes} +does, but also reports loop progress using the functions described +above. It allows you to save some typing. + +You can rewrite the example in the beginning of this node using +@code{dotimes-with-progress-reporter} macro this way: + +@example +(dotimes-with-progress-reporter + (k 500) + "Collecting some mana for Emacs..." + (sit-for 0.01)) +@end example +@end defmac + @node Invisible Text @section Invisible Text =20 Index: lisp/ses.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/ses.el,v retrieving revision 1.9 diff -u -p -r1.9 ses.el --- lisp/ses.el=094 May 2004 16:13:43 -0000=091.9 +++ lisp/ses.el=0915 Nov 2004 16:09:53 -0000 @@ -397,26 +397,6 @@ (setq ses--header-row row) t) =20 -(defmacro ses-dotimes-msg (spec msg &rest body) - "(ses-dotimes-msg (VAR LIMIT) MSG BODY...): Like `dotimes', but -a message is emitted using MSG every second or so during the loop." - (let ((msgvar (make-symbol "msg")) -=09(limitvar (make-symbol "limit")) -=09(var (car spec)) -=09(limit (cadr spec))) - `(let ((,limitvar ,limit) -=09 (,msgvar ,msg)) - (setq ses-start-time (float-time)) - (message ,msgvar) - (setq ,msgvar (concat ,msgvar " (%d%%)")) - (dotimes (,var ,limitvar) -=09 (ses-time-check ,msgvar '(/ (* ,var 100) ,limitvar)) -=09 ,@body) - (message nil)))) - -(put 'ses-dotimes-msg 'lisp-indent-function 2) -(def-edebug-spec ses-dotimes-msg ((symbolp form) form body)) - (defmacro ses-dorange (curcell &rest body) "Execute BODY repeatedly, with the variables `row' and `col' set to ea= ch cell in the range specified by CURCELL. The range is available in the @@ -1210,7 +1190,8 @@ to each symbol." (let (reform) (let (mycell newval) - (ses-dotimes-msg (row ses--numrows) "Relocating formulas..." + (dotimes-with-progress-reporter +=09 (row ses--numrows) "Relocating formulas..." =09(dotimes (col ses--numcols) =09 (setq ses-relocate-return nil =09=09mycell (ses-get-cell row col) @@ -1238,7 +1219,8 @@ (cond ((and (<=3D rowincr 0) (<=3D colincr 0)) =09;;Deletion of rows and/or columns -=09(ses-dotimes-msg (row (- ses--numrows minrow)) "Relocating variables.= =2E." +=09(dotimes-with-progress-reporter +=09 (row (- ses--numrows minrow)) "Relocating variables..." =09 (setq myrow (+ row minrow)) =09 (dotimes (col (- ses--numcols mincol)) =09 (setq mycol (+ col mincol) @@ -1254,7 +1236,8 @@ =09(let ((disty (1- ses--numrows)) =09 (distx (1- ses--numcols)) =09 myrow mycol) -=09 (ses-dotimes-msg (row (- ses--numrows minrow)) "Relocating variable= s..." +=09 (dotimes-with-progress-reporter +=09 (row (- ses--numrows minrow)) "Relocating variables..." =09 (setq myrow (- disty row)) =09 (dotimes (col (- ses--numcols mincol)) =09 (setq mycol (- distx col) @@ -1468,7 +1451,7 @@ (put-text-property (point-min) (1+ (point-min)) 'front-sticky t) ;;Create intangible properties, which also indicate which cell the t= ext ;;came from. - (ses-dotimes-msg (row ses--numrows) "Finding cells..." + (dotimes-with-progress-reporter (row ses--numrows) "Finding cells...= " (dotimes (col ses--numcols) =09(setq pos end =09 sym (ses-cell-symbol row col)) @@ -1731,7 +1714,7 @@ ;;find the data area when inserting or deleting *skip* values for ce= lls (dotimes (row ses--numrows) (insert-and-inherit ses--blank-line)) - (ses-dotimes-msg (row ses--numrows) "Reprinting..." + (dotimes-with-progress-reporter (row ses--numrows) "Reprinting..." (if (eq (ses-cell-value row 0) '*skip*) =09 ;;Column deletion left a dangling skip =09 (ses-set-cell row 0 'value nil)) @@ -1816,11 +1799,13 @@ ;;Reconstruct reference lists. (let (refs x yrow ycol) ;;Delete old reference lists - (ses-dotimes-msg (row ses--numrows) "Deleting references..." + (dotimes-with-progress-reporter +=09(row ses--numrows) "Deleting references..." (dotimes (col ses--numcols) =09(ses-set-cell row col 'references nil))) ;;Create new reference lists - (ses-dotimes-msg (row ses--numrows) "Computing references..." + (dotimes-with-progress-reporter +=09(row ses--numrows) "Computing references..." (dotimes (col ses--numcols) =09(dolist (ref (ses-formula-references (ses-cell-formula row col))) =09 (setq x (ses-sym-rowcol ref) @@ -2080,7 +2065,7 @@ (ses-set-parameter 'ses--numrows (+ ses--numrows count)) ;;Insert each row (ses-goto-print row 0) - (ses-dotimes-msg (x count) "Inserting row..." + (dotimes-with-progress-reporter (x count) "Inserting row..." ;;Create a row of empty cells. The `symbol' fields will be set by ;;the call to ses-relocate-all. (setq newrow (make-vector ses--numcols nil)) @@ -2170,7 +2155,7 @@ (ses-create-cell-variable-range 0 (1- ses--numrows) =09=09=09=09 ses--numcols (+ ses--numcols count -1)) ;;Insert each column. - (ses-dotimes-msg (x count) "Inserting column..." + (dotimes-with-progress-reporter (x count) "Inserting column..." ;;Create a column of empty cells. The `symbol' fields will be set= by ;;the call to ses-relocate-all. (ses-adjust-print-width col (1+ width)) @@ -2229,7 +2214,7 @@ (ses-begin-change) (ses-set-parameter 'ses--numcols (- ses--numcols count)) (ses-adjust-print-width col (- width)) - (ses-dotimes-msg (row ses--numrows) "Deleting column..." + (dotimes-with-progress-reporter (row ses--numrows) "Deleting column.= =2E." ;;Delete lines from cell data area (ses-goto-data row col) (ses-delete-line count) @@ -2475,7 +2460,7 @@ =09 (colincr (- (cdr rowcol) (cdr first))) =09 (pos 0) =09 myrow mycol x) -=09(ses-dotimes-msg (row needrows) "Yanking..." +=09(dotimes-with-progress-reporter (row needrows) "Yanking..." =09 (setq myrow (+ row (car rowcol))) =09 (dotimes (col needcols) =09 (setq mycol (+ col (cdr rowcol)) Index: lisp/subr.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/subr.el,v retrieving revision 1.425 diff -u -p -r1.425 subr.el --- lisp/subr.el=098 Nov 2004 16:55:56 -0000=091.425 +++ lisp/subr.el=0915 Nov 2004 16:10:00 -0000 @@ -2631,7 +2631,7 @@ (defun make-progress-reporter (message min-value max-value =09=09=09=09 &optional current-value =09=09=09=09 min-change min-time) - "Return progress reporter object usage with `progress-reporter-update'= =2E + "Return progress reporter object to be used with `progress-reporter-up= date'. =20 MESSAGE is shown in the echo area. When at least 1% of operation is complete, the exact percentage will be appended to the @@ -2720,5 +2720,32 @@ "Print reporter's message followed by word \"done\" in echo area." (message "%sdone" (aref (cdr reporter) 3))) =20 +(defmacro dotimes-with-progress-reporter (spec message &rest body) + "Loop a certain number of times and report progress in the echo area. +Evaluate BODY with VAR bound to successive integers running from +0, inclusive, to COUNT, exclusive. Then evaluate RESULT to get +the return value (nil if RESULT is omitted). + +At each iteration MESSAGE followed by progress percentage is +printed in the echo area. After the loop is finished, MESSAGE +followed by word \"done\" is printed. This macro is a +convenience wrapper around `make-progress-reporter' and friends. + +\(fn (VAR COUNT [RESULT]) MESSAGE BODY...)" + (declare (indent 2) (debug ((symbolp form &optional form) form body))) + (let ((temp (make-symbol "--dotimes-temp--")) +=09(temp2 (make-symbol "--dotimes-temp2--")) +=09(start 0) +=09(end (nth 1 spec))) + `(let ((,temp ,end) +=09 (,(car spec) ,start) +=09 (,temp2 (make-progress-reporter ,message ,start ,end))) + (while (< ,(car spec) ,temp) +=09 ,@body +=09 (progress-reporter-update ,temp2 +=09=09=09=09 (setq ,(car spec) (1+ ,(car spec))))) + (progress-reporter-done ,temp2) + nil ,@(cdr (cdr spec))))) + ;; arch-tag: f7e0e6e5-70aa-4897-ae72-7a3511ec40bc ;;; subr.el ends here