From: Samuel Wales <samologist@gmail.com>
To: Jeff Mickey <jeff@archlinux.org>
Cc: emacs-orgmode Org-Mode <emacs-orgmode@gnu.org>
Subject: Re: Sort by Inactive Timestamp
Date: Thu, 6 Dec 2012 17:35:09 -0700 [thread overview]
Message-ID: <CAJcAo8vd9UtrdpOy4XdZ=cZVTy-hMGUuc6WodzK6D5R6vn-mUQ@mail.gmail.com> (raw)
In-Reply-To: <CAKr=PyOSH9mWBu-5Tgai67ALVQ8ySY3X9eR_LvRCYgyU2vJUDw@mail.gmail.com>
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.
next prev parent reply other threads:[~2012-12-07 0:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-06 22:30 Sort by Inactive Timestamp Jeff Mickey
2012-12-07 0:35 ` Samuel Wales [this message]
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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJcAo8vd9UtrdpOy4XdZ=cZVTy-hMGUuc6WodzK6D5R6vn-mUQ@mail.gmail.com' \
--to=samologist@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=jeff@archlinux.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 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.