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

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

Re: Wait for compile to finish


From: Kevin Rodgers
Subject: Re: Wait for compile to finish
Date: Thu, 20 Oct 2005 10:31:42 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

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





reply via email to

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