From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.sources,gmane.emacs.help Subject: Re: wait for compilation process to be finished Date: Wed, 06 Aug 2008 11:02:57 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1218013566 23904 80.91.229.12 (6 Aug 2008 09:06:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 6 Aug 2008 09:06:06 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, gnu-emacs-sources@gnu.org To: dejfson Original-X-From: gnu-emacs-sources-bounces+gnu-gnu-emacs-sources=m.gmane.org@gnu.org Wed Aug 06 11:06:55 2008 Return-path: Envelope-to: gnu-gnu-emacs-sources@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KQeym-0008Qg-2Y for gnu-gnu-emacs-sources@m.gmane.org; Wed, 06 Aug 2008 11:06:48 +0200 Original-Received: from localhost ([127.0.0.1]:39074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQexq-0007k1-JB for gnu-gnu-emacs-sources@m.gmane.org; Wed, 06 Aug 2008 05:05:50 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQevC-0006QE-G8 for gnu-emacs-sources@gnu.org; Wed, 06 Aug 2008 05:03:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQev7-0006Mn-EM for gnu-emacs-sources@gnu.org; Wed, 06 Aug 2008 05:03:05 -0400 Original-Received: from [199.232.76.173] (port=52156 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQev7-0006MT-7i; Wed, 06 Aug 2008 05:03:01 -0400 Original-Received: from fmmailgate03.web.de ([217.72.192.234]:53932) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KQev6-0005jQ-Bz; Wed, 06 Aug 2008 05:03:00 -0400 Original-Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate03.web.de (Postfix) with ESMTP id BA57AE607020; Wed, 6 Aug 2008 11:02:58 +0200 (CEST) Original-Received: from [77.135.126.175] (helo=thursday) by smtp06.web.de with asmtp (WEB.DE 4.109 #226) id 1KQev4-0003eA-00; Wed, 06 Aug 2008 11:02:58 +0200 In-Reply-To: (dejfson@gmail.com's message of "Tue\, 5 Aug 2008 14\:52\:40 -0700 \(PDT\)") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2.50 (darwin) X-Sender: n_schumacher@web.de X-Provags-ID: V01U2FsdGVkX18SaQOXk3p1rx0QVT+thSj/bbfs/xK5ZsXKGUJ7 o+leTxh3bb/cQvvyg60+Booes2O+kwh4xGBZI0A6jdi1aXkKti ScNQDEEFE0ZMuo5rvO7A== X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-BeenThere: gnu-emacs-sources@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: GNU Emacs source code postings and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: gnu-emacs-sources-bounces+gnu-gnu-emacs-sources=m.gmane.org@gnu.org Errors-To: gnu-emacs-sources-bounces+gnu-gnu-emacs-sources=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.sources:2988 gmane.emacs.help:56208 Archived-At: dejfson 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