emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Make today's deadlines "close" without lead time
@ 2016-06-01  5:57 Don March
  2016-06-02  8:12 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Don March @ 2016-06-01  5:57 UTC (permalink / raw)
  To: emacs-orgmode

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

This patch makes a very small change to the function that determines if a
timestamp is close to the current day, which is used for showing/hiding items in
agenda views.

Under current behavior, a deadline of today is close only if it has some amount
of lead time. If your date is 2016-06-01, the following statements evaluate to
nil:
#+BEGIN_SRC emacs-lisp
(org-deadline-close "2016-06-01 Wed -0d") ;; but this is today!
(org-deadline-close "2016-06-02 Wed -1d")
#+END_SRC

One effect of this is that if you set =org-agenda-todo-ignore-deadlines= to
=far= and generate the TODO list agenda view (C-c a t), then items only appear
if you are one day past the point at which they should appear. For example, the
following item does not show up in my current TODO list:
#+BEGIN_EXAMPLE
* TODO due today, no lead time
DEADLINE: <2016-06-01 -0d>
#+END_EXAMPLE

[-- Attachment #2: 0001-Make-today-s-deadlines-close-without-lead-time.patch --]
[-- Type: text/x-patch, Size: 1023 bytes --]

From 5401da2076b9de890fbf086e472c09c3f0a66fdf Mon Sep 17 00:00:00 2001
From: Don March <don@ohspite.net>
Date: Wed, 1 Jun 2016 00:05:12 -0400
Subject: [PATCH] Make today's deadlines "close" without lead time

* org.el (org-deadline-close): A timestamp is close if the days between
  now and the timestamp are less then or equal to the days of lead time.
---
 lisp/org.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 680086d..fb9e101 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17479,7 +17479,7 @@ If SECONDS is non-nil, return the difference in seconds."
 (defun org-deadline-close (timestamp-string &optional ndays)
   "Is the time in TIMESTAMP-STRING close to the current date?"
   (setq ndays (or ndays (org-get-wdays timestamp-string)))
-  (and (< (org-time-stamp-to-now timestamp-string) ndays)
+  (and (<= (org-time-stamp-to-now timestamp-string) ndays)
        (not (org-entry-is-done-p))))
 
 (defun org-get-wdays (ts &optional delay zero-delay)
-- 
2.8.1


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

* Re: [PATCH] Make today's deadlines "close" without lead time
  2016-06-01  5:57 [PATCH] Make today's deadlines "close" without lead time Don March
@ 2016-06-02  8:12 ` Nicolas Goaziou
  2016-06-03  7:17   ` Don March
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2016-06-02  8:12 UTC (permalink / raw)
  To: Don March; +Cc: emacs-orgmode

Hello,

Don March <don@ohspite.net> writes:

> This patch makes a very small change to the function that determines if a
> timestamp is close to the current day, which is used for showing/hiding items in
> agenda views.
>
> Under current behavior, a deadline of today is close only if it has some amount
> of lead time. If your date is 2016-06-01, the following statements evaluate to
> nil:
> #+BEGIN_SRC emacs-lisp
> (org-deadline-close "2016-06-01 Wed -0d") ;; but this is today!
> (org-deadline-close "2016-06-02 Wed -1d")
> #+END_SRC
>
> One effect of this is that if you set =org-agenda-todo-ignore-deadlines= to
> =far= and generate the TODO list agenda view (C-c a t), then items only appear
> if you are one day past the point at which they should appear. For example, the
> following item does not show up in my current TODO list:
> #+BEGIN_EXAMPLE
> * TODO due today, no lead time
> DEADLINE: <2016-06-01 -0d>
> #+END_EXAMPLE

Thank you for the patch.

Did you sign FSF papers? Otherwise, a TINYCHANGE cookie is needed at the
end of the commit message.

Also, would you mind providing a few tests for this function, in
"test-org.el"?

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] Make today's deadlines "close" without lead time
  2016-06-02  8:12 ` Nicolas Goaziou
@ 2016-06-03  7:17   ` Don March
  2016-06-04 19:30     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Don March @ 2016-06-03  7:17 UTC (permalink / raw)
  To: mail, emacs-orgmode

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

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Thank you for the patch.

And thank you for your thousands of patches!

> Did you sign FSF papers?

Yes, August 2011, #699456.

> Also, would you mind providing a few tests for this function, in
> "test-org.el"?

Not at all. The new patch---which includes the original changes and the new
tests---is attached. While I was in there, I made a second patch that renames
the function to have a `-p' predicate suffix.

Hopefully I put the tests somewhere close to where they belong.

[-- Attachment #2: 0001-Make-today-s-deadlines-close-without-lead-time.patch --]
[-- Type: text/x-patch, Size: 2944 bytes --]

From 4953e495b938011582fb0c7c7bf9064530ce9294 Mon Sep 17 00:00:00 2001
From: Don March <don@ohspite.net>
Date: Wed, 1 Jun 2016 00:05:12 -0400
Subject: [PATCH 1/2] Make today's deadlines "close" without lead time

* lisp/org.el (org-deadline-close): A timestamp is close if the days
  between now and the timestamp are less then or equal to the days of
  lead time.

* testing/lisp/test-org.el: Add tests for org-deadline-close.
---
 lisp/org.el              |  2 +-
 testing/lisp/test-org.el | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index e015a77..13883c5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17480,7 +17480,7 @@ If SECONDS is non-nil, return the difference in seconds."
 (defun org-deadline-close (timestamp-string &optional ndays)
   "Is the time in TIMESTAMP-STRING close to the current date?"
   (setq ndays (or ndays (org-get-wdays timestamp-string)))
-  (and (< (org-time-stamp-to-now timestamp-string) ndays)
+  (and (<= (org-time-stamp-to-now timestamp-string) ndays)
        (not (org-entry-is-done-p))))
 
 (defun org-get-wdays (ts &optional delay zero-delay)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 6884c24..576402a 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -364,6 +364,34 @@
 	  (calendar-gregorian-from-absolute
 	   (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
 
+(ert-deftest test-org/deadline-close ()
+  "Test `org-deadline-close' specifications."
+  ;; Pretend that the current time is 2016-06-03 Fri 01:43
+  (cl-flet ((current-time () '(22353 6425 905205 644000)))
+    ;; Timestamps are close if they are within `ndays' of lead time.
+    (org-test-with-temp-text "* Heading"
+      (should (org-deadline-close "2016-06-03 Fri" 0))
+      (should (org-deadline-close "2016-06-02 Thu" 0))
+      (should-not (org-deadline-close "2016-06-04 Sat" 0))
+      (should (org-deadline-close "2016-06-04 Sat" 1))
+      (should (org-deadline-close "2016-06-03 Fri 12:00" 0)))
+    ;; Read `ndays' from timestamp if argument not given.
+    (org-test-with-temp-text "* H"
+      (should (org-deadline-close "2016-06-04 Sat -1d"))
+      (should-not (org-deadline-close "2016-06-04 Sat -0d"))
+      (should (org-deadline-close "2016-06-10 Fri -1w"))
+      (should-not (org-deadline-close "2016-06-11 Sat -1w")))
+    ;; Prefer `ndays' argument over lead time in timestamp.
+    (org-test-with-temp-text "* H"
+      (should (org-deadline-close "2016-06-04 Sat -0d" 1))
+      (should-not (org-deadline-close "2016-06-04 Sat -0d" 0)))
+    ;; Completed tasks are never close.
+    (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
+      (org-test-with-temp-text "* TODO Heading"
+	(should (org-deadline-close "2016-06-03")))
+      (org-test-with-temp-text "* DONE Heading"
+	(should-not (org-deadline-close "2016-06-03"))))))
+
 \f
 ;;; Drawers
 
-- 
2.8.1


[-- Attachment #3: 0002-Rename-org-deadline-is-close-to-have-p-suffix.patch --]
[-- Type: text/x-patch, Size: 5437 bytes --]

From 143f802073989fff8fe464244f53089e79e92812 Mon Sep 17 00:00:00 2001
From: Don March <don@ohspite.net>
Date: Fri, 3 Jun 2016 02:49:55 -0400
Subject: [PATCH 2/2] Rename org-deadline-is-close to have -p suffix

* lisp/org-agenda.el
  (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item):
* lisp/org.el (org-deadline-close): Rename to...
  (org-deadline-close-p): ...this.

* testing/lisp/test-org.el (test-org/deadline-close): Rename to...
  (test-org/deadline-close-p): ...this.
---
 lisp/org-agenda.el       |  4 ++--
 lisp/org.el              |  4 ++--
 testing/lisp/test-org.el | 30 +++++++++++++++---------------
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 50f520c..7994187 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5550,7 +5550,7 @@ This function is invoked if `org-agenda-todo-ignore-deadlines',
 	       (cond
 		((memq org-agenda-todo-ignore-deadlines '(t all)) t)
 		((eq org-agenda-todo-ignore-deadlines 'far)
-		 (not (org-deadline-close (match-string 1))))
+		 (not (org-deadline-close-p (match-string 1))))
 		((eq org-agenda-todo-ignore-deadlines 'future)
 		 (> (org-time-stamp-to-now
 		     (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
@@ -5560,7 +5560,7 @@ This function is invoked if `org-agenda-todo-ignore-deadlines',
 		((numberp org-agenda-todo-ignore-deadlines)
 		 (org-agenda-todo-custom-ignore-p
 		  (match-string 1) org-agenda-todo-ignore-deadlines))
-		(t (org-deadline-close (match-string 1)))))
+		(t (org-deadline-close-p (match-string 1)))))
 	  (and org-agenda-todo-ignore-timestamp
 	       (let ((buffer (current-buffer))
 		     (regexp
diff --git a/lisp/org.el b/lisp/org.el
index 13883c5..fc3e0c0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17477,7 +17477,7 @@ If SECONDS is non-nil, return the difference in seconds."
     (- (funcall fdiff (org-time-string-to-time timestamp-string))
        (funcall fdiff (current-time)))))
 
-(defun org-deadline-close (timestamp-string &optional ndays)
+(defun org-deadline-close-p (timestamp-string &optional ndays)
   "Is the time in TIMESTAMP-STRING close to the current date?"
   (setq ndays (or ndays (org-get-wdays timestamp-string)))
   (and (<= (org-time-stamp-to-now timestamp-string) ndays)
@@ -17533,7 +17533,7 @@ days.  If the prefix is a raw \\[universal-argument] prefix, all deadlines are s
 	 (case-fold-search nil)
 	 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
 	 (callback
-	  (lambda () (org-deadline-close (match-string 1) org-warn-days))))
+	  (lambda () (org-deadline-close-p (match-string 1) org-warn-days))))
     (message "%d deadlines past-due or due within %d days"
 	     (org-occur regexp nil callback)
 	     org-warn-days)))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 576402a..86b8866 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -364,33 +364,33 @@
 	  (calendar-gregorian-from-absolute
 	   (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
 
-(ert-deftest test-org/deadline-close ()
-  "Test `org-deadline-close' specifications."
+(ert-deftest test-org/deadline-close-p ()
+  "Test `org-deadline-close-p' specifications."
   ;; Pretend that the current time is 2016-06-03 Fri 01:43
   (cl-flet ((current-time () '(22353 6425 905205 644000)))
     ;; Timestamps are close if they are within `ndays' of lead time.
     (org-test-with-temp-text "* Heading"
-      (should (org-deadline-close "2016-06-03 Fri" 0))
-      (should (org-deadline-close "2016-06-02 Thu" 0))
-      (should-not (org-deadline-close "2016-06-04 Sat" 0))
-      (should (org-deadline-close "2016-06-04 Sat" 1))
-      (should (org-deadline-close "2016-06-03 Fri 12:00" 0)))
+      (should (org-deadline-close-p "2016-06-03 Fri" 0))
+      (should (org-deadline-close-p "2016-06-02 Thu" 0))
+      (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
+      (should (org-deadline-close-p "2016-06-04 Sat" 1))
+      (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
     ;; Read `ndays' from timestamp if argument not given.
     (org-test-with-temp-text "* H"
-      (should (org-deadline-close "2016-06-04 Sat -1d"))
-      (should-not (org-deadline-close "2016-06-04 Sat -0d"))
-      (should (org-deadline-close "2016-06-10 Fri -1w"))
-      (should-not (org-deadline-close "2016-06-11 Sat -1w")))
+      (should (org-deadline-close-p "2016-06-04 Sat -1d"))
+      (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
+      (should (org-deadline-close-p "2016-06-10 Fri -1w"))
+      (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
     ;; Prefer `ndays' argument over lead time in timestamp.
     (org-test-with-temp-text "* H"
-      (should (org-deadline-close "2016-06-04 Sat -0d" 1))
-      (should-not (org-deadline-close "2016-06-04 Sat -0d" 0)))
+      (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
+      (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
     ;; Completed tasks are never close.
     (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
       (org-test-with-temp-text "* TODO Heading"
-	(should (org-deadline-close "2016-06-03")))
+	(should (org-deadline-close-p "2016-06-03")))
       (org-test-with-temp-text "* DONE Heading"
-	(should-not (org-deadline-close "2016-06-03"))))))
+	(should-not (org-deadline-close-p "2016-06-03"))))))
 
 \f
 ;;; Drawers
-- 
2.8.1


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

* Re: [PATCH] Make today's deadlines "close" without lead time
  2016-06-03  7:17   ` Don March
@ 2016-06-04 19:30     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2016-06-04 19:30 UTC (permalink / raw)
  To: Don March; +Cc: emacs-orgmode

Hello,

Don March <don@ohspite.net> writes:

> Not at all. The new patch---which includes the original changes and the new
> tests---is attached. While I was in there, I made a second patch that renames
> the function to have a `-p' predicate suffix.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2016-06-04 19:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-01  5:57 [PATCH] Make today's deadlines "close" without lead time Don March
2016-06-02  8:12 ` Nicolas Goaziou
2016-06-03  7:17   ` Don March
2016-06-04 19:30     ` 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).