From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: strange results with org-map-entries Date: Tue, 10 Jan 2017 13:06:44 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f403045c12b4d7d3ba0545c15875 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cR0op-0005yj-Nd for emacs-orgmode@gnu.org; Tue, 10 Jan 2017 13:06:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cR0oo-0008U3-6u for emacs-orgmode@gnu.org; Tue, 10 Jan 2017 13:06:47 -0500 Received: from mail-it0-x232.google.com ([2607:f8b0:4001:c0b::232]:32996) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cR0oo-0008Tl-0p for emacs-orgmode@gnu.org; Tue, 10 Jan 2017 13:06:46 -0500 Received: by mail-it0-x232.google.com with SMTP id c20so23025536itb.0 for ; Tue, 10 Jan 2017 10:06:45 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --f403045c12b4d7d3ba0545c15875 Content-Type: text/plain; charset=UTF-8 On Tue, Jan 10, 2017 at 9:47 AM, Matt Price 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. --f403045c12b4d7d3ba0545c15875 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Tue, Jan 10, 2017 at 9:47 AM, Matt Price <moptop99@gmail.com&g= t; 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 :noexp=
ort: 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 backe=
nd: ")
  (let ((fn (cond ((equal backend "html") 'org-html-export-to-html<=
span class=3D"gmail-m_-3910960080772582379gmail-m_-3208652805390946851gmail=
-clo">)
                  ((equal backend=
 "latex") 'org-latex-export-to-latex)
                  ((equal backend=
 "pdf") &=
#39;org-latex-export-to-pdf))))
    (save-excursion
      (set-mark (po=
int-min))
      (goto-char (p=
oint-max))
      (org-map-entries (lambda () (funcall fn nil t)) "-noexport"=
 'region-start-level))))
<= br>
The error is :<=
br>Debugger entered--Lisp error: (error "Before first headline at posi=
tion 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.

<= /blockquote>
I think I misrepresented the problem in my initial email.= =C2=A0

With a test file test-export.org:

-----------
Pre-heading text

* Hea= ding 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 read= ing):

-------------------------
$ cat 01-heading-1.org 02-headin= g-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))
=C2=A0=C2=A0=C2=A0 (go= to-char (point-max))
=C2=A0=C2=A0=C2=A0 (org-map-entries (lambda () (fun= call 'org-org-export-to-org nil t)) "-noexport" 'region-s= tart-level)
#+END_SRC

gives the error:

Debugger= entered--Lisp error: (error "Before first headline at position 1 in b= uffer export.org<2>")

<= /div>

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 he= ading 1

# Created 2017-01-10 Tue 12:57
#+TITLE: Heading 1
#+AU= THOR: Matt Price
* Heading 1
text of heading 1
-------------

If I make additional headings, en every case the co= ntent of the resultant files will be replaced by the contents of the first = file.=C2=A0

What's going on here? Can any= one else reproduce this? I'm seeing it on org 9.0.3 up to date as of to= day, emacs git from 2017-01-04.=C2=A0

--f403045c12b4d7d3ba0545c15875--