* Sort by Inactive Timestamp
@ 2012-12-06 22:13 Jeff Mickey
2012-12-07 16:41 ` John Hendy
0 siblings, 1 reply; 8+ messages in thread
From: Jeff Mickey @ 2012-12-06 22:13 UTC (permalink / raw
To: emacs-orgmode Org-Mode
Hey Org mailing list!
So, I have been using org for years (2006?) now, absolutely adore it.
The generic org-export in contrib really excites me as well, I want to
try and write an org-e-mediawiki.el after I learn some more about
org's implementation.
However.. my current issue: I'd like to sort my todo's by when I
entered them. So in my capture template I put an inactive timestamp at
the bottom, so my headlines look something like:
--8<---------------cut here---------------start------------->8---
* Todo
** TODO call mom
- Ask about christmas
- Talk about Dad
- See if she bought a dog
[2012-12-05 Wed 16:36]
** TODO Yet another thing
[2012-12-05 Wed 16:37]
--8<---------------cut here---------------end--------------->8---
I'd love to have a way to bring up the agenda and have it sorted by
this ctime I'm manually inserting. Do people have suggestions on the
best way to support this?
Maybe add a property to my TODOs that is this creation time?
Has anyone else done something similar to this using
org-agenda-cmp-user-defined?
... is this the wrong place to ask this question?
I appreciate any and all help!
// jeff
^ permalink raw reply [flat|nested] 8+ messages in thread
* Sort by Inactive Timestamp
@ 2012-12-06 22:30 Jeff Mickey
2012-12-07 0:35 ` Samuel Wales
2012-12-07 19:43 ` Memnon Anon
0 siblings, 2 replies; 8+ messages in thread
From: Jeff Mickey @ 2012-12-06 22:30 UTC (permalink / raw
To: emacs-orgmode Org-Mode
Hey Org mailing list!
So, I have been using org for years (2006?) now, absolutely adore it.
The generic org-export in contrib really excites me as well, I want to
try and write an org-e-mediawiki.el after I learn some more about
org's implementation.
However.. my current issue: I'd like to sort my todo's by when I
entered them. So in my capture template I put an inactive timestamp at
the bottom, so my headlines look something like:
--8<---------------cut here---------------start------------->8---
* Todo
** TODO call mom
- Ask about christmas
- Talk about Dad
- See if she bought a dog
[2012-12-05 Wed 16:36]
** TODO Yet another thing
[2012-12-05 Wed 16:37]
--8<---------------cut here---------------end--------------->8---
I'd love to have a way to bring up the agenda and have it sorted by
this ctime I'm manually inserting. Do people have suggestions on the
best way to support this?
Maybe add a property to my TODOs that is this creation time?
Has anyone else done something similar to this using
org-agenda-cmp-user-defined?
... is this the wrong place to ask this question?
I appreciate any and all help!
// jeff
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Sort by Inactive Timestamp
2012-12-06 22:30 Sort by Inactive Timestamp Jeff Mickey
@ 2012-12-07 0:35 ` Samuel Wales
2012-12-07 0:38 ` Samuel Wales
2012-12-07 19:43 ` Memnon Anon
1 sibling, 1 reply; 8+ messages in thread
From: Samuel Wales @ 2012-12-07 0:35 UTC (permalink / raw
To: Jeff Mickey; +Cc: emacs-orgmode Org-Mode
I can't give you the answer, only the tools, as my setup contains
years of stuff.
The manual says how to do sorting in the outline and the agenda using
user-defined functions.
The key thing is converting timestamps into something that you can use
reliably. I wrote these over a long period years ago.
(defun alpha-org-timestamp-score (&optional sg)
"Return unix minutes as a floating point number.
;;;for 0..1
;;;Beware adding this to a much larger number (around 100); you will
;;;lose resolution. Multiply first by a number with a lot of
;;;zeroes. Then add to a number with a lot of zeroes.
Seems to be unix time as 1970 (or a few hours off, possibly
depending on time zone) epoch.
This is for sorting conversations, which have an inactive
timestamp near the beginning of a header, and for all tasks. Any
closed should be first inactive, followed by logbook if you sort
those reversed. This is what you usually want.
Return the first inactive timestamp even if it is CLOSED.
===
There is no way to get Org to return the first ts of any type.
If closed check is after ts check, then if there is an inactive
timestamp (such as in logbook) that is after CLOSED, will use
that first.
/fixme/ request a timestamp-any property. this gets you the
first timestamp no matter whether it is active and no matter
where it is.
This now checks closed first. So the bug now is if there is a ts
in the headline, closed will take precedence if it exists.
Still, this approach works OK; think of the time as always being
the time of closing for a doneish, else first ts. That is OK.
So not making the request now.
/Does not yet consider active timestamps/."
;;
;;make sure these work on any other processor or os
;;
;;(/ (org-time-string-to-seconds "1900-12-31 00:00") 60.0) nan
;;(/ (org-time-string-to-seconds "1901-12-31 00:00") 60.0) -35766300.0
;;(/ (org-time-string-to-seconds "1934-12-31 00:00") 60.0) -18409980.0
;;(/ (org-time-string-to-seconds "1960-12-31 00:00") 60.0) -4734300.0
;;(/ (org-time-string-to-seconds "1969-12-31 00:00") 60.0) -1020.0
;;(/ (org-time-string-to-seconds "1970-01-01 00:00") 60.0) 420.0
;;(/ (org-time-string-to-seconds "1980-01-01 00:00") 60.0) 5259300.0
;;(/ (org-time-string-to-seconds "1990-01-01 00:00") 60.0) 10519620.0
;;(/ (org-time-string-to-seconds "2010-01-01 00:00") 60.0) 21038820.0
;;(/ (org-time-string-to-seconds "2038-01-01 00:00") 60.0) 35765700.0
;;(/ (org-time-string-to-seconds "2138-01-01 00:00") 60.0) nan
;;if you do seconds instead of minutes, it changes order around 2010
;;seems ok to multiply by 1e7 or so
;;(+ 1.0 (* 10519620.0 1e8)) 1051962000000001.0 :)
;;(+ 1.0 (* 10519620.0 1e9)) 1.051962e+16 :(
;;(= (+ 1.0 (* 10519620.0 1e9)) (* 10519620.0 1e9)) t :(
;;(/ (org-time-string-to-seconds "1990-01-01 00:00") 60.0) 10,519,620.0
(let ((ts (or
;;this fixes either a doc bug or a real bug, not
;;sure which
(alpha-org-entry-get "CLOSED" sg)
(alpha-org-entry-get "TIMESTAMP_IA" sg))))
(aif ts
(/ (org-time-string-to-seconds it)
60.0)
0.0)))
;;all of my other get functions should use this. are there
;;issues with it?
(defun alpha-org-entry-get (property &optional sg inherit)
"Return the value of PROPERTY, whether you are in the outline
or the agenda, by calling `org-entry-get'.
SG is the agenda header string provided by user-defined agenda
sorting, or nil. If it is nil and you are in the outline, use
the current headline directly. If it is nil and you are in the
agenda, use the current headline by going to the outline.
INHERIT is the inherit argument for `org-entry-get'.
There are a few questions about Org properties:
1) What does it mean to get alltags without inheritance or tags
with inheritance? I guess org-entry-get was originally
meant for properties, not tags, so you don't use inherit?
2) How do you get the first timestamp in an entry? There seems
to be no way without specifying the type of timestamp.
According to the manual at the time of this writing, possible
properties include these.
TODO The TODO keyword of the entry.
TAGS The tags defined directly in the headline.
ALLTAGS All tags, including inherited ones.
CATEGORY The category of an entry.
PRIORITY The priority of the entry, a string with a single letter.
DEADLINE The deadline time string, without the angular brackets.
SCHEDULED The scheduling timestamp, without the angular brackets.
CLOSED When was this entry closed?
TIMESTAMP The first keyword-less timestamp in the entry.
- this works even in the headline
TIMESTAMP_IA The first inactive timestamp in the entry.
- this works even in the headline
- it does not seem to report CLOSED ts -- use CLOSED
CLOCKSUM The sum of CLOCK intervals in the subtree. org-clock-sum
must be run first to compute the values.
ITEM The content of the entry.
For anything else, you can use marker-buffer to get to the
outline and do manual parsing or use some other function. Or
possibly modify org-entry-get to understand it and send a patch
to the org mailing list, along with an update of this docstring.
The idea is to use this as a single way to get most metadata no
matter where you are.
"
;;=doubtful do we want the literal-nil argument so that we can
;;ret "nil" as string? check elsewhere here for nil vs. string
;;for todo kw or whatever. we only need it if it helps with
;;consistency. not important and prob useless for this
;;purpose. (other ways of getting todo kw will not obey it so
;;it might not help.)
(org-entry-get
(cond
((eq major-mode 'org-agenda-mode)
(let* ((s (or sg (buffer-substring (point-at-bol)
(point-at-eol))))
(m (or (get-text-property 1 'org-marker s)
(get-text-property 1 'org-hd-marker s))))
;;do this to get to the buffer if you need other data that
;;org-entry-get cannot extract
;;(b (and m (marker-buffer m))))
;;; (if b
;;; (with-current-buffer b
;;; (goto-char m)
m))
((eq major-mode 'org-mode) (point))
(t (error "Not in an org-mode buffer")))
property
inherit))
--
The Kafka Pandemic: http://thekafkapandemic.blogspot.com
The disease DOES progress. MANY people have died from it. ANYBODY
can get it. There is no hope without action.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Sort by Inactive Timestamp
2012-12-07 0:35 ` Samuel Wales
@ 2012-12-07 0:38 ` Samuel Wales
0 siblings, 0 replies; 8+ messages in thread
From: Samuel Wales @ 2012-12-07 0:38 UTC (permalink / raw
To: Jeff Mickey; +Cc: emacs-orgmode Org-Mode
I think your setup is only by time, so you don't really need to
convert the timestamps, and you don't really need the generalized get
function. You can just use org-entry-get.
--
The Kafka Pandemic: http://thekafkapandemic.blogspot.com
The disease DOES progress. MANY people have died from it. ANYBODY
can get it. There is no hope without action.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Sort by Inactive Timestamp
2012-12-06 22:13 Jeff Mickey
@ 2012-12-07 16:41 ` John Hendy
0 siblings, 0 replies; 8+ messages in thread
From: John Hendy @ 2012-12-07 16:41 UTC (permalink / raw
To: Jeff Mickey; +Cc: emacs-orgmode Org-Mode
[-- Attachment #1: Type: text/plain, Size: 2263 bytes --]
On Thu, Dec 6, 2012 at 4:13 PM, Jeff Mickey <j@codemac.net> wrote:
> Hey Org mailing list!
>
> So, I have been using org for years (2006?) now, absolutely adore it.
> The generic org-export in contrib really excites me as well, I want to
> try and write an org-e-mediawiki.el after I learn some more about
> org's implementation.
>
> However.. my current issue: I'd like to sort my todo's by when I
> entered them. So in my capture template I put an inactive timestamp at
> the bottom, so my headlines look something like:
>
> --8<---------------cut here---------------start------------->8---
> * Todo
> ** TODO call mom
> - Ask about christmas
> - Talk about Dad
> - See if she bought a dog
>
> [2012-12-05 Wed 16:36]
> ** TODO Yet another thing
> [2012-12-05 Wed 16:37]
> --8<---------------cut here---------------end--------------->8---
>
> I'd love to have a way to bring up the agenda and have it sorted by
> this ctime I'm manually inserting. Do people have suggestions on the
> best way to support this?
>
>
Two thoughts:
1) I recently requested a feature addition like this for sparse trees and
Bastian quickly and awesomely added it:
- http://comments.gmane.org/gmane.emacs.orgmode/55501
I wonder if something similar could be added to agenda to allow for what
you want?
2) On that note, have you looked at the agenda log mode? It seems that it's
nearly got what you're looking for, except at the moment it only allows for
things with inactive time stamps that are todo state changes, clocked, or
have been marked done.
Perhaps log mode could have a "journal" mode in which all time stamped
items are extracted?
I'm thinking someone will have to add a tweak to current functionality.
There's a bit I found when googling that org-mode can sort by timestamps --
I'm assuming this means to rearrange actual headlines in the file, which is
probably not what you want. Perhaps the build in sorting combined with the
above could get you the view you're looking for.
Best regards,
John
> Maybe add a property to my TODOs that is this creation time?
> Has anyone else done something similar to this using
> org-agenda-cmp-user-defined?
>
> ... is this the wrong place to ask this question?
>
> I appreciate any and all help!
>
> // jeff
>
>
[-- Attachment #2: Type: text/html, Size: 3183 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Sort by Inactive Timestamp
2012-12-06 22:30 Sort by Inactive Timestamp Jeff Mickey
2012-12-07 0:35 ` Samuel Wales
@ 2012-12-07 19:43 ` Memnon Anon
2012-12-09 4:54 ` Jeff Mickey
1 sibling, 1 reply; 8+ messages in thread
From: Memnon Anon @ 2012-12-07 19:43 UTC (permalink / raw
To: emacs-orgmode
Jeff Mickey <jeff@archlinux.org> writes:
> However.. my current issue: I'd like to sort my todo's by when I
> entered them. So in my capture template I put an inactive timestamp at
> the bottom, so my headlines look something like:
>
> --8<---------------cut here---------------start------------->8---
> * Todo
> ** TODO call mom
> - Ask about christmas
> - Talk about Dad
> - See if she bought a dog
>
> [2012-12-05 Wed 16:36]
> ** TODO Yet another thing
> [2012-12-05 Wed 16:37]
> --8<---------------cut here---------------end--------------->8---
>
> I'd love to have a way to bring up the agenda and have it sorted by
> this ctime I'm manually inserting. Do people have suggestions on the
> best way to support this?
>
> Maybe add a property to my TODOs that is this creation time?
> Has anyone else done something similar to this using
> org-agenda-cmp-user-defined?
Hmmm.
If your 'creation' timestamp is the only inactive timestamp, you won't
need a special property; org-entry-get should give you the right one.
I am not good at this, but what about something like:
--8<---------------cut here---------------start------------->8---
(defun my-agenda-sort-by-inactive-timestamp (a b)
"Sort by interactive timestamp. Oldest first, items without any ts at the bottom."
(let* ((ma (or (get-text-property 1 'org-marker a)
(get-text-property 1 'org-hd-marker a)))
(mb (or (get-text-property 1 'org-marker b)
(get-text-property 1 'org-hd-marker b)))
(tsa (org-entry-get ma "TIMESTAMP_IA"))
(tsb (org-entry-get mb "TIMESTAMP_IA"))
(ta (when tsa (date-to-time tsa)))
(tb (when tsb (date-to-time tsb))))
(cond ((eq tsa nil) +1)
((eq tsb nil) -1)
((time-less-p ta tb)
-1)
((time-less-p tb ta)
+1)
(t nil))))
(setq org-agenda-custom-commands
'(("x" "Tasks" todo ""
((org-agenda-overriding-header "Tasks sorted by
TIMESTAMP_IA")
(org-agenda-cmp-user-defined 'my-agenda-sort-by-inactive-timestamp)
(org-agenda-sorting-strategy
'(user-defined-up)))
)))
--8<---------------cut here---------------end--------------->8---
Does that work?
If you use :logbook:, entries within will 'override' your inactive
timestamp at the end of the entry. A special CREATED property would be
useful in this case.
> ... is this the wrong place to ask this question?
Definitely not :).
Memnon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Sort by Inactive Timestamp
2012-12-07 19:43 ` Memnon Anon
@ 2012-12-09 4:54 ` Jeff Mickey
2012-12-09 16:11 ` Memnon Anon
0 siblings, 1 reply; 8+ messages in thread
From: Jeff Mickey @ 2012-12-09 4:54 UTC (permalink / raw
To: Memnon Anon; +Cc: emacs-orgmode Org-Mode
On Fri, Dec 7, 2012 at 11:43 AM, Memnon Anon
<gegendosenfleisch@googlemail.com> wrote:
> --8<---------------cut here---------------start------------->8---
> (defun my-agenda-sort-by-inactive-timestamp (a b)
> "Sort by interactive timestamp. Oldest first, items without any ts at the bottom."
> (let* ((ma (or (get-text-property 1 'org-marker a)
> (get-text-property 1 'org-hd-marker a)))
> (mb (or (get-text-property 1 'org-marker b)
> (get-text-property 1 'org-hd-marker b)))
> (tsa (org-entry-get ma "TIMESTAMP_IA"))
> (tsb (org-entry-get mb "TIMESTAMP_IA"))
> (ta (when tsa (date-to-time tsa)))
> (tb (when tsb (date-to-time tsb))))
>
> (cond ((eq tsa nil) +1)
> ((eq tsb nil) -1)
> ((time-less-p ta tb)
> -1)
> ((time-less-p tb ta)
> +1)
> (t nil))))
>
> (setq org-agenda-custom-commands
> '(("x" "Tasks" todo ""
> ((org-agenda-overriding-header "Tasks sorted by
> TIMESTAMP_IA")
> (org-agenda-cmp-user-defined 'my-agenda-sort-by-inactive-timestamp)
> (org-agenda-sorting-strategy
> '(user-defined-up)))
> )))
> --8<---------------cut here---------------end--------------->8---
>
> Does that work?
Thank you Memnon! The (get-text-property 1 'org-marker a) is still
voodoo to me, but that worked perfectly.
// jeff
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Sort by Inactive Timestamp
2012-12-09 4:54 ` Jeff Mickey
@ 2012-12-09 16:11 ` Memnon Anon
0 siblings, 0 replies; 8+ messages in thread
From: Memnon Anon @ 2012-12-09 16:11 UTC (permalink / raw
To: emacs-orgmode
Jeff Mickey <jeff@archlinux.org> writes:
> Thank you Memnon! The (get-text-property 1 'org-marker a) is still
> voodoo to me, but that worked perfectly.
Hehe, it *is* black magic.
Carsten recommended to have a look at the org-cmp-* functions
(http://article.gmane.org/gmane.emacs.orgmode/14634).
Those lines are basically cut&paste/kill&yank from org-cmp-todo-state in
org-agenda.el.
Follow Carstens advice
,----[ http://article.gmane.org/gmane.emacs.orgmode/14634 ]
| "You can look at these properties by pressing `C-u C-x =' on a line in
| the agenda."
`----
and voodoo downgrades to black magic.
Gmane rocks!
Memnon
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-12-09 16:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-06 22:30 Sort by Inactive Timestamp Jeff Mickey
2012-12-07 0:35 ` Samuel Wales
2012-12-07 0:38 ` Samuel Wales
2012-12-07 19:43 ` Memnon Anon
2012-12-09 4:54 ` Jeff Mickey
2012-12-09 16:11 ` Memnon Anon
-- strict thread matches above, loose matches on Subject: below --
2012-12-06 22:13 Jeff Mickey
2012-12-07 16:41 ` John Hendy
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.