[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] [RFC PATCH] ox-extra: Merge sections from ignored headlines
From: |
Kyle Meyer |
Subject: |
[O] [RFC PATCH] ox-extra: Merge sections from ignored headlines |
Date: |
Sat, 29 Apr 2017 12:58:49 -0400 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] [RFC PATCH] ox-extra: Merge sections from ignored headlines,
Kyle Meyer <=