unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Memnon Anon <gegendosenfleisch@googlemail.com>
To: help-gnu-emacs@gnu.org
Subject: elisp: `quit-process' and `sleep-for'
Date: Tue, 24 Aug 2010 19:24:19 +0200	[thread overview]
Message-ID: <87hbikuf4m.fsf@mean.albasani.net> (raw)

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	other threads:[~2010-08-24 17:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-24 17:24 Memnon Anon [this message]
     [not found] <mailman.2.1282670669.15527.help-gnu-emacs@gnu.org>
2010-08-24 18:02 ` elisp: `quit-process' and `sleep-for' Jeff Clough

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hbikuf4m.fsf@mean.albasani.net \
    --to=gegendosenfleisch@googlemail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).