emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Egli Christian (KIRO 41)" <christian.egli@credit-suisse.com>
To: emacs-orgmode@gnu.org
Subject: [Patch] Sort agenda items by todo-state
Date: Wed, 21 Nov 2007 13:13:09 +0100	[thread overview]
Message-ID: <52D89C75FEE9444E8D9C016E3730098306CE6B@chsa1036.share.beluni.net> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1799 bytes --]


* Introduction
  I live in my org agenda view and I schedule all my tasks to the
  day that I want to do them. I also would like to see my
  achievements so I keep the TODOs that are done in the agenda
  view. However I would like them to get out of the way so that I
  can better see the tasks that are still open. That is why for a
  long time I've been wanting to sort the agenda items by todo
  state.
  
* Patch
  I finally looked at the code and realized that this was not very
  hard to do. The following patch (against 5.13i) implements a new
  org-agenda-sorting-strategy that allows you to sort agenda items
  by todo-state.
  
* Notes
  The patch is basically a "works-for-me" implementation. It only
  sorts todo and scheduled items. It should probably do the same
  for deadlines. Maybe even for timestamps? 
  
  The doc strings need to be updated.
  
  Carsten at one time talked about implementing this feature by
  using priorities, i.e. factoring the todo-state into the priority
  (which uses the actual priority plus some calculation based on
  how many days the task is overdue). This patch takes a different
  route.
  
  The sorting is done by comparing the todo-state of the items. It
  first orders them by done state, i.e. all done items come after
  (or before) the items that are not done. After that it compares
  the todo-states with a string compare. This should probably use
  some kind of ordering information from the relevant
  org-todo-keywords sequence.
  
* Conclusion
  So the basic question is: Should I clean up this patch to get it
  included? Is the proposed route (of not taking the priorities)
  ok? And finally: How do I sort taking the sequence order into
  consideration?
    
Christian


 <<org.diff>> 

[-- Attachment #1.2: Type: text/html, Size: 4070 bytes --]

[-- Attachment #2: org.diff --]
[-- Type: application/octet-stream, Size: 4586 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

             reply	other threads:[~2007-11-21 12:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-21 12:13 Egli Christian (KIRO 41) [this message]
2007-11-22  7:35 ` [Patch] Sort agenda items by todo-state Carsten Dominik

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=52D89C75FEE9444E8D9C016E3730098306CE6B@chsa1036.share.beluni.net \
    --to=christian.egli@credit-suisse.com \
    --cc=emacs-orgmode@gnu.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 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).