From: Pierre Corry <284a6c54@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [HELP]: How to export top level trees in an org file to corresponding files?
Date: Wed, 21 Sep 2016 19:50:24 +0200 [thread overview]
Message-ID: <CAGbK8tfaXjzxOb+pt7HkAf=ma8jipMn0azKeq4wOvSWzSLke4w@mail.gmail.com> (raw)
In-Reply-To: <CAGbK8tfp-5OrRiudVZnyZYLyQSDUW1P6zyOROW8nc8jy2MyALg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 6820 bytes --]
Well, I ended up with my custom function then...
So case is closed.
Thank for the help anyway!
(defun me/org-map-entries (org-file in-tags func)
(let* ((tags (if (stringp in-tags)
(list in-tags)
in-tags)))
(with-temp-buffer
(org-mode)
(insert-file-contents org-file-main)
;; Execute func at each heading that matches tags.
(while (< (point) (point-max))
;; If find a heading...
(and (search-forward-regexp "^\* " nil "end")
;; ...that matches the given tags...
(seq-reduce
(lambda(a b) (and a b))
(mapcar
(lambda (tag)
(beginning-of-line)
(search-forward-regexp
(concat ":" tag ":") (line-end-position) "end"))
tags)
t)
;; ... then execute given function with cursor at beginning of
;; heading.
(progn
(beginning-of-line)
(save-excursion
(funcall func))
(end-of-line)))))))
2016-09-21 12:29 GMT+02:00 Pierre Corry <284a6c54@gmail.com>:
> Hi!
>
> Executing the following code should create, for each top level tree in
> your file `~/tmp/file.org`, an other file in `~/tmp` named after the tree
> heading and containing its content.
>
> Problem: it does not work.
>
> The content is not the one expected...
>
> Is it me or the code that is wrong? Both?
> Question on emacs.stackexchange
> <http://emacs.stackexchange.com/questions/27226/how-to-export-top-level-trees-in-an-org-file-to-corresponding-files>
>
> (require 'ox-publish)
>
> (let ()
> (with-temp-buffer
> (org-mode)
> (insert-file-contents "~/tmp/file.org")
> (set-mark (point-min))
> (goto-char (point-max))
>
> (org-map-entries
> (lambda ()
> (let ((entry_id (replace-regexp-in-string " " "_" (downcase
> (nth 4 (org-heading-components))))))
> (org-set-property
> "EXPORT_FILE_NAME"
> (expand-file-name entry_id "~/tmp")))
> (org-org-export-to-org nil t)
> )
> nil
> 'region-start-level)))
>
> Content of `file.org`:
>
> * Headline 1
> :ready:
>
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent
> libero orci,
> auctor sed, faucibus vestibulum, gravida vitae, arcu. Nunc posuere.
> Suspendisse
> potenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros.
> Sed pulvinar
> vehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta
> eu,
> leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci
> neque, faucibus
> et, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus
> facilisis
> augue. Nullam fringilla consectetuer sapien. Aenean neque augue,
> bibendum a,
> feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat
> condimentum
> pretium. Vestibulum tempor odio et leo. Sed sodales vestibulum
> justo. Cras
> convallis pellentesque augue. In eu magna. In pede turpis, feugiat
> pulvinar,
> sodales eget, bibendum consectetuer, magna. Pellentesque vitae augue.
>
> [[file:data/fool.jpg][Foo]]
>
>
>
> * Headline 2
> :ready:
>
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent
> libero orci,
> auctor sed, faucibus vestibulum, gravida vitae, arcu. Nunc posuere.
> Suspendisse
> potenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros.
> Sed pulvinar
> vehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta
> eu,
> leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci
> neque, faucibus
> et, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus
> facilisis
> augue. Nullam fringilla consectetuer sapien. Aenean neque augue,
> bibendum a,
> feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat
> condimentum
> pretium. Vestibulum tempor odio et leo. Sed sodales vestibulum
> justo. Cras
> convallis pellentesque augue. In eu magna. In pede turpis, feugiat
> pulvinar,
> sodales eget, bibendum consectetuer, magna. Pellentesque vitae augue.
>
> [[file:data/fool-2.jpg][Foo2]]
>
>
> Expected result:
>
> `heading_1.org`:
>
> * Headline 1
> :ready:
>
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent
> libero orci,
> auctor sed, faucibus vestibulum, gravida vitae, arcu. Nunc posuere.
> Suspendisse
> potenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros.
> Sed pulvinar
> vehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta
> eu,
> leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci
> neque, faucibus
> et, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus
> facilisis
> augue. Nullam fringilla consectetuer sapien. Aenean neque augue,
> bibendum a,
> feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat
> condimentum
> pretium. Vestibulum tempor odio et leo. Sed sodales vestibulum
> justo. Cras
> convallis pellentesque augue. In eu magna. In pede turpis, feugiat
> pulvinar,
> sodales eget, bibendum consectetuer, magna. Pellentesque vitae augue.
>
> [[file:data/fool.jpg][Foo]]
>
>
> `heading_2.org`:
>
> * Headline 2
> :ready:
>
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent
> libero orci,
> auctor sed, faucibus vestibulum, gravida vitae, arcu. Nunc posuere.
> Suspendisse
> potenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros.
> Sed pulvinar
> vehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta
> eu,
> leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci
> neque, faucibus
> et, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus
> facilisis
> augue. Nullam fringilla consectetuer sapien. Aenean neque augue,
> bibendum a,
> feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat
> condimentum
> pretium. Vestibulum tempor odio et leo. Sed sodales vestibulum
> justo. Cras
> convallis pellentesque augue. In eu magna. In pede turpis, feugiat
> pulvinar,
> sodales eget, bibendum consectetuer, magna. Pellentesque vitae augue.
>
> [[file:data/fool-2.jpg][Foo]]
>
> Maybe a duplicate of : [this question][1] but did not help...
>
> `GNU Emacs 25.1.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version
> 10.9.5 (Build 13F1911)) of 2016-09-17`
>
> `Org-mode version 8.3.6`
>
>
>
>
> [1]: http://emacs.stackexchange.com/questions/2259/how-to-
> export-top-level-headings-of-org-mode-buffer-to-separate-files "this
> question"
>
[-- Attachment #2: Type: text/html, Size: 10074 bytes --]
parent reply other threads:[~2016-09-21 17:51 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <CAGbK8tfp-5OrRiudVZnyZYLyQSDUW1P6zyOROW8nc8jy2MyALg@mail.gmail.com>]
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGbK8tfaXjzxOb+pt7HkAf=ma8jipMn0azKeq4wOvSWzSLke4w@mail.gmail.com' \
--to=284a6c54@gmail.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 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).