emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Sort by Inactive Timestamp


From: Samuel Wales
Subject: Re: [O] Sort by Inactive Timestamp
Date: Thu, 6 Dec 2012 17:35:09 -0700

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]