emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [RFC PATCH] ox-extra: Merge sections from ignored headlines
@ 2017-04-29 16:58 Kyle Meyer
  0 siblings, 0 replies; only message in thread
From: Kyle Meyer @ 2017-04-29 16:58 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: aaronecay, edgimar

Hello,

I'd like to apply the following patch to maint.  It solves an issue that
results from using ox-extra's "ignore headlines" feature along with
ox-texinfo.  org-export-ignore-headlines transforms the tree to remove
headlines with the "ignore" tag, moving the ignored headline's content
to the previous element.  This can result in a headline having multiple
sections, which in turn results in ox-texinfo generating multiple menu
entries.

I described the problem in a bit more detail here:
https://github.com/magit/magit/pull/2914#issuecomment-294663336

A couple questions:

  * ox-texinfo is correct in assuming the one headline to one section
    mapping, right?  I think so, but I wasn't able to find any specific
    documentation on this.

  * Does this patch seem like a reasonable approach?  I wasn't able to
    think of a way to modify org-export-ignore-headlines so that it
    doesn't create multiple sections in the first place.

Thanks.

-- >8 --
Subject: [RFC PATCH] ox-extra: Merge sections from ignored headlines

* contrib/lisp/ox-extra.el (org-extra--merge-sections): New function.
(org-export-ignore-headlines): Merge multiple sections that result
from removing ignored headlines.

Prevent org-export-ignore-headlines from violating the one headline to
one section mapping that is relied on by at least one export backend,
ox-texinfo.  (ox-texinfo uses each section to generate the menu.)
---
 contrib/lisp/ox-extra.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/contrib/lisp/ox-extra.el b/contrib/lisp/ox-extra.el
index 85dae471f..cc01edf54 100644
--- a/contrib/lisp/ox-extra.el
+++ b/contrib/lisp/ox-extra.el
@@ -150,8 +150,27 @@ (defun org-export-ignore-headlines (data backend info)
                 (org-element-contents object)))
         (org-element-extract-element object)))
     info nil)
+  (org-extra--merge-sections data backend info)
   data)
 
+(defun org-extra--merge-sections (data _backend info)
+  (org-element-map data 'headline
+    (lambda (hl)
+      (let ((sections
+             (cl-loop
+              for el in (org-element-map (org-element-contents hl)
+                            '(headline section) #'identity info)
+              until (eq (org-element-type el) 'headline)
+              collect el)))
+        (when (and sections
+                   (> (length sections) 1))
+          (apply #'org-element-adopt-elements
+                 (car sections)
+                 (cl-mapcan (lambda (s) (org-element-contents s))
+                            (cdr sections)))
+          (mapc #'org-element-extract-element (cdr sections)))))
+    info))
+
 (defconst ox-extras
   '((latex-header-blocks org-latex-header-blocks-filter org-export-before-parsing-hook)
     (ignore-headlines org-export-ignore-headlines org-export-filter-parse-tree-functions))
-- 
2.12.2

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

only message in thread, other threads:[~2017-04-29 16:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-29 16:58 [RFC PATCH] ox-extra: Merge sections from ignored headlines Kyle Meyer

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