From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikolai Weibull Subject: Re: [PATCH 2/2] Allow inserting diary entries last in date tree Date: Sun, 23 Aug 2015 19:11:05 +0200 Message-ID: References: <87pp7aqycy.fsf@nicolasgoaziou.fr> <1440071480-32747-1-git-send-email-now@disu.se> <1440071480-32747-2-git-send-email-now@disu.se> <878u92lag3.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTYnT-00072a-To for emacs-orgmode@gnu.org; Sun, 23 Aug 2015 13:11:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTYnT-00033B-2R for emacs-orgmode@gnu.org; Sun, 23 Aug 2015 13:11:07 -0400 Received: from mail-la0-x22d.google.com ([2a00:1450:4010:c03::22d]:33621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTYnS-00032x-QU for emacs-orgmode@gnu.org; Sun, 23 Aug 2015 13:11:06 -0400 Received: by lalv9 with SMTP id v9so64790545lal.0 for ; Sun, 23 Aug 2015 10:11:05 -0700 (PDT) In-Reply-To: <878u92lag3.fsf@nicolasgoaziou.fr> 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: Nikolai Weibull , emacs-orgmode@gnu.org On Sun, Aug 23, 2015 at 9:40 AM, Nicolas Goaziou w= rote: >> + (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=E2=80=99s what I used first, but that doesn=E2=80=99t work if the subt= ree has children that has children.