aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2004-10-08 17:35:47 +0000
committerEli Zaretskii2004-10-08 17:35:47 +0000
commit276dd8a8c76b987171a258b9fbb23151cba69647 (patch)
treebcf8e7f7f016ccb81d0f64648f0556abbbba3dd1
parent4f124fb5287c38e0f8e507a2b8a5edd4d0cfb42c (diff)
downloademacs-276dd8a8c76b987171a258b9fbb23151cba69647.tar.gz
emacs-276dd8a8c76b987171a258b9fbb23151cba69647.zip
(Progress): New node.
-rw-r--r--lispref/display.texi99
1 files changed, 99 insertions, 0 deletions
diff --git a/lispref/display.texi b/lispref/display.texi
index 518234ff4f8..d7e1303abad 100644
--- a/lispref/display.texi
+++ b/lispref/display.texi
@@ -16,6 +16,7 @@ that Emacs presents to the user.
16* Truncation:: Folding or wrapping long text lines. 16* Truncation:: Folding or wrapping long text lines.
17* The Echo Area:: Where messages are displayed. 17* The Echo Area:: Where messages are displayed.
18* Warnings:: Displaying warning messages for the user. 18* Warnings:: Displaying warning messages for the user.
19* Progress:: Informing user about progress of a long operation.
19* Invisible Text:: Hiding part of the buffer text. 20* Invisible Text:: Hiding part of the buffer text.
20* Selective Display:: Hiding part of the buffer text (the old way). 21* Selective Display:: Hiding part of the buffer text (the old way).
21* Overlay Arrow:: Display of an arrow to indicate position. 22* Overlay Arrow:: Display of an arrow to indicate position.
@@ -533,6 +534,104 @@ symbols. If it matches the first few elements in a warning type, then
533that warning is not logged. 534that warning is not logged.
534@end defopt 535@end defopt
535 536
537@node Progress
538@section Reporting Operation Progress
539@cindex progress reporting
540
541When an operation can take a while to finish, you should inform the
542user about the progress it makes. This way the user can estimate
543remaining time and clearly see that Emacs is busy working, not hung.
544
545Functions listed in this section provide simple and efficient way of
546reporting operation progress. Here is a working example that does
547nothing useful:
548
549@example
550(let ((progress-reporter
551 (make-progress-reporter "Collecting some mana for Emacs..."
552 0 500)))
553 (dotimes (k 500)
554 (sit-for 0.01)
555 (progress-reporter-update progress-reporter k))
556 (progress-reporter-done progress-reporter))
557@end example
558
559@defun make-progress-reporter message min-value max-value &optional current-value min-change min-time
560This function creates a progress reporter---the object you will use as
561an argument for all other functions listed here. The idea is to
562precompute as much data as possible to make progress reporting very
563fast.
564
565The @var{message} will be displayed in the echo area, followed by
566progress percentage. @var{message} is treated as a simple string. If
567you need it to depend on a filename, for instance, use @code{format}
568before calling this function.
569
570@var{min-value} and @var{max-value} arguments stand for starting and
571final states of your operation. For instance, if you scan a buffer,
572they should be the results of @code{point-min} and @code{point-max}
573correspondingly. It is required that @var{max-value} is greater than
574@var{min-value}. If you create progress reporter when some part of
575the operation has already been completed, then specify
576@var{current-value} argument. But normally you should omit it or set
577it to @code{nil}---it will default to @var{min-value} then.
578
579Remaining arguments control the rate of echo area updates. Progress
580reporter will wait for at least @var{min-change} more percents of the
581operation to be completed before printing next message.
582@var{min-time} specifies the minimum time in seconds to pass between
583successive prints. It can be fractional. Depending on Emacs and
584system capabilities, progress reporter may or may not respect this
585last argument or do it with varying precision. Default value for
586@var{min-change} is 1 (one percent), for @var{min-time}---0.2
587(seconds.)
588
589This function calls @code{progress-reporter-update}, so the first
590message is printed immediately.
591@end defun
592
593@defun progress-reporter-update reporter value
594This function does the main work of reporting progress of your
595operation. It print the message of @var{reporter} followed by
596progress percentage determined by @var{value}. If percentage is zero,
597then it is not printed at all.
598
599@var{reporter} must be the result of a call to
600@code{make-progress-reporter}. @var{value} specifies the current
601state of your operation and must be between @var{min-value} and
602@var{max-value} (inclusive) as passed to
603@code{make-progress-reporter}. For instance, if you scan a buffer,
604then @var{value} should be the result of a call to @code{point}.
605
606This function respects @var{min-change} and @var{min-time} as passed
607to @code{make-progress-reporter} and so does not output new messages
608on every invocation. It is thus very fast and normally you should not
609try to reduce the number of calls to it: resulting overhead will most
610likely negate your effort.
611@end defun
612
613@defun progress-reporter-force-update reporter value &optional new-message
614This function is similar to @code{progress-reporter-update} except
615that it prints a message in the echo area unconditionally.
616
617The first two arguments have the same meaning as for
618@code{progress-reporter-update}. Optional @var{new-message} allows
619you to change the message of the @var{reporter}. Since this functions
620always updates the echo area, such a change will be immediately
621presented to the user.
622@end defun
623
624@defun progress-reporter-done reporter
625This function should be called when the operation is finished. It
626prints the message of @var{reporter} followed by word ``done'' in the
627echo area.
628
629You should always call this function and not hope for
630@code{progress-reporter-update} to print ``100%.'' Firstly, it may
631never print it, there are many good reasons for this not to happen.
632Secondly, ``done'' is more explicit.
633@end defun
634
536@node Invisible Text 635@node Invisible Text
537@section Invisible Text 636@section Invisible Text
538 637