* Tangling src blocks to files as part of export
@ 2014-11-13 15:54 Michael Weylandt
2014-11-13 16:15 ` Michael Weylandt
0 siblings, 1 reply; 4+ messages in thread
From: Michael Weylandt @ 2014-11-13 15:54 UTC (permalink / raw)
To: emacs-orgmode
Is it possible to have certain blocks tangled as part of export so that they are available as input files to later source blocks?
E.g.,
#+BEGIN_SRC python :tangle hello.py
print "Hello World"
#+END_SRC
#+BEGIN_SRC sh
python hello.py
#+END_SRC
If I tangle before running, then the second code block will work; else, it fails because 'hello.py' is not found. [1]
I can run tangle and export in a row (and I have my own function to do just that) but is there a native org way to do so?
Michael
[1] My actual case involves a JAGS model file and the R code to run it, so executing the first source block directly isn't an option.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tangling src blocks to files as part of export
2014-11-13 15:54 Tangling src blocks to files as part of export Michael Weylandt
@ 2014-11-13 16:15 ` Michael Weylandt
2014-11-13 16:56 ` Fabrice Niessen
2014-11-14 8:39 ` Rainer M Krug
0 siblings, 2 replies; 4+ messages in thread
From: Michael Weylandt @ 2014-11-13 16:15 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
> On Nov 13, 2014, at 10:54 AM, Michael Weylandt <michael.weylandt@gmail.com> wrote:
>
> Is it possible to have certain blocks tangled as part of export so that they are available as input files to later source blocks?
>
> E.g.,
>
> #+BEGIN_SRC python :tangle hello.py
> print "Hello World"
> #+END_SRC
>
> #+BEGIN_SRC sh
> python hello.py
> #+END_SRC
>
> If I tangle before running, then the second code block will work; else, it fails because 'hello.py' is not found. [1]
>
> I can run tangle and export in a row (and I have my own function to do just that) but is there a native org way to do so?
Adding org-babel-tangle to the org-export-before-processing-hook does the job, but I'd still be interested in knowing if there's a more official method.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tangling src blocks to files as part of export
2014-11-13 16:15 ` Michael Weylandt
@ 2014-11-13 16:56 ` Fabrice Niessen
2014-11-14 8:39 ` Rainer M Krug
1 sibling, 0 replies; 4+ messages in thread
From: Fabrice Niessen @ 2014-11-13 16:56 UTC (permalink / raw)
To: emacs-orgmode-mXXj517/zsQ
Hello Michael,
Michael Weylandt wrote:
>> On Nov 13, 2014, at 10:54 AM, Michael Weylandt <michael.weylandt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>
>> Is it possible to have certain blocks tangled as part of export so
>> that they are available as input files to later source blocks?
>>
>> E.g.,
>>
>> #+BEGIN_SRC python :tangle hello.py
>> print "Hello World"
>> #+END_SRC
>>
>> #+BEGIN_SRC sh
>> python hello.py
>> #+END_SRC
>>
>> If I tangle before running, then the second code block will work;
>> else, it fails because 'hello.py' is not found. [1]
>>
>> I can run tangle and export in a row (and I have my own function to
>> do just that) but is there a native org way to do so?
>
> Adding org-babel-tangle to the org-export-before-processing-hook does
> the job, but I'd still be interested in knowing if there's a more
> official method.
For such a work, I'm using this home-made function:
--8<---------------cut here---------------start------------->8---
(with-eval-after-load "org"
(defun org-save-buffer-and-do-related ()
"Save buffer, execute/tangle code blocks, and export to HTML/PDF."
(interactive)
(let* ((orgfile (buffer-file-name))
(base-name (file-name-base orgfile))
(htmlfile (concat base-name ".html"))
(pdffile (concat base-name ".pdf")))
(save-buffer) ; See other commands in
; `before-save-hook':
; `org-update-all-dblocks'
; `org-table-iterate-buffer-tables'.
(when (derived-mode-p 'org-mode)
;; (org-babel-execute-buffer) ; XXX Why should we execute all code blocks?
(let ((before-save-hook nil))
(save-buffer))
(org-babel-tangle)
(when (file-exists-p htmlfile)
(if (file-newer-than-file-p orgfile htmlfile)
(org-html-export-to-html)
(message "HTML is up to date with Org file")))
(when (file-exists-p pdffile)
(if (file-newer-than-file-p orgfile pdffile)
(if (string-match "^#\\+BEAMER_THEME: " (buffer-string))
(org-beamer-export-to-pdf)
(org-latex-export-to-pdf))
(message "PDF is up to date with Org file")))
(beep))))
(define-key org-mode-map (kbd "<f9>") 'org-save-buffer-and-do-related))
--8<---------------cut here---------------end--------------->8---
Best regards,
Fabrice
--
Fabrice Niessen
Leuven, Belgium
http://www.pirilampo.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tangling src blocks to files as part of export
2014-11-13 16:15 ` Michael Weylandt
2014-11-13 16:56 ` Fabrice Niessen
@ 2014-11-14 8:39 ` Rainer M Krug
1 sibling, 0 replies; 4+ messages in thread
From: Rainer M Krug @ 2014-11-14 8:39 UTC (permalink / raw)
To: Michael Weylandt; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]
Michael Weylandt <michael.weylandt@gmail.com> writes:
>> On Nov 13, 2014, at 10:54 AM, Michael Weylandt <michael.weylandt@gmail.com> wrote:
>>
>> Is it possible to have certain blocks tangled as part of export so
>> that they are available as input files to later source blocks?
>>
>> E.g.,
>>
>> #+BEGIN_SRC python :tangle hello.py
>> print "Hello World"
>> #+END_SRC
>>
>> #+BEGIN_SRC sh
>> python hello.py
>> #+END_SRC
>>
>> If I tangle before running, then the second code block will work; else, it fails because 'hello.py' is not found. [1]
>>
>> I can run tangle and export in a row (and I have my own function to
>> do just that) but is there a native org way to do so?
>
> Adding org-babel-tangle to the org-export-before-processing-hook does
> the job, but I'd still be interested in knowing if there's a more
> official method.
I think this is the more-or-less official way of doing it - that's what
hooks are for: to do pre- and post-processing, which is exactly what you
want to do.
I like it actually.
Do you set the hook as a file local variable, and if yes, how?
Because this would be brilliant.
Cheers,
Rainer
>
>
--
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-11-14 8:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-13 15:54 Tangling src blocks to files as part of export Michael Weylandt
2014-11-13 16:15 ` Michael Weylandt
2014-11-13 16:56 ` Fabrice Niessen
2014-11-14 8:39 ` Rainer M Krug
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).