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: Re: simple patch for `etags.el' Date: Mon, 20 Sep 2004 23:25:47 -0200 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <200409202325.47369.pogonyshev@gmx.net> References: <200409201650.26315.pogonyshev@gmx.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1095711766 24438 80.91.229.6 (20 Sep 2004 20:22:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 20 Sep 2004 20:22:46 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 20 22:22:35 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 1C9UgF-0006vs-00 for ; Mon, 20 Sep 2004 22:22:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C9Um8-0005Vd-DL for ged-emacs-devel@m.gmane.org; Mon, 20 Sep 2004 16:28:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C9Uly-0005Tp-Vp for emacs-devel@gnu.org; Mon, 20 Sep 2004 16:28:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C9Uly-0005TG-7s for emacs-devel@gnu.org; Mon, 20 Sep 2004 16:28:30 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C9Uly-0005T6-4s for emacs-devel@gnu.org; Mon, 20 Sep 2004 16:28:30 -0400 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.34) id 1C9Ufo-0005FN-Sn for emacs-devel@gnu.org; Mon, 20 Sep 2004 16:22:09 -0400 Original-Received: (qmail 22067 invoked by uid 65534); 20 Sep 2004 20:22:05 -0000 Original-Received: from unknown (EHLO localhost.localdomain) (195.50.12.121) by mail.gmx.net (mp012) with SMTP; 20 Sep 2004 22:22:05 +0200 X-Authenticated: #16844820 Original-To: emacs-devel@gnu.org User-Agent: KMail/1.4.3 In-Reply-To: <200409201650.26315.pogonyshev@gmx.net> 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: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:27345 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:27345 I wrote: > This patch speeds building of tags table completion up several > times. Better yet, how about generalizing progress reporting between modules? For instance, it could look like this... (defun make-progress-reporter (format-string =09=09=09 min-value max-value &optional current-value) "Return a list suitable for reporting operation progress with `progress= -reporter-update'. FORMAT-STRING must contain a single %-sequence, `%d', which will be substituted with the progress percentage. If, for some reason, you need to change this string, simply create a new reporter. MIN-VALUE and MAX-VALUE designate starting (0% complete) and final (100% complete) states of operation. Optional CURRENT-VALUE specifies the progress by the moment you call this function. You should omit it in most cases." (let ((reporter (list min-value =09=09=09(if (fboundp 'current-time) (list 0 0 0) nil) =09=09=09min-value =09=09=09(/ (float (- max-value min-value)) 100.0) =09=09=09format-string))) (progress-reporter-update reporter (or current-value min-value)) reporter)) (defun progress-reporter-update (reporter value) "Report progress of an operation in the minibuffer. First parameter, REPORTER, should be the result of a call to `make-progress-reporter'. Second, VALUE, determines the actual progress of operation; it must be between MIN-VALUE and MAX-VALUE as passed to `make-progress-reporter'. This function tries to be very inexpensive. If Emacs has `current-time' function, then it will update minibuffer at most 5 times a second. In any case, it never prints same percentage more than once." (when (and (>=3D value (car reporter)) =09 ;; Update time is nil if we don't have `current-time' =09 ;; function anyway. =09 (or (null (cadr reporter)) =09=09 (let ((update-time (cadr reporter)) =09=09 (current-time (current-time))) =09=09 (when (and (>=3D (nth 1 current-time) (nth 1 update-time)) =09=09=09 (>=3D (nth 2 current-time) (nth 2 update-time)) =09=09=09 (>=3D (nth 0 current-time) (nth 0 update-time))) =09=09 ;; Compute the time of next update as now + 1/5 =09=09 ;; of a second. =09=09 (setcar (cddr current-time) =09=09=09 (if (< (nth 2 current-time) 800000) =09=09=09=09 (+ (nth 2 current-time) 200000) =09=09=09 (when (=3D (setcar (cdr current-time) =09=09=09=09=09=09(1+ (nth 1 current-time))) =09=09=09=09=090) =09=09=09=09 (setcar current-time (1+ (car current-time)))) =09=09=09 (- (nth 2 current-time) 800000))) =09=09 (setcar (cdr reporter) current-time))))) (let* ((min-value (nth 2 reporter)) =09 (one-percent (nth 3 reporter)) =09 (percentage (truncate (/ (- value min-value) one-percent)))) (message (nth 4 reporter) percentage) ;; Make sure we return as soon as possible from this function ;; anything until progress percentage changes. (setcar reporter (+ min-value (* (1+ percentage) one-percent))) (when (integerp value) =09(setcar reporter (ceiling (car reporter))))))) =09=09 =20 --- etags.el=0928 Aug 2004 13:30:31 -0200=091.181 +++ etags.el=0920 Sep 2004 23:25:01 -0200=09 @@ -1229,10 +1229,11 @@ where they were found." =20 (defun etags-tags-completion-table () (let ((table (make-vector 511 0)) -=09(point-max (/ (float (point-max)) 100.0)) -=09(msg-fmt (format=20 -=09=09 "Making tags completion table for %s...%%d%%%%" -=09=09 buffer-file-name))) +=09(progress-reporter +=09 (make-progress-reporter +=09 (format "Making tags completion table for %s...%%d%%%%" +=09=09 buffer-file-name) +=09 (point-min) (point-max)))) (save-excursion (goto-char (point-min)) ;; This monster regexp matches an etags tag line. @@ -1253,7 +1254,7 @@ where they were found." =09=09=09 (buffer-substring (match-beginning 5) (match-end 5)) =09=09=09 ;; No explicit tag name. Best guess. =09=09=09 (buffer-substring (match-beginning 3) (match-end 3))) -=09=09 (message msg-fmt (/ (point) point-max))) +=09=09 (progress-reporter-update progress-reporter (point))) =09=09table))) table)) =20