From mboxrd@z Thu Jan 1 00:00:00 1970 From: Justus-dev@Piater.name Subject: Patch: org-agenda-skip-deadline-prewarning-if-scheduled prior to scheduled date Date: Wed, 17 Oct 2012 09:56:23 +0200 Message-ID: <87wqypedlk.fsf@pc130-c703.uibk.ac.at> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:47708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOOUS-00070Q-Kx for emacs-orgmode@gnu.org; Wed, 17 Oct 2012 03:56:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOOUQ-0007Hm-Jj for emacs-orgmode@gnu.org; Wed, 17 Oct 2012 03:56:32 -0400 Received: from lmr1.uibk.ac.at ([138.232.1.142]:49226 helo=smtp.uibk.ac.at) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOOUQ-0007Go-5a for emacs-orgmode@gnu.org; Wed, 17 Oct 2012 03:56:30 -0400 Received: from pc130-c703.uibk.ac.at (chello213047235242.tirol.surfer.at [213.47.235.242]) (authenticated bits=0) by smtp.uibk.ac.at (8.13.8/8.13.8/F1) with ESMTP id q9H7uO5r011530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Wed, 17 Oct 2012 09:56:24 +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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=presched-24.2.1.diff --- 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)) --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=presched-latest.diff --- 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)) --=-=-=--