From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Emin.shopper Martinian.shopper" Subject: Re: How do you control sorting in org agenda? Date: Fri, 21 May 2010 08:36:19 -0400 Message-ID: References: <87sk5vecvz.fsf@gollum.intra.norang.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=50044 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFRSi-0001Z7-9k for emacs-orgmode@gnu.org; Fri, 21 May 2010 08:36:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OFRSg-0003Kl-4W for emacs-orgmode@gnu.org; Fri, 21 May 2010 08:36:24 -0400 Received: from mail-iw0-f169.google.com ([209.85.214.169]:60468) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OFRSf-0003KZ-R2 for emacs-orgmode@gnu.org; Fri, 21 May 2010 08:36:22 -0400 Received: by iwn39 with SMTP id 39so1038790iwn.0 for ; Fri, 21 May 2010 05:36:19 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bernt Hansen Cc: emacs-orgmode@gnu.org It turned out my previous attempt at sorting didn't quite work, here is an improved version of the hack for anyone else who wants to add sub-priorities to control sorting of todo items: (defun org-cmp-sub-priority (a b) """Compare the titles of string A and B This function can be used in the org-agenda-cmp-user-defined variable and org-agenda-sorting-strategy to compare the sort order of org entries. It looks for something of the from TODO[]- where is one of #A, #B, #C indicating an org prioity and is a sub-priority which org doesn't know about but which controls the sorting order. For example, I have TODO entries like TODO [#A]-01 foo TODO [#A]-02 bar TODO [#A]-03 baz and use this function to make sure they get sorted properly in the todo screen of org-agenda. """ (let* ((aa (car (last (split-string (substring-no-properties a) "TODO .#.= ")))) (bb (car (last (split-string (substring-no-properties b) "TODO .#.")))) (use-a (string-match "^.?-[0-9]" aa)) (use-b (string-match "^.?-[0-9]" bb)) ) (cond ((and use-a use-b) ;; check if both aa and bb have a priority (cond ((string-lessp aa bb) -1) ;; if so, just compare strings ((string-lessp bb aa) +1) (t nil))) (use-a -1) ;; a has priority but not b (use-b +1) ;; b has priority but not a (t nil)) ;; nobody has priority so don't compare )) (setq org-agenda-cmp-user-defined 'org-cmp-sub-priority) (setq org-agenda-sorting-strategy '((agenda habit-down time-up priority-down category-keep) (todo priority-down user-defined-up) (tags priority-down category-keep) (search category-keep))) On Mon, May 17, 2010 at 7:50 AM, Emin.shopper Martinian.shopper wrote: > On Thu, May 13, 2010 at 4:59 PM, Bernt Hansen wrote: >> "Emin.shopper Martinian.shopper" writes: >> >> >> See the variable org-agenda-sorting-strategy. >> >> -Bernt > > > Thanks for the pointer. I put the following in my .emacs file and the > I change my prioritized items to things like TODO [#A]-01 foo, TODO > [#A]-02 bar, etc. and things sort as I wanted. > > > (defun org-cmp-title (a b) > =A0"Compare the titles of string A and B" > =A0(cond ((string-lessp a b) -1) > =A0 =A0 =A0 =A0((string-lessp b a) +1) > =A0 =A0 =A0 =A0(t nil))) > > (setq org-agenda-cmp-user-defined 'org-cmp-title) > > (setq org-agenda-sorting-strategy > =A0 =A0 =A0'((agenda habit-down time-up priority-down category-keep) > =A0 =A0 =A0 =A0(todo =A0 priority-down user-defined-up category-keep) > =A0 =A0 =A0 =A0(tags =A0 priority-down category-keep) > =A0 =A0 =A0 =A0(search category-keep))) >