From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: [PATCH] org-clone-subtree-with-time-shift: Accept 0 clones Date: Mon, 22 Jun 2015 12:50:11 -0400 Message-ID: <87616fbscc.fsf@kyleam.com> References: <87h9q08pqi.fsf@kmlap.domain.org> <87mvzstb3o.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z74vI-0007z0-Vc for emacs-orgmode@gnu.org; Mon, 22 Jun 2015 12:50:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z74vF-0007TG-Q4 for emacs-orgmode@gnu.org; Mon, 22 Jun 2015 12:50:16 -0400 Received: from mail-qk0-f175.google.com ([209.85.220.175]:33805) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z74vF-0007TA-LR for emacs-orgmode@gnu.org; Mon, 22 Jun 2015 12:50:13 -0400 Received: by qkeo142 with SMTP id o142so86309675qke.1 for ; Mon, 22 Jun 2015 09:50:12 -0700 (PDT) Received: from localhost (nat-130-132-173-5.central.yale.edu. [130.132.173.5]) by mx.google.com with ESMTPSA id p65sm61521qgd.12.2015.06.22.09.50.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jun 2015 09:50:11 -0700 (PDT) In-Reply-To: <87mvzstb3o.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Mon, 22 Jun 2015 10:12:59 +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: Org-mode --=-=-= Content-Type: text/plain Nicolas Goaziou 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-clone-subtree-with-time-shift-Accept-0-clones.patch >From fe596d7d9a2687f8f553997e2a75fe40f1424ef3 Mon Sep 17 00:00:00 2001 From: Kyle Meyer 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))))) ;;; Fixed-Width Areas -- 2.4.4 --=-=-= Content-Type: text/plain -- Kyle --=-=-=--