From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH 2/2] Allow inserting diary entries last in date tree Date: Sun, 23 Aug 2015 09:40:12 +0200 Message-ID: <878u92lag3.fsf@nicolasgoaziou.fr> References: <87pp7aqycy.fsf@nicolasgoaziou.fr> <1440071480-32747-1-git-send-email-now@disu.se> <1440071480-32747-2-git-send-email-now@disu.se> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTPrT-0005Uh-Mn for emacs-orgmode@gnu.org; Sun, 23 Aug 2015 03:38:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTPrS-0001p5-KJ for emacs-orgmode@gnu.org; Sun, 23 Aug 2015 03:38:39 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:52624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTPrS-0001oZ-D4 for emacs-orgmode@gnu.org; Sun, 23 Aug 2015 03:38:38 -0400 In-Reply-To: <1440071480-32747-2-git-send-email-now@disu.se> (Nikolai Weibull's message of "Thu, 20 Aug 2015 13:51:20 +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: Nikolai Weibull Cc: emacs-orgmode@gnu.org Hello, Nikolai Weibull writes: > * org-agenda.el (org-agenda-insert-diary-strategy): Add new value > 'date-tree-last. > (org-agenda-insert-diary-make-new-entry): Handle > `org-agenda-insert-diary-strategy' set to 'date-tree-last. > > To allow for diary entries to be entered in time order in the date tree, > add a new value to `org-agenda-insert-diary-strategy' that allows for > this. The code for handling this value, 'date-tree-last, is a bit > tricky, as we need to keep track of whether the date-tree already had > one or more entries for the given date. Thank you. > + (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) You don't need `has-children' binding at all. Regards, -- Nicolas Goaziou