From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: [PATCH] org-closest-date: Don't accept canceled repeater Date: Wed, 15 Jul 2015 21:50:13 -0400 Message-ID: <871tg8yip6.fsf@kmlap.domain.org> References: <87380viemx.fsf@kmlap.domain.org> <87mvz01icw.fsf@gmx.us> <87wpy4nlkc.fsf@kyleam.com> <87h9p51gt6.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFYJc-0004bl-EY for emacs-orgmode@gnu.org; Wed, 15 Jul 2015 21:50:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFYJV-0003a5-Um for emacs-orgmode@gnu.org; Wed, 15 Jul 2015 21:50:24 -0400 Received: from mail-qk0-f181.google.com ([209.85.220.181]:33568) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFYJV-0003Yx-QV for emacs-orgmode@gnu.org; Wed, 15 Jul 2015 21:50:17 -0400 Received: by qkdl129 with SMTP id l129so41418954qkd.0 for ; Wed, 15 Jul 2015 18:50:15 -0700 (PDT) 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: Rasmus Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Rasmus wrote: > Kyle Meyer writes: >> ** TODO h >> DEADLINE: <2015-07-13 Mon +3w> >> >> and I run org-todo with a numeric prefix of -1, the repeater is canceled >> by changing it to +0w: > > I see. Shouldn't org-todo rather remove the repeater? That seems fine to me. I wonder if there was a particular reason the original code set it to 0 instead. >> (+ daynr 1000))) >> - ((and daynr (string-match "\\+[0-9]+[hdwmy]" s)) >> + ((and daynr (not (string-match "\\+0[hdwmy]" s)) >> + (string-match "\\+[0-9]+[hdwmy]" s)) > > for no particular reason I prefer: > > (and daynr (string-match "\\+\\([0-9]+\\)[hdwmy]" s) > (> (string-to-number (match-string 1)) 0)) I do too (though I think s should be added to the match-string call). >> - (setq dn (string-to-number (match-string 1 change)) >> - dw (cdr (assoc (match-string 2 change) a1))) >> + (when (string-match "\\(\\+[0-9]+\\)\\([hdwmy]\\)" change) >> + (setq dn (string-to-number (match-string 1 change)) >> + dw (cdr (assoc (match-string 2 change) a1)))) >> + (unless (wholenump dn) > > Shouldn'it it also test that dn > 0? Doh, it should. I've attached an updated patch. Thanks for your comments. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-closest-date-Don-t-accept-canceled-repeater.patch >From 06e6f0bf1e1a23c4d9426191c321a971cdfeafae Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 10 Jul 2015 22:34:24 -0400 Subject: [PATCH] org-closest-date: Don't accept canceled repeater * lisp/org.el (org-time-string-to-absolute): Don't pass a canceled repeater to org-closest-date. (org-closest-date): Raise an error when passed a canceled repeater. Prevent arith-error from occurring when a canceled repeater is passed to org-closest-date. --- lisp/org.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 085b763..31e7674 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -17564,7 +17564,8 @@ (defun org-time-string-to-absolute (s &optional daynr prefer show-all buffer pos (if (org-diary-sexp-entry (match-string 1 s) "" date) daynr (+ daynr 1000))) - ((and daynr (string-match "\\+[0-9]+[hdwmy]" s)) + ((and daynr (string-match "\\+\\([0-9]+\\)[hdwmy]" s) + (> (string-to-number (match-string 1 s)) 0)) (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr (time-to-days (current-time))) (match-string 0 s) prefer show-all)) @@ -17680,9 +17681,10 @@ (defun org-closest-date (start current change prefer show-all) (if (<= cday sday) (throw 'exit sday)) - (if (string-match "\\(\\+[0-9]+\\)\\([hdwmy]\\)" change) - (setq dn (string-to-number (match-string 1 change)) - dw (cdr (assoc (match-string 2 change) a1))) + (when (string-match "\\(\\+[0-9]+\\)\\([hdwmy]\\)" change) + (setq dn (string-to-number (match-string 1 change)) + dw (cdr (assoc (match-string 2 change) a1)))) + (unless (and dn (> dn 0)) (user-error "Invalid change specifier: %s" change)) (if (eq dw 'week) (setq dw 'day dn (* 7 dn))) (cond -- 2.4.5 --=-=-= Content-Type: text/plain -- Kyle --=-=-=--