On Sun, Aug 23, 2015 at 9:40 AM, Nicolas Goaziou <m...@nicolasgoaziou.fr> wrote:
>> + (let ((last (eq org-agenda-insert-diary-strategy 'date-tree-last)) >> + (has-children (save-excursion (org-goto-first-child)))) >> + (if (not (and last has-children)) >> + (outline-next-heading) >> + (org-goto-first-child) >> + (while (org-get-next-sibling))) >> + (org-back-over-empty-lines) >> + (unless (looking-at "[ \t]*$") (save-excursion (insert "\n"))) >> + (org-insert-heading nil t) >> + (unless has-children >> + (org-do-demote))) > > This part is incorrect, when tree is ill-formed, and slightly > inefficient when there are many children. > > Assuming point is on the parent headline, I think a faster way to do > this would be > > (org-end-of-subtree t t) > (org-insert-heading nil t) > (org-do-demote) That’s what I used first, but that doesn’t work if the subtree has children that has children.