emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple patch for `etags.el'


From: Paul Pogonyshev
Subject: Re: simple patch for `etags.el'
Date: Tue, 21 Sep 2004 00:08:09 -0200
User-agent: KMail/1.4.3

> I wrote:
> > 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...
>
> Or even better, like this.  Timing showed that it is cheaper
> to not use `current-time'.  Also simpler a lot.
>
> Paul
>
>
> (defun make-progress-reporter (format-string
>                                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 ;; Force a call to `message' now.
>                         min-value
>                         (/ (float (- max-value min-value)) 100.0)
>                         format-string)))
>     (progress-reporter-update reporter (or current-value min-value))
>     reporter))
>
> (defsubst 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 is inexpensive.  It never prints same percentage
> more than once, so it will not call `message' more than 101 times
> in total during whole operation."
>   (when (>= value (car reporter))
>     (progress-reporter-do-update reporter value)))
>
> (defun progress-reporter-do-update (reporter value)
>   (let* ((min-value   (nth 1 reporter))
>        (one-percent (nth 2 reporter))
>        (percentage  (truncate (/ (- value min-value) one-percent))))
>     (message (nth 3 reporter) percentage)
>     (setcar reporter (+ min-value (* (1+ percentage) one-percent)))
>     (when (integerp value)
>       (setcar reporter (ceiling (car reporter)))))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]