From 5a0239b9fc0124608964f8fe0370632c56659794 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 2 Mar 2013 14:34:45 +0100 Subject: [PATCH] ox: Ignore inlinetasks with a :noexport: tag * lisp/ox.el (org-export--selected-trees): Also mark inlinetasks with a select tag. (org-export--skip-p): Skip inlinetasks with a :noexport: tag. * testing/lisp/test-ox.el: Add tests. --- lisp/ox.el | 60 ++++++++++++++++------------- testing/lisp/test-ox.el | 83 +++++++++++++++++++++++++++-------------- 2 files changed, 88 insertions(+), 55 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index dce804631..c44b1c38d 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -1854,40 +1854,47 @@ export options." ignore)) (defun org-export--selected-trees (data info) - "Return list of headlines containing a select tag in their tree. + "Return list of headlines and inlinetasks with a select tag in their tree. DATA is parsed data as returned by `org-element-parse-buffer'. INFO is a plist holding export options." (let* (selected-trees - walk-data ; for byte-compiler. + walk-data ; For byte-compiler. (walk-data (function (lambda (data genealogy) - (case (org-element-type data) - (org-data (mapc (lambda (el) (funcall walk-data el genealogy)) - (org-element-contents data))) - (headline - (let ((tags (org-element-property :tags data))) - (if (loop for tag in (plist-get info :select-tags) - thereis (member tag tags)) - ;; When a select tag is found, mark full - ;; genealogy and every headline within the tree - ;; as acceptable. - (setq selected-trees - (append - genealogy - (org-element-map data 'headline 'identity) - selected-trees)) - ;; Else, continue searching in tree, recursively. - (mapc - (lambda (el) (funcall walk-data el (cons data genealogy))) - (org-element-contents data)))))))))) - (funcall walk-data data nil) selected-trees)) + (let ((type (org-element-type data))) + (cond + ((memq type '(headline inlinetask)) + (let ((tags (org-element-property :tags data))) + (if (loop for tag in (plist-get info :select-tags) + thereis (member tag tags)) + ;; When a select tag is found, mark full + ;; genealogy and every headline within the tree + ;; as acceptable. + (setq selected-trees + (append + genealogy + (org-element-map data '(headline inlinetask) + 'identity) + selected-trees)) + ;; If at a headline, continue searching in tree, + ;; recursively. + (when (eq type 'headline) + (mapc (lambda (el) + (funcall walk-data el (cons data genealogy))) + (org-element-contents data)))))) + ((or (eq type 'org-data) + (memq type org-element-greater-elements)) + (mapc (lambda (el) (funcall walk-data el genealogy)) + (org-element-contents data))))))))) + (funcall walk-data data nil) + selected-trees)) (defun org-export--skip-p (blob options selected) "Non-nil when element or object BLOB should be skipped during export. OPTIONS is the plist holding export options. SELECTED, when -non-nil, is a list of headlines belonging to a tree with a select -tag." +non-nil, is a list of headlines or inlinetasks belonging to +a tree with a select tag." (case (org-element-type blob) (clock (not (plist-get options :with-clocks))) (drawer @@ -1902,13 +1909,15 @@ tag." (if (eq (car with-drawers-p) 'not) (member-ignore-case name (cdr with-drawers-p)) (not (member-ignore-case name with-drawers-p)))))))) - (headline + ((headline inlinetask) (let ((with-tasks (plist-get options :with-tasks)) (todo (org-element-property :todo-keyword blob)) (todo-type (org-element-property :todo-type blob)) (archived (plist-get options :with-archived-trees)) (tags (org-element-property :tags blob))) (or + (and (eq (org-element-type blob) 'inlinetask) + (not (plist-get options :with-inlinetasks))) ;; Ignore subtrees with an exclude tag. (loop for k in (plist-get options :exclude-tags) thereis (member k tags)) @@ -1925,7 +1934,6 @@ tag." (and (memq with-tasks '(todo done)) (not (eq todo-type with-tasks))) (and (consp with-tasks) (not (member todo with-tasks)))))))) - (inlinetask (not (plist-get options :with-inlinetasks))) ((latex-environment latex-fragment) (not (plist-get options :with-latex))) (planning (not (plist-get options :with-plannings))) (statistics-cookie (not (plist-get options :with-statistics-cookies))) diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 1e66a8392..7584d5fd1 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -247,25 +247,19 @@ Paragraph" (ert-deftest test-org-export/handle-options () "Test if export options have an impact on output." - ;; Test exclude tags. - (org-test-with-temp-text "* Head1 :noexport:" - (org-test-with-backend test - (should - (equal (org-export-as 'test nil nil nil '(:exclude-tags ("noexport"))) - "")))) - ;; Test include tags. - (org-test-with-temp-text " -* Head1 -* Head2 -** Sub-Head2.1 :export: -*** Sub-Head2.1.1 -* Head2" - (org-test-with-backend test - (should - (equal - "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n" - (let ((org-tags-column 0)) - (org-export-as 'test nil nil nil '(:select-tags ("export")))))))) + ;; Test exclude tags for headlines and inlinetasks. + (should + (equal "" + (org-test-with-temp-text "* Head1 :noexp:" + (org-test-with-backend test + (org-export-as 'test nil nil nil '(:exclude-tags ("noexp"))))))) + ;; Test include tags for headlines and inlinetasks. + (should + (equal "* H2\n** Sub :exp:\n*** Sub Sub\n" + (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3" + (let ((org-tags-column 0)) + (org-test-with-backend test + (org-export-as 'test nil nil nil '(:select-tags ("exp")))))))) ;; Test mixing include tags and exclude tags. (org-test-with-temp-text " * Head1 :export: @@ -281,16 +275,18 @@ Paragraph" 'test nil nil nil '(:select-tags ("export") :exclude-tags ("noexport"))))))) ;; Ignore tasks. - (let ((org-todo-keywords '((sequence "TODO" "DONE")))) - (org-test-with-temp-text "* TODO Head1" - (org-test-with-backend test - (should (equal (org-export-as 'test nil nil nil '(:with-tasks nil)) - ""))))) - (let ((org-todo-keywords '((sequence "TODO" "DONE")))) - (org-test-with-temp-text "* TODO Head1" - (org-test-with-backend test - (should (equal (org-export-as 'test nil nil nil '(:with-tasks t)) - "* TODO Head1\n"))))) + (should + (equal "" + (let ((org-todo-keywords '((sequence "TODO" "DONE")))) + (org-test-with-temp-text "* TODO Head1" + (org-test-with-backend test + (org-export-as 'test nil nil nil '(:with-tasks nil))))))) + (should + (equal "* TODO Head1\n" + (let ((org-todo-keywords '((sequence "TODO" "DONE")))) + (org-test-with-temp-text "* TODO Head1" + (org-test-with-backend test + (org-export-as 'test nil nil nil '(:with-tasks t))))))) ;; Archived tree. (org-test-with-temp-text "* Head1 :archive:" (let ((org-archive-tag "archive")) @@ -1230,6 +1226,35 @@ Paragraph[fn:1]" (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no)) info)))))) +(ert-deftest test-org-export/handle-inlinetasks () + "Test inlinetask export." + ;; Inlinetask with an exclude tag. + (when (featurep 'org-inlinetask) + (should + (equal + "" + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end" + (org-test-with-backend test + (org-export-as 'test nil nil nil '(:exclude-tags ("noexp")))))))) + ;; Inlinetask with an include tag. + (should + (equal + "* H2\n*** Inline :exp:\n" + (let ((org-inlinetask-min-level 3) + (org-tags-column 0)) + (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:" + (org-test-with-backend test + (org-export-as 'test nil nil nil '(:select-tags ("exp")))))))) + ;; Ignore inlinetask with a TODO keyword and tasks excluded. + (should + (equal "" + (let ((org-todo-keywords '((sequence "TODO" "DONE"))) + (org-inlinetask-min-level 3)) + (org-test-with-temp-text "*** TODO Inline" + (org-test-with-backend test + (org-export-as 'test nil nil nil '(:with-tasks nil))))))))) + ;;; Links