all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Run an external program on the file visited in current buffer and open a new buffer with results
@ 2006-04-18 14:12 Suttles, Andrew
  2006-04-18 14:21 ` Kevin Rodgers
  0 siblings, 1 reply; 7+ messages in thread
From: Suttles, Andrew @ 2006-04-18 14:12 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 2559 bytes --]

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))))))))


[-- Attachment #1.2: Type: text/html, Size: 8584 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Run an external program on the file visited in current buffer and   open a new buffer with results
  2006-04-18 14:12 Run an external program on the file visited in current buffer and open a new buffer with results Suttles, Andrew
@ 2006-04-18 14:21 ` Kevin Rodgers
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2006-04-18 14:21 UTC (permalink / raw)


Suttles, Andrew wrote:
 > 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.

You could visit the output file and turn on auto revert mode so that the
buffer would be updated (at an interval of your choosing -- see
auto-revert-interval).

-- 
Kevin Rodgers

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

* Re: Run an external program on the file visited in current buffer and open a new buffer with results
       [not found] <mailman.535.1145369538.9609.help-gnu-emacs@gnu.org>
@ 2006-04-18 18:13 ` Alan Mackenzie
  2006-04-19 16:01   ` Mathias Dahl
  2006-04-21 13:17   ` Hadron Quark
  2006-04-18 18:22 ` Peter Tury
  1 sibling, 2 replies; 7+ messages in thread
From: Alan Mackenzie @ 2006-04-18 18:13 UTC (permalink / raw)


Suttles, Andrew <andrew.suttles@analexcleveland.com> wrote on Tue, 18 Apr
2006 10:12:13 -0400:
> This is a multi-part message in MIME format.

