From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nathan Neff Subject: Re: Agenda search: setting sort-order Date: Mon, 18 Jun 2018 13:16:41 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000489e82056eee91e4" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUyhp-0005yY-G9 for emacs-orgmode@gnu.org; Mon, 18 Jun 2018 14:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUyhn-0006xH-UW for emacs-orgmode@gnu.org; Mon, 18 Jun 2018 14:16:45 -0400 Received: from mail-it0-x234.google.com ([2607:f8b0:4001:c0b::234]:36935) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fUyhn-0006vY-Me for emacs-orgmode@gnu.org; Mon, 18 Jun 2018 14:16:43 -0400 Received: by mail-it0-x234.google.com with SMTP id l6-v6so13362264iti.2 for ; Mon, 18 Jun 2018 11:16:43 -0700 (PDT) In-Reply-To: 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" To: emacs-orgmode --000000000000489e82056eee91e4 Content-Type: text/plain; charset="UTF-8" I had a look at org-agenda.el, and took a first stab at "coding" :) I fixed the sorting problem when using agenda-search-view, and I have a DIFF/patch at the bottom of this e-mail [1] that provided the fix. Would this be of interest to the org-mode project? This code fixes the problem, but it is duplicated in the function org-agenda-get-todos, and seems redundant, therefore a more "long term" fix would probably not resemble the minor patch below. Also, I have no experience with lisp, nor the org-mode codebase :-O Here's steps I used to find the problem. Feel free to skip to [1] for the DIFF/patch. I found that if I perform an agenda-search, and change the sort method to priority or tag, then the agenda items matching my search are indeed sorted in the correct order. This lead me to think to inspect the code that is performing the time/date comparison of entries found by the org-search-view. I put a debug-watch on the function org-cmp-ts and set the sort method to "ts-down". I ran an agenda search, and I noticed that none of the entries matching my search had a 'ts-date property. I ran another agenda search (by tag) and noticed that the entries being compared in the org-cmp-ts function did indeed have a 'ts-date property. So, I came to the conclusion that org-search-view does not give matching entries a 'ts-date property. Also, the 'type property of these entries needed the ts-date-type appended to their 'type property (e.g. "search timestamp" instead of just "search"). Otherwise, the org-cmp-ts function would think the two entries it was comparing did not have matching timestamp types and simply return nil, indicating both entries were "equal" in sort order. Thanks, --Nate [1] I ran a DIFF of org-agenda.el (mine) against org-agenda.el (9.1.13) and here's the DIFF. diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 322480c..5af6743 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -4567,6 +4567,9 @@ is active." (goto-char beg) (setq marker (org-agenda-new-marker (point)) category (org-get-category) + ts-date-pair (org-agenda-entry-get-agenda-timestamp (point)) + ts-date (car ts-date-pair) + ts-date-type (cdr ts-date-pair) level (make-string (org-reduced-level (org-outline-level)) ? ) inherited-tags (or (eq org-agenda-show-inherited-tags 'always) @@ -4584,10 +4587,12 @@ is active." (org-add-props txt props 'org-marker marker 'org-hd-marker marker 'org-todo-regexp org-todo-regexp + 'ts-date ts-date + 'ts-date-type ts-date-type 'level level 'org-complex-heading-regexp org-complex-heading-regexp 'priority 1000 - 'type "search") + 'type (concat "search" ts-date-type)) (push txt ee) (goto-char (1- end)))))))))) (setq rtn (nreverse ee)) On Tue, Jun 12, 2018 at 3:07 PM, Nathan Neff wrote: > Bumping this question to see if anyone has a workaround - > I recently have been wishing to search for keywords and order > the results in reverse timestamp order. > > This sounds like a fairly useful and common feature, so I think > there must be something I'm configuring incorrectly. I am able > to reproduce the problem using a fairly clean Emacs install (a > VM with no customizations). > > Thanks, > --Nate > > > > On Wed, May 30, 2018 at 4:57 PM, Nathan Neff > wrote: > >> Hi all, >> >> I'm using org-mode version 9.1.13 from elpa, and >> have a custom agenda command: >> >> >> (setq org-agenda-custom-commands >> '( >> ("z" search "" >> ((org-agenda-sorting-strategy '(timestamp-up)))))) >> >> And I have an org-file with this data: >> >> * TODO [#C] Test1 >> :foo: >> <2018-04-24 Tue 19:30> >> * TODO [#A] Test2 >> :foo: >> <2018-05-24 Thu 19:30> >> * TODO [#B] Test3 >> :foo: >> <2017-12-24 Sun 23:33> >> >> The data is not sorted according to timestamp. I cannot seem to >> get the data sorted in any fashion when using the "search" agenda mode. >> >> However, if I change "search" to "tags" and search for the "foo" tag, then >> it appears that the sorting works. I've tested it with priority and >> timestamp >> using the above data and it sorts the items correctly. >> >> Why is my "search" agenda command ignoring the >> org-agenda-sorting-strategy? >> >> Thanks, >> --Nate >> > > --000000000000489e82056eee91e4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I had a look at org-agenda.el, and took a first stab at &q= uot;coding" :)
I fixed the sorting problem when using agenda-searc= h-view, and
I have a DIFF/patch at the bottom of this e-mail [1] = that provided the fix.

