* Re: wait for compilation process to be finished
[not found] <c025d817-68b7-4232-916c-430744a15fd7@p25g2000hsf.googlegroups.com>
@ 2008-08-06 9:02 ` Nikolaj Schumacher
[not found] ` <mailman.15932.1218013390.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 2+ messages in thread
From: Nikolaj Schumacher @ 2008-08-06 9:02 UTC (permalink / raw
To: dejfson; +Cc: help-gnu-emacs, gnu-emacs-sources
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: wait for compilation process to be finished
[not found] ` <mailman.15932.1218013390.18990.help-gnu-emacs@gnu.org>
@ 2008-08-06 11:22 ` Rupert Swarbrick
0 siblings, 0 replies; 2+ messages in thread
From: Rupert Swarbrick @ 2008-08-06 11:22 UTC (permalink / raw
To: help-gnu-emacs
Please don't?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-08-06 11:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <c025d817-68b7-4232-916c-430744a15fd7@p25g2000hsf.googlegroups.com>
2008-08-06 9:02 ` wait for compilation process to be finished Nikolaj Schumacher
[not found] ` <mailman.15932.1218013390.18990.help-gnu-emacs@gnu.org>
2008-08-06 11:22 ` Rupert Swarbrick
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.