summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-14 13:19:12 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-10-14 13:19:12 +0200
commitc1c0c70c8921550dc790e9f9ac7a56dacb4147bc (patch)
tree98a4b84b06283854d9c0f89674aa8b5dca99b2a3
parentf287ab418dd2149d47854382f0d5745e21a52624 (diff)
downloadorg-mode-c1c0c70c8921550dc790e9f9ac7a56dacb4147bc.tar.gz
org-export: Add tag inheritance to `org-export-get-tags'
* contrib/lisp/org-export.el (org-export-get-tags): Add optional tag inheritance. * testing/lisp/test-org-export.el: Add test.
-rw-r--r--contrib/lisp/org-export.el28
-rw-r--r--testing/lisp/test-org-export.el10
2 files changed, 31 insertions, 7 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index d654e73..56abbed 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -3157,7 +3157,7 @@ INFO is a plist used as a communication channel."
(pop roman)))
res)))
-(defun org-export-get-tags (element info &optional tags)
+(defun org-export-get-tags (element info &optional tags inherited)
"Return list of tags associated to ELEMENT.
ELEMENT has either an `headline' or an `inlinetask' type. INFO
@@ -3167,11 +3167,27 @@ Select tags (see `org-export-select-tags') and exclude tags (see
`org-export-exclude-tags') are removed from the list.
When non-nil, optional argument TAGS should be a list of strings.
-Any tag belonging to this list will also be removed."
- (org-remove-if (lambda (tag) (or (member tag (plist-get info :select-tags))
- (member tag (plist-get info :exclude-tags))
- (member tag tags)))
- (org-element-property :tags element)))
+Any tag belonging to this list will also be removed.
+
+When optional argument INHERITED is non-nil, tags can also be
+inherited from parent headlines.."
+ (org-remove-if
+ (lambda (tag) (or (member tag (plist-get info :select-tags))
+ (member tag (plist-get info :exclude-tags))
+ (member tag tags)))
+ (if (not inherited) (org-element-property :tags element)
+ ;; Build complete list of inherited tags.
+ (let ((current-tag-list (org-element-property :tags element)))
+ (mapc
+ (lambda (parent)
+ (mapc
+ (lambda (tag)
+ (when (and (memq (org-element-type parent) '(headline inlinetask))
+ (not (member tag current-tag-list)))
+ (push tag current-tag-list)))
+ (org-element-property :tags parent)))
+ (org-export-get-genealogy element))
+ current-tag-list))))
(defun org-export-get-node-property (property blob &optional inherited)
"Return node PROPERTY value for BLOB.
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index e3b9af0..c8a1cd7 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -750,7 +750,15 @@ Paragraph[fn:1]"
(should-not
(org-test-with-parsed-data "* Headline :ignore:"
(org-export-get-tags (org-element-map tree 'headline 'identity info t)
- info '("ignore"))))))
+ info '("ignore"))))
+ ;; Allow tag inheritance.
+ (should
+ (equal
+ '(("tag") ("tag"))
+ (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
+ (org-element-map
+ tree 'headline
+ (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
(ert-deftest test-org-export/get-node-property ()
"Test`org-export-get-node-property' specifications."