all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Scripting with org-mode
@ 2015-11-30 16:43 Shakthi Kannan
  2015-11-30 18:48 ` briangpowell .
  2015-11-30 19:15 ` John Kitchin
  0 siblings, 2 replies; 6+ messages in thread
From: Shakthi Kannan @ 2015-11-30 16:43 UTC (permalink / raw)
  To: emacs-orgmode

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?

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com

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

* Re: Scripting with org-mode
  2015-11-30 16:43 Scripting with org-mode Shakthi Kannan
@ 2015-11-30 18:48 ` briangpowell .
  2015-11-30 19:15 ` John Kitchin
  1 sibling, 0 replies; 6+ messages in thread
From: briangpowell . @ 2015-11-30 18:48 UTC (permalink / raw)
  To: Shakthi Kannan; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

* Assuming that entire file is made up of shell commands (like the ones in
the example you gave) since, in such a case as your example the "#" in the
first column would ignore the rest of the lines as comments:

M<
Mx set-mark
M>
Mx shell-command-on-region

On Mon, Nov 30, 2015 at 11:43 AM, Shakthi Kannan <shakthimaan@gmail.com>
wrote:

> 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?
>
> SK
>
> --
> Shakthi Kannan
> http://www.shakthimaan.com
>
>

[-- Attachment #2: Type: text/html, Size: 1600 bytes --]

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

* Re: Scripting with org-mode
  2015-11-30 16:43 Scripting with org-mode Shakthi Kannan
  2015-11-30 18:48 ` briangpowell .
@ 2015-11-30 19:15 ` John Kitchin
  2015-11-30 20:22   ` Nick Dokos
  1 sibling, 1 reply; 6+ messages in thread
From: John Kitchin @ 2015-11-30 19:15 UTC (permalink / raw)
  To: Shakthi Kannan; +Cc: emacs-orgmode

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?
>
> SK

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

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

* Re: Scripting with org-mode
  2015-11-30 19:15 ` John Kitchin
@ 2015-11-30 20:22   ` Nick Dokos
  2015-11-30 20:36     ` John Kitchin
  2015-12-01  1:03     ` Shakthi Kannan
  0 siblings, 2 replies; 6+ messages in thread
From: Nick Dokos @ 2015-11-30 20:22 UTC (permalink / raw)
  To: emacs-orgmode

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

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

* Re: Scripting with org-mode
  2015-11-30 20:22   ` Nick Dokos
@ 2015-11-30 20:36     ` John Kitchin
  2015-12-01  1:03     ` Shakthi Kannan
  1 sibling, 0 replies; 6+ messages in thread
From: John Kitchin @ 2015-11-30 20:36 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1881 bytes --]

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 <ndokos@gmail.com> wrote:

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

[-- Attachment #2: Type: text/html, Size: 3083 bytes --]

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

* Re: Scripting with org-mode
  2015-11-30 20:22   ` Nick Dokos
  2015-11-30 20:36     ` John Kitchin
@ 2015-12-01  1:03     ` Shakthi Kannan
  1 sibling, 0 replies; 6+ messages in thread
From: Shakthi Kannan @ 2015-12-01  1:03 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

Hi,

--- On Tue, Dec 1, 2015 at 1:52 AM, Nick Dokos <ndokos@gmail.com> wrote:
| IIUC, org-babel-execute-buffer is exactly what the OP
| needs.
\--

Yes, that did it. Thanks!

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com

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

end of thread, other threads:[~2015-12-01  1:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-30 16:43 Scripting with org-mode Shakthi Kannan
2015-11-30 18:48 ` briangpowell .
2015-11-30 19:15 ` John Kitchin
2015-11-30 20:22   ` Nick Dokos
2015-11-30 20:36     ` John Kitchin
2015-12-01  1:03     ` Shakthi Kannan

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.