* elisp: `quit-process' and `sleep-for'
@ 2010-08-24 17:24 Memnon Anon
0 siblings, 0 replies; 2+ messages in thread
From: Memnon Anon @ 2010-08-24 17:24 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: elisp: `quit-process' and `sleep-for'
[not found] <mailman.2.1282670669.15527.help-gnu-emacs@gnu.org>
@ 2010-08-24 18:02 ` Jeff Clough
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Clough @ 2010-08-24 18:02 UTC (permalink / raw)
To: help-gnu-emacs
Memnon Anon <gegendosenfleisch@googlemail.com> writes:
> Hi,
>
> I am having trouble with this function:
>
> (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))
As a point of comparison, does this work as intended if you use
delete-process instead of quit-process?
Jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-08-24 18:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.2.1282670669.15527.help-gnu-emacs@gnu.org>
2010-08-24 18:02 ` elisp: `quit-process' and `sleep-for' Jeff Clough
2010-08-24 17:24 Memnon Anon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).