From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: Include files to be used in literate programming Date: Mon, 13 Sep 2010 08:47:16 -0400 Message-ID: <87fwxdhktn.fsf@stats.ox.ac.uk> References: <4A6B29B6-07EA-46F0-99E9-718F93DAE558@me.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=53089 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ov8Ri-0003mi-7X for emacs-orgmode@gnu.org; Mon, 13 Sep 2010 08:47:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ov8Rg-0005QE-Kk for emacs-orgmode@gnu.org; Mon, 13 Sep 2010 08:47:41 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:59672) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ov8Rg-0005Pw-D9 for emacs-orgmode@gnu.org; Mon, 13 Sep 2010 08:47:40 -0400 In-Reply-To: <4A6B29B6-07EA-46F0-99E9-718F93DAE558@me.com> (Giorgio Valoti's message of "Sun, 12 Sep 2010 19:02:18 +0200") 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: Giorgio Valoti Cc: emacs-orgmode@gnu.org Giorgio Valoti writes: > Hi all, > I=E2=80=99ve just switched from OmniFocus and began using Org mode. But I= also discovered that it can be used for literate programming and I=E2=80= =99d 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, lik= e this: > > =3D=3D=3D commons.org contents =3D=3D=3D > * Variabili comuni > :PROPERTIES: > :END: > #+SRCNAME: entity-name > #+BEGIN_SRC :noweb yes > nome_tabella > #+END_SRC > > > =3D=3D=3D main.org contents =3D=3D=3D > #+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=E2=80=99s 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. 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)) =20=20 (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