diff -c /home/egli/Desktop/org.el.orig /home/egli/Desktop/org.el
*** /home/egli/Desktop/org.el.orig	2007-11-21 07:56:11.000000000 +0100
--- /home/egli/Desktop/org.el	2007-11-21 08:00:25.000000000 +0100
***************
*** 2547,2553 ****
  	 (const time-up) (const time-down)
  	 (const category-keep) (const category-up) (const category-down)
  	 (const tag-down) (const tag-up)
! 	 (const priority-up) (const priority-down))))
  
    (defcustom org-agenda-sorting-strategy
      '((agenda time-up category-keep priority-down)
--- 2547,2554 ----
  	 (const time-up) (const time-down)
  	 (const category-keep) (const category-up) (const category-down)
  	 (const tag-down) (const tag-up)
! 	 (const priority-up) (const priority-down)
! 	 (const todo-state-up) (const todo-state-down))))
  
    (defcustom org-agenda-sorting-strategy
      '((agenda time-up category-keep priority-down)
***************
*** 19878,19884 ****
  				     "\\)\\>"))
  			   org-not-done-regexp)
  			 "[^\n\r]*\\)"))
! 	 marker priority category tags
  	 ee txt beg end)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
--- 19879,19885 ----
  				     "\\)\\>"))
  			   org-not-done-regexp)
  			 "[^\n\r]*\\)"))
! 	 marker priority category tags todo-state
  	 ee txt beg end)
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
***************
*** 19903,19913 ****
  	      category (org-get-category)
  	      tags (org-get-tags-at (point))
  	      txt (org-format-agenda-item "" (match-string 1) category tags)
! 	      priority (1+ (org-get-priority txt)))
  	(org-add-props txt props
  	  'org-marker marker 'org-hd-marker marker
  	  'priority priority 'org-category category
! 	  'type "todo")
  	(push txt ee)
  	(if org-agenda-todo-list-sublevels
  	    (goto-char (match-end 1))
--- 19904,19916 ----
  	      category (org-get-category)
  	      tags (org-get-tags-at (point))
  	      txt (org-format-agenda-item "" (match-string 1) category tags)
! 	      priority (1+ (org-get-priority txt))
! 	      todo-state (org-get-todo-state))
  	(org-add-props txt props
  	  'org-marker marker 'org-hd-marker marker
  	  'priority priority 'org-category category
! 	  'type "todo"
! 	  'todo-state todo-state)
  	(push txt ee)
  	(if org-agenda-todo-list-sublevels
  	    (goto-char (match-end 1))
***************
*** 20238,20244 ****
  		  'type (if pastschedp "past-scheduled" "scheduled")
  		  'date (if pastschedp d2 date)
  		  'priority (+ 94 (- 5 diff) (org-get-priority txt))
! 		  'org-category category)
  		(push txt ee))))))
      (nreverse ee)))
  
--- 20241,20248 ----
  		  'type (if pastschedp "past-scheduled" "scheduled")
  		  'date (if pastschedp d2 date)
  		  'priority (+ 94 (- 5 diff) (org-get-priority txt))
! 		  'org-category category
! 		  'todo-state head)
  		(push txt ee))))))
      (nreverse ee)))
  
***************
*** 20587,20592 ****
--- 20591,20609 ----
  	  ((string-lessp cb ca) +1)
  	  (t nil))))
  
+ (defsubst org-cmp-todo-state (a b)
+   "Compare the todo states of strings A and B."
+   (let* ((ta (or (get-text-property 1 'todo-state a) ""))
+ 	 (tb (or (get-text-property 1 'todo-state b) ""))
+ 	 (donepa (member ta org-done-keywords)) 
+ 	 (donepb (member tb org-done-keywords)))
+     (message "Compare todo %s and %s (state: %s, %s)" ta tb donepa donepb)
+     (cond ((and donepa (not donepb)) -1)
+ 	  ((and (not donepa) donepb) +1)
+ 	  ((string-lessp ta tb) -1)
+ 	  ((string-lessp tb ta) +1)
+ 	  (t nil))))
+ 
  (defsubst org-cmp-tag (a b)
    "Compare the string values of categories of strings A and B."
    (let ((ta (car (last (get-text-property 1 'tags a))))
***************
*** 20618,20624 ****
  	 (category-down (if category-up (- category-up) nil))
  	 (category-keep (if category-up +1 nil))
  	 (tag-up (org-cmp-tag a b))
! 	 (tag-down (if tag-up (- tag-up) nil)))
      (cdr (assoc
  	  (eval (cons 'or org-agenda-sorting-strategy-selected))
  	  '((-1 . t) (1 . nil) (nil . nil))))))
--- 20635,20643 ----
  	 (category-down (if category-up (- category-up) nil))
  	 (category-keep (if category-up +1 nil))
  	 (tag-up (org-cmp-tag a b))
! 	 (tag-down (if tag-up (- tag-up) nil))
! 	 (todo-state-up (org-cmp-todo-state a b))
! 	 (todo-state-down (if todo-state-up (- todo-state-up) nil)))
      (cdr (assoc
  	  (eval (cons 'or org-agenda-sorting-strategy-selected))
  	  '((-1 . t) (1 . nil) (nil . nil))))))

Diff finished.  Wed Nov 21 08:00:36 2007
