emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [Orgmode] wish list: sort tasks by age


From: Christopher League
Subject: Re: [Orgmode] wish list: sort tasks by age
Date: Wed, 1 Jul 2009 09:26:14 -0400

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 <address@hidden> 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 via email to

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