From c9a52787c14c3a7429bcd3c8975350525e0baa04 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 24 Mar 2015 00:32:15 +0100 Subject: [PATCH] ox: Ignore export settings in commented subtrees * lisp/ox.el (org-export--delete-commented-subtrees): New function. (org-export-as): Use new function. * testing/lisp/test-ox.el (org-test-with-parsed-data, test-org-export/get-inbuffer-options): Use new function. (test-org-export/expand-macro): Add tests. Reported-by: Andreas Leha --- lisp/ox.el | 11 +++++++++++ testing/lisp/test-ox.el | 33 ++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index ec2685f5e..939673a93 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -2665,6 +2665,16 @@ The function assumes BUFFER's major mode is `org-mode'." (overlays-in (point-min) (point-max))) ov-set))))) +(defun org-export--delete-commented-subtrees () + "Delete commented subtrees or inlinetasks in the buffer." + (org-with-wide-buffer + (goto-char (point-min)) + (let ((regexp (concat org-outline-regexp-bol org-comment-string))) + (while (re-search-forward regexp nil t) + (delete-region + (line-beginning-position) + (org-element-property :end (org-element-at-point))))))) + (defun org-export--prune-tree (data info) "Prune non exportable elements from DATA. DATA is the parse tree to traverse. INFO is the plist holding @@ -2855,6 +2865,7 @@ Return code as a string." (run-hook-with-args 'org-export-before-processing-hook (org-export-backend-name backend)) (org-export-expand-include-keyword) + (org-export--delete-commented-subtrees) ;; Update macro templates since #+INCLUDE keywords might have ;; added some new ones. (org-macro-initialize-templates) diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index f5a065d11..be61f8223 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -48,6 +48,7 @@ body to execute. Parse tree is available under the `tree' variable, and communication channel under `info'." (declare (debug (form body)) (indent 1)) `(org-test-with-temp-text ,data + (org-export--delete-commented-subtrees) (let* ((tree (org-element-parse-buffer)) (info (org-export-get-environment))) (org-export--prune-tree tree info) @@ -187,7 +188,16 @@ variable, and communication channel under `info'." :options '((:k1 "KEYWORD") (:k2 "KEYWORD"))))) (org-test-with-temp-text "#+KEYWORD: value" - (org-export--get-inbuffer-options backend)))))) + (org-export--get-inbuffer-options backend))))) + ;; Keywords in commented subtrees are ignored. + (should-not + (equal "Me" + (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me" + (plist-get info :author)))) + (should-not + (equal "Mine" + (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine" + (plist-get info :email))))) (ert-deftest test-org-export/get-subtree-options () "Test setting options from headline's properties." @@ -1107,13 +1117,26 @@ Footnotes[fn:2], foot[fn:test], digit only[3], and [fn:inline:anonymous footnote ;; Date macro takes a optional formatting argument (should (equal "09-02-15\n" - (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>" - (org-export-as (org-test-default-backend))))) + (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>" + (org-export-as (org-test-default-backend))))) ;; Only single timestamps are formatted (should (equal "<2015-02x-09>\n" - (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>" - (org-export-as (org-test-default-backend)))))) + (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>" + (org-export-as (org-test-default-backend))))) + ;; Throw an error when a macro definition is missing. + (should-error + (org-test-with-temp-text "{{{missing}}}" + (org-export-as (org-test-default-backend)))) + ;; Macros defined in commented subtrees are ignored. + (should-error + (org-test-with-temp-text + "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}" + (org-export-as (org-test-default-backend)))) + (should-error + (org-test-with-temp-text + "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}" + (org-export-as (org-test-default-backend))))) (ert-deftest test-org-export/before-processing-hook () "Test `org-export-before-processing-hook'."