From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [bug, patch, ox] INCLUDE and footnotes Date: Tue, 09 Dec 2014 20:10:46 +0100 Message-ID: <87mw6wskp5.fsf@gmx.us> References: <87h9x5hwso.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyQBb-000168-16 for emacs-orgmode@gnu.org; Tue, 09 Dec 2014 14:11:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XyQBV-0000oU-NN for emacs-orgmode@gnu.org; Tue, 09 Dec 2014 14:11:02 -0500 Received: from plane.gmane.org ([80.91.229.3]:36472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyQBV-0000oK-Ge for emacs-orgmode@gnu.org; Tue, 09 Dec 2014 14:10:57 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XyQBU-0005dU-Fl for emacs-orgmode@gnu.org; Tue, 09 Dec 2014 20:10:56 +0100 Received: from 46.166.186.232 ([46.166.186.232]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Dec 2014 20:10:56 +0100 Received: from rasmus by 46.166.186.232 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Dec 2014 20:10:56 +0100 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Rasmus writes: > The attached patch fixes this by explicitly saving the footnote section As per usual my first patch is dodgy. It occurred to me that Org can handle several footnote sections (that's how #+INCLUDE supports footnotes, I guess). The attached patch how supports export of t2.org in this example $> cat t{1,2}.org # this is t1.org * foo bar[fn:1] baz[fn:2] * Footnotes [fn:1] bar.corp * Footnotes [fn:2] baz.corp # this is t2.org #+INCLUDE: "/tmp/t1.org::*foo" However, there is a pitch-fall when doing #+INCLUDE: "/tmp/t1.org::*foo0" #+INCLUDE: "/tmp/t1.org::*foo1" Now *foo1 will be inserted under the footnote-heading of *foo0 which means it won't be exported. If min-level is used this is not an issue of course, but that's kind of unexpected (so is the fact that the second include will become a child of the first include, but that's another patch) . Perhaps a better overall approach (if the above limitation is unacceptable) would to translate all footnotes in an INCLUDEd file to inline ones, e.g. when including * foo in t1.org above, what would be inserted is * foo bar[fn::bar.corp] baz[fn::baz.corp] Yet another solution would be to return a cond of (included-text . included-footnotes) and make sure to insert footnotes at the very end. WDYT? —Rasmus -- . . . The proofs are technical in nature and provides no real understanding --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox.el-Fix-footnote-bug-in-INCLUDE-keyword.patch >From 2a943b40c024df092cc2cf020bdf2646e7ab4b2c Mon Sep 17 00:00:00 2001 From: rasmus Date: Tue, 9 Dec 2014 12:40:52 +0100 Subject: [PATCH] ox.el: Fix footnote-bug in #+INCLUDE-keyword * ox.el (org-export--prepare-file-contents): Preserve footnote-section when using the LINES argument. --- lisp/ox.el | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 9d9e794..bf2ce4d 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3260,8 +3260,27 @@ with footnotes is included in a document." (end (if (zerop lend) (point-max) (goto-char (point-min)) (forward-line (1- lend)) - (point)))) - (narrow-to-region beg end))) + (point))) + (footnote-section-re + (concat "^\\*+[ \t]+" org-footnote-section "[ \t]*$")) + (footnote-sections + (save-match-data + (save-excursion + (goto-char (point-min)) + (loop do + (or (search-forward-regexp footnote-section-re nil t) + (end-of-buffer)) + while (not (eobp)) + collect + (buffer-substring + (line-beginning-position) + (or (and + (search-forward-regexp org-heading-regexp nil t) + (goto-char (match-beginning 0))) + (point-max)))))))) + (narrow-to-region beg end) + (and footnote-sections + (insert "\n" (mapconcat 'identity footnote-sections "\n"))))) ;; Remove blank lines at beginning and end of contents. The logic ;; behind that removal is that blank lines around include keyword ;; override blank lines in included file. -- 2.1.3 --=-=-=--