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

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

Run an external program on the file visited in current buffer and open a


From: Suttles, Andrew
Subject: Run an external program on the file visited in current buffer and open a new buffer with results
Date: Tue, 18 Apr 2006 10:12:13 -0400

I use emacs to edit large data files which I submit to a computer program for analysis.  My normal method of operation is to 1) edit the file in emacs, 2) close or minimize emacs, 3) run the program on the file in a shell window, 4) watch for program completion, then 5) view the output file in a new buffer.  I’m getting proficient enough to do these types of things without leaving emacs (multiple buffers with shells open), but I know there must be a better way.

 

I’d like to edit a data file in a buffer and then execute an elisp command which will run “program” on the file being edited and then pop up a new frame with the resultant output file after the analysis.  I’ve tried using shell command, but emacs blocks while the program is running (from 5 mins to 10+ hours).  If I use shell command asynchronously, it works fine, but I have to constantly watch for program termination before opening the output file in a new buffer.

 

I’ve tried the lisp code below which doesn’t quite work…

 

The goal here is to save the current buffer, open a shell process, run “program” on the file visited in the buffer, exit the shell after the program finishes, detect that the process is dead, and then visit the output file in a new frame.  The problem is that when “program” is run synchronously, the program must finish before the sentinel gets set.  For some reason, setting the sentinel and then issuing the command doesn’t seem to work.  

 

I’m sure I’m not doing this the most efficient way.  Any help would be appreciated.

 

<lisp code retyped from different computer – assume all tabs and parenthesis are correct in the original>

 

(defun acs-run-program-current-buffer ()

  (interactive)

  (prong

    (save-buffer)

    (save-excursion

      (let ((infile (buffer-file-name (current-buffer)))

            (outfile (concat (file-name-sans-extension (buffer-file-name (current-buffer))) “.f06”))

            (shellname (concat “PROGRAM->” (buffer-file-name (current-buffer)))))

        (switch-to-buffer (shell shellname))

        (comint-simple-send

          (get-buffer-proccess (current-buffer)

            (concat “program –switch “ infile “; exit”))

        (set-process-sentinel

          (get-buffer-process (current-buffer)

                                      (lambda (process event)

                                        (kill-buffer (current-buffer))

                                        (find-file-other-frame outfile))))))))


reply via email to

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