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

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

Re: wait for compilation process to be finished


From: Nikolaj Schumacher
Subject: Re: wait for compilation process to be finished
Date: Wed, 06 Aug 2008 11:02:57 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2.50 (darwin)

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




reply via email to

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