[Top][All Lists]

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

[Orgmode] [babel] evaluating shell commands for side effect

From: Sullivan, Gregory (US SSA)
Subject: [Orgmode] [babel] evaluating shell commands for side effect
Date: Thu, 19 Aug 2010 12:51:18 -0400

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

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

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 

Currently, it never returns (until C-g).  It might be related to the issues 
discussed last November, 
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.


-- Greg

Greg Sullivan,   address@hidden
(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))
       (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)
             (set-buffer session)
              (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")))
              (session org-babel-sh-eoe-output t body)
             (lambda (line)
               (insert line) (comint-send-input nil t) (sleep-for 0.25))
              (split-string (org-babel-trim body) "\n")
              (list org-babel-sh-eoe-indicator))))
          2)) "\n")))))

reply via email to

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