emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-closest-date: Don't accept canceled repeater
@ 2015-07-11  2:58 Kyle Meyer
  2015-07-13 10:07 ` Rasmus
  0 siblings, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2015-07-11  2:58 UTC (permalink / raw)
  To: Org-mode

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

Hello,

The attached patch fixes an arithmetic error that occurs when calling
org-agenda on a file that contains a heading with a canceled repeater.

--
Kyle


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-closest-date-Don-t-accept-canceled-repeater.patch --]
[-- Type: text/x-diff, Size: 1797 bytes --]

From 61cba7d42e19479ad3137f0f1ee01dc116d853e2 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
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..e1edeb1 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 (not (string-match "\\+0[hdwmy]" s))
+	 (string-match "\\+[0-9]+[hdwmy]" s))
     (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 (wholenump dn)
 	(user-error "Invalid change specifier: %s" change))
       (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
       (cond
-- 
2.4.5


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

* Re: [PATCH] org-closest-date: Don't accept canceled repeater
  2015-07-11  2:58 [PATCH] org-closest-date: Don't accept canceled repeater Kyle Meyer
@ 2015-07-13 10:07 ` Rasmus
  2015-07-13 15:06   ` Kyle Meyer
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus @ 2015-07-13 10:07 UTC (permalink / raw)
  To: emacs-orgmode

Hi Kyle,

Thanks for your patch.

Kyle Meyer <kyle@kyleam.com> writes:

> The attached patch fixes an arithmetic error that occurs when calling
> org-agenda on a file that contains a heading with a canceled repeater.

I'm happy to push your commit, but I don't really know what you mean by
canceled repeater.  Since you are the expert, would you mind posting an
example of a document with the error you fix?

Rasmus

-- 
When in doubt, do it!

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

* Re: [PATCH] org-closest-date: Don't accept canceled repeater
  2015-07-13 10:07 ` Rasmus
@ 2015-07-13 15:06   ` Kyle Meyer
  2015-07-15 17:17     ` Rasmus
  0 siblings, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2015-07-13 15:06 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hi Rasmus,

Rasmus <rasmus@gmx.us> wrote:
[...]
> I'm happy to push your commit, but I don't really know what you mean by
> canceled repeater.  Since you are the expert, would you mind posting an
> example of a document with the error you fix?

Sorry, I should have included an example.

If I have a heading that looks like

    ** 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:

    ** DONE h
    CLOSED: [2015-07-13 Mon 10:47] DEADLINE: <2015-07-13 Mon +0w>

If I call org-agenda-list on a file with an entry like above, I get an
arith-error from +0w being passed to org-closest-date.

--
Kyle
expert of +0

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

* Re: [PATCH] org-closest-date: Don't accept canceled repeater
  2015-07-13 15:06   ` Kyle Meyer
@ 2015-07-15 17:17     ` Rasmus
  2015-07-16  1:50       ` Kyle Meyer
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus @ 2015-07-15 17:17 UTC (permalink / raw)
  To: kyle; +Cc: emacs-orgmode

Hi,

Thanks for the example.

Kyle Meyer <kyle@kyleam.com> writes:

> Sorry, I should have included an example.
>
> If I have a heading that looks like
>
>     ** 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?

>     ** DONE h
>     CLOSED: [2015-07-13 Mon 10:47] DEADLINE: <2015-07-13 Mon +0w>
>
> If I call org-agenda-list on a file with an entry like above, I get an
> arith-error from +0w being passed to org-closest-date.

On your patch:

>        (+ 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))

You can also use (not (zerop ·)).  But feel free to use whatever you
prefer.

> -	  (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?

Rasmus

-- 
To err is human. To screw up 10⁶ times per second, you need a computer

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

* Re: [PATCH] org-closest-date: Don't accept canceled repeater
  2015-07-15 17:17     ` Rasmus
@ 2015-07-16  1:50       ` Kyle Meyer
  2015-07-16  9:44         ` Rasmus
  0 siblings, 1 reply; 6+ messages in thread
From: Kyle Meyer @ 2015-07-16  1:50 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

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

Rasmus <rasmus@gmx.us> wrote:
> Kyle Meyer <kyle@kyleam.com> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-closest-date-Don-t-accept-canceled-repeater.patch --]
[-- Type: text/x-diff, Size: 1813 bytes --]

From 06e6f0bf1e1a23c4d9426191c321a971cdfeafae Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
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


[-- Attachment #3: Type: text/plain, Size: 9 bytes --]


--
Kyle

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

* Re: [PATCH] org-closest-date: Don't accept canceled repeater
  2015-07-16  1:50       ` Kyle Meyer
@ 2015-07-16  9:44         ` Rasmus
  0 siblings, 0 replies; 6+ messages in thread
From: Rasmus @ 2015-07-16  9:44 UTC (permalink / raw)
  To: emacs-orgmode

Kyle Meyer <kyle@kyleam.com> writes:

> I've attached an updated patch.  Thanks for your comments.

Pushed, thanks.

-- 
However beautiful the theory, you should occasionally look at the evidence

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

end of thread, other threads:[~2015-07-16  9:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-11  2:58 [PATCH] org-closest-date: Don't accept canceled repeater Kyle Meyer
2015-07-13 10:07 ` Rasmus
2015-07-13 15:06   ` Kyle Meyer
2015-07-15 17:17     ` Rasmus
2015-07-16  1:50       ` Kyle Meyer
2015-07-16  9:44         ` Rasmus

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