From: Kyle Meyer <kyle@kyleam.com>
To: emacs-orgmode@gnu.org
Cc: aaronecay@gmail.com, edgimar@gmail.com
Subject: [RFC PATCH] ox-extra: Merge sections from ignored headlines
Date: Sat, 29 Apr 2017 12:58:49 -0400 [thread overview]
Message-ID: <87lgqj6th2.fsf@kyleam.com> (raw)
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.)
---
| 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
--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
reply other threads:[~2017-04-29 16:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87lgqj6th2.fsf@kyleam.com \
--to=kyle@kyleam.com \
--cc=aaronecay@gmail.com \
--cc=edgimar@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).