Browse Source

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 <andreas.leha@med.uni-goettingen.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/96267>
Nicolas Goaziou 10 years ago
parent
commit
c9a52787c1
2 changed files with 39 additions and 5 deletions
  1. 11 0
      lisp/ox.el
  2. 28 5
      testing/lisp/test-ox.el

+ 11 - 0
lisp/ox.el

@@ -2665,6 +2665,16 @@ The function assumes BUFFER's major mode is `org-mode'."
 	      (overlays-in (point-min) (point-max)))
 	      (overlays-in (point-min) (point-max)))
 	     ov-set)))))
 	     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)
 (defun org-export--prune-tree (data info)
   "Prune non exportable elements from DATA.
   "Prune non exportable elements from DATA.
 DATA is the parse tree to traverse.  INFO is the plist holding
 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
 	 (run-hook-with-args 'org-export-before-processing-hook
 			     (org-export-backend-name backend))
 			     (org-export-backend-name backend))
 	 (org-export-expand-include-keyword)
 	 (org-export-expand-include-keyword)
+	 (org-export--delete-commented-subtrees)
 	 ;; Update macro templates since #+INCLUDE keywords might have
 	 ;; Update macro templates since #+INCLUDE keywords might have
 	 ;; added some new ones.
 	 ;; added some new ones.
 	 (org-macro-initialize-templates)
 	 (org-macro-initialize-templates)

+ 28 - 5
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'."
 variable, and communication channel under `info'."
   (declare (debug (form body)) (indent 1))
   (declare (debug (form body)) (indent 1))
   `(org-test-with-temp-text ,data
   `(org-test-with-temp-text ,data
+     (org-export--delete-commented-subtrees)
      (let* ((tree (org-element-parse-buffer))
      (let* ((tree (org-element-parse-buffer))
 	    (info (org-export-get-environment)))
 	    (info (org-export-get-environment)))
        (org-export--prune-tree tree info)
        (org-export--prune-tree tree info)
@@ -187,7 +188,16 @@ variable, and communication channel under `info'."
 			  :options '((:k1 "KEYWORD")
 			  :options '((:k1 "KEYWORD")
 				     (:k2 "KEYWORD")))))
 				     (:k2 "KEYWORD")))))
 	    (org-test-with-temp-text "#+KEYWORD: value"
 	    (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 ()
 (ert-deftest test-org-export/get-subtree-options ()
   "Test setting options from headline's properties."
   "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
   ;; Date macro takes a optional formatting argument
   (should
   (should
    (equal "09-02-15\n"
    (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
   ;; Only single timestamps are formatted
   (should
   (should
    (equal "<2015-02x-09>\n"
    (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 ()
 (ert-deftest test-org-export/before-processing-hook ()
   "Test `org-export-before-processing-hook'."
   "Test `org-export-before-processing-hook'."