From: "Ryan C. Thompson" <rct@thompsonclan.org>
To: org-mode Mailinglist <emacs-orgmode@gnu.org>
Subject: Useful utility function: org-sort-multi
Date: Fri, 28 Aug 2009 18:38:00 -0700 [thread overview]
Message-ID: <4A988678.6020202@gmail.com> (raw)
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))
next reply other threads:[~2009-08-29 1:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-29 1:38 Ryan C. Thompson [this message]
2009-08-30 8:09 ` Useful utility function: org-sort-multi Carsten Dominik
2009-08-30 8:33 ` Benjamin Andresen
2009-08-30 20:55 ` Ryan C. Thompson
2009-08-31 5:40 ` 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=4A988678.6020202@gmail.com \
--to=rct@thompsonclan.org \
--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).