From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Scripting with org-mode Date: Mon, 30 Nov 2015 15:36:24 -0500 Message-ID: References: <87fuzngrv7.fsf@alphaville.usersys.redhat.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114b3238a365e90525c7fe7f Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3VBS-0002Zq-Mn for emacs-orgmode@gnu.org; Mon, 30 Nov 2015 15:36:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3VBR-0002oh-CP for emacs-orgmode@gnu.org; Mon, 30 Nov 2015 15:36:26 -0500 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:33317) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3VBR-0002oc-3x for emacs-orgmode@gnu.org; Mon, 30 Nov 2015 15:36:25 -0500 Received: by wmec201 with SMTP id c201so174777133wme.0 for ; Mon, 30 Nov 2015 12:36:24 -0800 (PST) In-Reply-To: <87fuzngrv7.fsf@alphaville.usersys.redhat.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nick Dokos Cc: "emacs-orgmode@gnu.org" --001a114b3238a365e90525c7fe7f Content-Type: text/plain; charset=UTF-8 of course there is a simpler way ;) John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Mon, Nov 30, 2015 at 3:22 PM, Nick Dokos wrote: > John Kitchin writes: > > > I think one of these will do what you want: > > > > ** Rerun all src blocks > > > > #+BEGIN_SRC emacs-lisp > > (defun run-blocks () > > (interactive) > > (save-excursion > > (org-element-map (org-element-parse-buffer) 'src-block > > (lambda (src-block) > > (goto-char (org-element-property :begin src-block)) > > (org-babel-execute-src-block))))) > > > > > > #+END_SRC > > > > #+RESULTS: > > : run-blocks > > > > > > #+BEGIN_SRC emacs-lisp > > (defun run-blocks-2 () > > (interactive) > > (save-excursion > > (goto-char (point-min)) > > (while (re-search-forward "^#\\+BEGIN_SRC" nil t) > > (org-babel-execute-src-block)))) > > #+END_SRC > > #+RESULTS: > > > > > > > > > > > > Shakthi Kannan writes: > > > >> Hi, > >> > >> Is there a way to execute all the org-mode code blocks in a file, and > >> send the output to stdout? > >> > >> For example, I have the following org file: > >> > >> === BEGIN === > >> > >> * Greeting > >> > >> #+BEGIN_SRC sh :results output > >> echo "Hello $USER! Today is `date`" > >> #+END_SRC > >> > >> * Current directory > >> > >> #+BEGIN_SRC sh :results output > >> pwd > >> #+END_SRC > >> > >> === END === > >> > >> I could go to each code block, and type C-c C-c to produce an output. > >> But, I just want to be able to execute the entire file, and produce > >> one single output. > >> > >> Is this possible? > >> > > > IIUC, org-babel-execute-buffer is exactly what the OP > needs. > > -- > Nick > > > --001a114b3238a365e90525c7fe7f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
of course there is a simpler way ;)

John

-----------------------------------=
Professor John Kitchin=C2=A0
Doherty Hall A207F
Department of Che= mical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
= 412-268-7803

On Mon, Nov 30, 2015 at 3:22 PM, Nick Dokos = <ndokos@gmail.com> wrote:
<= div class=3D"HOEnZb">
John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I think one of these will do what you want:
>
> ** Rerun all src blocks
>
> #+BEGIN_SRC emacs-lisp
> (defun run-blocks ()
>=C2=A0 =C2=A0(interactive)
>=C2=A0 =C2=A0(save-excursion
>=C2=A0 =C2=A0 =C2=A0(org-element-map (org-element-parse-buffer) 'sr= c-block
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda (src-block)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (org-element-property :beg= in src-block))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-babel-execute-src-block)))))
>
>
> #+END_SRC
>
> #+RESULTS:
> : run-blocks
>
>
> #+BEGIN_SRC emacs-lisp
> (defun run-blocks-2 ()
>=C2=A0 =C2=A0(interactive)
>=C2=A0 =C2=A0(save-excursion
>=C2=A0 =C2=A0 =C2=A0(goto-char (point-min))
>=C2=A0 =C2=A0 =C2=A0(while (re-search-forward "^#\\+BEGIN_SRC"= ; nil t)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(org-babel-execute-src-block))))
> #+END_SRC
> #+RESULTS:
>
>
>
>
>
> Shakthi Kannan writes:
>
>> Hi,
>>
>> Is there a way to execute all the org-mode code blocks in a file, = and
>> send the output to stdout?
>>
>> For example, I have the following org file:
>>
>> =3D=3D=3D BEGIN =3D=3D=3D
>>
>> * Greeting
>>
>> #+BEGIN_SRC sh :results output
>>=C2=A0 =C2=A0echo "Hello $USER! Today is `date`"
>> #+END_SRC
>>
>> * Current directory
>>
>> #+BEGIN_SRC sh :results output
>>=C2=A0 =C2=A0pwd
>> #+END_SRC
>>
>> =3D=3D=3D END =3D=3D=3D
>>
>> I could go to each code block, and type C-c C-c to produce an outp= ut.
>> But, I just want to be able to execute the entire file, and produc= e
>> one single output.
>>
>> Is this possible?
>>


IIUC, org-babel-execute-buffer is exactly what the OP
needs.

--
Nick



--001a114b3238a365e90525c7fe7f--