emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Separate Org file from Subtree
@ 2015-02-16 10:41 simon
  2015-02-16 12:54 ` John Kitchin
  2015-08-05  0:00 ` Bastien Guerry
  0 siblings, 2 replies; 6+ messages in thread
From: simon @ 2015-02-16 10:41 UTC (permalink / raw)
  To: emacs-orgmode

Hi there,

I think I must be missing something.

I have  a collection of articles in one org file (under separate
headings). I can export these as a subtree using Org's normal export
function as html etc., but I want to export the selected subtree as an
individual org file using the properties under each heading.)

In other words I want to export this subtree ...
* DONE Article One
:PROPERTIES:
:EXPORT_TITLE: An Interesting Article
:EXPORT_AUTHOR: Simon Jones
:EXPORT_FILENAME: an-interesting-article
:EXPORT_DATE: 2015-02-16
:END:

Article content ....

into an Org file entitled 'an-interesting-article.org' that looks like
this ...

#+TITLE: An Interesting Article
#+AUTHOR: Simon Jones
#+DATE: 2015-02-16

Article content...

Can anyone help me with this? I'm very sorry if I'm missing something
obvious.

Simon.

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

* Re: Separate Org file from Subtree
  2015-02-16 10:41 Separate Org file from Subtree simon
@ 2015-02-16 12:54 ` John Kitchin
  2015-02-16 14:40   ` simon
  2015-08-05  0:00 ` Bastien Guerry
  1 sibling, 1 reply; 6+ messages in thread
From: John Kitchin @ 2015-02-16 12:54 UTC (permalink / raw)
  To: simon; +Cc: emacs-orgmode

Change :EXPORT_FILENAME: an-interesting-article to :EXPORT_FILE_NAME:
an-interesting-article

Then,

C-c C-e C-s O o

should export to that file. I notice in the org export that the
properties are not getting exported, and even the headline is not
exported as the title though.

Here is a function that seems to do what you want.

#+BEGIN_SRC emacs-lisp
(defun export-subtree ()
 (interactive)
 (let ((fname  (concat (org-entry-get (point) "EXPORT_FILE_NAME") ".org"))
       (author (org-entry-get (point) "EXPORT_AUTHOR"))
       (title (org-entry-get (point) "EXPORT_TITLE"))
       (date (org-entry-get (point) "EXPORT_DATE"))
       (content (progn (set-buffer (org-org-export-as-org nil t t))
                   (buffer-string))))
   ;; warning you can delete something unintentionally
   (when (file-exists-p fname) (delete-file fname))
   (find-file fname)
   (insert "#+TITLE: " title "\n")
   (insert "#+AUTHOR: " author "\n")
   (insert "#+DATE: " date "\n")
   (insert "\n" content)
   ;; remove properties drawer. Kind of hacky.
   (goto-char (point-min))
   (re-search-forward ":PROPERTIES:")
   (setf (buffer-substring
          (org-element-property :begin (org-element-context))
          (org-element-property :end (org-element-context)))
           "")
   (save-buffer)))

(export-subtree)
#+END_SRC

simon@psilas.com writes:

> Hi there,
>
> I think I must be missing something.
>
> I have  a collection of articles in one org file (under separate
> headings). I can export these as a subtree using Org's normal export
> function as html etc., but I want to export the selected subtree as an
> individual org file using the properties under each heading.)
>
> In other words I want to export this subtree ...
> * DONE Article One
> :PROPERTIES:
> :EXPORT_TITLE: An Interesting Article
> :EXPORT_AUTHOR: Simon Jones
> :EXPORT_FILENAME: an-interesting-article
> :EXPORT_DATE: 2015-02-16
> :END:
>
> Article content ....
>
> into an Org file entitled 'an-interesting-article.org' that looks like
> this ...
>
> #+TITLE: An Interesting Article
> #+AUTHOR: Simon Jones
> #+DATE: 2015-02-16
>
> Article content...
>
> Can anyone help me with this? I'm very sorry if I'm missing something
> obvious.
>
> Simon.

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

* Re: Separate Org file from Subtree
  2015-02-16 12:54 ` John Kitchin
@ 2015-02-16 14:40   ` simon
  2015-02-16 14:59     ` John Kitchin
  0 siblings, 1 reply; 6+ messages in thread
From: simon @ 2015-02-16 14:40 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

