sleep in emacs lisp

Viewed 5501

script A

    (insert (current-time-string))
    (sleep-for 5)
    (insert (current-time-string))

M-x eval-buffer, two time strings are inserted with 5 secs apart

script B

some comint code (that add hook, and start process)

    (sleep-for 60) ;delay a bit for process to finish
    (insert "ZZZ")

M-x eval-buffer, "ZZZ" is inserted right away, without any time delay

what might have happened? btw, it's Emacs 23.2 on Win XP

3 Answers

From the official documentation it might be implemented not only by 'sleep-for but by the 'sit-for also:

(defun smart-translate ()
  "Shows translation of a word at the current point
at the full frame for several seconds and 
returns to the initial buffer"
  (interactive)
  (google-translate-at-point)
  (switch-to-buffer "*Google Translate*")
  (delete-other-windows)
  (sit-for 5)
  (previous-buffer)
  )
Related