emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Patch: org-agenda-skip-deadline-prewarning-if-scheduled prior to scheduled date
@ 2012-10-17  7:56 Justus-dev
  2012-10-17 13:07 ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Justus-dev @ 2012-10-17  7:56 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

I have scratched an itch:

I would like not to be bothered with TODOs that have a scheduled date in
the future.  However, as of that scheduled date I would like their
deadline prewarnings to appear in the agenda, just like non-scheduled
TODOs.  I do not see how to achieve this behavior using the existing
org-mode facilities (I run the org shipped with Emacs 24.2.1).

I solved this by adding an option to
org-agenda-skip-deadline-prewarning-if-scheduled that behaves like
setting it to an integer value (custom deadline warning lead time), but
sets it to the number of days between scheduled and deadline dates.  As
a result, deadline warnings prior to the scheduled date are eliminated.

I attach two diffs: presched-24.2.1.diff reflects the change against
org-agenda.el from Emacs 24.2.1 I developed and tested;
presched-latest.diff (almost identical) reflects the same change against
today's org-agenda.el from the org-mode git.  The latter is untested,
but I'm fairly confident it works since the changes are very localized
and do not appear to interact with differences between the two original
org-agenda.els.

Please review the patch carefully:

- In org-agenda-get-deadlines, I moved the relevant form ("(setq
  suppress-prewarning ...)") down into the middle of a long (setq ...)
  because it builds on values computed above and provides values used
  below.

- I split the long (setq ...) into three separate (setq ...)s for
  readability because all other assignments are compact while this one
  is long and complex.

- Because of this complexity I added some comments which hopefully makes
  things readable.  However, a more experienced lisp programmer may be
  able to rewrite the code such that it is crystal clear even without
  comments.

- Instead of the lead-time logic described above, a different way to
  achieve a similar effect would be to add a condition that checks
  whether the scheduled date is in the future, in which case the
  prewarning is removed unconditionally.  This would presumably be done
  by setting suppress-prewarning to 0.  I have not tried to implement
  this.  As far as I can see, this would likewise involve computing the
  difference between two dates, and the resulting code would be of about
  the same complexity, but setting the max. lead to the scheduled date
  (instead of to 0) appears more sound to me.

Here's a suggested commit message:

org-agenda: New option: skip deadline prewarning if scheduled in the future

* lisp/org-agenda.el (org-agenda-skip-deadline-prewarning-if-scheduled):
  Add an option to skip the deadline prewarning if the scheduled date is
  in the future.

Comments?

Justus


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: presched-24.2.1.diff --]
[-- Type: text/x-diff, Size: 3655 bytes --]

--- org-agenda-24.2.1.el	2012-09-08 23:58:12.000000000 +0200
+++ org-agenda-24.2.1-presched.el	2012-10-17 09:12:01.020184803 +0200
@@ -789,9 +789,10 @@
 This will apply on all days where a prewarning for the deadline would
 be shown, but not at the day when the entry is actually due.  On that day,
 the deadline will be shown anyway.
-This variable may be set to nil, t, or a number which will then give
-the number of days before the actual deadline when the prewarnings
-should resume.
+This variable may be set to nil, t, the symbol `pre-scheduled', 
+or a number which will then give the number of days before the actual
+deadline when the prewarnings should resume.  The symbol `pre-scheduled'
+eliminates the deadline prewarning only prior to the scheduled date.
 This can be used in a workflow where the first showing of the deadline will
 trigger you to schedule it, and then you don't want to be reminded of it
 because you will take care of it on the day when scheduled."
@@ -800,6 +801,7 @@
   :version "24.1"
   :type '(choice
 	  (const :tag "Alwas show prewarning" nil)
+	  (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
 	  (const :tag "Remove prewarning if entry is scheduled" t)
 	  (integer :tag "Restart prewarning N days before deadline")))
 
@@ -5206,23 +5208,13 @@
 	 (regexp org-deadline-time-regexp)
 	 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
 	 (d1 (calendar-absolute-from-gregorian date))  ; DATE bound by calendar
