all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Wait for compile to finish
@ 2005-10-20 13:07 Toto
  2005-10-20 16:31 ` Kevin Rodgers
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Toto @ 2005-10-20 13:07 UTC (permalink / raw)


Greetings!

My problem is the following:

I would like to have a function, which runs the program, that belongs to
the buffer i'm editing or compile it first if it isn't done already.
To make it more clear. Say, i'm editing helloworld.c and i call this
function, it should execute helloworld.exe (yes, i'm on windows). If
there is no hello.exe in the current directory (or it is older than the
source file) emacs should compile it first and run it afterwards.

For this purpose I have come up with a funcion similar to the one below.

But: Compile is asynchronous, so this funcion tries to execute the exe
file before the compilation finishes (and the exe is created).

My question is:
Is there a synchronous version of compile? Or how can i determine that
compile has finished (and get the result of the compilation - success
or failure)?

The (pseudo) code is as follows:

(defun run-compiled-program (params)
  "Runs the program with the same name as the buffer."
  (interactive "sRun with parameter(s): ")
  (setq exe (concat
			 (file-name-sans-extension (buffer-file-name))
			 ".exe"
			 )
		)
     (if (not (file-newer-than-file-p exe (buffer-file-name)))
 	 (compile-this-buffer) ;; using the compile funcion
 	  )
  (shell-command
   (concat exe " " params)
   )
  )
;; GNU Emacs 22.0.50.1 (i386-mingw-nt5.1.2600) of 2005-03-08 on S8472


Any suggestions are welcome.

Ps.: my english might not be the best ;)
-- 
				[ Toto ]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Wait for compile to finish
  2005-10-20 13:07 Wait for compile to finish Toto
@ 2005-10-20 16:31 ` Kevin Rodgers
  2005-10-20 19:40   ` Eli Zaretskii
  2005-10-21 15:43 ` William Xu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Kevin Rodgers @ 2005-10-20 16:31 UTC (permalink / raw)