Would you PLEASE, PLEASE turn this imbecilic MIME stuff off!  Your
posting is 346 lines long, but its content is a mere 51 lines.  It has a
signal to noise ratio of around 5% (if you're lucky).  Do you realise
what an idiot this makes you look?

Your posting is chock full of spam.  The following content-free fragment
appears around 30 times:

> <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
> style=3D'font-size:10.0pt;
> font-family:Arial'>(defun acs-run-program-current-buffer =
> ....<o:p></o:p></span></font></p>

Do you really think this interests anybody, even if it only appeared
once?  How about taking responsibility for the tools you use and setting
them up properly?  (Hint: Microsoft programs are suboptimal for composing
articles for mailing lists.)

Your, in exasperation,

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

* Re: Run an external program on the file visited in current buffer and open a new buffer with results
       [not found] <mailman.535.1145369538.9609.help-gnu-emacs@gnu.org>
  2006-04-18 18:13 ` Alan Mackenzie
@ 2006-04-18 18:22 ` Peter Tury
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Tury @ 2006-04-18 18:22 UTC (permalink / raw)


On Tue, 18 Apr 2006 10:12:13 -0400, Suttles, Andrew wrote:

> 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.

Have you considered using compilation-mode? C-h f compile -> "Compile the
program including the current buffer.  Default: run `make'.
Runs command, a shell command, in a separate process asynchronously
with output going to the buffer `*compilation*'".

I think M-x grep would work in the same way. Both of these can run any
programs, I guess, and gets their output into *compilation*/*grep* buffer. 

So you can use them freely for anything. I use to run a batch file (.cmd on
MS Windows) using M-x compile (or M-x recompile!). See the Emacs manual for
more details: C-h F compile (on cvs Emacs).

Examining compilation-error-regexp-alist's usage can be useful also. 

However I don' know if these can be used well in case your program doesn't
write to stdout... maybe you should run a batch file what sends the result
of your "main" program to the stdout...?

Also consult the emacs lisp manual at "Creating an Asynchronous Process"
(e.g. Functions start-process or start-process-shell-command).

Br,
P

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

* Re: Run an external program on the file visited in current buffer and open a new buffer with results
  2006-04-18 18:13 ` Alan Mackenzie
@ 2006-04-19 16:01   ` Mathias Dahl
  2006-04-21  7:48     ` Annamalai Gurusami
  2006-04-21 13:17   ` Hadron Quark
  1 sibling, 1 reply; 7+ messages in thread
From: Mathias Dahl @ 2006-04-19 16:01 UTC (permalink / raw)


Alan Mackenzie <acm@muc.de> writes:

> Would you PLEASE, PLEASE turn this imbecilic MIME stuff off!  Your
> posting is 346 lines long, but its content is a mere 51 lines.  It has a
> signal to noise ratio of around 5% (if you're lucky).  Do you realise
> what an idiot this makes you look?
>
> Your posting is chock full of spam.  The following content-free fragment
> appears around 30 times:

> ...
>
> Do you really think this interests anybody, even if it only appeared
> once?  How about taking responsibility for the tools you use and setting
> them up properly?  (Hint: Microsoft programs are suboptimal for composing
> articles for mailing lists.)

Sheesh ke-bab! Give this guy a break!

(Disclaimer: I use Gnus so I did not even see the "crap" you refer
to.)

I saw this as a very well written post from soneone who had clearly
tried to solve his problem himself before posting, that seems to have
taken the time to understand some concepts of Emacs etc. And he gets
*this* as a response, and to the whole group/list?!

Do we want to attract more users to this wonderful program or do we
want to alienate them?

Sheesh. Kebab...

/Mathias - trying to tame the Emacs beast since 1997, sometimes doing
           things right, sometimes not...

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

* Re: Run an external program on the file visited in current buffer and open a new buffer with results
  2006-04-19 16:01   ` Mathias Dahl
@ 2006-04-21  7:48     ` Annamalai Gurusami
  0 siblings, 0 replies; 7+ messages in thread
From: Annamalai Gurusami @ 2006-04-21  7:48 UTC (permalink / raw)
  Cc: help-gnu-emacs

Mathias Dahl <brakjoller@gmail.com> writes:

> Alan Mackenzie <acm@muc.de> writes:
>
>> Would you PLEASE, PLEASE turn this imbecilic MIME stuff off!  Your
>> posting is 346 lines long, but its content is a mere 51 lines.  It
>> has a signal to noise ratio of around 5% (if you're lucky).  Do you
>> realise what an idiot this makes you look?

...

> (Disclaimer: I use Gnus so I did not even see the "crap" you refer
> to.)

I too use Gnus for my mail, but I do see all the HTML tags as it is,
if the HTML is not well-formed.  Do you have any non-default
configuration setting for this?

Rgds,
anna

-- 

http://missingrainbow.wordpress.com

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

* Re: Run an external program on the file visited in current buffer and open a new buffer with results
  2006-04-18 18:13 ` Alan Mackenzie
  2006-04-19 16:01   ` Mathias Dahl
@ 2006-04-21 13:17   ` Hadron Quark
  1 sibling, 0 replies; 7+ messages in thread
From: Hadron Quark @ 2006-04-21 13:17 UTC (permalink / raw)


 "Alan"posted on 2006-04-18:

> Suttles, Andrew <andrew.suttles@analexcleveland.com> wrote on Tue, 18 Apr
> 2006 10:12:13 -0400:
>> This is a multi-part message in MIME format.
>
> Would you PLEASE, PLEASE turn this imbecilic MIME stuff off!  Your
> posting is 346 lines long, but its content is a mere 51 lines.  It has a
> signal to noise ratio of around 5% (if you're lucky).  Do you realise
> what an idiot this makes you look?
>
> Your posting is chock full of spam.  The following content-free fragment
> appears around 30 times:
>
>> <p class=3DMsoNormal><font size=3D2 face=3DArial><span =
>> style=3D'font-size:10.0pt;
>> font-family:Arial'>(defun acs-run-program-current-buffer =
>> ....<o:p></o:p></span></font></p>
>
> Do you really think this interests anybody, even if it only appeared
> once?  How about taking responsibility for the tools you use and setting
> them up properly?  (Hint: Microsoft programs are suboptimal for composing
> articles for mailing lists.)

Microsoft programs are as effective as any others when (a) chosen
correctly and (b) configured correctly.

Other than that I agree : I'm sick to death of people posting with PGP
headers/MIME headers. I mean : who the hell thinks their opinions are
valuable enough to mark them with PGP keys on a public anonymous
newsgoup?

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

end of thread, other threads:[~2006-04-21 13:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-18 14:12 Run an external program on the file visited in current buffer and open a new buffer with results Suttles, Andrew
2006-04-18 14:21 ` Kevin Rodgers
     [not found] <mailman.535.1145369538.9609.help-gnu-emacs@gnu.org>
2006-04-18 18:13 ` Alan Mackenzie
2006-04-19 16:01   ` Mathias Dahl
2006-04-21  7:48     ` Annamalai Gurusami
2006-04-21 13:17   ` Hadron Quark
2006-04-18 18:22 ` Peter Tury

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.