From mboxrd@z Thu Jan 1 00:00:00 1970 From: "s@1042.ch" Subject: Tangling with cross-references coming from included files Date: Tue, 28 Mar 2017 09:20:48 +0200 Message-ID: Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Content-Type: multipart/signed; boundary="Apple-Mail=_93E6F93C-8C91-48C5-9F52-2986F9674A16"; protocol="application/pgp-signature"; micalg=pgp-sha256 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cslRD-0007w4-2t for Emacs-orgmode@gnu.org; Tue, 28 Mar 2017 03:21:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cslR8-0003Q7-95 for Emacs-orgmode@gnu.org; Tue, 28 Mar 2017 03:21:06 -0400 Received: from mailauth3.nine.ch ([94.230.211.187]:56118) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cslR7-0003OH-Rn for Emacs-orgmode@gnu.org; Tue, 28 Mar 2017 03:21:02 -0400 Received: from localhost (localhost [127.0.0.1]) by mailauth3.nine.ch (Postfix) with ESMTP id C139611F9CC for ; Tue, 28 Mar 2017 09:20:51 +0200 (CEST) Received: from mailauth3.nine.ch ([127.0.0.1]) by localhost (mailauth3.nine.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EnTHI-yOo-SW for ; Tue, 28 Mar 2017 09:20:50 +0200 (CEST) Received: from [192.168.0.129] (unknown [194.230.159.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: s@1042.ch) by mailauth3.nine.ch (Postfix) with ESMTPSA for ; Tue, 28 Mar 2017 09:20:50 +0200 (CEST) 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@gnu.org Sender: "Emacs-orgmode" To: Emacs-orgmode@gnu.org --Apple-Mail=_93E6F93C-8C91-48C5-9F52-2986F9674A16 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi I am trying to achieve the tangling of an org-file which is composed by multiple (included) org-files. I am using Emacs 25.1.1 and Org mode 9.0.5. Here an example of what I am trying to achieve. =E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94Example starts = here=E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94 =3D=3D=3D=3D File A.org =3D=3D=3D=3D [Text here =E2=80=A6] #+BEGIN_SRC python :tangle src/a.py :noweb tangle class Foo(object): <> #+END [More text here ...] #+INCLUDE: =E2=80=9C./b.org" =3D=3D=3D=3D File b.org =3D=3D=3D=3D [Text =E2=80=A6] #+BEGIN_SRC python :exports none def foo(self): print(=E2=80=9Cbar=E2=80=9D) #+END =E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94Example ends = here=E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94=E2=80=94 My problem is, that the included parts are not being tangled. When having all the parts in one file, there is no problem at all, but having = only file is not an option. An easy approach would be, as I thought at first, to use = "org-org-export-as-org", which does include all into one buffer. Then one could simply tangle that buffer. The problem with that approach = is however, that all arguments get stripped from #+BEGIN_SRC and therefore =E2=80=9C:tangle =E2=80=A6=E2=80= =9D too. So, looking at the list=E2=80=99s archive and on org mode hacks, I found = a workaround, which uses a hook when exporting ([1] and [2]): #+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 That is to use the hook to make a copy of the buffer right before = exporting. This buffer, which has all files tied together, gets written to a temp. file and this file is then tangled. = This is done using the string =E2=80=9Cbuffer-string=E2=80=9D generated by the exporter. The problem with that solution is, that it concerns org versions < 9, = using the =E2=80=9Cold=E2=80=9D exporter. Within the new exporter there is no such hook and therefore no string = =E2=80=9Cbuffer-string=E2=80=9D holding the complete buffer (as far as I saw). Instead there is org-before-parsing-hook [3], wich does essentially the = same (as far as I understood). But instead using a string for copying the buffer for exporting, the = exporter uses a temporary buffer, =E2=80=9Cbuf-copy=E2=80=9D. I tried to get the contents of that buffer within the hook like so: #+begin_src emacs-lisp (defun ded/org-export-as-org-to-buffer () (interactive) (let* ((tmp-file (make-temp-file "org-tangle-with-include")) (org-before-parsing-hook `((lambda () (setq ((b (get-buffer ,buf-copy))) (with-temp-file ,tmp-file (insert b))))))) (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 But it does not work as buf-copy is void. What am I doing wrong? How do = I get the buffer =E2=80=9Cbuf-copy=E2=80=9D? I am assuming that it is =E2=80=9Cbuf-copy=E2=80=9D as the call of the = hook happens within the context of =E2=80=9Corg-export-with-buffer-copy=E2= =80=9D. Is my assumption wrong? Any help is greatly appreciated. Sven [1]: http://orgmode.org/worg/org-hacks.html#sec-1-10-2 [2]: = https://lists.gnu.org/archive/html/emacs-orgmode/2010-09/msg00771.html [3]: http://orgmode.org/worg/doc.html#org-export-before-parsing-hook --Apple-Mail=_93E6F93C-8C91-48C5-9F52-2986F9674A16 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJY2g7RAAoJEGBuK3Iw+hVpIf4IAIu0QVZCrazkE26m2fh0HPf5 /07fsllXU/WqkTCVXLkDLAL8QIq/AQFqhkhiXaU2t86tnQWJjaeowMrcQnMd20E0 gp6pNKYJluk7JtwC4r7vc0HhMpg6re0Z//rzgzBvgAAxe+SfOyFClWff6mry6WgV KkrBie6scCJTqTu0nb1ZBFBMMW9Xq+S7slaYTolK13icUaNwzPZK21XIOxd0ktLT vAvKKmigPWvjFe1yEP0loPaLVgYm8jl2F8qUzAOABH+p7ICUvdr3+aEP29se2NWk 8nq8nDRVBF3xrH5NdfT9VLGF9b5In5RO0LbD81vYoTeJkrWjFVSAZS4qd6HN0M0= =ep0N -----END PGP SIGNATURE----- --Apple-Mail=_93E6F93C-8C91-48C5-9F52-2986F9674A16--