[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Time-based event-handler



   From: kumyew@eagle.mit.edu (Kum-Yew Lai)
   To: info-macl@cambridge.apple.COM
    
   does anyone know how i can create an event handler
   based on time (e.g., one that gets executed at noon).
   if there're other ways to achieve the same effect
   (e.g., spawn a background process?), i'd also be interested.
    
   thanks!

Look at the documentation for *EVENTHOOK*.  *EVENTHOOK* can be set to a
function or list of functions which get first crack at events. To execute
something at noon, you could do something like the following (warning,
untested code follows):

   From: kumyew@eagle.mit.edu (Kum-Yew Lai)
   To: info-macl@cambridge.apple.COM
    
   does anyone know how i can create an event handler
   based on time (e.g., one that gets executed at noon).
   if there're other ways to achieve the same effect
   (e.g., spawn a background process?), i'd also be interested.
    
   thanks!

Look at the documentation for *EVENTHOOK*. *EVENTHOOK* can be set to a
function or list of functions which get first crack at events. To execute
something at noon, you could do something like the following (warning,
untested code follows):

(defun run-function-at-time (function time)
  (let (hook)
    (setq hook #'(lambda ()
                   (when (>= (get-universal-time) time)
                     (setq *eventhook* (delete hook *eventhook*))
                     (funcall function))
                   nil))                ; we didn't handle the event
    (push hook *eventhook*)
    t))

(run-function-at-time
 #'(lambda ()
     (ed-beep) 
     (print "It's 12:00.  Do you know where your parentheses are?"))
 (encode-universal-time 0 0 12 26 3 91))