emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: [bug, patch, ox] INCLUDE and footnotes
Date: Sun, 21 Dec 2014 23:39:12 +0100	[thread overview]
Message-ID: <878ui039wv.fsf@gmx.us> (raw)
In-Reply-To: 87d27cyas6.fsf@nicolasgoaziou.fr

[-- Attachment #1: Type: text/plain, Size: 2510 bytes --]

Hi,

Thanks for the comments.  I've attached a new version.

Nicolas Goaziou <mail@nicolasgoaziou.fr> 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<point>#+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!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-ox.el-Guess-the-minlevel-for-INCLUDE-keywords.patch --]
[-- Type: text/x-diff, Size: 3879 bytes --]

From b7112471b3e4b5334d98caf528e1e687232dee2f Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
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<point>#+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<point>#+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


  reply	other threads:[~2014-12-21 22:39 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-09 11:44 [bug, patch, ox] INCLUDE and footnotes Rasmus
2014-12-09 19:10 ` Rasmus
2014-12-09 19:14 ` Nicolas Goaziou
2014-12-09 21:21   ` Rasmus
2014-12-09 21:37     ` Nicolas Goaziou
2014-12-10  0:57       ` Rasmus
2014-12-10 11:21         ` Nicolas Goaziou
2014-12-10 11:58           ` Rasmus
2014-12-10 15:44             ` Nicolas Goaziou
2014-12-13 21:45               ` Rasmus
2014-12-17 23:30                 ` Nicolas Goaziou
2014-12-18 17:37                   ` Rasmus
2014-12-19 16:44                     ` Rasmus
2014-12-21 21:04                       ` Nicolas Goaziou
2014-12-21 22:39                         ` Rasmus [this message]
2014-12-21 23:38                           ` Nicolas Goaziou
2014-12-22  1:42                             ` Rasmus
2014-12-22  9:05                               ` Nicolas Goaziou
2014-12-24 18:03                                 ` Rasmus
2014-12-24 21:14                                   ` Nicolas Goaziou
2014-12-25  1:38                                     ` Rasmus
2014-12-25  2:04                                     ` Rasmus
2014-12-21 20:52                     ` Nicolas Goaziou
2014-12-22  1:49                       ` Rasmus
2014-12-22 11:10                         ` Nicolas Goaziou
2014-12-22 12:36                           ` Rasmus
2014-12-22 20:54                             ` Nicolas Goaziou
2014-12-22 22:11                               ` Rasmus
2014-12-22 22:51                                 ` Nicolas Goaziou
2014-12-23  2:09                                   ` Rasmus
2014-12-24 17:54                                   ` Rasmus
2014-12-24 18:10                                     ` [git-101] How to push a branch and avoid merge-message? (was: [bug, patch, ox] INCLUDE and footnotes) Rasmus
2014-12-24 21:09                                       ` [git-101] How to push a branch and avoid merge-message? Nicolas Goaziou

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=878ui039wv.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --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).