emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt Price <moptop99@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: strange results with org-map-entries
Date: Tue, 10 Jan 2017 13:06:44 -0500	[thread overview]
Message-ID: <CAN_Dec8frKUqBGAX3Kopdm4A1gvvWykbpHwPcUWsqyTSM9XxvA@mail.gmail.com> (raw)

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

             reply	other threads:[~2017-01-10 18:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10 18:06 Matt Price [this message]
2017-01-10 23:58 ` strange results with org-map-entries Nicolas Goaziou
2017-01-11  0:34   ` Matt Price
2017-01-11 14:01     ` Matt Price

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=CAN_Dec8frKUqBGAX3Kopdm4A1gvvWykbpHwPcUWsqyTSM9XxvA@mail.gmail.com \
    --to=moptop99@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).