emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Treat node or subtree as source block?


From: Thorsten Jolitz
Subject: Re: [O] Treat node or subtree as source block?
Date: Sat, 05 Mar 2016 19:22:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

"Paul M." <address@hidden> writes:

Hi,

> I'm interested in treating an entire node or subtree as a source block
> for the purposes of tangling.
>
> Is there some way to specify that, say with properties, without having
> to explicitly surround text to be tangled with
> "#+BEGIN_SRC...#+END_SRC" ?

It depends what you want. Tangling actually is for removing the Org
text from Org-mode files, just leaving the content of source blocks,
so your whole idea is a bit against the flow.

If you want to conserve the whole node you probably need to wrap it
in #+BEGIN_SRC org ... #+END_SRC.

If you want to transform it to a source block you could use org-dp.el:

#+BEGIN_SRC elisp
  (defun tj/node-to-src-block ()
    "Transform node to src block."
    (interactive)
    (org-dp-rewire 'src-block t 'append nil nil
       :language '(lambda (old elem)
                     (car (org-element-property :tags elem)))
       :parameters '(lambda (old elem)
                      (format ":exports %s"
                        (cadr (org-element-property :tags elem))))
       :value '(lambda (old elem) (org-dp-contents 'elem t t))))
#+END_SRC

#+results:
: tj/node-to-src-block


Calling this function with point on the following headline appends
the (working) src-block that results from transforming the headline:

* Hello World :elisp:results:
(print "Hello World")

#+BEGIN_SRC elisp :exports results
  (print "Hello World")
#+END_SRC

-- 
cheers,
Thorsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]