emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Justus-bulk@Piater.name
To: Nicolas Goaziou <n.goaziou@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Patch: org-agenda-skip-deadline-prewarning-if-scheduled prior to scheduled date
Date: Fri, 26 Oct 2012 13:16:39 +0200	[thread overview]
Message-ID: <87txthh4a0.fsf@pc130-c703.uibk.ac.at> (raw)
In-Reply-To: <87zk3lmelw.fsf@gmail.com> (Nicolas Goaziou's message of "Wed, 17 Oct 2012 15:07:23 +0200")

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

Hello,

Nicolas Goaziou <n.goaziou@gmail.com> wrote on Wed, 17 Oct 2012 15:07:23
+0200:

> Since you provide both the patch and the commit message, what about
> providing it completely as an attachement (with i.e. git format-patch)?

I attach a patch against the current git master.

>> -	 d2 diff dfrac wdays pos pos1 category category-pos level
>> +	 ds d2 diff dfrac wdays pos pos1 category category-pos level
>
> I wouldn't define the "ds" variable here, since it's local to
> suppress-prewarning computation. It's clearer to let-bind it around the
> (if (and org-agenda-skip-deadline-prewarning-if-scheduled ....)).
>
>> +			 (setq ds (save-match-data
>> +				    (if (string-match
>> +					 org-scheduled-time-regexp item)
>> +					(match-string 1 item))))))
>
> Since it is setq'ed only once, it can be let-bound.

I did not find a fully satisfactory way to do this.  I can wrap the (if
(and org-agenda-skip-deadline-prewarning-if-scheduled ...)) inside a
dedicated (let ...), but I would like to evaluate ds only if org-... is
non-nil, so I would have to keep the setq inside the conditional.  The
only gain would be the limited scope of the ds, but the price of the
additional (let ...) clutter is high, I think.

My current solution (see the patch) involves some minor refactoring at
the price of an extra (if ds ...) that I don't see a way to get rid of,
but I find the result quite readable.

Also, I replaced the if-elseif chain by a cond for clarity.

> Also, since your contribution is more than 20 lines long, did you sign
> the FSF papers?

I signed the FSF GNU EMACS copyright assignment form a few years ago.
Do I need to do something else for org-mode?

Justus



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda-New-option-skip-deadline-prewarning-if-sc.patch --]
[-- Type: text/x-diff, Size: 4103 bytes --]

From 342abbe56b786fa7361c6ef574623c4c07915058 Mon Sep 17 00:00:00 2001
From: Justus Piater <justus-dev@piater.name>
Date: Fri, 26 Oct 2012 12:47:47 +0200
Subject: [PATCH] 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.
---
 lisp/org-agenda.el |   45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 08066d2..ea4abfd 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -827,9 +827,10 @@ deadlines are always turned off when the item is DONE."
 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 @@ because you will take care of it on the day when scheduled."
   :version "24.1"
   :type '(choice
 	  (const :tag "Always 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")))
 
@@ -5812,18 +5814,8 @@ See also the user option `org-agenda-clock-consistency-checks'."
 	 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 @@ See also the user option `org-agenda-clock-consistency-checks'."
 	      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
+	      (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
+			     (let ((item (buffer-substring (point-at-bol)
+							   (point-at-eol))))
+			       (save-match-data
+				 (and (string-match
+				       org-scheduled-time-regexp item)
+				      (match-string 1 item)))))))
+		(if ds
+		    ;; The current item has a scheduled date (in ds),
+		    ;; so evaluate its prewarning lead time.
+		    (cond
+		     ((integerp
+		       org-agenda-skip-deadline-prewarning-if-scheduled)
+		      ;; Use globally-customized prewarning-restart lead time.
+		      org-agenda-skip-deadline-prewarning-if-scheduled)
+		     ((eq org-agenda-skip-deadline-prewarning-if-scheduled
+			  'pre-scheduled)
+		      ;; Set prewarning to no earlier than scheduled.
+		      (min (- d2 (org-time-string-to-absolute
+				  ds d1 'past show-all (current-buffer) pos))
+			   org-deadline-warning-days))
+		     (t 0))))) ;; Set prewarning to deadline.
+	(setq wdays (if suppress-prewarning
 			(let ((org-deadline-warning-days suppress-prewarning))
 			  (org-get-wdays s))
 		      (org-get-wdays s))
-- 
1.7.10.4


  parent reply	other threads:[~2012-10-26 11:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2012-10-28 10:20     ` Nicolas Goaziou
2012-10-28 12:27       ` Justus-bulk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87txthh4a0.fsf@pc130-c703.uibk.ac.at \
    --to=justus-bulk@piater.name \
    --cc=emacs-orgmode@gnu.org \
    --cc=n.goaziou@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).