From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thibault Marin Subject: Export tangle filename with source block Date: Sat, 30 Jul 2016 22:45:42 -0500 Message-ID: <87bn1ewjvd.fsf@dell-desktop.WORKGROUP> Reply-To: thibault.marin@gmx.com Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTzbN-0002yO-Ka for emacs-orgmode@gnu.org; Sun, 31 Jul 2016 18:52:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTzbJ-0003gb-Eb for emacs-orgmode@gnu.org; Sun, 31 Jul 2016 18:52:56 -0400 Received: from mout.gmx.net ([212.227.17.20]:55026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTzbJ-0003gO-3j for emacs-orgmode@gnu.org; Sun, 31 Jul 2016 18:52:53 -0400 Received: from dell-desktop.WORKGROUP ([99.47.196.62]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0M6vSj-1b77Z90lTJ-00wkbT for ; Mon, 01 Aug 2016 00:52:50 +0200 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: Org Mode Hi list, I have an org file that I am tangling into multiple files, and exporting to html. What I would like to do is to label each source block in the exported html with the filename used for tangling this specific block. I don't have a strong opinion about the actual appearance of the label (adding a comment at the top of the source block, hover in the code textarea, other?). I couldn't find any option to do that, so I initially though of using `org-export-filter-src-block-functions' (following http://orgmode.org/manual/Advanced-configuration.html). I was not able to get the org-element object for the current block from the parameter received by the filter. It looks like the third parameter (`info') may have more information but I currently don't see how to get (1) the current source block, and (2) the tangling filename. I then tried to define a derived backend with custom handling of source blocks as described in the documentation. I currently have the following, where I try to get the tangle filename using `org-babel-get-src-block-info', and later insert it into the html content using an ugly regexp. (defun my-html-src-block (src-block contents info) "Transcode a SRC-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist used as a communication channel." (let* ((lang (org-element-property :language src-block)) (src-info (org-babel-get-src-block-info t src-block)) (tang (cdr (assq :tangle (nth 2 src-info)))) (export-out (org-export-with-backend 'html src-block contents info)) ) (if (and (string= lang "lua") (and tang (> (length tang) 0))) (progn (let ((src-start-pat "\\(
\\)"))
            (replace-regexp-in-string src-start-pat
                                      (concat "\\1"
                                              "\n-- ["
                                              tang
                                              "]\n\n") export-out)
            )
          )
      export-out
      )
    )
  )

(org-export-define-derived-backend 'my-html 'html
  :translate-alist '((src-block . my-html-src-block)))

Besides feeling wrong, this always gets the tangle name from the top
level org option ("#+PROPERTY: tangle main-file" at the top of the file)
instead of the one overridden by individual blocks "#+BEGIN_SRC :tangle
other-file".  Moreover the added comment is not syntax highlighted and
this feels really wrong.

Does anybody have any idea on how to achieve this?

Thanks in advance.

thibault