[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sleep-for does not work as expected - or perhaps my expection is inc
From: |
PJ Weisberg |
Subject: |
Re: sleep-for does not work as expected - or perhaps my expection is incorrect |
Date: |
Tue, 12 Jul 2011 10:39:09 -0700 |
On Tue, Jul 12, 2011 at 7:42 AM, C K Kashyap <ckkashyap@gmail.com> wrote:
> Hi,
> (defun somefun ()
> (insert "Hello ")
> (sleep-for 1)
> (insert "world\n"))
>
> When I invoke "somefun" by doign - M-: (somefun) <return>
>
> I see that "Hello world" gets printed after 1 second instead of printing
> Hello and then printing world after one second.
>
> What can I do to get the script to write out "hello" first and then wait for
> a second and then write out world?
>
> Regards,
> Kashyap
(defun somefun ()
(insert "Hello ")
(redisplay t)
(sleep-for 1)
(insert "world\n"))
Your function *is* waiting one second before it writes out world--but
Emacs is waiting for your function to finish before it tries to show
any of the changes it's made to the buffer. :-)
-PJ