From mboxrd@z Thu Jan 1 00:00:00 1970 From: Justus-bulk@Piater.name Subject: Re: Patch: org-agenda-skip-deadline-prewarning-if-scheduled prior to scheduled date Date: Fri, 26 Oct 2012 13:16:39 +0200 Message-ID: <87txthh4a0.fsf@pc130-c703.uibk.ac.at> References: <87wqypedlk.fsf@pc130-c703.uibk.ac.at> <87zk3lmelw.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:54504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRhuA-0004cH-On for emacs-orgmode@gnu.org; Fri, 26 Oct 2012 07:16:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRhu9-00080C-5H for emacs-orgmode@gnu.org; Fri, 26 Oct 2012 07:16:46 -0400 Received: from lmr1.uibk.ac.at ([138.232.1.142]:55271 helo=smtp.uibk.ac.at) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRhu8-0007z2-Qe for emacs-orgmode@gnu.org; Fri, 26 Oct 2012 07:16:45 -0400 In-Reply-To: <87zk3lmelw.fsf@gmail.com> (Nicolas Goaziou's message of "Wed, 17 Oct 2012 15:07:23 +0200") 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nicolas Goaziou Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Nicolas Goaziou 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-agenda-New-option-skip-deadline-prewarning-if-sc.patch >From 342abbe56b786fa7361c6ef574623c4c07915058 Mon Sep 17 00:00:00 2001 From: Justus Piater 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 --=-=-=--