emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Patch] Fix date-based sorting of tags and tags-todo agenda views
@ 2015-02-07 19:05 Yuri D Lensky
  2015-02-07 21:14 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Yuri D Lensky @ 2015-02-07 19:05 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 3604 bytes --]

An example to test this problem:

Evaluate:
(setq org-agenda-custom-commands
      '(("t" "TEST" tags-todo "tag"
         ((org-agenda-sorting-strategy '(deadline-up))))))
then run the view. It will not be sorted properly before the patch, but will be after.

I would also recommend factoring the code that I added out into a separate function (as it also appears almost verbatim in org-agenda-get-todos), but I am not sure the conventions or desire for this.

From c8a7211639d9c138a3b3dcb7e3ce7c85264580f1 Mon Sep 17 00:00:00 2001
From: "Yuri D. Lensky" <ydl@ydl.cm>
Date: Sat, 7 Feb 2015 13:37:46 -0500
Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda

* lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
  add timestamp property, completely analogously to org-agenda-get-todos.

Before this fix, timestamps were ignored when sorting agenda views of
the 'tags' and 'tags-todo' types.
---
 lisp/org.el | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index a095f8d..54b375e 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14177,7 +14177,7 @@ headlines matching this string."
          lspos tags tags-list
 	 (tags-alist (list (cons 0 org-file-tags)))
 	 (llast 0) rtn rtn1 level category i txt
-	 todo marker entry priority)
+	 todo marker entry priority ts-date ts-date-type)
     (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
       (setq action (list 'lambda nil action)))
     (save-excursion
@@ -14194,6 +14194,34 @@ headlines matching this string."
 	  (goto-char (setq lspos (match-beginning 0)))
 	  (setq level (org-reduced-level (org-outline-level))
 		category (org-get-category))
+          (when (eq action 'agenda)
+            (setq ts-date (let (ts)
+			(save-match-data
+			  (cond ((org-em 'scheduled-up 'scheduled-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "SCHEDULED")
+				       ts-date-type " scheduled"))
+				((org-em 'deadline-up 'deadline-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "DEADLINE")
+				       ts-date-type " deadline"))
+				((org-em 'ts-up 'ts-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "TIMESTAMP")
+				       ts-date-type " timestamp"))
+				((org-em 'tsia-up 'tsia-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
+				       ts-date-type " timestamp_ia"))
+				((org-em 'timestamp-up 'timestamp-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (or (org-entry-get (point) "SCHEDULED")
+					      (org-entry-get (point) "DEADLINE")
+					      (org-entry-get (point) "TIMESTAMP")
+					      (org-entry-get (point) "TIMESTAMP_IA"))
+				       ts-date-type ""))
+				(t (setq ts-date-type "")))
+			  (when ts (ignore-errors (org-time-string-to-absolute ts)))))))
 	  (setq i llast llast level)
 	  ;; remove tag lists from same and sublevels
 	  (while (>= i level)
@@ -14265,7 +14293,9 @@ headlines matching this string."
 	      (org-add-props txt props
 		'org-marker marker 'org-hd-marker marker 'org-category category
 		'todo-state todo
-		'priority priority 'type "tagsmatch")
+                'ts-date ts-date
+		'priority priority
+                'type (concat "tagsmatch" ts-date-type))
 	      (push txt rtn))
 	     ((functionp action)
 	      (setq org-map-continue-from nil)
-- 
1.9.4.msysgit.2


[-- Attachment #2: 0001-Fix-timestamp-based-sorting-of-tags-based-entries-in.patch --]
[-- Type: application/octet-stream, Size: 3057 bytes --]

From c8a7211639d9c138a3b3dcb7e3ce7c85264580f1 Mon Sep 17 00:00:00 2001
From: "Yuri D. Lensky" <ydl@ydl.cm>
Date: Sat, 7 Feb 2015 13:37:46 -0500
Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda

* lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
  add timestamp property, completely analogously to org-agenda-get-todos.

Before this fix, timestamps were ignored when sorting agenda views of
the 'tags' and 'tags-todo' types.
---
 lisp/org.el | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index a095f8d..54b375e 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14177,7 +14177,7 @@ headlines matching this string."
          lspos tags tags-list
 	 (tags-alist (list (cons 0 org-file-tags)))
 	 (llast 0) rtn rtn1 level category i txt
-	 todo marker entry priority)
+	 todo marker entry priority ts-date ts-date-type)
     (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
       (setq action (list 'lambda nil action)))
     (save-excursion
@@ -14194,6 +14194,34 @@ headlines matching this string."
 	  (goto-char (setq lspos (match-beginning 0)))
 	  (setq level (org-reduced-level (org-outline-level))
 		category (org-get-category))
+          (when (eq action 'agenda)
+            (setq ts-date (let (ts)
+			(save-match-data
+			  (cond ((org-em 'scheduled-up 'scheduled-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "SCHEDULED")
+				       ts-date-type " scheduled"))
+				((org-em 'deadline-up 'deadline-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "DEADLINE")
+				       ts-date-type " deadline"))
+				((org-em 'ts-up 'ts-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "TIMESTAMP")
+				       ts-date-type " timestamp"))
+				((org-em 'tsia-up 'tsia-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
+				       ts-date-type " timestamp_ia"))
+				((org-em 'timestamp-up 'timestamp-down
+					 org-agenda-sorting-strategy-selected)
+				 (setq ts (or (org-entry-get (point) "SCHEDULED")
+					      (org-entry-get (point) "DEADLINE")
+					      (org-entry-get (point) "TIMESTAMP")
+					      (org-entry-get (point) "TIMESTAMP_IA"))
+				       ts-date-type ""))
+				(t (setq ts-date-type "")))
+			  (when ts (ignore-errors (org-time-string-to-absolute ts)))))))
 	  (setq i llast llast level)
 	  ;; remove tag lists from same and sublevels
 	  (while (>= i level)
@@ -14265,7 +14293,9 @@ headlines matching this string."
 	      (org-add-props txt props
 		'org-marker marker 'org-hd-marker marker 'org-category category
 		'todo-state todo
-		'priority priority 'type "tagsmatch")
+                'ts-date ts-date
+		'priority priority
+                'type (concat "tagsmatch" ts-date-type))
 	      (push txt rtn))
 	     ((functionp action)
 	      (setq org-map-continue-from nil)
-- 
1.9.4.msysgit.2


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

* Re: [Patch] Fix date-based sorting of tags and tags-todo agenda views
  2015-02-07 19:05 [Patch] Fix date-based sorting of tags and tags-todo agenda views Yuri D Lensky
@ 2015-02-07 21:14 ` Nicolas Goaziou
  2015-02-08 18:54   ` Yuri D. Lensky
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2015-02-07 21:14 UTC (permalink / raw)
  To: Yuri D Lensky; +Cc: emacs-orgmode@gnu.org

Hello,

Yuri D Lensky <ydl@mit.edu> writes:

> An example to test this problem:
>
> Evaluate:
> (setq org-agenda-custom-commands
>       '(("t" "TEST" tags-todo "tag"
>          ((org-agenda-sorting-strategy '(deadline-up))))))
> then run the view. It will not be sorted properly before the patch,
> but will be after.

Thank you. It looks good.

> I would also recommend factoring the code that I added out into
> a separate function (as it also appears almost verbatim in
> org-agenda-get-todos), but I am not sure the conventions or desire for
> this.

I agree it would be good to do that refactoring. Do you want to take
care of it in the same patch?

> From c8a7211639d9c138a3b3dcb7e3ce7c85264580f1 Mon Sep 17 00:00:00 2001
> From: "Yuri D. Lensky" <ydl@ydl.cm>
> Date: Sat, 7 Feb 2015 13:37:46 -0500
> Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda
>
> * lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
>   add timestamp property, completely analogously to org-agenda-get-todos.
>
> Before this fix, timestamps were ignored when sorting agenda views of
> the 'tags' and 'tags-todo' types.

You need to add TINYCHANGE at the end of the commit message. If your
patch ends up being more than 20 lines long, you'll also need to sign
FSF assignment (if not already done). See

  http://orgmode.org/worg/org-contribute.html#unnumbered-2


Regards,

-- 
Nicolas Goaziou

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

* Re: [Patch] Fix date-based sorting of tags and tags-todo agenda views
  2015-02-07 21:14 ` Nicolas Goaziou
@ 2015-02-08 18:54   ` Yuri D. Lensky
  2015-02-08 20:18     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Yuri D. Lensky @ 2015-02-08 18:54 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 7693 bytes --]

Done.

From 131435ac43d950bad2bb42b92982f498de74a31f Mon Sep 17 00:00:00 2001
From: "Yuri D. Lensky" <ydl@ydl.cm>
Date: Sat, 7 Feb 2015 13:37:46 -0500
Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda

* lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
  add timestamp property, completely analogously to
  org-agenda-get-todos.
* lisp/org-agenda.el (org-agenda-entry-get-agenda-timestamp,
  org-agenda-get-todos): Factored timestamp retrieval code out to
  separate function org-agenda-entry-get-agenda-timestamp from
  org-agenda-get-todos.

Before this fix, timestamps were ignored when sorting agenda views of
the 'tags' and 'tags-todo' types.
---
 lisp/org-agenda.el | 66 +++++++++++++++++++++++++++++++-----------------------
 lisp/org.el        | 11 +++++++--
 2 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index e7cfd27..5b04cac 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5362,6 +5362,39 @@ the documentation of `org-diary'."
 (defvar org-heading-keyword-regexp-format) ; defined in org.el
 (defvar org-agenda-sorting-strategy-selected nil)
 
+(defun org-agenda-entry-get-agenda-timestamp (pom)
+  "Given a point or maker POM, returns a cons cell of the
+timestamp and the timestamp type relevant for the sorting
+strategy in `org-agenda-sorting-strategy-selected'."
+  (let (ts ts-date-type)
+    (save-match-data
+      (cond ((org-em 'scheduled-up 'scheduled-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "SCHEDULED")
+		   ts-date-type " scheduled"))
+	    ((org-em 'deadline-up 'deadline-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "DEADLINE")
+		   ts-date-type " deadline"))
+	    ((org-em 'ts-up 'ts-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP")
+		   ts-date-type " timestamp"))
+	    ((org-em 'tsia-up 'tsia-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP_IA")
+		   ts-date-type " timestamp_ia"))
+	    ((org-em 'timestamp-up 'timestamp-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (or (org-entry-get pom "SCHEDULED")
+			  (org-entry-get pom "DEADLINE")
+			  (org-entry-get pom "TIMESTAMP")
+			  (org-entry-get pom "TIMESTAMP_IA"))
+		   ts-date-type ""))
+	    (t (setq ts-date-type "")))
+      (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
+	    ts-date-type))))
+
 (defun org-agenda-get-todos ()
   "Return the TODO information for agenda display."
   (let* ((props (list 'face nil
@@ -5386,7 +5419,8 @@ the documentation of `org-diary'."
 					       "|")
 					      "\\|") "\\)"))
 			  (t org-not-done-regexp))))
-	 marker priority category level tags todo-state ts-date ts-date-type
+	 marker priority category level tags todo-state
+	 ts-date ts-date-type ts-date-pair
 	 ee txt beg end inherited-tags todo-state-end-pos)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
@@ -5406,33 +5440,9 @@ the documentation of `org-diary'."
 	(goto-char (match-beginning 2))
 	(setq marker (org-agenda-new-marker (match-beginning 0))
 	      category (org-get-category)
-	      ts-date (let (ts)
-			(save-match-data
-			  (cond ((org-em 'scheduled-up 'scheduled-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "SCHEDULED")
-				       ts-date-type " scheduled"))
-				((org-em 'deadline-up 'deadline-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "DEADLINE")
-				       ts-date-type " deadline"))
-				((org-em 'ts-up 'ts-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP")
-				       ts-date-type " timestamp"))
-				((org-em 'tsia-up 'tsia-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
-				       ts-date-type " timestamp_ia"))
-				((org-em 'timestamp-up 'timestamp-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (or (org-entry-get (point) "SCHEDULED")
-					      (org-entry-get (point) "DEADLINE")
-					      (org-entry-get (point) "TIMESTAMP")
-					      (org-entry-get (point) "TIMESTAMP_IA"))
-				       ts-date-type ""))
-				(t (setq ts-date-type "")))
-			  (when ts (ignore-errors (org-time-string-to-absolute ts)))))
+	      ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+	      ts-date (car ts-date-pair)
+	      ts-date-type (cdr ts-date-pair)
 	      txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
 	      inherited-tags
 	      (or (eq org-agenda-show-inherited-tags 'always)
diff --git a/lisp/org.el b/lisp/org.el
index a095f8d..795186a 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14177,7 +14177,8 @@ headlines matching this string."
          lspos tags tags-list
 	 (tags-alist (list (cons 0 org-file-tags)))
 	 (llast 0) rtn rtn1 level category i txt
-	 todo marker entry priority)
+	 todo marker entry priority
+	 ts-date ts-date-type ts-date-pair)
     (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
       (setq action (list 'lambda nil action)))
     (save-excursion
@@ -14194,6 +14195,10 @@ headlines matching this string."
 	  (goto-char (setq lspos (match-beginning 0)))
 	  (setq level (org-reduced-level (org-outline-level))
 		category (org-get-category))
+          (when (eq action 'agenda)
+            (setq ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+		  ts-date (car ts-date-pair)
+		  ts-date-type (cdr ts-date-pair)))
 	  (setq i llast llast level)
 	  ;; remove tag lists from same and sublevels
 	  (while (>= i level)
@@ -14265,7 +14270,9 @@ headlines matching this string."
 	      (org-add-props txt props
 		'org-marker marker 'org-hd-marker marker 'org-category category
 		'todo-state todo
-		'priority priority 'type "tagsmatch")
+                'ts-date ts-date
+		'priority priority
+                'type (concat "tagsmatch" ts-date-type))
 	      (push txt rtn))
 	     ((functionp action)
 	      (setq org-map-continue-from nil)
-- 
1.9.4.msysgit.2

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Yuri D Lensky <ydl@mit.edu> writes:
>
>> An example to test this problem:
>>
>> Evaluate:
>> (setq org-agenda-custom-commands
>>       '(("t" "TEST" tags-todo "tag"
>>          ((org-agenda-sorting-strategy '(deadline-up))))))
>> then run the view. It will not be sorted properly before the patch,
>> but will be after.
>
> Thank you. It looks good.
>
>> I would also recommend factoring the code that I added out into
>> a separate function (as it also appears almost verbatim in
>> org-agenda-get-todos), but I am not sure the conventions or desire for
>> this.
>
> I agree it would be good to do that refactoring. Do you want to take
> care of it in the same patch?
>
>> From c8a7211639d9c138a3b3dcb7e3ce7c85264580f1 Mon Sep 17 00:00:00 2001
>> From: "Yuri D. Lensky" <ydl@ydl.cm>
>> Date: Sat, 7 Feb 2015 13:37:46 -0500
>> Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda
>>
>> * lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
>>   add timestamp property, completely analogously to org-agenda-get-todos.
>>
>> Before this fix, timestamps were ignored when sorting agenda views of
>> the 'tags' and 'tags-todo' types.
>
> You need to add TINYCHANGE at the end of the commit message. If your
> patch ends up being more than 20 lines long, you'll also need to sign
> FSF assignment (if not already done). See
>
>   http://orgmode.org/worg/org-contribute.html#unnumbered-2
>
>
> Regards,

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch --]
[-- Type: text/x-patch, Size: 6187 bytes --]

From 131435ac43d950bad2bb42b92982f498de74a31f Mon Sep 17 00:00:00 2001
From: "Yuri D. Lensky" <ydl@ydl.cm>
Date: Sat, 7 Feb 2015 13:37:46 -0500
Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda

* lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
  add timestamp property, completely analogously to
  org-agenda-get-todos.
* lisp/org-agenda.el (org-agenda-entry-get-agenda-timestamp,
  org-agenda-get-todos): Factored timestamp retrieval code out to
  separate function org-agenda-entry-get-agenda-timestamp from
  org-agenda-get-todos.

Before this fix, timestamps were ignored when sorting agenda views of
the 'tags' and 'tags-todo' types.
---
 lisp/org-agenda.el | 66 +++++++++++++++++++++++++++++++-----------------------
 lisp/org.el        | 11 +++++++--
 2 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index e7cfd27..5b04cac 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5362,6 +5362,39 @@ the documentation of `org-diary'."
 (defvar org-heading-keyword-regexp-format) ; defined in org.el
 (defvar org-agenda-sorting-strategy-selected nil)
 
+(defun org-agenda-entry-get-agenda-timestamp (pom)
+  "Given a point or maker POM, returns a cons cell of the
+timestamp and the timestamp type relevant for the sorting
+strategy in `org-agenda-sorting-strategy-selected'."
+  (let (ts ts-date-type)
+    (save-match-data
+      (cond ((org-em 'scheduled-up 'scheduled-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "SCHEDULED")
+		   ts-date-type " scheduled"))
+	    ((org-em 'deadline-up 'deadline-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "DEADLINE")
+		   ts-date-type " deadline"))
+	    ((org-em 'ts-up 'ts-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP")
+		   ts-date-type " timestamp"))
+	    ((org-em 'tsia-up 'tsia-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP_IA")
+		   ts-date-type " timestamp_ia"))
+	    ((org-em 'timestamp-up 'timestamp-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (or (org-entry-get pom "SCHEDULED")
+			  (org-entry-get pom "DEADLINE")
+			  (org-entry-get pom "TIMESTAMP")
+			  (org-entry-get pom "TIMESTAMP_IA"))
+		   ts-date-type ""))
+	    (t (setq ts-date-type "")))
+      (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
+	    ts-date-type))))
+
 (defun org-agenda-get-todos ()
   "Return the TODO information for agenda display."
   (let* ((props (list 'face nil
@@ -5386,7 +5419,8 @@ the documentation of `org-diary'."
 					       "|")
 					      "\\|") "\\)"))
 			  (t org-not-done-regexp))))
-	 marker priority category level tags todo-state ts-date ts-date-type
+	 marker priority category level tags todo-state
+	 ts-date ts-date-type ts-date-pair
 	 ee txt beg end inherited-tags todo-state-end-pos)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
@@ -5406,33 +5440,9 @@ the documentation of `org-diary'."
 	(goto-char (match-beginning 2))
 	(setq marker (org-agenda-new-marker (match-beginning 0))
 	      category (org-get-category)
-	      ts-date (let (ts)
-			(save-match-data
-			  (cond ((org-em 'scheduled-up 'scheduled-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "SCHEDULED")
-				       ts-date-type " scheduled"))
-				((org-em 'deadline-up 'deadline-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "DEADLINE")
-				       ts-date-type " deadline"))
-				((org-em 'ts-up 'ts-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP")
-				       ts-date-type " timestamp"))
-				((org-em 'tsia-up 'tsia-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
-				       ts-date-type " timestamp_ia"))
-				((org-em 'timestamp-up 'timestamp-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (or (org-entry-get (point) "SCHEDULED")
-					      (org-entry-get (point) "DEADLINE")
-					      (org-entry-get (point) "TIMESTAMP")
-					      (org-entry-get (point) "TIMESTAMP_IA"))
-				       ts-date-type ""))
-				(t (setq ts-date-type "")))
-			  (when ts (ignore-errors (org-time-string-to-absolute ts)))))
+	      ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+	      ts-date (car ts-date-pair)
+	      ts-date-type (cdr ts-date-pair)
 	      txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
 	      inherited-tags
 	      (or (eq org-agenda-show-inherited-tags 'always)
diff --git a/lisp/org.el b/lisp/org.el
index a095f8d..795186a 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14177,7 +14177,8 @@ headlines matching this string."
          lspos tags tags-list
 	 (tags-alist (list (cons 0 org-file-tags)))
 	 (llast 0) rtn rtn1 level category i txt
-	 todo marker entry priority)
+	 todo marker entry priority
+	 ts-date ts-date-type ts-date-pair)
     (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
       (setq action (list 'lambda nil action)))
     (save-excursion
@@ -14194,6 +14195,10 @@ headlines matching this string."
 	  (goto-char (setq lspos (match-beginning 0)))
 	  (setq level (org-reduced-level (org-outline-level))
 		category (org-get-category))
+          (when (eq action 'agenda)
+            (setq ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+		  ts-date (car ts-date-pair)
+		  ts-date-type (cdr ts-date-pair)))
 	  (setq i llast llast level)
 	  ;; remove tag lists from same and sublevels
 	  (while (>= i level)
@@ -14265,7 +14270,9 @@ headlines matching this string."
 	      (org-add-props txt props
 		'org-marker marker 'org-hd-marker marker 'org-category category
 		'todo-state todo
-		'priority priority 'type "tagsmatch")
+                'ts-date ts-date
+		'priority priority
+                'type (concat "tagsmatch" ts-date-type))
 	      (push txt rtn))
 	     ((functionp action)
 	      (setq org-map-continue-from nil)
-- 
1.9.4.msysgit.2


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

* Re: [Patch] Fix date-based sorting of tags and tags-todo agenda views
  2015-02-08 18:54   ` Yuri D. Lensky
@ 2015-02-08 20:18     ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2015-02-08 20:18 UTC (permalink / raw)
  To: Yuri D. Lensky; +Cc: emacs-orgmode@gnu.org

ydl@mit.edu (Yuri D. Lensky) writes:

> Done.

Thank you.

However, you didn't tell me your status wrt FSF assignment (or forgot
the TINYCHANGE part in your commit message).

> +(defun org-agenda-entry-get-agenda-timestamp (pom)
> +  "Given a point or maker POM, returns a cons cell of the
> +timestamp and the timestamp type relevant for the sorting
> +strategy in `org-agenda-sorting-strategy-selected'."

First line in a docstring needs to be a single sentence.

Regards,

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

* Re: [Patch] Fix date-based sorting of tags and tags-todo agenda views
@ 2015-02-09  1:37 Yuri D. Lensky
  2015-02-09 23:13 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Yuri D. Lensky @ 2015-02-09  1:37 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 6249 bytes --]


Done.

From 64c0ea3d6ac89d8ab12b030b9270ea21599a5c83 Mon Sep 17 00:00:00 2001
From: "Yuri D. Lensky" <ydl@ydl.cm>
Date: Sat, 7 Feb 2015 13:37:46 -0500
Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda

* lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
  add timestamp property, completely analogously to
  org-agenda-get-todos.
* lisp/org-agenda.el (org-agenda-entry-get-agenda-timestamp,
  org-agenda-get-todos): Factored timestamp retrieval code out to
  separate function org-agenda-entry-get-agenda-timestamp from
  org-agenda-get-todos.

Before this fix, timestamps were ignored when sorting agenda views of
the 'tags' and 'tags-todo' types.

TINYCHANGE
---
 lisp/org-agenda.el | 67 +++++++++++++++++++++++++++++++-----------------------
 lisp/org.el        | 11 +++++++--
 2 files changed, 48 insertions(+), 30 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 1872ca5..10d52bb 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5362,6 +5362,40 @@ the documentation of `org-diary'."
 (defvar org-heading-keyword-regexp-format) ; defined in org.el
 (defvar org-agenda-sorting-strategy-selected nil)
 
+(defun org-agenda-entry-get-agenda-timestamp (pom)
+  "Retrieve timestamp information for sorting agenda views.
+Given a point or marker POM, returns a cons cell of the timestamp
+and the timestamp type relevant for the sorting strategy in
+`org-agenda-sorting-strategy-selected'."
+  (let (ts ts-date-type)
+    (save-match-data
+      (cond ((org-em 'scheduled-up 'scheduled-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "SCHEDULED")
+		   ts-date-type " scheduled"))
+	    ((org-em 'deadline-up 'deadline-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "DEADLINE")
+		   ts-date-type " deadline"))
+	    ((org-em 'ts-up 'ts-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP")
+		   ts-date-type " timestamp"))
+	    ((org-em 'tsia-up 'tsia-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP_IA")
+		   ts-date-type " timestamp_ia"))
+	    ((org-em 'timestamp-up 'timestamp-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (or (org-entry-get pom "SCHEDULED")
+			  (org-entry-get pom "DEADLINE")
+			  (org-entry-get pom "TIMESTAMP")
+			  (org-entry-get pom "TIMESTAMP_IA"))
+		   ts-date-type ""))
+	    (t (setq ts-date-type "")))
+      (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
+	    ts-date-type))))
+
 (defun org-agenda-get-todos ()
   "Return the TODO information for agenda display."
   (let* ((props (list 'face nil
@@ -5386,7 +5420,8 @@ the documentation of `org-diary'."
 					       "|")
 					      "\\|") "\\)"))
 			  (t org-not-done-regexp))))
-	 marker priority category level tags todo-state ts-date ts-date-type
+	 marker priority category level tags todo-state
+	 ts-date ts-date-type ts-date-pair
 	 ee txt beg end inherited-tags todo-state-end-pos)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
@@ -5406,33 +5441,9 @@ the documentation of `org-diary'."
 	(goto-char (match-beginning 2))
 	(setq marker (org-agenda-new-marker (match-beginning 0))
 	      category (org-get-category)
-	      ts-date (let (ts)
-			(save-match-data
-			  (cond ((org-em 'scheduled-up 'scheduled-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "SCHEDULED")
-				       ts-date-type " scheduled"))
-				((org-em 'deadline-up 'deadline-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "DEADLINE")
-				       ts-date-type " deadline"))
-				((org-em 'ts-up 'ts-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP")
-				       ts-date-type " timestamp"))
-				((org-em 'tsia-up 'tsia-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
-				       ts-date-type " timestamp_ia"))
-				((org-em 'timestamp-up 'timestamp-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (or (org-entry-get (point) "SCHEDULED")
-					      (org-entry-get (point) "DEADLINE")
-					      (org-entry-get (point) "TIMESTAMP")
-					      (org-entry-get (point) "TIMESTAMP_IA"))
-				       ts-date-type ""))
-				(t (setq ts-date-type "")))
-			  (when ts (ignore-errors (org-time-string-to-absolute ts)))))
+	      ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+	      ts-date (car ts-date-pair)
+	      ts-date-type (cdr ts-date-pair)
 	      txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
 	      inherited-tags
 	      (or (eq org-agenda-show-inherited-tags 'always)
diff --git a/lisp/org.el b/lisp/org.el
index d7d9c61..6e12d02 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14189,7 +14189,8 @@ headlines matching this string."
          lspos tags tags-list
 	 (tags-alist (list (cons 0 org-file-tags)))
 	 (llast 0) rtn rtn1 level category i txt
-	 todo marker entry priority)
+	 todo marker entry priority
+	 ts-date ts-date-type ts-date-pair)
     (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
       (setq action (list 'lambda nil action)))
     (save-excursion
@@ -14206,6 +14207,10 @@ headlines matching this string."
 	  (goto-char (setq lspos (match-beginning 0)))
 	  (setq level (org-reduced-level (org-outline-level))
 		category (org-get-category))
+          (when (eq action 'agenda)
+            (setq ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+		  ts-date (car ts-date-pair)
+		  ts-date-type (cdr ts-date-pair)))
 	  (setq i llast llast level)
 	  ;; remove tag lists from same and sublevels
 	  (while (>= i level)
@@ -14277,7 +14282,9 @@ headlines matching this string."
 	      (org-add-props txt props
 		'org-marker marker 'org-hd-marker marker 'org-category category
 		'todo-state todo
-		'priority priority 'type "tagsmatch")
+                'ts-date ts-date
+		'priority priority
+                'type (concat "tagsmatch" ts-date-type))
 	      (push txt rtn))
 	     ((functionp action)
 	      (setq org-map-continue-from nil)
-- 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 6258 bytes --]

From 64c0ea3d6ac89d8ab12b030b9270ea21599a5c83 Mon Sep 17 00:00:00 2001
From: "Yuri D. Lensky" <ydl@ydl.cm>
Date: Sat, 7 Feb 2015 13:37:46 -0500
Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in agenda

* lisp/org.el (org-scan-tags): Fix agenda org tags scans to properly
  add timestamp property, completely analogously to
  org-agenda-get-todos.
* lisp/org-agenda.el (org-agenda-entry-get-agenda-timestamp,
  org-agenda-get-todos): Factored timestamp retrieval code out to
  separate function org-agenda-entry-get-agenda-timestamp from
  org-agenda-get-todos.

Before this fix, timestamps were ignored when sorting agenda views of
the 'tags' and 'tags-todo' types.

TINYCHANGE
---
 lisp/org-agenda.el | 67 +++++++++++++++++++++++++++++++-----------------------
 lisp/org.el        | 11 +++++++--
 2 files changed, 48 insertions(+), 30 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 1872ca5..10d52bb 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5362,6 +5362,40 @@ the documentation of `org-diary'."
 (defvar org-heading-keyword-regexp-format) ; defined in org.el
 (defvar org-agenda-sorting-strategy-selected nil)
 
+(defun org-agenda-entry-get-agenda-timestamp (pom)
+  "Retrieve timestamp information for sorting agenda views.
+Given a point or marker POM, returns a cons cell of the timestamp
+and the timestamp type relevant for the sorting strategy in
+`org-agenda-sorting-strategy-selected'."
+  (let (ts ts-date-type)
+    (save-match-data
+      (cond ((org-em 'scheduled-up 'scheduled-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "SCHEDULED")
+		   ts-date-type " scheduled"))
+	    ((org-em 'deadline-up 'deadline-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "DEADLINE")
+		   ts-date-type " deadline"))
+	    ((org-em 'ts-up 'ts-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP")
+		   ts-date-type " timestamp"))
+	    ((org-em 'tsia-up 'tsia-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (org-entry-get pom "TIMESTAMP_IA")
+		   ts-date-type " timestamp_ia"))
+	    ((org-em 'timestamp-up 'timestamp-down
+		     org-agenda-sorting-strategy-selected)
+	     (setq ts (or (org-entry-get pom "SCHEDULED")
+			  (org-entry-get pom "DEADLINE")
+			  (org-entry-get pom "TIMESTAMP")
+			  (org-entry-get pom "TIMESTAMP_IA"))
+		   ts-date-type ""))
+	    (t (setq ts-date-type "")))
+      (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
+	    ts-date-type))))
+
 (defun org-agenda-get-todos ()
   "Return the TODO information for agenda display."
   (let* ((props (list 'face nil
@@ -5386,7 +5420,8 @@ the documentation of `org-diary'."
 					       "|")
 					      "\\|") "\\)"))
 			  (t org-not-done-regexp))))
-	 marker priority category level tags todo-state ts-date ts-date-type
+	 marker priority category level tags todo-state
+	 ts-date ts-date-type ts-date-pair
 	 ee txt beg end inherited-tags todo-state-end-pos)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
@@ -5406,33 +5441,9 @@ the documentation of `org-diary'."
 	(goto-char (match-beginning 2))
 	(setq marker (org-agenda-new-marker (match-beginning 0))
 	      category (org-get-category)
-	      ts-date (let (ts)
-			(save-match-data
-			  (cond ((org-em 'scheduled-up 'scheduled-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "SCHEDULED")
-				       ts-date-type " scheduled"))
-				((org-em 'deadline-up 'deadline-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "DEADLINE")
-				       ts-date-type " deadline"))
-				((org-em 'ts-up 'ts-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP")
-				       ts-date-type " timestamp"))
-				((org-em 'tsia-up 'tsia-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
-				       ts-date-type " timestamp_ia"))
-				((org-em 'timestamp-up 'timestamp-down
-					 org-agenda-sorting-strategy-selected)
-				 (setq ts (or (org-entry-get (point) "SCHEDULED")
-					      (org-entry-get (point) "DEADLINE")
-					      (org-entry-get (point) "TIMESTAMP")
-					      (org-entry-get (point) "TIMESTAMP_IA"))
-				       ts-date-type ""))
-				(t (setq ts-date-type "")))
-			  (when ts (ignore-errors (org-time-string-to-absolute ts)))))
+	      ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+	      ts-date (car ts-date-pair)
+	      ts-date-type (cdr ts-date-pair)
 	      txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
 	      inherited-tags
 	      (or (eq org-agenda-show-inherited-tags 'always)
diff --git a/lisp/org.el b/lisp/org.el
index d7d9c61..6e12d02 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14189,7 +14189,8 @@ headlines matching this string."
          lspos tags tags-list
 	 (tags-alist (list (cons 0 org-file-tags)))
 	 (llast 0) rtn rtn1 level category i txt
-	 todo marker entry priority)
+	 todo marker entry priority
+	 ts-date ts-date-type ts-date-pair)
     (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
       (setq action (list 'lambda nil action)))
     (save-excursion
@@ -14206,6 +14207,10 @@ headlines matching this string."
 	  (goto-char (setq lspos (match-beginning 0)))
 	  (setq level (org-reduced-level (org-outline-level))
 		category (org-get-category))
+          (when (eq action 'agenda)
+            (setq ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
+		  ts-date (car ts-date-pair)
+		  ts-date-type (cdr ts-date-pair)))
 	  (setq i llast llast level)
 	  ;; remove tag lists from same and sublevels
 	  (while (>= i level)
@@ -14277,7 +14282,9 @@ headlines matching this string."
 	      (org-add-props txt props
 		'org-marker marker 'org-hd-marker marker 'org-category category
 		'todo-state todo
-		'priority priority 'type "tagsmatch")
+                'ts-date ts-date
+		'priority priority
+                'type (concat "tagsmatch" ts-date-type))
 	      (push txt rtn))
 	     ((functionp action)
 	      (setq org-map-continue-from nil)
-- 
1.9.4.msysgit.2


[-- Attachment #3: Type: text/plain, Size: 16 bytes --]

1.9.4.msysgit.2

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

* Re: [Patch] Fix date-based sorting of tags and tags-todo agenda views
  2015-02-09  1:37 Yuri D. Lensky
@ 2015-02-09 23:13 ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2015-02-09 23:13 UTC (permalink / raw)
  To: Yuri D. Lensky; +Cc: emacs-orgmode

ydl@ydl.cm (Yuri D. Lensky) writes:

> From: "Yuri D. Lensky" <ydl@ydl.cm>
> Date: Sat, 7 Feb 2015 13:37:46 -0500
> Subject: [PATCH] Fix timestamp-based sorting of tags-based entries in
> agenda

Applied. Thank you.

Regards,

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

end of thread, other threads:[~2015-02-09 23:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-07 19:05 [Patch] Fix date-based sorting of tags and tags-todo agenda views Yuri D Lensky
2015-02-07 21:14 ` Nicolas Goaziou
2015-02-08 18:54   ` Yuri D. Lensky
2015-02-08 20:18     ` Nicolas Goaziou
  -- strict thread matches above, loose matches on Subject: below --
2015-02-09  1:37 Yuri D. Lensky
2015-02-09 23:13 ` Nicolas Goaziou

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