views:

147

answers:

2

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.

+10  A: 

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.

Trey Jackson
+4  A: 

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.

Yu Shen
We were channeling the same vibe, down to the word "periodically".
Trey Jackson