-	 d2 diff dfrac wdays pos pos1 category org-category-pos
+	 ds d2 diff dfrac wdays pos pos1 category org-category-pos
 	 tags suppress-prewarning ee txt head face s todo-state
 	 show-all upcomingp donep timestr)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (setq suppress-prewarning nil)
       (catch :skip
 	(org-agenda-skip)
-	(when (and org-agenda-skip-deadline-prewarning-if-scheduled
-		   (save-match-data
-		     (string-match org-scheduled-time-regexp
-				   (buffer-substring (point-at-bol)
-						     (point-at-eol)))))
-	  (setq suppress-prewarning
-		(if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
-		    org-agenda-skip-deadline-prewarning-if-scheduled
-		  0)))
 	(setq s (match-string 1)
 	      txt nil
 	      pos (1- (match-beginning 1))
@@ -5233,8 +5225,31 @@
 	      d2 (org-time-string-to-absolute
 		  (match-string 1) d1 'past show-all
 		  (current-buffer) pos)
-	      diff (- d2 d1)
-	      wdays (if suppress-prewarning
+	      diff (- d2 d1))
+	(setq suppress-prewarning
+	      (if (and org-agenda-skip-deadline-prewarning-if-scheduled
+		       (let ((item (buffer-substring (point-at-bol)
+						     (point-at-eol))))
+			 (setq ds (save-match-data
+				    (if (string-match
+					 org-scheduled-time-regexp item)
+					(match-string 1 item))))))
+		  ;; If prewarnings of scheduled items are to be skipped
+		  ;;    and the current item has a scheduled date (in ds),
+		  ;; calculate prewarning lead time:
+		  (if (integerp
+		       org-agenda-skip-deadline-prewarning-if-scheduled)
+		      ;; use prewarning-restart lead time:
+		      org-agenda-skip-deadline-prewarning-if-scheduled
+		    (if (eq org-agenda-skip-deadline-prewarning-if-scheduled
+			    'pre-scheduled)
+			;; show first prewarning no earlier than scheduled date:
+			(min (- d2 (org-time-string-to-absolute
+				    ds d1 'past show-all (current-buffer) pos))
+			     org-deadline-warning-days)
+		      ;; set prewarning to deadline:
+		      0))))
+	(setq wdays (if suppress-prewarning
 			(let ((org-deadline-warning-days suppress-prewarning))
 			  (org-get-wdays s))
 		      (org-get-wdays s))

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: presched-latest.diff --]
[-- Type: text/x-diff, Size: 3668 bytes --]

--- org-agenda-latest.el	2012-10-17 08:39:50.101427177 +0200
+++ org-agenda-latest-presched.el	2012-10-17 09:17:40.170574930 +0200
@@ -827,9 +827,10 @@
 This will apply on all days where a prewarning for the deadline would
 be shown, but not at the day when the entry is actually due.  On that day,
 the deadline will be shown anyway.
-This variable may be set to nil, t, or a number which will then give
-the number of days before the actual deadline when the prewarnings
-should resume.
+This variable may be set to nil, t, the symbol `pre-scheduled', 
+or a number which will then give the number of days before the actual
+deadline when the prewarnings should resume.  The symbol `pre-scheduled'
+eliminates the deadline prewarning only prior to the scheduled date.
 This can be used in a workflow where the first showing of the deadline will
 trigger you to schedule it, and then you don't want to be reminded of it
 because you will take care of it on the day when scheduled."
@@ -838,6 +839,7 @@
   :version "24.1"
   :type '(choice
 	  (const :tag "Alwas show prewarning" nil)
+	  (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
 	  (const :tag "Remove prewarning if entry is scheduled" t)
 	  (integer :tag "Restart prewarning N days before deadline")))
 
@@ -5807,23 +5809,13 @@
 	 (regexp org-deadline-time-regexp)
 	 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
 	 (d1 (calendar-absolute-from-gregorian date))  ; DATE bound by calendar
-	 d2 diff dfrac wdays pos pos1 category category-pos level
+	 ds d2 diff dfrac wdays pos pos1 category category-pos level
 	 tags suppress-prewarning ee txt head face s todo-state
 	 show-all upcomingp donep timestr warntime)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
-      (setq suppress-prewarning nil)
       (catch :skip
 	(org-agenda-skip)
-	(when (and org-agenda-skip-deadline-prewarning-if-scheduled
-		   (save-match-data
-		     (string-match org-scheduled-time-regexp
-				   (buffer-substring (point-at-bol)
-						     (point-at-eol)))))
-	  (setq suppress-prewarning
-		(if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
-		    org-agenda-skip-deadline-prewarning-if-scheduled
-		  0)))
 	(setq s (match-string 1)
 	      txt nil
 	      pos (1- (match-beginning 1))
@@ -5834,8 +5826,31 @@
 	      d2 (org-time-string-to-absolute
 		  (match-string 1) d1 'past show-all
 		  (current-buffer) pos)
-	      diff (- d2 d1)
-	      wdays (if suppress-prewarning
+	      diff (- d2 d1))
+	(setq suppress-prewarning
+	      (if (and org-agenda-skip-deadline-prewarning-if-scheduled
+		       (let ((item (buffer-substring (point-at-bol)
+						     (point-at-eol))))
+			 (setq ds (save-match-data
+				    (if (string-match
+					 org-scheduled-time-regexp item)
+					(match-string 1 item))))))
+		  ;; If prewarnings of scheduled items are to be skipped
+		  ;;    and the current item has a scheduled date (in ds),
+		  ;; calculate prewarning lead time:
+		  (if (integerp
+		       org-agenda-skip-deadline-prewarning-if-scheduled)
+		      ;; use prewarning-restart lead time:
+		      org-agenda-skip-deadline-prewarning-if-scheduled
+		    (if (eq org-agenda-skip-deadline-prewarning-if-scheduled
+			    'pre-scheduled)
+			;; show first prewarning no earlier than scheduled date:
+			(min (- d2 (org-time-string-to-absolute
+				    ds d1 'past show-all (current-buffer) pos))
+			     org-deadline-warning-days)
+		      ;; set prewarning to deadline:
+		      0))))
+	(setq wdays (if suppress-prewarning
 			(let ((org-deadline-warning-days suppress-prewarning))
 			  (org-get-wdays s))
 		      (org-get-wdays s))

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

end of thread, other threads:[~2012-10-28 12:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-17  7:56 Patch: org-agenda-skip-deadline-prewarning-if-scheduled prior to scheduled date Justus-dev
2012-10-17 13:07 ` Nicolas Goaziou
2012-10-17 14:29   ` Justus-dev
2012-10-25 13:36     ` Nicolas Goaziou
2012-10-26 11:16   ` Justus-bulk
2012-10-28 10:20     ` Nicolas Goaziou
2012-10-28 12:27       ` Justus-bulk

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