From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Sullivan, Gregory (US SSA)" Subject: RE: [babel] evaluating shell commands for side effect Date: Fri, 20 Aug 2010 19:59:32 -0400 Message-ID: <83D2ABE0B13B7F409D1DE93916009DAD069C85D910@GLDMS60322.goldlnk.rootlnka.net> References: <83D2ABE0B13B7F409D1DE93916009DAD069C85D90E@GLDMS60322.goldlnk.rootlnka.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=40250 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OmbUq-0000tq-6l for emacs-orgmode@gnu.org; Fri, 20 Aug 2010 19:59:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OmbUo-0003X5-RL for emacs-orgmode@gnu.org; Fri, 20 Aug 2010 19:59:40 -0400 Received: from dmzms99902.na.baesystems.com ([149.32.200.66]:11709) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OmbUo-0003Uw-Oo for emacs-orgmode@gnu.org; Fri, 20 Aug 2010 19:59:38 -0400 In-Reply-To: <83D2ABE0B13B7F409D1DE93916009DAD069C85D90E@GLDMS60322.goldlnk.rootlnka.net> Content-Language: en-US List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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)=20 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* :expor= ts code" blocks, I'm prompted whether I want to evaluate the code. However= , I thought ":exports code" would avoid evaluation on export (and that :ses= sion 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=3Dbaesystems.com@gnu.org [mail= to:emacs-orgmode-bounces+gregory.sullivan=3Dbaesystems.com@gnu.org] On Beha= lf 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, su= ch as:=20 #+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 s= hell process. That is, I want readers to read along, and then execute the c= ode as needed. Currently, it never returns (until C-g). It might be related to the issues= discussed last November,=20 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-prom= pt-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 Righ= t Thing to do is. Appended is a cheap hack that checks for "ignore" as a r= esults string (e.g. #+begin_src sh :session *shell* :results ignore) and se= nds the lines one at a time to the inferior shell buffer. But I suspect th= ere'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