* strange results with org-map-entries
@ 2017-01-10 18:06 Matt Price
2017-01-10 23:58 ` Nicolas Goaziou
0 siblings, 1 reply; 4+ messages in thread
From: Matt Price @ 2017-01-10 18:06 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1: Type: text/plain, Size: 2982 bytes --]
On Tue, Jan 10, 2017 at 9:47 AM, Matt Price <moptop99@gmail.com> wrote:
>
> In a buffer with text before the first heading, I get an error using
> org-map-entries in this function:
>
> (defun org-export-all (backend)
> "Export all subtrees that are *not* tagged with :noexport: to
> separate files.
>
> Note that subtrees must have the :EXPORT_FILE_NAME: property set
> to a unique value for this to work properly."
> (interactive "sEnter backend: ")
> (let ((fn (cond ((equal backend "html") 'org-html-export-to-html)
> ((equal backend "latex") 'org-latex-export-to-latex)
> ((equal backend "pdf") 'org-latex-export-to-pdf))))
> (save-excursion
> (set-mark (point-min))
> (goto-char (point-max))
> (org-map-entries (lambda () (funcall fn nil t)) "-noexport" 'region-start-level))))
>
> The error is :
> Debugger entered--Lisp error: (error "Before first headline at position 1 in buffer test.org<2>")
>
> Is there a better way to map over first-level heading,
> or alternatively, a better way to set the mark? I tried setting mark to :
>
>
> (goto-char (point-min)) (re-search-forward "
> \\\*"))
>
> but that gave strange results, with the wrong trees
> being sent to individual files.
>
> I think I misrepresented the problem in my initial email.
With a test file test-export.org:
-----------
Pre-heading text
* Heading 1
:PROPERTIES:
:EXPORT_FILE_NAME: 01-heading-1
:END:
text of heading 1
* Heading 2
:PROPERTIES:
:EXPORT_FILE_NAME: 02-heading-2
:END:
text of heading 2
-----------
running eval-expression
(org-map-entries (lambda () (funcall 'org-org-export-to-org nil t))
"-noexport" nil)
gives the expected result (2 line breaks added for ease of reading):
-------------------------
$ cat 01-heading-1.org 02-heading-2.org
# Created 2017-01-10 Tue 12:51
#+TITLE: Heading 1
#+AUTHOR: Matt Price
text of heading 1
# Created 2017-01-10 Tue 12:51
#+TITLE: Heading 2
#+AUTHOR: Matt Price
text of heading 2
-------------------------------
However, running
#+BEGIN_SRC emacs-lisp
(set-mark (point-min))
(goto-char (point-max))
(org-map-entries (lambda () (funcall 'org-org-export-to-org nil t))
"-noexport" 'region-start-level)
#+END_SRC
gives the error:
Debugger entered--Lisp error: (error "Before first headline at position 1
in buffer export.org<2>")
If I delete the text before the first heading, the command runs without
error but produces the following output:
--------
$ cat 01-heading-1.org 02-heading-2.org
# Created 2017-01-10 Tue 12:57
#+TITLE: Heading 1
#+AUTHOR: Matt Price
text of heading 1
# Created 2017-01-10 Tue 12:57
#+TITLE: Heading 1
#+AUTHOR: Matt Price
* Heading 1
text of heading 1
-------------
If I make additional headings, en every case the content of the resultant
files will be replaced by the contents of the first file.
What's going on here? Can anyone else reproduce this? I'm seeing it on org
9.0.3 up to date as of today, emacs git from 2017-01-04.
[-- Attachment #2: Type: text/html, Size: 12418 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: strange results with org-map-entries 2017-01-10 18:06 strange results with org-map-entries Matt Price @ 2017-01-10 23:58 ` Nicolas Goaziou 2017-01-11 0:34 ` Matt Price 0 siblings, 1 reply; 4+ messages in thread From: Nicolas Goaziou @ 2017-01-10 23:58 UTC (permalink / raw) To: Matt Price; +Cc: Org Mode Hello, Matt Price <moptop99@gmail.com> writes: > What's going on here? Can anyone else reproduce this? I'm seeing it on org > 9.0.3 up to date as of today, emacs git from 2017-01-04. You mark a region then jump around the buffer with `org-map-entries'. At some point the region contains no headline, but you request a subtree export, hence the error. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: strange results with org-map-entries 2017-01-10 23:58 ` Nicolas Goaziou @ 2017-01-11 0:34 ` Matt Price 2017-01-11 14:01 ` Matt Price 0 siblings, 1 reply; 4+ messages in thread From: Matt Price @ 2017-01-11 0:34 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 668 bytes --] On Tue, Jan 10, 2017 at 6:58 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote: > Hello, > > Matt Price <moptop99@gmail.com> writes: > > > What's going on here? Can anyone else reproduce this? I'm seeing it on > org > > 9.0.3 up to date as of today, emacs git from 2017-01-04. > > You mark a region then jump around the buffer with `org-map-entries'. At > some point the region contains no headline, but you request a subtree > export, hence the error. > But what about the weird export results, where files don't seem to contain the expected content? And is there a better way (than marking and bouncing) to constrain org-map-entries to first-level headings only? [-- Attachment #2: Type: text/html, Size: 1115 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: strange results with org-map-entries 2017-01-11 0:34 ` Matt Price @ 2017-01-11 14:01 ` Matt Price 0 siblings, 0 replies; 4+ messages in thread From: Matt Price @ 2017-01-11 14:01 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 2594 bytes --] On Tue, Jan 10, 2017 at 7:34 PM, Matt Price <moptop99@gmail.com> wrote: > > > On Tue, Jan 10, 2017 at 6:58 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> > wrote: > >> Hello, >> >> Matt Price <moptop99@gmail.com> writes: >> >> > What's going on here? Can anyone else reproduce this? I'm seeing it on >> org >> > 9.0.3 up to date as of today, emacs git from 2017-01-04. >> >> You mark a region then jump around the buffer with `org-map-entries'. At >> some point the region contains no headline, but you request a subtree >> export, hence the error. >> > > But what about the weird export results, where files don't seem to contain > the expected content? And is there a better way (than marking and bouncing) > to constrain org-map-entries to first-level headings only? > Well, I can't answer the first question, about the wierd export results, but here at least is a better way, using org-element-map: (defun mwp-org-export-all-to-org () (interactive) (org-element-map (org-element-parse-buffer)'headline (lambda (headline) (let ((begin (org-element-property :begin headline)) (level (org-element-property :level headline)) (commentedp (org-element-property :commentedp headline)) (tags (org-element-property :tags headline))) (unless (or (> level 1) commentedp (member "noexport" tags) ;; I would prefer to get the exclude-tags dynamically but ;; I'm not sure how to do it properly -- need to access exclude-tags somehow ;; (cl-loop for k in (plist-get options :exclude-tags) ;; thereis (member k tags)) ) (save-excursion (goto-char begin) (org-org-export-to-org nil t ))))))) On Tue, Jan 10, 2017 at 7:34 PM, Matt Price <moptop99@gmail.com> wrote: > > > On Tue, Jan 10, 2017 at 6:58 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> > wrote: > >> Hello, >> >> Matt Price <moptop99@gmail.com> writes: >> >> > What's going on here? Can anyone else reproduce this? I'm seeing it on >> org >> > 9.0.3 up to date as of today, emacs git from 2017-01-04. >> >> You mark a region then jump around the buffer with `org-map-entries'. At >> some point the region contains no headline, but you request a subtree >> export, hence the error. >> > > But what about the weird export results, where files don't seem to contain > the expected content? And is there a better way (than marking and bouncing) > to constrain org-map-entries to first-level headings only? > [-- Attachment #2: Type: text/html, Size: 4442 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-01-11 14:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-01-10 18:06 strange results with org-map-entries Matt Price 2017-01-10 23:58 ` Nicolas Goaziou 2017-01-11 0:34 ` Matt Price 2017-01-11 14:01 ` Matt Price
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.