emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: [HELP]: How to export top level trees in an org file to corresponding files?
       [not found] <CAGbK8tfp-5OrRiudVZnyZYLyQSDUW1P6zyOROW8nc8jy2MyALg@mail.gmail.com>
@ 2016-09-21 17:50 ` Pierre Corry
  0 siblings, 0 replies; only message in thread
From: Pierre Corry @ 2016-09-21 17:50 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-09-21 17:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAGbK8tfp-5OrRiudVZnyZYLyQSDUW1P6zyOROW8nc8jy2MyALg@mail.gmail.com>
2016-09-21 17:50 ` [HELP]: How to export top level trees in an org file to corresponding files? Pierre Corry

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