Toto wrote:
 > I would like to have a function, which runs the program, that belongs to
 > the buffer i'm editing or compile it first if it isn't done already.
 > To make it more clear. Say, i'm editing helloworld.c and i call this
 > function, it should execute helloworld.exe (yes, i'm on windows). If
 > there is no hello.exe in the current directory (or it is older than the
 > source file) emacs should compile it first and run it afterwards.
 >
 > For this purpose I have come up with a funcion similar to the one below.
 >
 > But: Compile is asynchronous, so this funcion tries to execute the exe
 > file before the compilation finishes (and the exe is created).
 >
 > My question is:
 > Is there a synchronous version of compile? Or how can i determine that
 > compile has finished (and get the result of the compilation - success
 > or failure)?
 >
 > The (pseudo) code is as follows:
 >
 > (defun run-compiled-program (params)
 >   "Runs the program with the same name as the buffer."
 >   (interactive "sRun with parameter(s): ")
 >   (setq exe (concat
 > 			 (file-name-sans-extension (buffer-file-name))
 > 			 ".exe"
 > 			 )
 > 		)
 >      (if (not (file-newer-than-file-p exe (buffer-file-name)))
 >  	 (compile-this-buffer) ;; using the compile funcion
 >  	  )
 >   (shell-command
 >    (concat exe " " params)
 >    )
 >   )
 > ;; GNU Emacs 22.0.50.1 (i386-mingw-nt5.1.2600) of 2005-03-08 on S8472

Use the make utility to compile your program before you run it:

(defun run-buffer-program (&optional args)
   "Compile the visited file into a program and run it with command line 
ARGS."
   (interactive "sArgs: ")
   (let ((program (file-name-sans-extension
                   (file-name-nondirectory buffer-file-name))))
     ;; What is the list of systems that require the .exe extension?
     (when (memq system-type '(dos))
       (setq program (concat program ".exe")))
     (shell-command (format "make %s && ./%s %s" program program args))))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Wait for compile to finish
  2005-10-20 16:31 ` Kevin Rodgers
@ 2005-10-20 19:40   ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2005-10-20 19:40 UTC (permalink / raw)


> From: Kevin Rodgers <ihs_4664@yahoo.com>
> Date: Thu, 20 Oct 2005 10:31:42 -0600
> 
>      ;; What is the list of systems that require the .exe extension?
>      (when (memq system-type '(dos))
>        (setq program (concat program ".exe")))
>      (shell-command (format "make %s && ./%s %s" program program args))))

This part is bogus, on several accounts.  First, there's no
system-type `dos' in Emacs, only `ms-dos'.  Second, Windows
executables also have the .exe extension.  And third, there's no need
to append the extension, since Make will DTRT on these systems even
without the .exe.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Wait for compile to finish
  2005-10-20 13:07 Wait for compile to finish Toto
  2005-10-20 16:31 ` Kevin Rodgers
@ 2005-10-21 15:43 ` William Xu
  2005-10-21 21:18 ` Kevin Ryde
  2005-10-22 16:07 ` Vagn Johansen
  3 siblings, 0 replies; 7+ messages in thread
From: William Xu @ 2005-10-21 15:43 UTC (permalink / raw)


bago@ludens.elte.hu (Toto) writes:

> Greetings!
>
> My problem is the following:
>
> I would like to have a function, which runs the program, that belongs to
> the buffer i'm editing or compile it first if it isn't done already.
> To make it more clear. Say, i'm editing helloworld.c and i call this
> function, it should execute helloworld.exe (yes, i'm on windows). If
> there is no hello.exe in the current directory (or it is older than the
> source file) emacs should compile it first and run it afterwards.
>
> For this purpose I have come up with a funcion similar to the one
> below.

For this purpose, you might be interested in this:

http://www.emacswiki.org/cgi-bin/emacs/smart-compile+.el


-- 
William

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Wait for compile to finish
  2005-10-20 13:07 Wait for compile to finish Toto
  2005-10-20 16:31 ` Kevin Rodgers
  2005-10-21 15:43 ` William Xu
@ 2005-10-21 21:18 ` Kevin Ryde
  2005-10-22 16:07 ` Vagn Johansen
  3 siblings, 0 replies; 7+ messages in thread
From: Kevin Ryde @ 2005-10-21 21:18 UTC (permalink / raw)


bago@ludens.elte.hu (Toto) writes:
>
> My question is:
> Is there a synchronous version of compile? Or how can i determine that
> compile has finished (and get the result of the compilation - success
> or failure)?

Personally I use a shell script "mr" and run that instead of "make"
from M-x compile, it does a compile and runs if successful.  You get
compile errors and program output both in the compilation buffer.

If you really want to know in elisp when M-x compile finishes, have a
look at makeinfo-compile in makeinfo.el which does that sort of thing,
but it's not too pretty.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Wait for compile to finish
  2005-10-20 13:07 Wait for compile to finish Toto
                   ` (2 preceding siblings ...)
  2005-10-21 21:18 ` Kevin Ryde
@ 2005-10-22 16:07 ` Vagn Johansen
  2005-10-24 10:22   ` Toto
  3 siblings, 1 reply; 7+ messages in thread
From: Vagn Johansen @ 2005-10-22 16:07 UTC (permalink / raw)


bago@ludens.elte.hu (Toto) writes:

> My question is:
> Is there a synchronous version of compile? Or how can i determine that
> compile has finished (and get the result of the compilation - success
> or failure)?

You can set the variable compilation-finish-function to a function.

"Documentation:
Functions to call when a compilation process finishes.
Each function is called with two arguments: the compilation buffer,
and a string describing how the process finished.

Defined in `compile'."

-- 
Vagn

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Wait for compile to finish
  2005-10-22 16:07 ` Vagn Johansen
@ 2005-10-24 10:22   ` Toto
  0 siblings, 0 replies; 7+ messages in thread
From: Toto @ 2005-10-24 10:22 UTC (permalink / raw)


In article <u4q79h6xb.fsf@hotmail.com>, Vagn Johansen <gonz808@hotmail.com> writes:
> bago@ludens.elte.hu (Toto) writes:
> 
>> My question is:
>> Is there a synchronous version of compile? Or how can i determine that
>> compile has finished (and get the result of the compilation - success
>> or failure)?
> 
> You can set the variable compilation-finish-function to a function.
> 
> "Documentation:
> Functions to call when a compilation process finishes.
> Each function is called with two arguments: the compilation buffer,
> and a string describing how the process finished.
> 
> Defined in `compile'."

That's close enough.
Thanks.

 
> -- 
> Vagn
-- 
				[ Toto ]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-10-24 10:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-20 13:07 Wait for compile to finish Toto
2005-10-20 16:31 ` Kevin Rodgers
2005-10-20 19:40   ` Eli Zaretskii
2005-10-21 15:43 ` William Xu
2005-10-21 21:18 ` Kevin Ryde
2005-10-22 16:07 ` Vagn Johansen
2005-10-24 10:22   ` Toto

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.