Browse Source

Merge branch 'maint'

Nicolas Goaziou 8 years ago
parent
commit
fe9e60d61b
2 changed files with 9 additions and 5 deletions
  1. 5 5
      lisp/org.el
  2. 4 0
      testing/lisp/test-org.el

+ 5 - 5
lisp/org.el

@@ -8888,14 +8888,15 @@ 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: ")
+  (when (org-before-first-heading-p) (user-error "No subtree to clone"))
   (let ((shift
 	 (or shift
 	     (if (and (not (equal current-prefix-arg '(4)))
 		      (save-excursion
-			(re-search-forward org-ts-regexp-both
-					   (save-excursion
-					     (org-end-of-subtree t)
-					     (point)) t)))
+			(org-back-to-heading t)
+			(re-search-forward
+			 org-ts-regexp-both
+			 (save-excursion (org-end-of-subtree t) (point)) t)))
 		 (read-from-minibuffer
 		  "Date shift per clone (e.g. +1w, empty to copy unchanged): ")
 	       ""))) ;; No time shift
@@ -8917,7 +8918,6 @@ with the original repeater."
 				     ("m" . month) ("y" . year))))))
     (when (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
     (setq nmin 1 nmax n)
-    (org-back-to-heading t)
     (setq beg (point))
     (setq idprop (org-entry-get nil "ID"))
     (org-end-of-subtree t t)

+ 4 - 0
testing/lisp/test-org.el

@@ -1324,6 +1324,10 @@
 
 (ert-deftest test-org/clone-with-time-shift ()
   "Test `org-clone-subtree-with-time-shift'."
+  ;; Raise an error before first heading.
+  (should-error
+   (org-test-with-temp-text ""
+     (org-clone-subtree-with-time-shift 1)))
   ;; Clone non-repeating once.
   (should
    (equal "\