From: Thibault Marin <thibault.marin@gmx.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: Export tangle filename with source block
Date: Sat, 30 Jul 2016 22:45:42 -0500 [thread overview]
Message-ID: <87bn1ewjvd.fsf@dell-desktop.WORKGROUP> (raw)
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 "\\(<pre class=\"src src-lua\" id=\"[^\"]+*\">\\)"))
(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
next reply other threads:[~2016-07-31 22:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-31 3:45 Thibault Marin [this message]
2016-10-08 19:36 ` Export tangle filename with source block Thibault Marin
2016-10-11 18:57 ` Nicolas Goaziou
2016-10-12 4:39 ` Thibault Marin
2016-10-12 23:48 ` Thibault Marin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bn1ewjvd.fsf@dell-desktop.WORKGROUP \
--to=thibault.marin@gmx.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.