From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [bug, patch, ox] INCLUDE and footnotes Date: Mon, 22 Dec 2014 02:42:56 +0100 Message-ID: <87mw6g1mu7.fsf@gmx.us> References: <87h9x5hwso.fsf@gmx.us> <87oarcbppe.fsf@nicolasgoaziou.fr> <87fvcozfhf.fsf@gmx.us> <87h9x4bj33.fsf@nicolasgoaziou.fr> <87iohks4ne.fsf@gmx.us> <87d27rbvio.fsf@nicolasgoaziou.fr> <87bnnbhg2x.fsf@gmx.us> <878uifbjc7.fsf@nicolasgoaziou.fr> <87388j9qbv.fsf@gmx.us> <87y4q57t2i.fsf@nicolasgoaziou.fr> <87lhm4n9ky.fsf@pank.eu> <87y4q3a8tc.fsf@pank.eu> <87d27cyas6.fsf@nicolasgoaziou.fr> <878ui039wv.fsf@gmx.us> <878ui0y3nx.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2s1a-0007pk-Lx for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 20:43:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y2s1V-0004FS-7J for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 20:43:06 -0500 Received: from mout.gmx.net ([212.227.15.19]:53533) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2s1U-0004FM-Sx for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 20:43:01 -0500 Received: from W530 ([46.165.210.17]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0MFuC6-1Y5Yua0Hzi-00EvDr for ; Mon, 22 Dec 2014 02:42:58 +0100 In-Reply-To: <878ui0y3nx.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Mon, 22 Dec 2014 00:38:26 +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 Nicolas Goaziou writes: > I suggest to do it differently, then. We first process every include > keyword in the document, but simply add a text property (e.g. > `org-include-level') over them specifying > [...] > Include lines are not modified and this variable only applies to Org > documents. WDYT? That's a nice solution. Implemented in attached patch. Should this be added to ORG-NEWS? Is a "feature" or a "bug-fix"? Thanks, Rasmus -- Vote for proprietary math! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-ox.el-Guess-the-minlevel-for-INCLUDE-keywords.patch >From 1fa88054255e66922ea9e2cd61310461901ac6ee Mon Sep 17 00:00:00 2001 From: Rasmus Date: Thu, 18 Dec 2014 16:48:49 +0100 Subject: [PATCH 2/2] ox.el: Guess the :minlevel for INCLUDE-keywords * ox.el (org-export-expand-include-keyword): Guess :minlevel for included Org documents if missing. * test-ox.el (org-export-expand-include-keyword): Tests for automatic :minlevel. --- lisp/ox.el | 14 ++++++++++---- testing/lisp/test-ox.el | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 11b9a29..11426fb 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3063,10 +3063,17 @@ storing and resolving footnotes. It is created automatically." (let ((case-fold-search t) (file-prefix (make-hash-table :test #'equal)) (current-prefix 0) - (footnotes (or footnotes (make-hash-table :test #'equal)))) + (footnotes (or footnotes (make-hash-table :test #'equal))) + (include-re "^[ \t]*#\\+INCLUDE:")) + ;; Add :minlevel to all include words that no explicitly have one. (goto-char (point-min)) + (while (re-search-forward include-re nil t) + (add-text-properties (line-beginning-position) (line-end-position) + `(org-include-induced-level + ,(1+ (org-reduced-level (or (org-current-level) 0)))))) ;; Expand INCLUDE keywords. - (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t) + (goto-char (point-min)) + (while (re-search-forward include-re nil t) (let ((element (save-match-data (org-element-at-point)))) (when (eq (org-element-type element) 'keyword) (beginning-of-line) @@ -3111,8 +3118,7 @@ storing and resolving footnotes. It is created automatically." (if (string-match ":minlevel +\\([0-9]+\\)" value) (prog1 (string-to-number (match-string 1 value)) (setq value (replace-match "" nil nil value))) - (let ((cur (org-current-level))) - (if cur (1+ (org-reduced-level cur)) 1))))) + (get-text-property (point) 'org-include-induced-level)))) (src-args (and (eq env 'literal) (match-string 1 value))) (block (and (string-match "\\<\\(\\S-+\\)\\>" value) diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 37e2e23..91f9eab 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -1003,7 +1003,44 @@ Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote (org-test-with-temp-text (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir) (org-export-expand-include-keyword) - (buffer-string))))) + (buffer-string)))) + ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified. + (should + (org-every (lambda (level) (zerop (1- level))) + (org-test-with-temp-text + (concat + (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n" org-test-dir) + (format "#+INCLUDE: \"%s/examples/include.org::*Heading\"" org-test-dir)) + (org-export-expand-include-keyword) + (org-element-map (org-element-parse-buffer) 'headline + (lambda (head) (org-element-property :level head)))))) + ;; INCLUDE does not insert induced :minlevel for src-blocks. + (should-not + (equal + (org-test-with-temp-text + (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir) + (org-export-expand-include-keyword) + (buffer-string)) + (org-test-with-temp-text + (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1" org-test-dir) + (org-export-expand-include-keyword) + (buffer-string)))) + ;; INCLUDE assigns the relative :minlevel conditional on narrowing. + (should + (org-test-with-temp-text + (format "* h1\n#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir) + (org-narrow-to-element) + (org-export-expand-include-keyword) + (goto-char (point-min)) + (eq 1 (org-element-property :level (org-element-at-point))))) + ;; If :minlevel is present do not alter it. + (should + (org-test-with-temp-text + (format "* h1\n#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3" org-test-dir) + (org-narrow-to-element) + (org-export-expand-include-keyword) + (goto-char (point-min)) + (eq 3 (org-element-property :level (org-element-at-point)))))) (ert-deftest test-org-export/expand-macro () "Test macro expansion in an Org buffer." -- 2.2.1 --=-=-=--