In the following function in emacs Lisp,
(defun show-life ()
(interactive)
(switch-to-buffer "*Life-Window*") ; show how life goes on while living
(live)) ; it takes 70 years to finish and return!
I'd like to create the buffer "Life-Window", and have the life event generated by (live) displayed continuously while live goes on.
Unfortunately, the buffer only becomes visible after the (live) returns (when it's over!)
I also tried pop-to-buffer, the behavior is the same.
Add a call to 'sit-for
just before the call to 'live
, e.g.
(defun show-life ()
(interactive)
(switch-to-buffer "*Life-Window*") ; show how life goes on while living
(sit-for 0) ; perform redisplay
(live)) ; it takes 70 years to finish and return!
And, if you want to see the results of 'live
, it should periodically call 'sit-for
as well.
The doc string for 'sit-for
is:
sit-for is a compiled Lisp function in `subr.el'. (sit-for seconds &optional nodisp)
Perform redisplay, then wait for seconds seconds or until input is available. seconds may be a floating-point value. (On operating systems that do not support waiting for fractions of a second, floating-point values are rounded down to the nearest integer.)
If optional arg nodisp is t, don't redisplay, just wait for input. Redisplay does not happen if input is available before it starts.
Value is t if waited the full time with no input arriving, and nil otherwise.
I found out the solution. I have to use (sit-for <time-to-wait>)
to get the buffer to show the update of life events.
So the code segment should be modified as follows:
(defun show-life () (interactive) (switch-to-buffer "*Life-Window*") ; show how life goes on while living (sit-for 0) (live)) ; it takes 70 years to finish and return!
Maybe inside of the live
body, sit-for
should be called periodically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With