emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* custom sorting of agenda items
@ 2010-08-04 19:27 Ilya Shlyakhter
  2010-08-04 22:51 ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Ilya Shlyakhter @ 2010-08-04 19:27 UTC (permalink / raw)
  To: emacs-orgmode

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?
thanks,
ilya

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-04 19:27 custom sorting of agenda items Ilya Shlyakhter
@ 2010-08-04 22:51 ` Bastien
  2010-08-04 23:01   ` Ilya Shlyakhter
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2010-08-04 22:51 UTC (permalink / raw)
  To: Ilya Shlyakhter; +Cc: emacs-orgmode

Hi Ilya,

Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-04 22:51 ` Bastien
@ 2010-08-04 23:01   ` Ilya Shlyakhter
  2010-08-16 12:54     ` Carsten Dominik
  2010-08-17 16:51     ` Samuel Wales
  0 siblings, 2 replies; 12+ messages in thread
From: Ilya Shlyakhter @ 2010-08-04 23:01 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

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?

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 <bastien.guerry@wikimedia.fr> wrote:
> Hi Ilya,
>
> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-04 23:01   ` Ilya Shlyakhter
@ 2010-08-16 12:54     ` Carsten Dominik
  2010-08-16 12:59       ` Ilya Shlyakhter
  2010-08-17 16:51     ` Samuel Wales
  1 sibling, 1 reply; 12+ messages in thread
From: Carsten Dominik @ 2010-08-16 12:54 UTC (permalink / raw)
  To: Ilya Shlyakhter; +Cc: emacs-orgmode, Bastien


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  
> <bastien.guerry@wikimedia.fr> wrote:
>> Hi Ilya,
>>
>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-16 12:54     ` Carsten Dominik
@ 2010-08-16 12:59       ` Ilya Shlyakhter
  2010-08-16 13:14         ` Carsten Dominik
  2010-08-16 13:40         ` Carsten Dominik
  0 siblings, 2 replies; 12+ messages in thread
From: Ilya Shlyakhter @ 2010-08-16 12:59 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode, Bastien

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?

ilya

On Mon, Aug 16, 2010 at 8:54 AM, Carsten Dominik
<carsten.dominik@gmail.com> 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 <bastien.guerry@wikimedia.fr>
>> wrote:
>>>
>>> Hi Ilya,
>>>
>>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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
>
>
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-16 12:59       ` Ilya Shlyakhter
@ 2010-08-16 13:14         ` Carsten Dominik
  2010-08-16 13:40         ` Carsten Dominik
  1 sibling, 0 replies; 12+ messages in thread
From: Carsten Dominik @ 2010-08-16 13:14 UTC (permalink / raw)
  To: Ilya Shlyakhter; +Cc: emacs-orgmode, Bastien


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?

This would be similar in speed, I think.  At least my proposal
only goes to the stuff that has made it into the agenda.

Ahh, you need the stuff in the sorting function - so it is too
late when the stuff is in the agenda.

I'll look into adding a hook...

- Carsten

>
> ilya
>
> On Mon, Aug 16, 2010 at 8:54 AM, Carsten Dominik
> <carsten.dominik@gmail.com> 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  
>>> <bastien.guerry@wikimedia.fr>
>>> wrote:
>>>>
>>>> Hi Ilya,
>>>>
>>>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-16 12:59       ` Ilya Shlyakhter
  2010-08-16 13:14         ` Carsten Dominik
@ 2010-08-16 13:40         ` Carsten Dominik
  2010-08-17 16:40           ` Ilya Shlyakhter
  1 sibling, 1 reply; 12+ messages in thread
From: Carsten Dominik @ 2010-08-16 13:40 UTC (permalink / raw)
  To: Ilya Shlyakhter; +Cc: Martin Pohlack, emacs-orgmode Mode, Bastien Guerry


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
> <carsten.dominik@gmail.com> 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  
>>> <bastien.guerry@wikimedia.fr>
>>> wrote:
>>>>
>>>> Hi Ilya,
>>>>
>>>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-16 13:40         ` Carsten Dominik
@ 2010-08-17 16:40           ` Ilya Shlyakhter
  2010-08-18  7:35             ` Carsten Dominik
  0 siblings, 1 reply; 12+ messages in thread
From: Ilya Shlyakhter @ 2010-08-17 16:40 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Martin Pohlack, emacs-orgmode Mode, Bastien Guerry

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.

It seems that _appending_ text to the agenda line should be safe.  Is
that correct?

thanks,

ilya

On Mon, Aug 16, 2010 at 9:40 AM, Carsten Dominik
<carsten.dominik@gmail.com> 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
>> <carsten.dominik@gmail.com> 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 <bastien.guerry@wikimedia.fr>
>>>> wrote:
>>>>>
>>>>> Hi Ilya,
>>>>>
>>>>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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
>
>
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-04 23:01   ` Ilya Shlyakhter
  2010-08-16 12:54     ` Carsten Dominik
@ 2010-08-17 16:51     ` Samuel Wales
  1 sibling, 0 replies; 12+ messages in thread
From: Samuel Wales @ 2010-08-17 16:51 UTC (permalink / raw)
  To: Ilya Shlyakhter; +Cc: emacs-orgmode, Bastien

On 2010-08-04, Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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?

Here is code of a general nature.

(defun alpha-org-entry-get (property &optional sg inherit)
  "Return the value of PROPERTY, whether you are in the outline
or the agenda, by calling `org-entry-get'.

