* [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones
@ 2015-06-22 2:02 Kyle Meyer
2015-06-22 8:12 ` Nicolas Goaziou
0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2015-06-22 2:02 UTC (permalink / raw)
To: Org-mode
[-- Attachment #1: Type: text/plain, Size: 887 bytes --]
Hello,
I'd like to clone a subtree with a repeating timestamp so that the
repeater is removed from the original subtree and a single shifted and
repeating clone is created. I don't think this is currently possible
with org-clone-subtree-with-time-shift. For example, running
org-clone-subtree-with-time-shift with 1 clone and a shift of +2d on
* sub
<2015-06-21 Sun +1w>
results in
* sub
<2015-06-21 Sun>
* sub
<2015-06-23 Tue>
* sub
<2015-06-25 Thu +1w>
This is inline with the docstring of org-clone-subtree-with-time-shift.
The one clone is the subtree in the middle, and the two flanking
subtrees are how a repeating timestamp is handled.
The attached patch allows the number of specified clones to be 0,
resulting in
* sub
<2015-06-21 Sun>
* sub
<2015-06-23 Tue +1w>
which is still consistent with the documented behavior.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-clone-subtree-with-time-shift-Accept-0-clones.patch --]
[-- Type: text/x-diff, Size: 4331 bytes --]
From 37a917e4f7e4d2c05355735ab08f1f555b9dc942 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Sun, 21 Jun 2015 21:46:54 -0400
Subject: [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones
* lisp/org.el (org-clone-subtree-with-time-shift): Allow argument
specifying number of clones to be 0.
* testing/lisp/test-org.el (test-org/clone-with-time-shift): Add
tests.
This makes it possible to clone a subtree with a repeating timestamp
so that the repeater is removed from the original subtree and a single
shifted, repeating clone is created. If the original subtree does not
have a repeating timestamp, no clones will be made.
---
etc/ORG-NEWS | 4 ++++
lisp/org.el | 9 +++++++--
testing/lisp/test-org.el | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 92be86b..bcbd068 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -392,6 +392,10 @@ of tables and lists of listings can be inserted in the document with
*** Countdown timer support hh:mm:ss format
In addition to setting countdown timers in minutes, they can also be
set using the hh:mm:ss format.
+*** Extend ~org-clone-subtree-with-time-shift~
+~org-clone-subtree-with-time-shift~ now accepts 0 as an argument for
+the number of clones, which removes the repeater from the original
+subtree and creates one shifted, repeating clone.
** Miscellaneous
*** Strip all meta data from ITEM special property
ITEM special property does not contain TODO, priority or tags anymore.
diff --git a/lisp/org.el b/lisp/org.el
index 7b720f8..25f8cd0 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8739,7 +8739,12 @@ (defun org-clone-subtree-with-time-shift (n &optional shift)
- the start days in the repeater in the original entry will be shifted
to past the last clone.
In this way you can spell out a number of instances of a repeating task,
-and still retain the repeater to cover future instances of the task."
+and still retain the repeater to cover future instances of the task.
+
+As described above, N+1 clones are produced when the original
+subtree has a repeater. Setting N to 0, then, can be used to
+remove the repeater from a subtree and create a shifted clone
+with the original repeater."
(interactive "nNumber of clones to produce: ")
(let ((shift
(or shift
@@ -8757,7 +8762,7 @@ (defun org-clone-subtree-with-time-shift (n &optional shift)
(org-clock-re (format "^[ \t]*%s.*$" org-clock-string))
beg end template task idprop
shift-n shift-what doshift nmin nmax)
- (if (not (and (integerp n) (> n 0)))
+ (if (not (and (integerp n) (>= n 0)))
(user-error "Invalid number of replications %s" n))
(if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
(not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([hdwmy]\\)[ \t]*\\'"
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 04e0843..e8287a2 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1067,6 +1067,44 @@ (ert-deftest test-org/insert-todo-heading-respect-content ()
(org-insert-todo-heading-respect-content)
(and (eobp) (org-at-heading-p)))))
+(ert-deftest test-org/clone-with-time-shift ()
+ "Test `org-clone-subtree-with-time-shift'."
+ ;; Clone non-repeating once.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+* H1\n<2015-06-23 Tue>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
+ (org-clone-subtree-with-time-shift 1 "+2d")
+ (buffer-string))))
+ ;; Clone repeating once.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+* H1\n<2015-06-23 Tue>
+* H1\n<2015-06-25 Thu +1w>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
+ (org-clone-subtree-with-time-shift 1 "+2d")
+ (buffer-string))))
+ ;; Clone non-repeating zero times.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
+ (org-clone-subtree-with-time-shift 0 "+2d")
+ (buffer-string))))
+ ;; Clone repeating "zero" times.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+* H1\n<2015-06-23 Tue +1w>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
+ (org-clone-subtree-with-time-shift 0 "+2d")
+ (buffer-string)))))
\f
;;; Fixed-Width Areas
--
2.4.4
[-- Attachment #3: Type: text/plain, Size: 9 bytes --]
--
Kyle
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones
2015-06-22 2:02 [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones Kyle Meyer
@ 2015-06-22 8:12 ` Nicolas Goaziou
2015-06-22 16:50 ` Kyle Meyer
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2015-06-22 8:12 UTC (permalink / raw)
To: Kyle Meyer; +Cc: Org-mode
Hello,
Kyle Meyer <kyle@kyleam.com> writes:
> From 37a917e4f7e4d2c05355735ab08f1f555b9dc942 Mon Sep 17 00:00:00 2001
> From: Kyle Meyer <kyle@kyleam.com>
> Date: Sun, 21 Jun 2015 21:46:54 -0400
> Subject: [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones
Thank you for the patch.
> - (if (not (and (integerp n) (> n 0)))
> + (if (not (and (integerp n) (>= n 0)))
> (user-error "Invalid number of replications %s" n))
Nitpick: (unless (wholenump n) (user-error ...))
Otherwise, looks good.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones
2015-06-22 8:12 ` Nicolas Goaziou
@ 2015-06-22 16:50 ` Kyle Meyer
2015-06-22 19:51 ` Nicolas Goaziou
0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2015-06-22 16:50 UTC (permalink / raw)
To: Org-mode
[-- Attachment #1: Type: text/plain, Size: 268 bytes --]
Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>> - (if (not (and (integerp n) (> n 0)))
>> + (if (not (and (integerp n) (>= n 0)))
>> (user-error "Invalid number of replications %s" n))
>
> Nitpick: (unless (wholenump n) (user-error ...))
Thanks. Updated.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-clone-subtree-with-time-shift-Accept-0-clones.patch --]
[-- Type: text/x-diff, Size: 4390 bytes --]
From fe596d7d9a2687f8f553997e2a75fe40f1424ef3 Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Sun, 21 Jun 2015 21:46:54 -0400
Subject: [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones
* lisp/org.el (org-clone-subtree-with-time-shift): Allow argument
specifying number of clones to be 0.
* testing/lisp/test-org.el (test-org/clone-with-time-shift): Add
tests.
This makes it possible to clone a subtree with a repeating timestamp
so that the repeater is removed from the original subtree and a single
shifted, repeating clone is created. If the original subtree does not
have a repeating timestamp, no clones will be made.
---
etc/ORG-NEWS | 4 ++++
lisp/org.el | 11 ++++++++---
testing/lisp/test-org.el | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 92be86b..bcbd068 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -392,6 +392,10 @@ of tables and lists of listings can be inserted in the document with
*** Countdown timer support hh:mm:ss format
In addition to setting countdown timers in minutes, they can also be
set using the hh:mm:ss format.
+*** Extend ~org-clone-subtree-with-time-shift~
+~org-clone-subtree-with-time-shift~ now accepts 0 as an argument for
+the number of clones, which removes the repeater from the original
+subtree and creates one shifted, repeating clone.
** Miscellaneous
*** Strip all meta data from ITEM special property
ITEM special property does not contain TODO, priority or tags anymore.
diff --git a/lisp/org.el b/lisp/org.el
index 8eaaa3e..02f5c22 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8739,7 +8739,12 @@ (defun org-clone-subtree-with-time-shift (n &optional shift)
- the start days in the repeater in the original entry will be shifted
to past the last clone.
In this way you can spell out a number of instances of a repeating task,
-and still retain the repeater to cover future instances of the task."
+and still retain the repeater to cover future instances of the task.
+
+As described above, N+1 clones are produced when the original
+subtree has a repeater. Setting N to 0, then, can be used to
+remove the repeater from a subtree and create a shifted clone
+with the original repeater."
(interactive "nNumber of clones to produce: ")
(let ((shift
(or shift
@@ -8757,8 +8762,8 @@ (defun org-clone-subtree-with-time-shift (n &optional shift)
(org-clock-re (format "^[ \t]*%s.*$" org-clock-string))
beg end template task idprop
shift-n shift-what doshift nmin nmax)
- (if (not (and (integerp n) (> n 0)))
- (user-error "Invalid number of replications %s" n))
+ (unless (wholenump n)
+ (user-error "Invalid number of replications %s" n))
(if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
(not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([hdwmy]\\)[ \t]*\\'"
shift)))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 11004f0..55dbd49 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1067,6 +1067,44 @@ (ert-deftest test-org/insert-todo-heading-respect-content ()
(org-insert-todo-heading-respect-content)
(and (eobp) (org-at-heading-p)))))
+(ert-deftest test-org/clone-with-time-shift ()
+ "Test `org-clone-subtree-with-time-shift'."
+ ;; Clone non-repeating once.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+* H1\n<2015-06-23 Tue>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
+ (org-clone-subtree-with-time-shift 1 "+2d")
+ (buffer-string))))
+ ;; Clone repeating once.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+* H1\n<2015-06-23 Tue>
+* H1\n<2015-06-25 Thu +1w>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
+ (org-clone-subtree-with-time-shift 1 "+2d")
+ (buffer-string))))
+ ;; Clone non-repeating zero times.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
+ (org-clone-subtree-with-time-shift 0 "+2d")
+ (buffer-string))))
+ ;; Clone repeating "zero" times.
+ (should
+ (equal "\
+* H1\n<2015-06-21 Sun>
+* H1\n<2015-06-23 Tue +1w>
+"
+ (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
+ (org-clone-subtree-with-time-shift 0 "+2d")
+ (buffer-string)))))
\f
;;; Fixed-Width Areas
--
2.4.4
[-- Attachment #3: Type: text/plain, Size: 9 bytes --]
--
Kyle
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-22 19:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-22 2:02 [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones Kyle Meyer
2015-06-22 8:12 ` Nicolas Goaziou
2015-06-22 16:50 ` Kyle Meyer
2015-06-22 19:51 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.