emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: James TD Smith <ahktenzero@mohorovi.cc>
To: emacs-orgmode@gnu.org
Subject: [misc-new-features 1/5] Add two new special properties, SINCE and SINCE_IA.
Date: Mon, 13 Jul 2009 09:27:58 +0100	[thread overview]
Message-ID: <1247473682-23338-2-git-send-email-ahktenzero@mohorovi.cc> (raw)
In-Reply-To: <1247473682-23338-1-git-send-email-ahktenzero@mohorovi.cc>

These give the elapsed time since the TIMESTAMP and TIMESTAMP_IA
properties. This value is in days, as a floating point number.

For display in column view, this is converted to a human-readable time
interval in the form 8d 02h 12m 22s.
---
 lisp/ChangeLog      |   18 ++++++++++++++++--
 lisp/org-colview.el |   36 ++++++++++++++++++++++++------------
 lisp/org.el         |   23 ++++++++++++++++++-----
 3 files changed, 58 insertions(+), 19 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 351731d..348ade3 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
+2009-07-12  James TD Smith  <ahktenzero@mohorovi.cc>
+
+	* org-colview.el (org-format-time-period): Formats a time in
+	fractional days as days, hours, mins, seconds.
+	(org-columns-display-here): Add special handling for SINCE and
+	SINCE_IA to format for display.
+
+	* org.el (org-time-since): Add a function to get the time since an
+	org timestamp.
+	(org-entry-properties): Add two new special properties: SINCE and
+	SINCE_IA. These give the time since any active or inactive
+	timestamp in an entry.
+	(org-special-properties): Add SINCE, SINCE_IA.
+
 2009-07-08  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-clock.el (org-clock-goto): Find hidden headlines as well.
@@ -561,7 +575,7 @@
 	`org-export-push-to-kill-ring'.
 
 	* org-exp.el (org-export-show-temporary-export-buffer): New
-	option. 
+	option.
 
 	* org-latex.el (org-export-as-latex): Use
 	`org-export-show-temporary-export-buffer'.
@@ -2861,7 +2875,7 @@
 	(org-agenda-change-all-lines, org-tags-sparse-tree)
 	(org-time-string-to-absolute, org-small-year-to-year)
 	(org-link-escape): Re-apply changes accidentially overwritten
-	by last commit to Emacs.
+	by last commit to Emacs
 
 2008-11-23  Carsten Dominik  <carsten.dominik@gmail.com>
 
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 7633b5b..6a89849 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -190,18 +190,19 @@ This is the compiled version of the format.")
 		      (length property))
 	    f (format "%%-%d.%ds | " width width)
 	    val (or (cdr ass) "")
-	    modval (or (and org-columns-modify-value-for-display-function
-			    (functionp
-			     org-columns-modify-value-for-display-function)
-			    (funcall
-			     org-columns-modify-value-for-display-function
-			     title val))
-		       (if (equal property "ITEM")
-			   (if (org-mode-p)
-			       (org-columns-cleanup-item
-				val org-columns-current-fmt-compiled)
-			     (org-agenda-columns-cleanup-item
-			      val pl cphr org-columns-current-fmt-compiled)))))
+	    modval (cond ((and org-columns-modify-value-for-display-function
+			       (functionp
+				org-columns-modify-value-for-display-function))
+			  (funcall org-columns-modify-value-for-display-function
+				   title val))
+		       ((equal property "ITEM")
+			(if (org-mode-p)
+			    (org-columns-cleanup-item
+			     val org-columns-current-fmt-compiled)
+			  (org-agenda-columns-cleanup-item
+			   val pl cphr org-columns-current-fmt-compiled)))
+		       ((or (equal property "SINCE") (equal property "SINCE_IA"))
+			(org-format-time-period val))))
       (setq s2 (org-columns-add-ellipses (or modval val) width))
       (setq string (format f s2))
       ;; Create the overlay
@@ -1388,6 +1389,17 @@ This will add overlays to the date lines, to show the summary for each day."
 			   (equal (nth 4 a) (nth 4 fm)))
 		  (org-columns-compute (car fm)))))))))))
 