SG is the agenda header string provided by user-defined agenda
sorting, or nil.  If it is nil and you are in the outline, use
the current headline directly.  If it is nil and you are in the
agenda, use the current headline by going to the outline.

INHERIT is the inherit argument for org-entry-get.

According to the manual at the time of this writing, possible
properties include these.

     TODO         The TODO keyword of the entry.
     TAGS         The tags defined directly in the headline.
     ALLTAGS      All tags, including inherited ones.
     CATEGORY     The category of an entry.
     PRIORITY     The priority of the entry, a string with a single letter.
     DEADLINE     The deadline time string, without the angular brackets.
     SCHEDULED    The scheduling timestamp, without the angular brackets.
     CLOSED       When was this entry closed?
     TIMESTAMP    The first keyword-less timestamp in the entry.
       - this works even in the headline
     TIMESTAMP_IA The first inactive timestamp in the entry.
       - this works even in the headline
       - it does not seem to report CLOSED ts -- use CLOSED
     CLOCKSUM     The sum of CLOCK intervals in the subtree.  org-clock-sum
                  must be run first to compute the values.
     ITEM         The content of the entry.

For anything else, you can use marker-buffer to get to the
outline and do manual parsing or use some other function.  Or
possibly modify org-entry-get to understand it and send a patch
to the org mailing list.

The idea is to use this as a single way to get most metadata no
matter where you are.
"
  (org-entry-get
   (cond
     ((eq major-mode 'org-agenda-mode)
      (let* ((s (or sg (buffer-substring (point-at-bol) (point-at-eol))))
             (m (or (get-text-property 1 'org-marker s)
                    (get-text-property 1 'org-hd-marker s))))
        ;;do this to get to the buffer if you need other data that
        ;;org-entry-get cannot extract
        ;;(b (and m (marker-buffer m))))
;;;        (if b
;;;            (with-current-buffer b
;;;              (goto-char m)
        m))
     ((eq major-mode 'org-mode) (point))
     (t (error "Not in an org-mode buffer")))
   property
   inherit))


>
> 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 <bastien.guerry@wikimedia.fr> wrote:
>> Hi Ilya,
>>
>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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
>


-- 
Q: How many CDC "scientists" does it take to change a lightbulb?
A: "You only think it's dark." [CDC has denied a deadly disease for 25 years]
==========
Retrovirus: http://www.wpinstitute.org/xmrv/index.html -- PLEASE DONATE
===
PNAS must publish the original Lo and Alter NIH/FDA XMRV paper
verbatim along with the new paper.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-17 16:40           ` Ilya Shlyakhter
@ 2010-08-18  7:35             ` Carsten Dominik
  2010-08-19 23:49               ` Ilya Shlyakhter
  0 siblings, 1 reply; 12+ messages in thread
From: Carsten Dominik @ 2010-08-18  7:35 UTC (permalink / raw)
  To: Ilya Shlyakhter; +Cc: Martin Pohlack, emacs-orgmode Mode, Bastien Guerry


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
> <carsten.dominik@gmail.com> 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
>>> <carsten.dominik@gmail.com> 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 <bastien.guerry@wikimedia.fr 
>>>>> >
>>>>> wrote:
>>>>>>
>>>>>> Hi Ilya,
>>>>>>
>>>>>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-18  7:35             ` Carsten Dominik
@ 2010-08-19 23:49               ` Ilya Shlyakhter
  2010-08-20  6:30                 ` Carsten Dominik
  0 siblings, 1 reply; 12+ messages in thread
From: Ilya Shlyakhter @ 2010-08-19 23:49 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Martin Pohlack, emacs-orgmode Mode, Bastien Guerry

> 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?

> 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
<carsten.dominik@gmail.com> 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
>> <carsten.dominik@gmail.com> 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
>>>> <carsten.dominik@gmail.com> 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 <bastien.guerry@wikimedia.fr>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Ilya,
>>>>>>>
>>>>>>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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
>
>
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: custom sorting of agenda items
  2010-08-19 23:49               ` Ilya Shlyakhter
@ 2010-08-20  6:30                 ` Carsten Dominik
  0 siblings, 0 replies; 12+ messages in thread
From: Carsten Dominik @ 2010-08-20  6:30 UTC (permalink / raw)
  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
> <carsten.dominik@gmail.com> 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
>>> <carsten.dominik@gmail.com> 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
>>>>> <carsten.dominik@gmail.com> 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 <bastien.guerry@wikimedia.fr 
>>>>>>> >
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi Ilya,
>>>>>>>>
>>>>>>>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-08-20  7:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-04 19:27 custom sorting of agenda items Ilya Shlyakhter
2010-08-04 22:51 ` Bastien
2010-08-04 23:01   ` Ilya Shlyakhter
2010-08-16 12:54     ` Carsten Dominik
2010-08-16 12:59       ` Ilya Shlyakhter
2010-08-16 13:14         ` Carsten Dominik
2010-08-16 13:40         ` Carsten Dominik
2010-08-17 16:40           ` Ilya Shlyakhter
2010-08-18  7:35             ` Carsten Dominik
2010-08-19 23:49               ` Ilya Shlyakhter
2010-08-20  6:30                 ` Carsten Dominik
2010-08-17 16:51     ` Samuel Wales

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).