|
From: | Pierre Corry |
Subject: | Re: [O] [HELP]: How to export top level trees in an org file to corresponding files? |
Date: | Wed, 21 Sep 2016 19:50:24 +0200 |
(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)))))))
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?(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. Suspendissepotenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros. Sed pulvinarvehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta eu,leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci neque, faucibuset, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus facilisisaugue. Nullam fringilla consectetuer sapien. Aenean neque augue, bibendum a,feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat condimentumpretium. Vestibulum tempor odio et leo. Sed sodales vestibulum justo. Crasconvallis 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. Suspendissepotenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros. Sed pulvinarvehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta eu,leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci neque, faucibuset, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus facilisisaugue. Nullam fringilla consectetuer sapien. Aenean neque augue, bibendum a,feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat condimentumpretium. Vestibulum tempor odio et leo. Sed sodales vestibulum justo. Crasconvallis 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:* Headline 1 :ready:Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent libero orci,auctor sed, faucibus vestibulum, gravida vitae, arcu. Nunc posuere. Suspendissepotenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros. Sed pulvinarvehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta eu,leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci neque, faucibuset, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus facilisisaugue. Nullam fringilla consectetuer sapien. Aenean neque augue, bibendum a,feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat condimentumpretium. Vestibulum tempor odio et leo. Sed sodales vestibulum justo. Crasconvallis 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. Suspendissepotenti. Praesent in arcu ac nisl ultricies ultricies. Fusce eros. Sed pulvinarvehicula ante. Maecenas urna dolor, egestas vel, tristique et, porta eu,leo. Curabitur vitae sem eget arcu laoreet vulputate. Cras orci neque, faucibuset, rhoncus ac, venenatis ac, magna. Aenean eu lacus. Aliquam luctus facilisisaugue. Nullam fringilla consectetuer sapien. Aenean neque augue, bibendum a,feugiat id, lobortis vel, nunc. Suspendisse in nibh quis erat condimentumpretium. Vestibulum tempor odio et leo. Sed sodales vestibulum justo. Crasconvallis 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`
[Prev in Thread] | Current Thread | [Next in Thread] |