+(defun org-format-time-period (interval)
+  (if (stringp interval)
+      ""
+    (let* ((days (floor interval))
+	   (frac-hours (* 24 (- interval days)))
+	   (hours (floor frac-hours))
+	   (minutes (floor (* 60 (- frac-hours hours))))
+	   (seconds (floor (* 60 (- (* 60 (- frac-hours hours)) minutes)))))
+      (format "%dd %02dh %02dm %02ds" days hours minutes seconds))))
+
+
 (provide 'org-colview)
 
 ;; arch-tag: 61f5128d-747c-4983-9479-e3871fa3d73c
diff --git a/lisp/org.el b/lisp/org.el
index feaa115..8843486 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6481,7 +6481,10 @@ WITH-CASE, the sorting considers case as well."
 		   (string-to-char (match-string 2))
 		 org-default-priority))
 	      ((= dcst ?r)
-	       (or (org-entry-get nil property) ""))
+	       (or (org-entry-get nil property)
+		   (if (or (equal property "SINCE") (equal property "SINCE_IA"))
+		       0
+		     "")))
 	      ((= dcst ?o)
 	       (if (looking-at org-complex-heading-regexp)
 		   (- 9999 (length (member (match-string 2)
@@ -11286,10 +11289,9 @@ a *different* entry, you cannot use these techniques."
 ;;;; Properties
 
 ;;; Setting and retrieving properties
-
 (defconst org-special-properties
   '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
-    "TIMESTAMP" "TIMESTAMP_IA")
+    "TIMESTAMP" "TIMESTAMP_IA" "SINCE" "SINCE_IA")
   "The special properties valid in Org-mode.
 
 These are properties that are not defined in the property drawer,
@@ -11433,8 +11435,13 @@ If WHICH is nil or `all', get all properties.  If WHICH is
 		  (setq key "TIMESTAMP")))
 	      (when (or (equal key clockstr) (not (assoc key props)))
 		(push (cons key string) props)))
-
-	    )
+	    (when (assoc "TIMESTAMP_IA" props)
+	      (push (cons "SINCE_IA"
+			  (org-time-since (cdr (assoc "TIMESTAMP_IA" props))))
+		    props))
+	    (when (assoc "TIMESTAMP" props)
+	      (push (cons "SINCE" (org-time-since (cdr (assoc "TIMESTAMP" props))))
+		    props)))
 
 	  (when (memq which '(all standard))
 	    ;; Get the standard properties, like :PROP: ...
@@ -11460,6 +11467,12 @@ If WHICH is nil or `all', get all properties.  If WHICH is
 	    (push (cons "CATEGORY" value) props))
 	  (append sum-props (nreverse props)))))))
 
+(defun org-time-since (time)
+  "Get the number of days since `time'"
+  (time-to-number-of-days (time-since (apply 'encode-time
+					     (org-parse-time-string time)))))
+
+
 (defun org-entry-get (pom property &optional inherit)
   "Get value of PROPERTY for entry at point-or-marker POM.
 If INHERIT is non-nil and the entry does not have the property,
-- 
1.6.3.3

  reply	other threads:[~2009-07-13  9:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-13  8:27 Working on org again James TD Smith
2009-07-13  8:27 ` James TD Smith [this message]
2009-07-13  8:27   ` [misc-new-features 2/5] Bugfixes, documentation and custom options for org-checklist James TD Smith
2009-07-13  8:28     ` [misc-new-features 3/5] Add an option to sort tags automatically James TD Smith
2009-07-13  8:28       ` [misc-new-features 4/5] Allow org-insert-link to check the X clipboard and the Emacs kill-ring for links, as well as the stored links. This makes getting URLs into org from a browser much easier, as you don't have to paste the URL into the minibuffer to insert a link James TD Smith
2009-07-13  8:28         ` [misc-new-features 5/5] Fix a problem I was having with plots using a script. Org-plot was deleting the data file before gnuplot read it in. I've moved the deletion of the temporary data file to an idle timer, which has fixed the problem James TD Smith
2009-07-13 11:56           ` Bernt Hansen
2009-07-14 11:57           ` Bastien
2009-07-17 17:03           ` Bastien
2009-07-13 11:55         ` [misc-new-features 4/5] Allow org-insert-link to check the X clipboard and the Emacs kill-ring for links, as well as the stored links. This makes getting URLs into org from a browser much easier, as you don't have to paste the URL into the minibuffer to insert a link Bernt Hansen
2009-07-13 12:13           ` [misc-new-features 4/5] extra long subject lines James TD Smith
2009-07-13 15:35             ` Bernt Hansen
2009-07-14 12:07         ` [misc-new-features 4/5] Allow org-insert-link to check the X clipboard and the Emacs kill-ring for links, as well as the stored links. This makes getting URLs into org from a browser much easier, as you don't have to paste the URL into the minibuffer to insert a link Bastien
2009-07-17 17:20         ` Bastien
2009-07-14 11:59       ` [misc-new-features 3/5] Add an option to sort tags automatically Bastien
2009-07-14 16:01         ` James TD Smith
2009-07-17 17:04           ` Bastien
2009-07-17 16:38       ` Bastien
2009-07-14 12:09     ` [misc-new-features 2/5] Bugfixes, documentation and custom options for org-checklist Bastien
2009-07-14  8:52       ` James TD Smith
2009-08-03 14:47     ` Carsten Dominik
2009-08-03 21:17       ` James TD Smith
2009-07-14 11:48   ` [misc-new-features 1/5] Add two new special properties, SINCE and SINCE_IA Bastien
2009-07-14 17:44     ` James TD Smith
2009-07-17 16:55   ` Bastien
2009-07-17 18:22     ` James TD Smith
2009-07-18  9:35       ` Bastien
2009-08-27 15:50         ` Manish
2009-08-28 17:59           ` James TD Smith

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=1247473682-23338-2-git-send-email-ahktenzero@mohorovi.cc \
    --to=ahktenzero@mohorovi.cc \
    --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).