From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: custom sorting of agenda items Date: Fri, 20 Aug 2010 08:30:51 +0200 Message-ID: <434E4A53-2465-4825-9900-58824EF819A8@gmail.com> References: <87r5ie2dpx.fsf@gnu.org> <693E7971-E33F-4354-B947-A07FA3D873A6@gmail.com> <4ADBC455-8259-4929-8D2C-C4DC63AB03A8@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 [140.186.70.92] (port=40893 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OmLrp-0004ek-JT for emacs-orgmode@gnu.org; Fri, 20 Aug 2010 03:18:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OmLrn-0007cq-Q8 for emacs-orgmode@gnu.org; Fri, 20 Aug 2010 03:18:21 -0400 Received: from mail-ew0-f41.google.com ([209.85.215.41]:46614) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OmLrn-0007bM-F7 for emacs-orgmode@gnu.org; Fri, 20 Aug 2010 03:18:19 -0400 Received: by mail-ew0-f41.google.com with SMTP id 28so2014034ewy.0 for ; Fri, 20 Aug 2010 00:18: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: Ilya Shlyakhter Cc: Martin Pohlack , emacs-orgmode Mode , Bastien Guerry On Aug 20, 2010, at 1:49 AM, Ilya Shlyakhter wrote: >> The problem here is that I would have to insert a call to the hook in >> many different places as there are many different functions that >> collect entries for the agenda. > > in org-finalize-agenda-entries, when you call > org-agenda-before-sorting-filter-function, could you > save-excursion and move to the original org entry before each call? I could. But some applications of this hook will not need this overhead, so it is better to put this overhead into the function itself. We can make it easier, like a single macro for going there and back again... Something like (untested): (defmacro org-agenda-with-point-at-orig-entry (string &rest body) "Execute BODY with point at location given by `org-hd-marker' property. If STRING is non-nil, the text property will be fetched from position 0 in that string. If STRING is nil, it will be fetched from the beginning of the current line." `(let ((marker (get-text-property (if string 0 (point-at-bol)) 'org-hd-marker string))) (with-current-buffer (marker-buffer marker) (save-excursion (goto-char marker) ,@body)))) And in your setup you would hen define the filter function like (defun my-before-sorting-filter (line-string) (org-agenda-with-point-at-orig-entry line-string .... .... )) - Carsten > >> It might be, but there is a possibility that updating the line after >> say a TODO state change will not work exactly like you wanted. > > that's ok in my case, the agenda items i'm collecting aren't todo > items. > thanks! maybe, document this in the docstring of > org-agenda-before-sorting-filter-function . > > On Wed, Aug 18, 2010 at 3:35 AM, Carsten Dominik > wrote: >> >> On Aug 17, 2010, at 6:40 PM, Ilya Shlyakhter wrote: >> >>> Thanks Carsten, org-agenda-before-sorting-filter-function does >>> what I >>> need. >>> >>> It would be better if it was called with the point already on the >>> corresponding headline in the corresponding buffer. >>> This would also be faster as you could call it for all entries in >>> one >>> buffer at a time, avoiding a separate excursion for each entry. >> >> The problem here is that I would have to insert a call to the hook in >> many different places as there are many different functions that >> collect entries for the agenda. >> >>> >>> It seems that _appending_ text to the agenda line should be safe. >>> Is >>> that correct? >> >> It might be, but there is a possibility that updating the line after >> say a TODO state change will not work exactly like you wanted. >> >> - Carsten >> >>> >>> thanks, >>> >>> ilya >>> >>> On Mon, Aug 16, 2010 at 9:40 AM, Carsten Dominik >>> wrote: >>>> >>>> On Aug 16, 2010, at 2:59 PM, Ilya Shlyakhter wrote: >>>> >>>>> Thanks! Would things work faster if there was a user-defined >>>>> hook >>>>> that was called at each agenda entry at the same time >>>>> the 'org-hd-marker property gets stored, so it could store any >>>>> other >>>>> things it needs from the entry as text properties for later >>>>> use by user-defined entry sorting routine? >>>> >>>> Please pull and take a look at the new variable >>>> `org-agenda-before-sorting-filter-function'. >>>> >>>> Martin, I think you could use this variable also for your >>>> "filtering" application. >>>> >>>> - Carsten >>>> >>>>> >>>>> ilya >>>>> >>>>> On Mon, Aug 16, 2010 at 8:54 AM, Carsten Dominik >>>>> wrote: >>>>>> >>>>>> On Aug 5, 2010, at 1:01 AM, Ilya Shlyakhter wrote: >>>>>> >>>>>>> When giving a user-defined function for org-agenda-cmp-user- >>>>>>> defined, >>>>>>> the function gets two agenda entries. Is there a way from an >>>>>>> agenda >>>>>>> entry >>>>>>> to get to the original org entry? >>>>>> >>>>>> Yes, the marker that points to the original entry is stored in >>>>>> text >>>>>> properties. >>>>>> You can take it and then go to the entry, for example with >>>>>> >>>>>> (org-with-point-at (org-get-at-bol 'org-hd-marker) >>>>>> ;; do here what you need to do at the location of the entry >>>>>> ) >>>>>> >>>>>> You could do this in org-finalize-agenda-hook for all entries, >>>>>> for >>>>>> example. >>>>>> Might slow things down, of cause. >>>>>> >>>>>> HTH >>>>>> >>>>>> - Carsten >>>>>> >>>>>>> >>>>>>> Best would be if, besides a user-defined sort function, you >>>>>>> could also >>>>>>> provide >>>>>>> a function that takes the org entry and the agenda item (i.e. >>>>>>> is run >>>>>>> with >>>>>>> point >>>>>>> on the org entry and is passed the agenda item), and can then >>>>>>> store >>>>>>> anything >>>>>>> it wants about the org entry as text properties on the agenda >>>>>>> item. >>>>>>> The companion user-defined sorting function could then use these >>>>>>> stored >>>>>>> text properties for ordering the agenda items. Could you add >>>>>>> such a >>>>>>> hook? >>>>>>> >>>>>>> thanks, >>>>>>> >>>>>>> ilya >>>>>>> >>>>>>> On Wed, Aug 4, 2010 at 6:51 PM, Bastien >>>>>> > >>>>>>> wrote: >>>>>>>> >>>>>>>> Hi Ilya, >>>>>>>> >>>>>>>> Ilya Shlyakhter writes: >>>>>>>> >>>>>>>>> I'd like to sort agenda entries in a custom agenda view by >>>>>>>>> the value >>>>>>>>> of a text property that I put on the headlines. >>>>>>>>> Is there a way to do that? >>>>>>>> >>>>>>>> Well, no. >>>>>>>> >>>>>>>> Maybe playing around with org-map-entries could yield some >>>>>>>> result. >>>>>>>> >>>>>>>> -- >>>>>>>> Bastien >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Emacs-orgmode mailing list >>>>>>> Please use `Reply All' to send replies to the list. >>>>>>> Emacs-orgmode@gnu.org >>>>>>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode >>>>>> >>>>>> - Carsten >>>>>> >>>>>> >>>>>> >>>>>> >>>> >>>> - Carsten >>>> >>>> >>>> >>>> >> >> - Carsten >> >> >> >> - Carsten