From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Re: Include files to be used in literate programming Date: Mon, 13 Sep 2010 17:39:55 +0200 Message-ID: <4C8E45CB.2000900@gmail.com> References: <4A6B29B6-07EA-46F0-99E9-718F93DAE558@me.com> <87fwxdhktn.fsf@stats.ox.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from [140.186.70.92] (port=58976 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OvB8W-0000eY-OT for emacs-orgmode@gnu.org; Mon, 13 Sep 2010 11:40:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OvB8S-0007cq-7b for emacs-orgmode@gnu.org; Mon, 13 Sep 2010 11:40:04 -0400 Received: from mail-ww0-f49.google.com ([74.125.82.49]:58559) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OvB8R-0007cZ-Vc for emacs-orgmode@gnu.org; Mon, 13 Sep 2010 11:40:00 -0400 Received: by wwb24 with SMTP id 24so6919227wwb.30 for ; Mon, 13 Sep 2010 08:39:59 -0700 (PDT) In-Reply-To: <87fwxdhktn.fsf@stats.ox.ac.uk> 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: Dan Davison Cc: emacs-orgmode@gnu.org, Giorgio Valoti -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 13/09/10 14:47, Dan Davison wrote: > Giorgio Valoti writes: > >> Hi all, >> I’ve just switched from OmniFocus and began using Org mode. But I also discovered that it can be used for literate programming and I’d like to ask if is there a way to use an included file in the tangling phase. In other words, I have a file which includes a commons.org file, like this: >> >> === commons.org contents === >> * Variabili comuni >> :PROPERTIES: >> :END: >> #+SRCNAME: entity-name >> #+BEGIN_SRC :noweb yes >> nome_tabella >> #+END_SRC >> >> >> === main.org contents === >> #+INCLUDE: "commons.org" >> >> * Sezione in SQL >> :PROPERTIES: >> :END: >> #+SRCNAME: sql-module >> #+BEGIN_SRC sql :tangle module.sql :noweb yes >> select * >> from table <>; >> #+END_SRC >> >> <> should come from the commons but it’s not. >> >> Is there a way to expand values from included files? > > Hi Giorgio, > > I don't know of a way currently but I agree that it is desirable. It > does seem temtping to want to use #+INCLUDE for this purpose; > however #+INCLUDE is an /export/ construct, and tangling is not > (technically at least) an Org-mode export method. So some options that > come to my mind are: > > 1. I am overlooking an existing way of doing this. > > 2. Implement #+INCLUDE when tangling, optionally or by default. I think that using this option, to include org files using the #INCLUDE and treat them as if they would be part of the original file would be a good solution, especially for literate programming - e.g. having often used code blocks in files, work with "org libraries", ... The only problem might be header properties defined at the beginning of the #+INCLUDEd file - they should probably be excluded from the inclusion. Nevertheless, that could probably be handled by an additional parameter to #+INCLUDE : #+INCLUDE externalORGfile.org :headers exclude where "exclude" is the default. Rainer > > 3. Implement a general way of including blocks of code from other files > in such a way that they behave as 'normal' code blocks. This would > have several potentially useful consequences. > > 4. It seems that it should be possible to get what you want by first > using `org-export-as-org' followed by `org-babel-tangle'. However, > `org-export-as-org' doesn't currently include #+INCLUDE'd files. I > wonder if it should. A hack to do what you want is below (You'll be > prompted for a file name to save the Org export buffer to.): > > #+begin_src emacs-lisp > (defun ded/org-export-as-org-to-buffer () > (interactive) > (let* ((tmp-file (make-temp-file "org-tangle-with-include")) > (org-export-preprocess-after-include-files-hook > `((lambda () (let ((s (buffer-string))) > (with-temp-file ,tmp-file (insert s))))))) > (save-window-excursion (org-export-as-html-to-buffer nil)) > (switch-to-buffer > (get-buffer-create "*Org Org Export*")) > (insert-file-contents tmp-file)) > (org-mode)) > > (defun ded/tangle-with-include-files () > (interactive) > (save-window-excursion > (ded/org-export-as-org-to-buffer) > (org-babel-tangle))) > #+end_src > > Dan > > >> >> Thank you in advance. >> >> -- >> Giorgio Valoti >> >> >> _______________________________________________ >> 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 > > _______________________________________________ > 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 - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel: +33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: Rainer@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyORcsACgkQoYgNqgF2egoZ0gCfai+D1C/2xCprMdBtUadiSFVs FLQAn3DPIyem4VMwNglzRJTWeWjn5w/T =M9XP -----END PGP SIGNATURE-----