help-gnu-emacs
[Top][All Lists]
Advanced

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

elisp: `quit-process' and `sleep-for'


From: Memnon Anon
Subject: elisp: `quit-process' and `sleep-for'
Date: Tue, 24 Aug 2010 19:24:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hi,

I am having trouble with this function: 

--8<---------------cut here---------------start------------->8---
(defun set_timer (rtcopt value)
; [...]

(start-process "alarmclock-mp3" nil "/usr/bin/mplayer" "-quiet" music)

(while (y-or-n-p "Snooze?")
      (when (get-process "alarmclock-mp3")
        (quit-process "alarmclock-mp3")
;        (debug)
        (sleep-for 100000)
        (sleep-for 5))
      (start-process "alarmclock-mp3" nil "/usr/bin/mplayer" "-quiet" music))
(kill-emacs))
--8<---------------cut here---------------end--------------->8---

Concise:

When I call this function, the first sleep-for seems to fail.
Only the second one works.
Can someone give me a hint why that is so?

Long:

I found this sesquicolon thingy and wanted to practice some elisp.  I
turned my laptop into an alarmclock, with suspend-to-ram, 'wake up x
minutes from now' or 'wake up at xx:yy' to wake me up. And it seems to
work (afaics, but it certainly needs some testing...)

As a last step, I wanted to add a snooze functionality:
a) Play the mp3. 
If I type "y': 
  b) stop music 
  c) wait x minutes 
  d) restart at a). 
However, I found that a single sleep-for was practically ignored.  I
tried to debug[fn:1] it, but while stepping through with 'd', the
sleep-for suddenly works?! When I call the function without the
debugger, it seems like only the second sleep-for kicks in (and waits as
long as specified); when there is only one, it consequently has no
effect at all.

So, it works. ... With two sleep-for's where one should be enough.
I am a bit puzzled, any hints very welcome.

Memnon
P.S.: I searched for some [sesquicolon | #!/usr/bin/emacs --script] files
      out there, but I found next to nothing :(. It's a pitty, would    
      have been very interesting to see some
      elisp-as-a-general-purpose-scripting-language files to learn from.

Footnotes:

[fn:1] With (debug) and C-M-x.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]