From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [bug, patch, ox] INCLUDE and footnotes Date: Sun, 21 Dec 2014 23:39:12 +0100 Message-ID: <878ui039wv.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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2p9y-0000wP-6G for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 17:39:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y2p9s-0004Uu-LC for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 17:39:34 -0500 Received: from plane.gmane.org ([80.91.229.3]:38057) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2p9s-0004Tg-A8 for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 17:39:28 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Y2p9p-0007wd-TC for emacs-orgmode@gnu.org; Sun, 21 Dec 2014 23:39:25 +0100 Received: from 46.165.210.17 ([46.165.210.17]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Dec 2014 23:39:25 +0100 Received: from rasmus by 46.165.210.17 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Dec 2014 23:39:25 +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 Hi, Thanks for the comments. I've attached a new version. Nicolas Goaziou writes: >> The recognition regexp is still not great, but the idea of the regexp >> is to only act on includes where there's no :minlevel already and no >> plain words (most obviously src and example, but any block really) >> when disregarding ":key value" pairs. > > This is not necessary. Even if :minlevel is used on these include > keywords, its value is ignored when inserting contents of the file. It's not neural to the org export buffer, though it's probably neutral to the *exported* document. E.g. (org-test-with-temp-text (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp" org-test-dir) (org-export-expand-include-keyword) (buffer-string)) => "#+BEGIN_src emacs-lisp :minlevel 1 Success! #+END_src " Which is turn is passed to babel (which also seems to ignoring it). I cannot easily condition on src (without using the previous complex regexp) since the file "~/my src folder/FILE" is not totally unlikely... If you are happy with the alteration, which might only be manifested in slightly uglier tests then we can go with the simpler solution. Note, for blocks the minlevel is not inserted: (org-test-with-temp-text (format "#+INCLUDE: \"%s/examples/include2.org\" foo" org-test-dir) (org-export-expand-include-keyword) (buffer-string)) => "#+BEGIN_foo Success! #+END_foo " >> + (while (re-search-forward >> + (concat include-re "[ \t]*" "\\(?:\".+?\"\\|[^ \t]+\\)[ \t]*" "\\(.*\\)$") >> + nil t) > > (re-search-forward include-re nil t) > > is enough. The regexp was motivated by the above concerns. >> + (insert (format " :minlevel %d" >> + (1+ (org-with-wide-buffer >> + (if (search-backward-regexp org-heading-regexp nil t) >> + (length (match-string 1)) >> + 0))))))))) > (insert (format " :minlevel %d" (1+ (org-outline-level)))) But this if the buffer is narrowed this would not work "correctly" in getting the "right" level. But it probably does not matter for export. See this test for my initial reasoning: (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 2 (org-element-property :level (org-element-at-point))))) This is changed now. —Rasmus -- Enough with the bla bla! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-ox.el-Guess-the-minlevel-for-INCLUDE-keywords.patch >From b7112471b3e4b5334d98caf528e1e687232dee2f 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 if missing and relevant. * test-ox.el (org-export-expand-include-keyword): Tests for automatic :minlevel. --- lisp/ox.el | 6 ++++++ testing/lisp/test-ox.el | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 99c4e9b..b65cea0 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3065,8 +3065,14 @@ storing and resolving footnotes. It is created automatically." (current-prefix 0) (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) + (unless (search-forward-regexp "[ \t]+:minlevel\\>" (line-end-position) t) + (end-of-line) + (insert (format " :minlevel %d" (1+ (org-outline-level)))))) ;; Expand INCLUDE keywords. + (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) diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 140c0a8..794de1f 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -854,7 +854,7 @@ text ;; Inclusion within a src-block. (should (equal - "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n" + "#+BEGIN_SRC emacs-lisp :minlevel 1\n(+ 2 1)\n#+END_SRC\n" (org-test-with-temp-text (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp" @@ -1045,7 +1045,44 @@ baz (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 is automatically inserted for src elements. + (should + (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 1" 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)))))) (ert-deftest test-org-export/expand-macro () "Test macro expansion in an Org buffer." -- 2.2.1 --=-=-=--