From mboxrd@z Thu Jan 1 00:00:00 1970 From: Fabrice Niessen Subject: Re: Tangling src blocks to files as part of export Date: Thu, 13 Nov 2014 17:56:50 +0100 Message-ID: <86tx23avjh.fsf@example.com> References: <3B947464-9723-45DA-9EB4-D84633366471@gmail.com> <871A2C12-586B-4E42-AEE9-31BFAA4C8EBF@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: 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-mXXj517/zsQ@public.gmane.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org To: emacs-orgmode-mXXj517/zsQ@public.gmane.org Hello Michael, Michael Weylandt wrote: >> On Nov 13, 2014, at 10:54 AM, Michael Weylandt 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 "") 'org-save-buffer-and-do-related)) --8<---------------cut here---------------end--------------->8--- Best regards, Fabrice -- Fabrice Niessen Leuven, Belgium http://www.pirilampo.org/