From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: [RFC PATCH] ox-extra: Merge sections from ignored headlines Date: Sat, 29 Apr 2017 12:58:49 -0400 Message-ID: <87lgqj6th2.fsf@kyleam.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4Vi3-0004e9-OX for emacs-orgmode@gnu.org; Sat, 29 Apr 2017 12:59:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4Vhz-0005iU-FZ for emacs-orgmode@gnu.org; Sat, 29 Apr 2017 12:59:03 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:54046 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d4Vhz-0005hu-A0 for emacs-orgmode@gnu.org; Sat, 29 Apr 2017 12:58:59 -0400 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: emacs-orgmode@gnu.org Cc: aaronecay@gmail.com, edgimar@gmail.com 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