Thanks very much for this John.  As you say, the normal export "C-c C-e
C-s O o" does not work as expected. Your function exported the
properties properly, but seemed to work on the visible text only and
wouldn't export the content of  headings (unless I unfold them all prior
to import). If the article was like this:

* DONE Article One
 :PROPERTIES:
 :EXPORT_TITLE: An Interesting Article
 :EXPORT_AUTHOR: Simon Jones
:EXPORT_FILE_NAME: an-interesting-article
:EXPORT_DATE: 2015-02-16
 :END:

Article content ....

** Section title
Section content

it would export as intended but without the section content. Thanks
again for your time.

Simon
-------


On Mon, 16 Feb 2015, at 12:54 PM, John Kitchin wrote:
> Change :EXPORT_FILENAME: an-interesting-article to :EXPORT_FILE_NAME:
> an-interesting-article
> 
> Then,
> 
> C-c C-e C-s O o
> 
> should export to that file. I notice in the org export that the
> properties are not getting exported, and even the headline is not
> exported as the title though.
> 
> Here is a function that seems to do what you want.
> 
> #+BEGIN_SRC emacs-lisp
> (defun export-subtree ()
>  (interactive)
>  (let ((fname  (concat (org-entry-get (point) "EXPORT_FILE_NAME")
>  ".org"))
>        (author (org-entry-get (point) "EXPORT_AUTHOR"))
>        (title (org-entry-get (point) "EXPORT_TITLE"))
>        (date (org-entry-get (point) "EXPORT_DATE"))
>        (content (progn (set-buffer (org-org-export-as-org nil t t))
>                    (buffer-string))))
>    ;; warning you can delete something unintentionally
>    (when (file-exists-p fname) (delete-file fname))
>    (find-file fname)
>    (insert "#+TITLE: " title "\n")
>    (insert "#+AUTHOR: " author "\n")
>    (insert "#+DATE: " date "\n")
>    (insert "\n" content)
>    ;; remove properties drawer. Kind of hacky.
>    (goto-char (point-min))
>    (re-search-forward ":PROPERTIES:")
>    (setf (buffer-substring
>           (org-element-property :begin (org-element-context))
>           (org-element-property :end (org-element-context)))
>            "")
>    (save-buffer)))
> 
> (export-subtree)
> #+END_SRC
> 
> simon@psilas.com writes:
> 
> > Hi there,
> >
> > I think I must be missing something.
> >
> > I have  a collection of articles in one org file (under separate
> > headings). I can export these as a subtree using Org's normal export
> > function as html etc., but I want to export the selected subtree as an
> > individual org file using the properties under each heading.)
> >
> > In other words I want to export this subtree ...
> > * DONE Article One
> > :PROPERTIES:
> > :EXPORT_TITLE: An Interesting Article
> > :EXPORT_AUTHOR: Simon Jones
> > :EXPORT_FILENAME: an-interesting-article
> > :EXPORT_DATE: 2015-02-16
> > :END:
> >
> > Article content ....
> >
> > into an Org file entitled 'an-interesting-article.org' that looks like
> > this ...
> >
> > #+TITLE: An Interesting Article
> > #+AUTHOR: Simon Jones
> > #+DATE: 2015-02-16
> >
> > Article content...
> >
> > Can anyone help me with this? I'm very sorry if I'm missing something
> > obvious.
> >
> > Simon.
> 
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu

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

