From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Useful utility function: org-sort-multi Date: Sun, 30 Aug 2009 10:09:01 +0200 Message-ID: References: <4A988678.6020202@gmail.com> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MhfTK-0000W3-Pc for emacs-orgmode@gnu.org; Sun, 30 Aug 2009 04:09:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MhfTG-0000Qd-51 for emacs-orgmode@gnu.org; Sun, 30 Aug 2009 04:09:10 -0400 Received: from [199.232.76.173] (port=58200 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MhfTF-0000Qa-W8 for emacs-orgmode@gnu.org; Sun, 30 Aug 2009 04:09:06 -0400 Received: from mail-ew0-f211.google.com ([209.85.219.211]:37857) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MhfTF-0008Az-G0 for emacs-orgmode@gnu.org; Sun, 30 Aug 2009 04:09:05 -0400 Received: by ewy7 with SMTP id 7so3108041ewy.31 for ; Sun, 30 Aug 2009 01:09:04 -0700 (PDT) In-Reply-To: <4A988678.6020202@gmail.com> 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: "Ryan C. Thompson" Cc: org-mode Mailinglist On Aug 29, 2009, at 3:38 AM, Ryan C. Thompson wrote: > I found myself having to sort by multiple criteria, and I was doing > it with multiple calls to org-sort-entries-or-items. Then I decided > to abstract the repetition into a function. Here it is: > > (defun org-sort-multi (&rest sort-types) > "Sort successively by a list of criteria, in descending order of > importance. > For example, sort first by TODO status, then by priority, then by > date, then alphabetically, case-sensitive. > Each criterion is either a character or a cons pair (BOOL . CHAR), > where BOOL is whether or not to sort case-sensitively, and CHAR is > one of the characters defined in ``org-sort-entries-or-items''. > So, the example above could be accomplished with: > (org-sort-multi ?o ?p ?t (t . ?a))" > (interactive) > (mapc #'(lambda (sort-type) > (when (characterp sort-type) (setq sort-type (cons nil > sort-type))) > (org-sort-entries-or-items (car sort-type) (cdr sort- > type))) > (reverse sort-types))) > > Note the call to reverse. This makes it so that the first criterion > you provide is the dominant criterion. Try it out to see how it > works, and let me know if there's a better way to pass the arguments. > > Just as an example, the particular sorting function I wanted to > write now becomes this: > > (defun org-sort-custom () > "Sort children of node by todo status and by priority and by date, > so the * TODO [#A] items with latest dates go to the top." > (interactive) > (org-sort-multi ?o ?p ?T)) Hi Ryan, this looks interesting, but I am not sure I understand how it works. It looks to me that each sorting step will completely re-sort the entire list of items, so the final sorting will win in the end. Or am I missing something here? - Carsten > > > _______________________________________________ > 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