From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bernt Hansen Subject: Re: Agenda TODO sorting by date Date: Sat, 03 Mar 2012 14:03:05 -0500 Message-ID: <87ty2533ti.fsf@norang.ca> References: <87pqcu4duz.wl%jamshark70@dewdrop-world.net> <87399qielx.fsf@norang.ca> <87399pzm9w.wl%jamshark70@dewdrop-world.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:52735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3uEg-0004se-OK for emacs-orgmode@gnu.org; Sat, 03 Mar 2012 14:03:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3uEe-0001IF-TR for emacs-orgmode@gnu.org; Sat, 03 Mar 2012 14:03:18 -0500 Received: from mho-01-ewr.mailhop.org ([204.13.248.71]:23614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3uEe-0001Gh-Pc for emacs-orgmode@gnu.org; Sat, 03 Mar 2012 14:03:16 -0500 In-Reply-To: <87399pzm9w.wl%jamshark70@dewdrop-world.net> (James Harkins's message of "Sun, 04 Mar 2012 00:23:23 +0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: James Harkins Cc: emacs-orgmode@gnu.org James Harkins writes: > At Fri, 02 Mar 2012 21:48:42 -0500, > Bernt Hansen wrote: >> You could write a custom sorting function that parses out the date from >> the heading and compares them. There may be a better way to do this >> that I'm not aware of for this. >> >> Set this function up in org-agenda-cmp-user-defined and >> org-agenda-sorting-strategy to get the results you want. > > OK, thanks. I was starting to think it would come to that. Kind of > surprising this isn't offered out of the box. > > I think I need a bit more guidance, from you or someone else. > >> parses out the date from the heading > > Is there already an org function to do this? C-h a searches on the > following yielded nothing that seemed interesting. > > org.*date.* > org.*timestamp.* > >> compares them > > I was about to make that more complicated, but actually string > comparison should be fine for this. No worries there. > > I have done rather little with emacs-lisp so... this is uphill for me. Thanks. I think this works --8<---------------cut here---------------start------------->8--- (defun bh/agenda-sort-by-heading-date (a b) "Sorting strategy for agenda items. Late deadlines first, then scheduled, then non-late deadlines" (message "Heading a: <%s>" a) (message "Heading b: <%s>" b) (let* ((date-regexp "\\(\\<[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\\) ") date-a date-b) (string-match date-regexp a) (setq date-a (match-string 1 a)) (string-match date-regexp b) (setq date-b (match-string 1 b)) (cond ((string< date-a date-b) -1) ((string< date-b date-a) +1) ((t nil))))) nil) ;; ;; Agenda sorting functions ;; (setq org-agenda-cmp-user-defined 'bh/agenda-sort-by-heading-date) (setq org-agenda-custom-commands (quote (("x" "Tasks" tags-todo "" ((org-agenda-overriding-header "Tasks sorted by date") (org-agenda-sorting-strategy '(user-defined-up))))))) --8<---------------cut here---------------end--------------->8--- Then C-c a < x Tag RET gives ,---- | Tasks sorted by date | scratch: TODO Third todo in file <2012-03-28 Wed> :Tag: | scratch: TODO Second todo in file <2012-03-29 Thu> :Tag: | scratch: TODO First todo in file <2012-03-30 Fri> :Tag: | scratch: TODO Fourth todo in file <2012-03-31 Sat> :Tag: `---- HTH, Bernt