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!