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.
This commit is contained in:
Nicolas Goaziou 2013-03-02 14:34:45 +01:00
parent 66d6a6c450
commit 5a0239b9fc
2 changed files with 88 additions and 55 deletions

View File

@ -1854,40 +1854,47 @@ export options."
ignore)) ignore))
(defun org-export--selected-trees (data info) (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'. DATA is parsed data as returned by `org-element-parse-buffer'.
INFO is a plist holding export options." INFO is a plist holding export options."
(let* (selected-trees (let* (selected-trees
walk-data ; for byte-compiler. walk-data ; For byte-compiler.
(walk-data (walk-data
(function (function
(lambda (data genealogy) (lambda (data genealogy)
(case (org-element-type data) (let ((type (org-element-type data)))
(org-data (mapc (lambda (el) (funcall walk-data el genealogy)) (cond
(org-element-contents data))) ((memq type '(headline inlinetask))
(headline (let ((tags (org-element-property :tags data)))
(let ((tags (org-element-property :tags data))) (if (loop for tag in (plist-get info :select-tags)
(if (loop for tag in (plist-get info :select-tags) thereis (member tag tags))
thereis (member tag tags)) ;; When a select tag is found, mark full
;; When a select tag is found, mark full ;; genealogy and every headline within the tree
;; genealogy and every headline within the tree ;; as acceptable.
;; as acceptable. (setq selected-trees
(setq selected-trees (append
(append genealogy
genealogy (org-element-map data '(headline inlinetask)
(org-element-map data 'headline 'identity) 'identity)
selected-trees)) selected-trees))
;; Else, continue searching in tree, recursively. ;; If at a headline, continue searching in tree,
(mapc ;; recursively.
(lambda (el) (funcall walk-data el (cons data genealogy))) (when (eq type 'headline)
(org-element-contents data)))))))))) (mapc (lambda (el)
(funcall walk-data data nil) selected-trees)) (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) (defun org-export--skip-p (blob options selected)
"Non-nil when element or object BLOB should be skipped during export. "Non-nil when element or object BLOB should be skipped during export.
OPTIONS is the plist holding export options. SELECTED, when OPTIONS is the plist holding export options. SELECTED, when
non-nil, is a list of headlines belonging to a tree with a select non-nil, is a list of headlines or inlinetasks belonging to
tag." a tree with a select tag."
(case (org-element-type blob) (case (org-element-type blob)
(clock (not (plist-get options :with-clocks))) (clock (not (plist-get options :with-clocks)))
(drawer (drawer
@ -1902,13 +1909,15 @@ tag."
(if (eq (car with-drawers-p) 'not) (if (eq (car with-drawers-p) 'not)
(member-ignore-case name (cdr with-drawers-p)) (member-ignore-case name (cdr with-drawers-p))
(not (member-ignore-case name with-drawers-p)))))))) (not (member-ignore-case name with-drawers-p))))))))
(headline ((headline inlinetask)
(let ((with-tasks (plist-get options :with-tasks)) (let ((with-tasks (plist-get options :with-tasks))
(todo (org-element-property :todo-keyword blob)) (todo (org-element-property :todo-keyword blob))
(todo-type (org-element-property :todo-type blob)) (todo-type (org-element-property :todo-type blob))
(archived (plist-get options :with-archived-trees)) (archived (plist-get options :with-archived-trees))
(tags (org-element-property :tags blob))) (tags (org-element-property :tags blob)))
(or (or
(and (eq (org-element-type blob) 'inlinetask)
(not (plist-get options :with-inlinetasks)))
;; Ignore subtrees with an exclude tag. ;; Ignore subtrees with an exclude tag.
(loop for k in (plist-get options :exclude-tags) (loop for k in (plist-get options :exclude-tags)
thereis (member k tags)) thereis (member k tags))
@ -1925,7 +1934,6 @@ tag."
(and (memq with-tasks '(todo done)) (and (memq with-tasks '(todo done))
(not (eq todo-type with-tasks))) (not (eq todo-type with-tasks)))
(and (consp with-tasks) (not (member todo 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))) ((latex-environment latex-fragment) (not (plist-get options :with-latex)))
(planning (not (plist-get options :with-plannings))) (planning (not (plist-get options :with-plannings)))
(statistics-cookie (not (plist-get options :with-statistics-cookies))) (statistics-cookie (not (plist-get options :with-statistics-cookies)))

View File

@ -247,25 +247,19 @@ Paragraph"
(ert-deftest test-org-export/handle-options () (ert-deftest test-org-export/handle-options ()
"Test if export options have an impact on output." "Test if export options have an impact on output."
;; Test exclude tags. ;; Test exclude tags for headlines and inlinetasks.
(org-test-with-temp-text "* Head1 :noexport:" (should
(org-test-with-backend test (equal ""
(should (org-test-with-temp-text "* Head1 :noexp:"
(equal (org-export-as 'test nil nil nil '(:exclude-tags ("noexport"))) (org-test-with-backend test
"")))) (org-export-as 'test nil nil nil '(:exclude-tags ("noexp")))))))
;; Test include tags. ;; Test include tags for headlines and inlinetasks.
(org-test-with-temp-text " (should
* Head1 (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
* Head2 (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
** Sub-Head2.1 :export: (let ((org-tags-column 0))
*** Sub-Head2.1.1 (org-test-with-backend test
* Head2" (org-export-as 'test nil nil nil '(:select-tags ("exp"))))))))
(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 mixing include tags and exclude tags. ;; Test mixing include tags and exclude tags.
(org-test-with-temp-text " (org-test-with-temp-text "
* Head1 :export: * Head1 :export:
@ -281,16 +275,18 @@ Paragraph"
'test nil nil nil 'test nil nil nil
'(:select-tags ("export") :exclude-tags ("noexport"))))))) '(:select-tags ("export") :exclude-tags ("noexport")))))))
;; Ignore tasks. ;; Ignore tasks.
(let ((org-todo-keywords '((sequence "TODO" "DONE")))) (should
(org-test-with-temp-text "* TODO Head1" (equal ""
(org-test-with-backend test (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
(should (equal (org-export-as 'test nil nil nil '(:with-tasks nil)) (org-test-with-temp-text "* TODO Head1"
""))))) (org-test-with-backend test
(let ((org-todo-keywords '((sequence "TODO" "DONE")))) (org-export-as 'test nil nil nil '(:with-tasks nil)))))))
(org-test-with-temp-text "* TODO Head1" (should
(org-test-with-backend test (equal "* TODO Head1\n"
(should (equal (org-export-as 'test nil nil nil '(:with-tasks t)) (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
"* TODO Head1\n"))))) (org-test-with-temp-text "* TODO Head1"
(org-test-with-backend test
(org-export-as 'test nil nil nil '(:with-tasks t)))))))
;; Archived tree. ;; Archived tree.
(org-test-with-temp-text "* Head1 :archive:" (org-test-with-temp-text "* Head1 :archive:"
(let ((org-archive-tag "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)) (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
info)))))) 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 ;;; Links