emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christopher League <league@contrapunctus.net>
To: David Maus <maus.david@gmail.com>
Cc: Bastien <bastienguerry@googlemail.com>,
	org-mode mailing list <Emacs-orgmode@gnu.org>
Subject: Re: wish list: sort tasks by age
Date: Wed, 1 Jul 2009 09:26:14 -0400	[thread overview]
Message-ID: <1B91C2B7-A9A5-4370-AF63-5549DB74746D@contrapunctus.net> (raw)
In-Reply-To: <87d48kipim.fsf@bzg.ath.cx>

Thanks everyone. I think I managed to get something like David's  
suggestion working... I spent the most time trying to initialize the  
creation times from git though, with vc-annotate.. I don't think that  
was meant to be used non-interactively, but I beat it into shape. :)   
The other end of it is the agenda view, so I made a comparison  
function that puts them in order oldest to youngest. I made a gist for  
the snippet here: http://gist.github.com/138770 and I'll also paste  
below.

org-expiry is interesting.. I didn't know about that. Certainly  
there's a similarity, although the point of view is different: "tasks  
that are old and should be archived" vs. "tasks that are old and  
should be FINISHED!!!" :)  I haven't thought too much yet about how to  
unify the two ideas...

Chris

On Jul 1, 2009, at 7:58 AM, Bastien wrote:
> David Maus <maus.david@gmail.com> writes:
>> And what a fun it is to train my elisp skills. A first hack that  
>> seems to work:
>>
>> (defun dmj/org-assure-creation-property ()
>>  "Process all orgmode entries of current buffer that do not
>>  match a defined search string"
>>  (interactive)
>>  (org-map-entries 'dmj/org-insert-creation-property "+Creation_Time= 
>> \"\"")
>> )
>>
>> (defun dmj/org-insert-creation-property ()
>>  "Insert Creation-Property in Orgmode entry at point"
>>  (let ((stamp (format-time-string (cdr org-time-stamp-formats)  
>> (current-time))))
>>    (setq stamp (concat "[" (substring stamp 1 -1) "]"))
>>    (org-entry-put (point-marker) "Creation_Time" stamp))
>> )
>>
> Thanks for this David -- you might also have a look at the code in
> org-expiry.el.  If there is anything there that you want to improve,
> please do so!


;;; sorting org-mode tasks by age

(defconst org-age-property "CREATED")

(defun org-age-set-to-today-if-missing ()
   (interactive)
   (or (org-entry-get (point) org-age-property)
       (let ((d (format-time-string "%Y-%m-%d" (current-time))))
         (org-entry-put (point) org-age-property d)
         d)))

(defconst org-date-regexp "\\b[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\ 
\b")

(defun org-age-set-from-vc-if-missing ()
   (interactive)
   (or (org-entry-get (point) org-age-property)
       (let ((current-line (count-lines (point-min) (point)))
             date-string)
         (save-window-excursion
           (vc-annotate buffer-file-name (vc-workfile-version buffer- 
file-name))
           (if (search-forward-regexp org-date-regexp
                                      (point-at-eol) t)
               (setq date-string (match-string 0)))
           (kill-buffer nil)) ;; otherwise next annotation may be wrong
         (when date-string
           (org-entry-put (point) org-age-property date-string)
           (basic-save-buffer)) ;; otherwise next annotation may be  
wrong
         date-string)))

(defvar org-age-todo-match "/TODO|PROJECT|MAYBE|WAIT")

(defun org-age-set-all (setf)
   (let ((rs (org-map-entries setf org-age-todo-match 'agenda)))
     rs))

(defun org-age-set-all-to-today ()
   (interactive)
   (org-age-set-all 'org-age-set-to-today-if-missing))
(org-age-set-all-to-today)

(defun org-age-set-all-from-vc ()
   (interactive)
   (org-age-set-all 'org-age-set-from-vc-if-missing))

(defun org-age-compare (a b)
   (let* ((ma (get-text-property 1 'org-marker a))
          (mb (get-text-property 1 'org-marker b))
          (da (with-current-buffer (marker-buffer ma)
                (goto-char (marker-position ma))
                (org-age-set-to-today-if-missing)))
          (db (with-current-buffer (marker-buffer mb)
                (goto-char (marker-position mb))
                (org-age-set-to-today-if-missing))))
     (cond
      ((string< da db) -1)
      ((string= da db) nil)
      (t +1))))

(setq org-agenda-cmp-user-defined 'org-age-compare)

(setq org-agenda-custom-commands
       '(("z" "description"
          todo "TODO"
          ((org-agenda-sorting-strategy '(user-defined-up))
           (org-agenda-archives-mode nil)))))

  reply	other threads:[~2009-07-01 13:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-30 20:04 wish list: sort tasks by age Christopher League
     [not found] ` <87tz1wzy1o.wl%maus.david@gmail.com>
2009-07-01  8:10   ` Manish
2009-07-01 10:24     ` David Maus
2009-07-01 11:58       ` Bastien
2009-07-01 13:26         ` Christopher League [this message]
2009-07-01 14:46           ` Bastien
2009-07-01 11:57 ` Bastien

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=1B91C2B7-A9A5-4370-AF63-5549DB74746D@contrapunctus.net \
    --to=league@contrapunctus.net \
    --cc=Emacs-orgmode@gnu.org \
    --cc=bastienguerry@googlemail.com \
    --cc=maus.david@gmail.com \
    /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).