From: Nikolaj Schumacher <n_schumacher@web.de>
To: dejfson <dejfson@gmail.com>
Cc: help-gnu-emacs@gnu.org, gnu-emacs-sources@gnu.org
Subject: Re: wait for compilation process to be finished
Date: Wed, 06 Aug 2008 11:02:57 +0200 [thread overview]
Message-ID: <m2fxpiikhq.fsf@nschum.de> (raw)
In-Reply-To: <c025d817-68b7-4232-916c-430744a15fd7@p25g2000hsf.googlegroups.com> (dejfson@gmail.com's message of "Tue\, 5 Aug 2008 14\:52\:40 -0700 \(PDT\)")
dejfson <dejfson@gmail.com> wrote:
> Dear All,
> I have sent this emacs to comp.emacs, however this group seems to me
> more appropriate, so I give
> it a try:
Actually gnu-emacs-sources is for posting finished programs.
help-gnu-emacs is appropriate for help requests, so I'm full-quoting and
CCing those guys, so they can catch my mistakes.
> i'd like to call compile command from elisp. I need a function, which
> exits when the compilation is finished. As compilation is asynchronous
> process, it needs to be synchronized. I wrote then a hook which should
> do the job, and called my compiling function:
>
> this is a hook declaration:
> ----------------------------->
> (setq cw-compile-flag t)
> (add-hook 'compilation-finish-functions #'(lambda (buf str) (progn
> (message "FOOKME") (setq cw-compile-flag nil))))
>
> and this is a function call:
> ----------------------------->
> (defun cw-compile-tags ()
> "Function compiles cw tags file. The filename is TAGS.cw and it is
> stored in the project directory, which must
> exist."
> ;; save the current buffer so it does not pop up with a question:
> (save-buffer)
> (setq cw-compile-flag t)
> (compile (concat "find " cw-project-directory " | egrep 'h$|hpp$'
> | etags -D -l c++ --regex='/[ \t]*class[ \t]+[A-Za-z0-9_]*[ \t\n]*[:
> {]/' -o " cw-project-directory "TAGS.cw -"))
>
> ;; as compilation is asynchronous, we need to wait until the
> compilation is finished:
> (while cw-compile-flag (sleep-for 0 100))
> )
>
> and now you run it:
> --------------------------->
> (cw-compile-tags)
>
> .................... and it hangs on wait loop there. From unknown
> reasons the compilation process does not
> start, *compilation* buffer is not opened, thus cw-compile-flag is
> always true what makes the loop infinite.
>
> When I run it without the while loop, everything works fine.
> How can I assure that compilation is started, and finished? I'd like
> to return from my function at the moment when the stuff is compiled.
This does not work, because ELisp doesn't support multi-threading. Yes,
you can run a process asynchronously, but the lisp call-backs are
synchronized. That means `compilation-finish-functions' isn't entered
/while/ you're still executing something else, only when it's turn the
event loop (or something) is reached.
The solution is simple: Just run a process synchronously with something
like this:
(call-process "/bin/sh" nil nil nil (concat "find " ...))
regards,
Nikolaj Schumacher
next parent reply other threads:[~2008-08-06 9:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <c025d817-68b7-4232-916c-430744a15fd7@p25g2000hsf.googlegroups.com>
2008-08-06 9:02 ` Nikolaj Schumacher [this message]
[not found] ` <mailman.15932.1218013390.18990.help-gnu-emacs@gnu.org>
2008-08-06 11:22 ` wait for compilation process to be finished Rupert Swarbrick
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2fxpiikhq.fsf@nschum.de \
--to=n_schumacher@web.de \
--cc=dejfson@gmail.com \
--cc=gnu-emacs-sources@gnu.org \
--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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.