emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] evaluating shell commands for side effect
@ 2010-08-19 16:51 Sullivan, Gregory (US SSA)
  2010-08-20 23:36 ` Sullivan, Gregory (US SSA)
  2010-08-25 17:24 ` Eric Schulte
  0 siblings, 2 replies; 6+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2010-08-19 16:51 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

I'm writing "how to" documents that include sequences of shell commands, such as: 

#+begin_src sh :session *shell*
 cd /home/sullivan/myproj/src
 ./configure --prefix /home/sullivan/myproj/install
 make
 make test
#+end_src

and simply want C-c C-c to send the lines, one at a time, to the inferior shell process. That is, I want readers to read along, and then execute the code as needed.

Currently, it never returns (until C-g).  It might be related to the issues discussed last November, 
	http://lists.gnu.org/archive/html/emacs-orgmode/2009-11/msg01166.html
I have the latest git version of org mode, and I think I've set comint-prompt-regexp correctly.

So: I don't want to filter the output, I don't want to collect the results - just send the commands and go.

Looking at ob-sh.el/org-babel-sh-evaluate, I can't figure out what the Right Thing to do is.  Appended is a cheap hack that checks for "ignore" as a results string (e.g. #+begin_src sh :session *shell* :results ignore) and sends the lines one at a time to the inferior shell buffer.  But I suspect there's a more straightforward way to do it.

Thoughts?
Thanks.

-- Greg

--
Greg Sullivan,   gregory.sullivan@baesystems.com
(781)262-4553 (desk),  (978)430-3461 (cell)

--

(defun org-babel-sh-evaluate (session body &optional result-params)
  "Pass BODY to the Shell process in BUFFER.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY."
  ((lambda (results)
     (if (or (member "scalar" result-params)
	     (member "ignore" result-params)
	     (member "output" result-params))
	 results
       (let ((tmp-file (make-temp-file "org-babel-sh")))
	 (with-temp-file tmp-file (insert results))
	 (org-babel-import-elisp-from-file tmp-file))))
   (if (not session)
       (org-babel-eval org-babel-sh-command (org-babel-trim body))
     (if (member "ignore" result-params)
	 (progn
	   (save-excursion
	     (set-buffer session)
	     (mapc
	      (lambda (line)
		(insert line) (comint-send-input nil t) (sleep-for 0.25))
	      (split-string (org-babel-trim body) "\n")))
	   '())

     (let ((tmp-file (make-temp-file "org-babel-sh")))
       (mapconcat
	#'org-babel-sh-strip-weird-long-prompt
	(mapcar
	 #'org-babel-trim
	 (butlast
	  (org-babel-comint-with-output
	      (session org-babel-sh-eoe-output t body)
	    (mapc
	     (lambda (line)
	       (insert line) (comint-send-input nil t) (sleep-for 0.25))
	     (append
	      (split-string (org-babel-trim body) "\n")
	      (list org-babel-sh-eoe-indicator))))
	  2)) "\n")))))
)

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

* RE: [babel] evaluating shell commands for side effect
  2010-08-19 16:51 [babel] evaluating shell commands for side effect Sullivan, Gregory (US SSA)
@ 2010-08-20 23:36 ` Sullivan, Gregory (US SSA)
  2010-08-20 23:59   ` Sullivan, Gregory (US SSA)
  2010-08-25 17:30   ` Eric Schulte
  2010-08-25 17:24 ` Eric Schulte
  1 sibling, 2 replies; 6+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2010-08-20 23:36 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA), emacs-orgmode@gnu.org

Another question related to using babel, shell commands, in a session:

When I try to export a .org file with "begin_src sh :session *shell* :exports code" blocks, I'm prompted whether I want to evaluate the code.  However, I thought ":exports code" would avoid evaluation on export (and that :session is only about evaluation).

Any help appreciated.
Thanks.

-- Greg

--
Greg Sullivan,   gregory.sullivan@baesystems.com
(781)262-4553 (desk),  (978)430-3461 (cell)


-----Original Message-----
From: emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org [mailto:emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org] On Behalf Of Sullivan, Gregory (US SSA)
Sent: Thursday, August 19, 2010 12:51 PM
To: emacs-orgmode@gnu.org
Subject: [Orgmode] [babel] evaluating shell commands for side effect

I'm writing "how to" documents that include sequences of shell commands, such as: 