Would this be of interest t= o the org-mode project?=C2=A0 This code fixes the problem,
but it= is duplicated in the function org-agenda-get-todos, and seems redundant,= =C2=A0
therefore a more "long term" fix would probably = not resemble the minor patch
below.=C2=A0 Also, I have no experie= nce with lisp, nor the org-mode codebase :-O

Here&= #39;s steps I used to find the problem.=C2=A0 Feel free to skip to [1]
for the DIFF/patch.

I found that if I p= erform an agenda-search, and change
the sort method to priority o= r tag, then the agenda items
matching my search are indeed sorted= in the correct order.

This lead me to think to in= spect the code that is performing
the time/date comparison of ent= ries found by the org-search-view.

I put a debug-w= atch on the function org-cmp-ts and set
the sort method to "= ts-down".=C2=A0 I ran an agenda search, and I=C2=A0
noticed = that none of the entries matching my search had a 'ts-date
pr= operty.

I ran another agenda search (by tag) and n= oticed that the entries
being compared in the org-cmp-ts function= did indeed have a 'ts-date
property.

So, I came to the conclusion that org-search-view does not give matching<= /div>
entries a 'ts-date property.=C2=A0 Also, the 'type proper= ty of these entries needed
the ts-date-type appended to their = 9;type property (e.g. "search timestamp"
instead of jus= t "search").=C2=A0 Otherwise, the org-cmp-ts function would think=
the two entries it was comparing did not have matching timestamp= types
and simply return nil, indicating both entries were "= equal" in sort order.

Thanks,
--Nat= e

[1]=C2=A0
I ran a DIFF of org-agenda.e= l (mine) against org-agenda.el (9.1.13) and
here's the DIFF.= =C2=A0

diff --git a/lisp/org-agenda.el b/lisp= /org-agenda.el
index 322480c..5af6743 100644
--- a/lisp= /org-agenda.el
+++ b/lisp/org-agenda.el
@@ -4567,6 +456= 7,9 @@ is active."
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char beg)
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (setq marker (org-agenda-new-marker (point))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 category (org-get-category)
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ts-date-pair (org-agenda-entry= -get-agenda-timestamp (point))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ts-date (car ts-date-pair)
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ts-date-type (cd= r ts-date-pair)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 level (make-string = (org-reduced-level (org-outline-level)) ? )
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 inherited-tags
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (or (eq = org-agenda-show-inherited-tags 'always)
@@ -4584,10 +4587,12 = @@ is active."
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-add-props txt props
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 'org-marker marker 'org-hd-marker marker
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 'org-todo-regexp org-todo-regexp
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'ts-date ts-date
+ = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'ts-date-type ts-date-t= ype
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 'level level
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 'org-complex-heading-regexp org-complex-heading-regexp
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 'priority 1000
- =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 'type "= ;search")
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= 'type (concat "search" ts-date-type))
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (pus= h txt ee)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char (1- end))))))))))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 (setq rtn (nreverse ee))


On Tue, = Jun 12, 2018 at 3:07 PM, Nathan Neff <nathan.neff@gmail.com> wrote:
Bumping this= question to see if anyone has a workaround -
I recently have been wish= ing to search for keywords and order
the results in reverse times= tamp order. =C2=A0

This sounds like a fairly usefu= l and common feature, so I think=C2=A0
there must be something I&= #39;m configuring incorrectly.=C2=A0 I am able=C2=A0
to reproduce= the problem using a fairly clean Emacs install (a=C2=A0
VM with = no customizations).

Thanks,
--Nate
=



On Wed, May 30, = 2018 at 4:57 PM, Nathan Neff <nathan.neff@gmail.com> wro= te:
Hi all,

I'm using org-mode version 9.1.13 from elpa, and
have = a custom agenda command:


(setq= org-agenda-custom-commands
=C2=A0 =C2=A0'(
=C2=A0 = =C2=A0 =C2=A0("z" search ""=C2=A0
=C2=A0 =C2= =A0 =C2=A0 =C2=A0((org-agenda-sorting-strategy '(timestamp-up))))))

And I have an org-file with this data:

* TODO [#C] Test1 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 :foo:
<2018-04-24 Tue 19:30>
* TODO [#A] T= est2 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :foo:
<2018-05-2= 4 Thu 19:30>
* TODO [#B] Test3 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 :foo:
<2017-12-24 Sun 23:33>
The data is not sorted according to timestamp.=C2=A0 I cannot s= eem to=C2=A0
get the data sorted in any fashion when using the &q= uot;search" agenda mode.

However, if I change= "search" to "tags" and search for the "foo" = tag, then
it appears that the sorting works.=C2=A0 I've teste= d it with priority and timestamp
using the above data and it sort= s the items correctly.

Why is my "search"= ; agenda command ignoring the org-agenda-sorting-strategy?

Thanks,
--Nate


--000000000000489e82056eee91e4--