From bea597be96e808a70764fe3f49974f1501acf109 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 29 Apr 2012 22:55:37 +0200 Subject: [PATCH] org-export: Add `active' and `inactive' alternatives to `org-export-with-timestamps' * contrib/lisp/org-export.el (org-export-with-timestamps): Allow to keep only active timestamps or inactive ones with respectively `active' and `inactive' values. (org-export--skip-p): Update tests to determine if a timestamp should be ignored. * testing/lisp/test-org-export.el: Add tests. * contrib/lisp/org-element.el: Fix some comments. --- contrib/lisp/org-element.el | 4 +- contrib/lisp/org-export.el | 75 +++++++++++++++++++++------------ testing/lisp/test-org-export.el | 16 ++++--- 3 files changed, 62 insertions(+), 33 deletions(-) diff --git a/contrib/lisp/org-element.el b/contrib/lisp/org-element.el index c48722e89..775842112 100644 --- a/contrib/lisp/org-element.el +++ b/contrib/lisp/org-element.el @@ -3032,8 +3032,8 @@ element or object type." ;; ;; `org-element-current-element' makes use of special modes. They are ;; activated for fixed element chaining (i.e. `plain-list' > `item') -;; or fixed conditional element chaining (i.e. `section' > -;; `planning'). Special modes are: `section', `quote-section', `item' +;; or fixed conditional element chaining (i.e. `headline' > +;; `section'). Special modes are: `section', `quote-section', `item' ;; and `table-row'. (defconst org-element--element-block-re diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index 463b35a95..5d57bab4d 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -600,9 +600,20 @@ e.g. \"timestamp:nil\"." :type 'boolean) (defcustom org-export-with-timestamps t - "If nil, do not export time stamps and associated keywords." + "Non nil means allow timestamps in export. + +It can be set to `active', `inactive', t or nil, in order to +export, respectively, only active timestamps, only inactive ones, +all of them or none. + +This option can also be set with the #+OPTIONS line, e.g. +\"<:nil\"." :group 'org-export-general - :type 'boolean) + :type '(choice + (const :tag "All timestamps" t) + (const :tag "Only active timestamps" active) + (const :tag "Only inactive timestamps" inactive) + (const :tag "No timestamp" nil))) (defcustom org-export-with-todo-keywords t "Non-nil means include TODO keywords in export. @@ -778,7 +789,7 @@ standard mode." ;; - type :: string ;; ;; + `:parse-tree' :: Whole parse tree, available at any time during -;; transcoding. +;; transcoding. ;; - category :: global ;; - type :: list (as returned by `org-element-parse-buffer') ;; @@ -793,15 +804,15 @@ standard mode." ;; - type :: symbol (nil, t) ;; ;; + `:select-tags' :: List of tags enforcing inclusion of sub-trees -;; in transcoding. When such a tag is present, -;; subtrees without it are de facto excluded from -;; the process. See `use-select-tags'. +;; in transcoding. When such a tag is present, subtrees without +;; it are de facto excluded from the process. See +;; `use-select-tags'. ;; - category :: option ;; - type :: list of strings ;; ;; + `:target-list' :: List of targets encountered in the parse tree. -;; This is used to partly resolve "fuzzy" links -;; (cf. `org-export-resolve-fuzzy-link'). +;; This is used to partly resolve "fuzzy" links +;; (cf. `org-export-resolve-fuzzy-link'). ;; - category :: tree ;; - type :: list of strings ;; @@ -817,7 +828,7 @@ standard mode." ;; - type :: symbol (nil, t, `headline') ;; ;; + `:with-author' :: Non-nil means author's name should be included -;; in the output. +;; in the output. ;; - category :: option ;; - type :: symbol (nil, t) ;; @@ -879,35 +890,33 @@ standard mode." ;; - type :: symbol (nil, {}, t) ;; ;; + `:with-tables' :: Non-nil means transcoding should interpret -;; tables. +;; tables. ;; - category :: option ;; - type :: symbol (nil, t) ;; ;; + `:with-tags' :: Non-nil means transcoding should keep tags in -;; headlines. A `not-in-toc' value will remove them -;; from the table of contents, if any, nonetheless. +;; headlines. A `not-in-toc' value will remove them from the +;; table of contents, if any, nonetheless. ;; - category :: option ;; - type :: symbol (nil, t, `not-in-toc') ;; ;; + `:with-tasks' :: Non-nil means transcoding should include -;; headlines with a TODO keyword. A `todo' value -;; will only include headlines with a todo type -;; keyword while a `done' value will do the -;; contrary. If a list of strings is provided, only -;; tasks with keywords belonging to that list will -;; be kept. +;; headlines with a TODO keyword. A `todo' value will only +;; include headlines with a todo type keyword while a `done' +;; value will do the contrary. If a list of strings is provided, +;; only tasks with keywords belonging to that list will be kept. ;; - category :: option ;; - type :: symbol (t, todo, done, nil) or list of strings ;; ;; + `:with-timestamps' :: Non-nil means transcoding should include -;; time stamps and associated keywords. Otherwise, completely -;; remove them. +;; time stamps. Special value `active' (resp. `inactive') ask to +;; export only active (resp. inactive) timestamps. Otherwise, +;; completely remove them. ;; - category :: option -;; - type :: symbol: (t, nil) +;; - type :: symbol: (`active', `inactive', t, nil) ;; ;; + `:with-toc' :: Non-nil means that a table of contents has to be -;; added to the output. An integer value limits its -;; depth. +;; added to the output. An integer value limits its depth. ;; - category :: option ;; - type :: symbol (nil, t or integer) ;; @@ -1459,7 +1468,8 @@ INFO is a plist holding export options." (defun org-export--skip-p (blob options select-tags) "Non-nil when element or object BLOB should be skipped during export. -OPTIONS is the plist holding export options." +OPTIONS is the plist holding export options. SELECT-TAGS, when +non-nil, is a list of tags marking a subtree as exportable." (case (org-element-type blob) ;; Check headline. (headline @@ -1487,7 +1497,20 @@ OPTIONS is the plist holding export options." (not (eq todo-type with-tasks))) (and (consp with-tasks) (not (member todo with-tasks)))))))) ;; Check timestamp. - (timestamp (not (plist-get options :with-timestamps))) + (timestamp + (case (plist-get options :with-timestamps) + ;; No timestamp allowed. + ('nil t) + ;; Only active timestamps allowed and the current one isn't + ;; active. + (active + (not (memq (org-element-property :type blob) + '(active active-range)))) + ;; Only inactive timestamps allowed and the current one isn't + ;; inactive. + (inactive + (not (memq (org-element-property :type blob) + '(inactive inactive-range)))))) ;; Check drawer. (drawer (or (not (plist-get options :with-drawers)) @@ -1510,7 +1533,7 @@ OPTIONS is the plist holding export options." ;;; The Transcoder ;; -;; This function reads Org data (obtained with, i.e. +;; `org-export-data' reads a parse tree (obtained with, i.e. ;; `org-element-parse-buffer') and transcodes it into a specified ;; back-end output. It takes care of updating local properties, ;; filtering out elements or objects according to export options and diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el index bcf946a5a..9967ce704 100644 --- a/testing/lisp/test-org-export.el +++ b/testing/lisp/test-org-export.el @@ -74,12 +74,12 @@ already filled in `info'." (equal (org-export-parse-option-keyword "arch:headline creator:comment d:(\"TEST\") - ^:{} toc:1 tags:not-in-toc tasks:todo num:2") + ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active") '( :section-numbers 2 :with-archived-trees headline :with-creator comment :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1 - :with-tags not-in-toc :with-tasks todo)))) + :with-tags not-in-toc :with-tasks todo :with-timestamps active)))) (ert-deftest test-org-export/get-inbuffer-options () "Test reading all standard export keywords." @@ -217,13 +217,19 @@ already filled in `info'." (equal (org-export-as 'test nil nil nil '(:with-drawers ("FOO"))) ":FOO:\nkeep\n:END:\n"))))) ;; Timestamps. - (org-test-with-temp-text "[2012-04-29 sun. 10:45]" + (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>" (org-test-with-backend "test" (should (equal (org-export-as 'test nil nil nil '(:with-timestamps t)) - "[2012-04-29 sun. 10:45]\n")) + "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n")) (should - (equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) "")))) + (equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) "")) + (should + (equal (org-export-as 'test nil nil nil '(:with-timestamps active)) + "<2012-04-29 sun. 10:45>\n")) + (should + (equal (org-export-as 'test nil nil nil '(:with-timestamps inactive)) + "[2012-04-29 sun. 10:45]\n")))) ;; Clocks. (let ((org-clock-string "CLOCK:")) (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"