emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: Bernt Hansen <bernt@norang.ca>,
	emacs-orgmode@gnu.org,
	Carsten Dominik <carsten.dominik@gmail.com>
Subject: Re: New exporter and dates in tables
Date: Sun, 14 Apr 2013 22:36:41 +0200	[thread overview]
Message-ID: <87sj2s7sti.fsf@gmail.com> (raw)
In-Reply-To: <87vc7p42bt.fsf@bzg.ath.cx> (Bastien's message of "Sun, 14 Apr 2013 16:24:54 +0200")

[-- Attachment #1: Type: text/plain, Size: 661 bytes --]

Bastien <bzg@gnu.org> writes:

> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> We can widen the definition of `standalone': a standalone timestamp is
>> a timestamp belonging to a paragraph that contains only timestamps
>> objects.
>
> Great.  If that's possible, then I think that's the best solution.

The following patch should do that. It comes with tests, but it should
be tested extensively, if only to know if this feature is as useful as
it seems.

Note that another option is to allow all timestamps, put timestamps you
don't want to export in a specific drawer (e.g. "TIME"), and ignore this
drawer during export.


Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-Add-more-options-to-skip-timestamps.patch --]
[-- Type: text/x-patch, Size: 7072 bytes --]

From 8faa562ce1d2a80988736e7a045b7c16aba7ebc9 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Sun, 14 Apr 2013 22:20:16 +0200
Subject: [PATCH] ox: Add more options to skip timestamps

* lisp/ox.el (org-export-with-timestamps): Allow `not-standalone',
  `active-not-standalone' and `inactive-not-standalone' values. Update
  docstring.
(org-export--skip-p): Skip timestamps according to new values.
* testing/lisp/test-ox.el: Add tests.
---
 lisp/ox.el              | 59 ++++++++++++++++++++++++++----------
 testing/lisp/test-ox.el | 79 +++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 107 insertions(+), 31 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index fffb7ce..75ea25a 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -721,9 +721,19 @@ also be set with the OPTIONS keyword, e.g. \"timestamp:nil\"."
 (defcustom org-export-with-timestamps t
   "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.
+It can be set to any of the following values:
+                        t export all timestamps.
+                 `active' export active timestamps only.
+  `active-not-standalone' export active timestamps which are not
+                          isolated in a paragraph containing only
+                          timestamps.
+               `inactive' export inactive timestamps only.
+`inactive-not-standalone' export inactive timestamps which are not
+                          isolated in a paragraph containing only
+                          timestamps.
+         `not-standalone' export timestamps which are not isolated
+                          in a paragraph containing only timestamps.
+                      nil do not export timestamps
 
 This option can also be set with the OPTIONS keyword, e.g.
 \"<:nil\"."
@@ -2017,19 +2027,36 @@ a tree with a select tag."
 	  (not (org-export-get-previous-element blob options))))
     (table-row (org-export-table-row-is-special-p blob options))
     (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))))))))
+     (let ((standalonep
+	    (lambda (ts)
+	      ;; Return a non-nil value when TS is a timestamp object
+	      ;; in a paragraph with only timestamps and whitespaces.
+	      (let ((parent (org-export-get-parent-element ts)))
+		(when (memq (org-element-type parent) '(paragraph verse-block))
+		  (not
+		   (org-element-map parent
+		       (cons 'plain-text
+			     (remq 'timestamp org-element-all-objects))
+		     (lambda (obj)
+		       (or (not (stringp obj)) (org-string-nw-p obj)))
+		     options t)))))))
+       (case (plist-get options :with-timestamps)
+	 ('nil t)
+	 (active
+	  (not (memq (org-element-property :type blob) '(active active-range))))
+	 (active-not-standalone
+	  (not (and (memq (org-element-property :type blob)
+			  '(active active-range))
+		    (not (funcall standalonep blob)))))
+	 (inactive-not-standalone
+	  (not
+	   (and (memq (org-element-property :type blob)
+		      '(inactive inactive-range))
+		(not (funcall standalonep blob)))))
+	 (inactive
+	  (not (memq (org-element-property :type blob)
+		     '(inactive inactive-range))))
+	 (not-standalone (funcall standalonep blob)))))))
 
 \f
 ;;; The Transcoder
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 46531a1..90b4eb5 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -394,21 +394,70 @@ Paragraph"
 	  (org-test-with-temp-text "[0/0]"
 	    (org-test-with-backend test
 	      (org-export-as
-	       'test nil nil nil '(:with-statistics-cookies nil))))))
-  ;; Timestamps.
-  (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]<2012-04-29 sun. 10:45>\n"))
-      (should
-       (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")))))
+	       'test nil nil nil '(:with-statistics-cookies nil)))))))
+
+(ert-deftest test-org-export/with-timestamps ()
+  "Test `org-export-with-timestamps' specifications."
+  ;; t value.
+  (should
+   (equal
+    "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"
+    (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
+      (org-test-with-backend test
+	(org-export-as 'test nil nil nil '(:with-timestamps t))))))
+  ;; nil value.
+  (should
+   (equal
+    ""
+    (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
+      (org-test-with-backend test
+	(org-export-as 'test nil nil nil '(:with-timestamps nil))))))
+  ;; `active' value.
+  (should
+   (equal
+    "<2012-04-29 sun. 10:45>\n"
+    (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
+      (org-test-with-backend test
+	(org-export-as 'test nil nil nil '(:with-timestamps active))))))
+  ;; `active-not-standalone' value.
+  (should
+   (equal
+    "Paragraph <2012-03-29 Thu>"
+    (org-test-with-temp-text
+	"<2012-04-29 Thu>\n\nParagraph <2012-03-29 Thu> [2012-03-29 Thu]"
+      (org-test-with-backend test
+	(org-trim
+	 (org-export-as 'test nil nil nil
+			'(:with-timestamps active-not-standalone)))))))
+  ;; `inactive' value.
+  (should
+   (equal
+    "[2012-04-29 sun. 10:45]\n"
+    (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
+      (org-test-with-backend test
+	(org-export-as 'test nil nil nil '(:with-timestamps inactive))))))
+  ;; `inactive-not-standalone' value.
+  (should
+   (equal
+    "Paragraph [2012-03-29 Thu]"
+    (org-test-with-temp-text
+	"[2012-04-29 Thu]\n\nParagraph <2012-03-29 Thu> [2012-03-29 Thu]"
+      (org-test-with-backend test
+	(org-trim
+	 (org-export-as 'test nil nil nil
+			'(:with-timestamps inactive-not-standalone)))))))
+  ;; `not-standalone' value.
+  (should
+   (equal
+    "Paragraph <2012-03-29 Thu> [2012-03-29 Thu]\n| [2012-03-29 Thu] |"
+    (org-test-with-temp-text "<2012-03-29 Thu> [2012-04-29 Thu]
+
+Paragraph <2012-03-29 Thu> [2012-03-29 Thu]
+| [2012-03-29 Thu] |"
+      (org-test-with-backend test
+	(org-trim
+	 (org-export-as 'test nil nil nil
+			'(:with-timestamps not-standalone))))))))
 
 (ert-deftest test-org-export/comment-tree ()
   "Test if export process ignores commented trees."
-- 
1.8.2.1


  reply	other threads:[~2013-04-14 20:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08  0:05 New exporter and dates in tables Bernt Hansen
2013-04-08  2:18 ` Mike McLean
2013-04-08  6:57 ` Nicolas Goaziou
2013-04-08 11:27   ` Bernt Hansen
2013-04-08 11:33     ` Carsten Dominik
2013-04-08 19:49       ` Nicolas Goaziou
2013-04-09 13:06         ` Carsten Dominik
2013-04-10 12:43           ` Nicolas Goaziou
2013-04-10 13:12             ` Carsten Dominik
2013-04-10 13:16             ` Bastien
2013-04-11 11:28               ` Nicolas Goaziou
2013-04-11 15:49                 ` Bastien
2013-04-13 10:54                   ` Nicolas Goaziou
2013-04-13 14:02                     ` Bastien
2013-04-13 17:33                       ` Nicolas Goaziou
2013-04-13 21:07                         ` Sebastien Vauban
2013-04-14  9:10                           ` Bastien
2013-04-14  8:58                         ` Bastien
2013-04-14 13:37                           ` Nicolas Goaziou
2013-04-14 13:45                             ` Bastien
2013-04-14 13:47                               ` Nicolas Goaziou
2013-04-14 14:01                                 ` Bastien
2013-04-14 14:06                                   ` Nicolas Goaziou
2013-04-14 14:24                                     ` Bastien
2013-04-14 20:36                                       ` Nicolas Goaziou [this message]
2013-04-15  3:58                                         ` Jambunathan K
2013-04-15  6:44                                         ` Bastien
2013-04-16  7:48                                         ` Bastien
2013-08-09  9:35                                           ` Carsten Dominik
2013-08-09 11:02                                             ` Bernt Hansen
2013-08-12  5:45                                               ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sj2s7sti.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=bernt@norang.ca \
    --cc=bzg@gnu.org \
    --cc=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).