* Re: Separate Org file from Subtree
  2015-02-16 14:40   ` simon
@ 2015-02-16 14:59     ` John Kitchin
  2015-02-16 15:30       ` simon
  0 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2015-02-16 14:59 UTC (permalink / raw)
  To: simon; +Cc: emacs-orgmode

I think if you change (org-org-export-as-org nil t t) to
(org-org-export-as-org nil t) you would get the section content. I
didn't test it though.

simon@psilas.com writes:

> Thanks very much for this John.  As you say, the normal export "C-c C-e
> C-s O o" does not work as expected. Your function exported the
> properties properly, but seemed to work on the visible text only and
> wouldn't export the content of  headings (unless I unfold them all prior
> to import). If the article was like this:
>
> * DONE Article One
>  :PROPERTIES:
>  :EXPORT_TITLE: An Interesting Article
>  :EXPORT_AUTHOR: Simon Jones
> :EXPORT_FILE_NAME: an-interesting-article
> :EXPORT_DATE: 2015-02-16
>  :END:
>
> Article content ....
>
> ** Section title
> Section content
>
> it would export as intended but without the section content. Thanks
> again for your time.
>
> Simon
> -------
>
>
> On Mon, 16 Feb 2015, at 12:54 PM, John Kitchin wrote:
>> Change :EXPORT_FILENAME: an-interesting-article to :EXPORT_FILE_NAME:
>> an-interesting-article
>>
>> Then,
>>
>> C-c C-e C-s O o
>>
>> should export to that file. I notice in the org export that the
>> properties are not getting exported, and even the headline is not
>> exported as the title though.
>>
>> Here is a function that seems to do what you want.
>>
>> #+BEGIN_SRC emacs-lisp
>> (defun export-subtree ()
>>  (interactive)
>>  (let ((fname  (concat (org-entry-get (point) "EXPORT_FILE_NAME")
>>  ".org"))
>>        (author (org-entry-get (point) "EXPORT_AUTHOR"))
>>        (title (org-entry-get (point) "EXPORT_TITLE"))
>>        (date (org-entry-get (point) "EXPORT_DATE"))
>>        (content (progn (set-buffer (org-org-export-as-org nil t t))
>>                    (buffer-string))))
>>    ;; warning you can delete something unintentionally
>>    (when (file-exists-p fname) (delete-file fname))
>>    (find-file fname)
>>    (insert "#+TITLE: " title "\n")
>>    (insert "#+AUTHOR: " author "\n")
>>    (insert "#+DATE: " date "\n")
>>    (insert "\n" content)
>>    ;; remove properties drawer. Kind of hacky.
>>    (goto-char (point-min))
>>    (re-search-forward ":PROPERTIES:")
>>    (setf (buffer-substring
>>           (org-element-property :begin (org-element-context))
>>           (org-element-property :end (org-element-context)))
>>            "")
>>    (save-buffer)))
>>
>> (export-subtree)
>> #+END_SRC
>>
>> simon@psilas.com writes:
>>
>> > Hi there,
>> >
>> > I think I must be missing something.
>> >
>> > I have  a collection of articles in one org file (under separate
>> > headings). I can export these as a subtree using Org's normal export
>> > function as html etc., but I want to export the selected subtree as an
>> > individual org file using the properties under each heading.)
>> >
>> > In other words I want to export this subtree ...
>> > * DONE Article One
>> > :PROPERTIES:
>> > :EXPORT_TITLE: An Interesting Article
>> > :EXPORT_AUTHOR: Simon Jones
>> > :EXPORT_FILENAME: an-interesting-article
>> > :EXPORT_DATE: 2015-02-16
>> > :END:
>> >
>> > Article content ....
>> >
>> > into an Org file entitled 'an-interesting-article.org' that looks like
>> > this ...
>> >
>> > #+TITLE: An Interesting Article
>> > #+AUTHOR: Simon Jones
>> > #+DATE: 2015-02-16
>> >
>> > Article content...
>> >
>> > Can anyone help me with this? I'm very sorry if I'm missing something
>> > obvious.
>> >
>> > Simon.
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

* Re: Separate Org file from Subtree
  2015-02-16 14:59     ` John Kitchin
