emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Treat node or subtree as source block?
@ 2016-02-15 18:05 Paul M.
  2016-03-05 18:22 ` Thorsten Jolitz
  0 siblings, 1 reply; 2+ messages in thread
From: Paul M. @ 2016-02-15 18:05 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

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" ?

Thanks,
Paul

[-- Attachment #2: Type: text/html, Size: 356 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Treat node or subtree as source block?
  2016-02-15 18:05 Treat node or subtree as source block? Paul M.
@ 2016-03-05 18:22 ` Thorsten Jolitz
  0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Jolitz @ 2016-03-05 18:22 UTC (permalink / raw)
  To: emacs-orgmode

"Paul M." <pmmagic@gmail.com> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-05 18:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-15 18:05 Treat node or subtree as source block? Paul M.
2016-03-05 18:22 ` Thorsten Jolitz

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).