#+begin_src sh :session *shell*
 cd /home/sullivan/myproj/src
 ./configure --prefix /home/sullivan/myproj/install
 make
 make test
#+end_src

and simply want C-c C-c to send the lines, one at a time, to the inferior shell process. That is, I want readers to read along, and then execute the code as needed.

Currently, it never returns (until C-g).  It might be related to the issues discussed last November, 
	http://lists.gnu.org/archive/html/emacs-orgmode/2009-11/msg01166.html
I have the latest git version of org mode, and I think I've set comint-prompt-regexp correctly.

So: I don't want to filter the output, I don't want to collect the results - just send the commands and go.

Looking at ob-sh.el/org-babel-sh-evaluate, I can't figure out what the Right Thing to do is.  Appended is a cheap hack that checks for "ignore" as a results string (e.g. #+begin_src sh :session *shell* :results ignore) and sends the lines one at a time to the inferior shell buffer.  But I suspect there's a more straightforward way to do it.

Thoughts?
Thanks.

-- Greg

--
Greg Sullivan,   gregory.sullivan@baesystems.com
(781)262-4553 (desk),  (978)430-3461 (cell)

--

(defun org-babel-sh-evaluate (session body &optional result-params)
  "Pass BODY to the Shell process in BUFFER.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY."
  ((lambda (results)
     (if (or (member "scalar" result-params)
	     (member "ignore" result-params)
	     (member "output" result-params))
	 results
       (let ((tmp-file (make-temp-file "org-babel-sh")))
	 (with-temp-file tmp-file (insert results))
	 (org-babel-import-elisp-from-file tmp-file))))
   (if (not session)
       (org-babel-eval org-babel-sh-command (org-babel-trim body))
     (if (member "ignore" result-params)
	 (progn
	   (save-excursion
	     (set-buffer session)
	     (mapc
	      (lambda (line)
		(insert line) (comint-send-input nil t) (sleep-for 0.25))
	      (split-string (org-babel-trim body) "\n")))
	   '())

     (let ((tmp-file (make-temp-file "org-babel-sh")))
       (mapconcat
	#'org-babel-sh-strip-weird-long-prompt
	(mapcar
	 #'org-babel-trim
	 (butlast
	  (org-babel-comint-with-output
	      (session org-babel-sh-eoe-output t body)
	    (mapc
	     (lambda (line)
	       (insert line) (comint-send-input nil t) (sleep-for 0.25))
	     (append
	      (split-string (org-babel-trim body) "\n")
	      (list org-babel-sh-eoe-indicator))))
	  2)) "\n")))))
)

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* RE: [babel] evaluating shell commands for side effect
  2010-08-20 23:36 ` Sullivan, Gregory (US SSA)
@ 2010-08-20 23:59   ` Sullivan, Gregory (US SSA)
  2010-08-25 17:30   ` Eric Schulte
  1 sibling, 0 replies; 6+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2010-08-20 23:59 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA), emacs-orgmode@gnu.org

I meant "whenever I want to _export_ the code" (C-c C-e h).

-- Greg

--
Greg Sullivan,   gregory.sullivan@baesystems.com
(781)262-4553 (desk),  (978)430-3461 (cell)


-----Original Message-----
From: Sullivan, Gregory (US SSA) 
Sent: Friday, August 20, 2010 7:37 PM
To: Sullivan, Gregory (US SSA); emacs-orgmode@gnu.org
Subject: RE: [babel] evaluating shell commands for side effect

Another question related to using babel, shell commands, in a session:

When I try to export a .org file with "begin_src sh :session *shell* :exports code" blocks, I'm prompted whether I want to evaluate the code.  However, I thought ":exports code" would avoid evaluation on export (and that :session is only about evaluation).

Any help appreciated.
Thanks.

-- Greg

--
Greg Sullivan,   gregory.sullivan@baesystems.com
(781)262-4553 (desk),  (978)430-3461 (cell)


-----Original Message-----
From: emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org [mailto:emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org] On Behalf Of Sullivan, Gregory (US SSA)
Sent: Thursday, August 19, 2010 12:51 PM
To: emacs-orgmode@gnu.org
Subject: [Orgmode] [babel] evaluating shell commands for side effect

I'm writing "how to" documents that include sequences of shell commands, such as: 

#+begin_src sh :session *shell*
 cd /home/sullivan/myproj/src
 ./configure --prefix /home/sullivan/myproj/install
 make
 make test
#+end_src

and simply want C-c C-c to send the lines, one at a time, to the inferior shell process. That is, I want readers to read along, and then execute the code as needed.

Currently, it never returns (until C-g).  It might be related to the issues discussed last November, 
	http://lists.gnu.org/archive/html/emacs-orgmode/2009-11/msg01166.html
I have the latest git version of org mode, and I think I've set comint-prompt-regexp correctly.

So: I don't want to filter the output, I don't want to collect the results - just send the commands and go.

Looking at ob-sh.el/org-babel-sh-evaluate, I can't figure out what the Right Thing to do is.  Appended is a cheap hack that checks for "ignore" as a results string (e.g. #+begin_src sh :session *shell* :results ignore) and sends the lines one at a time to the inferior shell buffer.  But I suspect there's a more straightforward way to do it.

Thoughts?
Thanks.

-- Greg

--
Greg Sullivan,   gregory.sullivan@baesystems.com
(781)262-4553 (desk),  (978)430-3461 (cell)

--

(defun org-babel-sh-evaluate (session body &optional result-params)
  "Pass BODY to the Shell process in BUFFER.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY."
  ((lambda (results)
     (if (or (member "scalar" result-params)
	     (member "ignore" result-params)
	     (member "output" result-params))
	 results
       (let ((tmp-file (make-temp-file "org-babel-sh")))
	 (with-temp-file tmp-file (insert results))
	 (org-babel-import-elisp-from-file tmp-file))))
   (if (not session)
       (org-babel-eval org-babel-sh-command (org-babel-trim body))
     (if (member "ignore" result-params)
	 (progn
	   (save-excursion
	     (set-buffer session)
	     (mapc
	      (lambda (line)
		(insert line) (comint-send-input nil t) (sleep-for 0.25))
	      (split-string (org-babel-trim body) "\n")))
	   '())

     (let ((tmp-file (make-temp-file "org-babel-sh")))
       (mapconcat
	#'org-babel-sh-strip-weird-long-prompt
	(mapcar
	 #'org-babel-trim
	 (butlast
	  (org-babel-comint-with-output
	      (session org-babel-sh-eoe-output t body)
	    (mapc
	     (lambda (line)
	       (insert line) (comint-send-input nil t) (sleep-for 0.25))
	     (append
	      (split-string (org-babel-trim body) "\n")
	      (list org-babel-sh-eoe-indicator))))
	  2)) "\n")))))
)

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [babel] evaluating shell commands for side effect
  2010-08-19 16:51 [babel] evaluating shell commands for side effect Sullivan, Gregory (US SSA)
  2010-08-20 23:36 ` Sullivan, Gregory (US SSA)
@ 2010-08-25 17:24 ` Eric Schulte
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Schulte @ 2010-08-25 17:24 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA); +Cc: emacs-orgmode@gnu.org

Hi Gregory,

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> I'm writing "how to" documents that include sequences of shell commands, such as: 
>
> #+begin_src sh :session *shell*
>  cd /home/sullivan/myproj/src
>  ./configure --prefix /home/sullivan/myproj/install
>  make
>  make test
> #+end_src
>
> and simply want C-c C-c to send the lines, one at a time, to the
> inferior shell process. That is, I want readers to read along, and
> then execute the code as needed.
>

I'm not sure why this is hanging when a session is used.  Could you
remove the session argument?  If so then it should execute fine, the
following works for me (but the same block fails to complete with a
session argument)

--8<---------------cut here---------------start------------->8---
#+begin_src sh :results silent
  cd ~/src/org/
  make
#+end_src
--8<---------------cut here---------------end--------------->8---

>
> Currently, it never returns (until C-g).  It might be related to the
>issues discussed last November,
> 	http://lists.gnu.org/archive/html/emacs-orgmode/2009-11/msg01166.html
> I have the latest git version of org mode, and I think I've set comint-prompt-regexp correctly.
>

I believe you're right, I've added this as a bug, and I hope to look
into it soon.

>
> So: I don't want to filter the output, I don't want to collect the
>results - just send the commands and go.
>

Using the ":results silent" argument as shown in the above code block.
See http://orgmode.org/manual/results.html#results

>
> Looking at ob-sh.el/org-babel-sh-evaluate, I can't figure out what the
>Right Thing to do is.  Appended is a cheap hack that checks for
>"ignore" as a results string (e.g. #+begin_src sh :session *shell*
>:results ignore) and sends the lines one at a time to the inferior
>shell buffer.  But I suspect there's a more straightforward way to do
>it.
>

We can't simply send the results and go, as there is still the more
common case where the results of the shell evaluation are required.  I
think the issue here is that for some reason the shell session is not
inserting results into the session buffer, and that's where the fix
should lie.

Thanks -- Eric

>
> Thoughts?
> Thanks.
>
> -- Greg
>
> --
> Greg Sullivan,   gregory.sullivan@baesystems.com
> (781)262-4553 (desk),  (978)430-3461 (cell)
>
> --
>
> (defun org-babel-sh-evaluate (session body &optional result-params)
>   "Pass BODY to the Shell process in BUFFER.
> If RESULT-TYPE equals 'output then return a list of the outputs
> of the statements in BODY, if RESULT-TYPE equals 'value then
> return the value of the last statement in BODY."
>   ((lambda (results)
>      (if (or (member "scalar" result-params)
> 	     (member "ignore" result-params)
> 	     (member "output" result-params))
> 	 results
>        (let ((tmp-file (make-temp-file "org-babel-sh")))
> 	 (with-temp-file tmp-file (insert results))
> 	 (org-babel-import-elisp-from-file tmp-file))))
>    (if (not session)
>        (org-babel-eval org-babel-sh-command (org-babel-trim body))
>      (if (member "ignore" result-params)
> 	 (progn
> 	   (save-excursion
> 	     (set-buffer session)
> 	     (mapc
> 	      (lambda (line)
> 		(insert line) (comint-send-input nil t) (sleep-for 0.25))
> 	      (split-string (org-babel-trim body) "\n")))
> 	   '())
>
>      (let ((tmp-file (make-temp-file "org-babel-sh")))
>        (mapconcat
> 	#'org-babel-sh-strip-weird-long-prompt
> 	(mapcar
> 	 #'org-babel-trim
> 	 (butlast
> 	  (org-babel-comint-with-output
> 	      (session org-babel-sh-eoe-output t body)
> 	    (mapc
> 	     (lambda (line)
> 	       (insert line) (comint-send-input nil t) (sleep-for 0.25))
> 	     (append
> 	      (split-string (org-babel-trim body) "\n")
> 	      (list org-babel-sh-eoe-indicator))))
> 	  2)) "\n")))))
> )
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: RE: [babel] evaluating shell commands for side effect
  2010-08-20 23:36 ` Sullivan, Gregory (US SSA)
  2010-08-20 23:59   ` Sullivan, Gregory (US SSA)
@ 2010-08-25 17:30   ` Eric Schulte
  2010-08-25 17:31     ` Sullivan, Gregory (US SSA)
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Schulte @ 2010-08-25 17:30 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA); +Cc: emacs-orgmode@gnu.org

good question: code blocks in sessions *are evaluated* even if the
results of that particular block are not needed for export.  This is
because those code blocks could make changes to session state, changes
which could be required for other code blocks whose results will be
included in the final export.

You can do the following to inhibit evaluation of the code block.
#+begin_src sh :session *shell* :noeval
  date
#+end_src

which will silently inhibit the evaluation of the code block.  This
:noeval header is not currently document, but it should be.  I'm adding
this to the babel task list.

Thanks -- Eric

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> Another question related to using babel, shell commands, in a session:
>
> When I try to export a .org file with "begin_src sh :session *shell* :exports code" blocks, I'm prompted whether I want to evaluate the code.  However, I thought ":exports code" would avoid evaluation on export (and that :session is only about evaluation).
>
> Any help appreciated.
> Thanks.
>
> -- Greg
>
> --
> Greg Sullivan,   gregory.sullivan@baesystems.com
> (781)262-4553 (desk),  (978)430-3461 (cell)
>
>
> -----Original Message-----
> From: emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org [mailto:emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org] On Behalf Of Sullivan, Gregory (US SSA)
> Sent: Thursday, August 19, 2010 12:51 PM
> To: emacs-orgmode@gnu.org
> Subject: [Orgmode] [babel] evaluating shell commands for side effect
>
> I'm writing "how to" documents that include sequences of shell commands, such as: 
>
> #+begin_src sh :session *shell*
>  cd /home/sullivan/myproj/src
>  ./configure --prefix /home/sullivan/myproj/install
>  make
>  make test
> #+end_src
>
> and simply want C-c C-c to send the lines, one at a time, to the inferior shell process. That is, I want readers to read along, and then execute the code as needed.
>
> Currently, it never returns (until C-g).  It might be related to the issues discussed last November, 
> 	http://lists.gnu.org/archive/html/emacs-orgmode/2009-11/msg01166.html
> I have the latest git version of org mode, and I think I've set comint-prompt-regexp correctly.
>
> So: I don't want to filter the output, I don't want to collect the results - just send the commands and go.
>
> Looking at ob-sh.el/org-babel-sh-evaluate, I can't figure out what the Right Thing to do is.  Appended is a cheap hack that checks for "ignore" as a results string (e.g. #+begin_src sh :session *shell* :results ignore) and sends the lines one at a time to the inferior shell buffer.  But I suspect there's a more straightforward way to do it.
>
> Thoughts?
> Thanks.
>
> -- Greg
>
> --
> Greg Sullivan,   gregory.sullivan@baesystems.com
> (781)262-4553 (desk),  (978)430-3461 (cell)
>
> --
>
> (defun org-babel-sh-evaluate (session body &optional result-params)
>   "Pass BODY to the Shell process in BUFFER.
> If RESULT-TYPE equals 'output then return a list of the outputs
> of the statements in BODY, if RESULT-TYPE equals 'value then
> return the value of the last statement in BODY."
>   ((lambda (results)
>      (if (or (member "scalar" result-params)
> 	     (member "ignore" result-params)
> 	     (member "output" result-params))
> 	 results
>        (let ((tmp-file (make-temp-file "org-babel-sh")))
> 	 (with-temp-file tmp-file (insert results))
> 	 (org-babel-import-elisp-from-file tmp-file))))
>    (if (not session)
>        (org-babel-eval org-babel-sh-command (org-babel-trim body))
>      (if (member "ignore" result-params)
> 	 (progn
> 	   (save-excursion
> 	     (set-buffer session)
> 	     (mapc
> 	      (lambda (line)
> 		(insert line) (comint-send-input nil t) (sleep-for 0.25))
> 	      (split-string (org-babel-trim body) "\n")))
> 	   '())
>
>      (let ((tmp-file (make-temp-file "org-babel-sh")))
>        (mapconcat
> 	#'org-babel-sh-strip-weird-long-prompt
> 	(mapcar
> 	 #'org-babel-trim
> 	 (butlast
> 	  (org-babel-comint-with-output
> 	      (session org-babel-sh-eoe-output t body)
> 	    (mapc
> 	     (lambda (line)
> 	       (insert line) (comint-send-input nil t) (sleep-for 0.25))
> 	     (append
> 	      (split-string (org-babel-trim body) "\n")
> 	      (list org-babel-sh-eoe-indicator))))
> 	  2)) "\n")))))
> )
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* RE: RE: [babel] evaluating shell commands for side effect
  2010-08-25 17:30   ` Eric Schulte
@ 2010-08-25 17:31     ` Sullivan, Gregory (US SSA)
  0 siblings, 0 replies; 6+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2010-08-25 17:31 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode@gnu.org

Perfect!  Thanks very much.

-- Greg

--
Greg Sullivan,   gregory.sullivan@baesystems.com
(781)262-4553 (desk),  (978)430-3461 (cell)


-----Original Message-----
From: Eric Schulte [mailto:schulte.eric@gmail.com] 
Sent: Wednesday, August 25, 2010 1:30 PM
To: Sullivan, Gregory (US SSA)
Cc: emacs-orgmode@gnu.org
Subject: Re: [Orgmode] RE: [babel] evaluating shell commands for side effect

good question: code blocks in sessions *are evaluated* even if the
results of that particular block are not needed for export.  This is
because those code blocks could make changes to session state, changes
which could be required for other code blocks whose results will be
included in the final export.

You can do the following to inhibit evaluation of the code block.
#+begin_src sh :session *shell* :noeval
  date
#+end_src

which will silently inhibit the evaluation of the code block.  This
:noeval header is not currently document, but it should be.  I'm adding
this to the babel task list.

Thanks -- Eric

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> Another question related to using babel, shell commands, in a session:
>
> When I try to export a .org file with "begin_src sh :session *shell* :exports code" blocks, I'm prompted whether I want to evaluate the code.  However, I thought ":exports code" would avoid evaluation on export (and that :session is only about evaluation).
>
> Any help appreciated.
> Thanks.
>
> -- Greg
>
> --
> Greg Sullivan,   gregory.sullivan@baesystems.com
> (781)262-4553 (desk),  (978)430-3461 (cell)
>
>
> -----Original Message-----
> From: emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org [mailto:emacs-orgmode-bounces+gregory.sullivan=baesystems.com@gnu.org] On Behalf Of Sullivan, Gregory (US SSA)
> Sent: Thursday, August 19, 2010 12:51 PM
> To: emacs-orgmode@gnu.org
> Subject: [Orgmode] [babel] evaluating shell commands for side effect
>
> I'm writing "how to" documents that include sequences of shell commands, such as: 
>
> #+begin_src sh :session *shell*
>  cd /home/sullivan/myproj/src
>  ./configure --prefix /home/sullivan/myproj/install
>  make
>  make test
> #+end_src
>
> and simply want C-c C-c to send the lines, one at a time, to the inferior shell process. That is, I want readers to read along, and then execute the code as needed.
>
> Currently, it never returns (until C-g).  It might be related to the issues discussed last November, 
> 	http://lists.gnu.org/archive/html/emacs-orgmode/2009-11/msg01166.html
> I have the latest git version of org mode, and I think I've set comint-prompt-regexp correctly.
>
> So: I don't want to filter the output, I don't want to collect the results - just send the commands and go.
>
> Looking at ob-sh.el/org-babel-sh-evaluate, I can't figure out what the Right Thing to do is.  Appended is a cheap hack that checks for "ignore" as a results string (e.g. #+begin_src sh :session *shell* :results ignore) and sends the lines one at a time to the inferior shell buffer.  But I suspect there's a more straightforward way to do it.
>
> Thoughts?
> Thanks.
>
> -- Greg
>
> --
> Greg Sullivan,   gregory.sullivan@baesystems.com
> (781)262-4553 (desk),  (978)430-3461 (cell)
>
> --
>
> (defun org-babel-sh-evaluate (session body &optional result-params)
>   "Pass BODY to the Shell process in BUFFER.
> If RESULT-TYPE equals 'output then return a list of the outputs
> of the statements in BODY, if RESULT-TYPE equals 'value then
> return the value of the last statement in BODY."
>   ((lambda (results)
>      (if (or (member "scalar" result-params)
> 	     (member "ignore" result-params)
> 	     (member "output" result-params))
> 	 results
>        (let ((tmp-file (make-temp-file "org-babel-sh")))
> 	 (with-temp-file tmp-file (insert results))
> 	 (org-babel-import-elisp-from-file tmp-file))))
>    (if (not session)
>        (org-babel-eval org-babel-sh-command (org-babel-trim body))
>      (if (member "ignore" result-params)
> 	 (progn
> 	   (save-excursion
> 	     (set-buffer session)
> 	     (mapc
> 	      (lambda (line)
> 		(insert line) (comint-send-input nil t) (sleep-for 0.25))
> 	      (split-string (org-babel-trim body) "\n")))
> 	   '())
>
>      (let ((tmp-file (make-temp-file "org-babel-sh")))
>        (mapconcat
> 	#'org-babel-sh-strip-weird-long-prompt
> 	(mapcar
> 	 #'org-babel-trim
> 	 (butlast
> 	  (org-babel-comint-with-output
> 	      (session org-babel-sh-eoe-output t body)
> 	    (mapc
> 	     (lambda (line)
> 	       (insert line) (comint-send-input nil t) (sleep-for 0.25))
> 	     (append
> 	      (split-string (org-babel-trim body) "\n")
> 	      (list org-babel-sh-eoe-indicator))))
> 	  2)) "\n")))))
> )
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-08-25 17:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-19 16:51 [babel] evaluating shell commands for side effect Sullivan, Gregory (US SSA)
2010-08-20 23:36 ` Sullivan, Gregory (US SSA)
2010-08-20 23:59   ` Sullivan, Gregory (US SSA)
2010-08-25 17:30   ` Eric Schulte
2010-08-25 17:31     ` Sullivan, Gregory (US SSA)
2010-08-25 17:24 ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).