@ 2015-02-16 15:30       ` simon
  0 siblings, 0 replies; 6+ messages in thread
From: simon @ 2015-02-16 15:30 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

That's perfect John, works a treat!

Thank you very much.

Simon.
-------

On Mon, 16 Feb 2015, at 02:59 PM, John Kitchin wrote:
> I think if you change (org-org-export-as-org nil t t) to
> (org-org-export-as-org nil t) you would get the section content. I
> didn't test it though.
> 
> simon@psilas.com writes:
> 
> > Thanks very much for this John.  As you say, the normal export "C-c C-e
> > C-s O o" does not work as expected. Your function exported the
> > properties properly, but seemed to work on the visible text only and
> > wouldn't export the content of  headings (unless I unfold them all prior
> > to import). If the article was like this:
> >
> > * DONE Article One
> >  :PROPERTIES:
> >  :EXPORT_TITLE: An Interesting Article
> >  :EXPORT_AUTHOR: Simon Jones
> > :EXPORT_FILE_NAME: an-interesting-article
> > :EXPORT_DATE: 2015-02-16
> >  :END:
> >
> > Article content ....
> >
> > ** Section title
> > Section content
> >
> > it would export as intended but without the section content. Thanks
> > again for your time.
> >
> > Simon
> > -------
> >
> >
> > On Mon, 16 Feb 2015, at 12:54 PM, John Kitchin wrote:
> >> Change :EXPORT_FILENAME: an-interesting-article to :EXPORT_FILE_NAME:
> >> an-interesting-article
> >>
> >> Then,
> >>
> >> C-c C-e C-s O o
> >>
> >> should export to that file. I notice in the org export that the
> >> properties are not getting exported, and even the headline is not
> >> exported as the title though.
> >>
> >> Here is a function that seems to do what you want.
> >>
> >> #+BEGIN_SRC emacs-lisp
> >> (defun export-subtree ()
> >>  (interactive)
> >>  (let ((fname  (concat (org-entry-get (point) "EXPORT_FILE_NAME")
> >>  ".org"))
> >>        (author (org-entry-get (point) "EXPORT_AUTHOR"))
> >>        (title (org-entry-get (point) "EXPORT_TITLE"))
> >>        (date (org-entry-get (point) "EXPORT_DATE"))
> >>        (content (progn (set-buffer (org-org-export-as-org nil t t))
> >>                    (buffer-string))))
> >>    ;; warning you can delete something unintentionally
> >>    (when (file-exists-p fname) (delete-file fname))
> >>    (find-file fname)
> >>    (insert "#+TITLE: " title "\n")
> >>    (insert "#+AUTHOR: " author "\n")
> >>    (insert "#+DATE: " date "\n")
> >>    (insert "\n" content)
> >>    ;; remove properties drawer. Kind of hacky.
> >>    (goto-char (point-min))
> >>    (re-search-forward ":PROPERTIES:")
> >>    (setf (buffer-substring
> >>           (org-element-property :begin (org-element-context))
> >>           (org-element-property :end (org-element-context)))
> >>            "")
> >>    (save-buffer)))
> >>
> >> (export-subtree)
> >> #+END_SRC
> >>
> >> simon@psilas.com writes:
> >>
> >> > Hi there,
> >> >
> >> > I think I must be missing something.
> >> >
> >> > I have  a collection of articles in one org file (under separate
> >> > headings). I can export these as a subtree using Org's normal export
> >> > function as html etc., but I want to export the selected subtree as an
> >> > individual org file using the properties under each heading.)
> >> >
> >> > In other words I want to export this subtree ...
> >> > * DONE Article One
> >> > :PROPERTIES:
> >> > :EXPORT_TITLE: An Interesting Article
> >> > :EXPORT_AUTHOR: Simon Jones
> >> > :EXPORT_FILENAME: an-interesting-article
> >> > :EXPORT_DATE: 2015-02-16
> >> > :END:
> >> >
> >> > Article content ....
> >> >
> >> > into an Org file entitled 'an-interesting-article.org' that looks like
> >> > this ...
> >> >
> >> > #+TITLE: An Interesting Article
> >> > #+AUTHOR: Simon Jones
> >> > #+DATE: 2015-02-16
> >> >
> >> > Article content...
> >> >
> >> > Can anyone help me with this? I'm very sorry if I'm missing something
> >> > obvious.
> >> >
> >> > Simon.
> >>
> >> --
> >> Professor John Kitchin
> >> Doherty Hall A207F
> >> Department of Chemical Engineering
> >> Carnegie Mellon University
> >> Pittsburgh, PA 15213
> >> 412-268-7803
> >> @johnkitchin
> >> http://kitchingroup.cheme.cmu.edu
> 
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu

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

* Re: Separate Org file from Subtree
  2015-02-16 10:41 Separate Org file from Subtree simon
  2015-02-16 12:54 ` John Kitchin
@ 2015-08-05  0:00 ` Bastien Guerry
  1 sibling, 0 replies; 6+ messages in thread
From: Bastien Guerry @ 2015-08-05  0:00 UTC (permalink / raw)
  To: simon; +Cc: emacs-orgmode

Hi Simon,

with a recent Org (>8.0) :

- load ox-org.el (require 'ox-org)
- go to your heading
- trigger the export menu with C-c C-e
- restrict to the subtree with C-s
- export as an Org file with O o

HTH,

-- 
 Bastien

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

end of thread, other threads:[~2015-08-05  0:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-16 10:41 Separate Org file from Subtree simon
2015-02-16 12:54 ` John Kitchin
2015-02-16 14:40   ` simon
2015-02-16 14:59     ` John Kitchin
2015-02-16 15:30       ` simon
2015-08-05  0:00 ` Bastien Guerry

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).