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.
This commit is contained in:
Kyle Meyer 2015-06-21 21:46:54 -04:00 committed by Nicolas Goaziou
parent 739853d128
commit 329683861c
3 changed files with 58 additions and 3 deletions

View File

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

View File

@ -8739,7 +8739,12 @@ the following will happen:
- 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 @@ and still retain the repeater to cover future instances of the task."
(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)))

View File

@ -1067,6 +1067,52 @@
(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>
* H1\n<2015-06-23>
"
(org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
(org-clone-subtree-with-time-shift 1 "+2d")
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
nil nil 1))))
;; Clone repeating once.
(should
(equal "\
* H1\n<2015-06-21>
* H1\n<2015-06-23>
* H1\n<2015-06-25 +1w>
"
(org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
(org-clone-subtree-with-time-shift 1 "+2d")
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
nil nil 1))))
;; Clone non-repeating zero times.
(should
(equal "\
* H1\n<2015-06-21>
"
(org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
(org-clone-subtree-with-time-shift 0 "+2d")
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
nil nil 1))))
;; Clone repeating "zero" times.
(should
(equal "\
* H1\n<2015-06-21>
* H1\n<2015-06-23 +1w>
"
(org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
(org-clone-subtree-with-time-shift 0 "+2d")
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
nil nil 1)))))
;;; Fixed-Width Areas