From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikolai Weibull Subject: [PATCH 2/2] Allow inserting diary entries last in date tree Date: Thu, 20 Aug 2015 13:51:20 +0200 Message-ID: <1440071480-32747-2-git-send-email-now@disu.se> References: <87pp7aqycy.fsf@nicolasgoaziou.fr> <1440071480-32747-1-git-send-email-now@disu.se> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSONs-0007sX-LS for emacs-orgmode@gnu.org; Thu, 20 Aug 2015 07:51:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSONn-0005dr-KE for emacs-orgmode@gnu.org; Thu, 20 Aug 2015 07:51:52 -0400 Received: from smtprelay-h31.telenor.se ([213.150.131.4]:36682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSONn-0005dh-9C for emacs-orgmode@gnu.org; Thu, 20 Aug 2015 07:51:47 -0400 Received: from ipb4.telenor.se (ipb4.telenor.se [195.54.127.167]) by smtprelay-h31.telenor.se (Postfix) with ESMTP id 35E4EF726 for ; Thu, 20 Aug 2015 13:51:46 +0200 (CEST) In-Reply-To: <1440071480-32747-1-git-send-email-now@disu.se> 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: emacs-orgmode@gnu.org Cc: Nikolai Weibull * 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. --- lisp/org-agenda.el | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 5fd1cd4..22a4ad9 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -9417,11 +9417,13 @@ buffer, display it in another window." "Where in `org-agenda-diary-file' should new entries be added? Valid values: -date-tree in the date tree, as child of the date -top-level as top-level entries at the end of the file." +date-tree in the date tree, as first child of the date +date-tree-last in the date tree, as last child of the date +top-level as top-level entries at the end of the file." :group 'org-agenda :type '(choice - (const :tag "in a date tree" date-tree) + (const :tag "first in a date tree" date-tree) + (const :tag "last in a date tree" date-tree-last) (const :tag "as top level at end of file" top-level))) (defcustom org-agenda-insert-diary-extract-time nil @@ -9525,14 +9527,20 @@ a timestamp can be added there." (when org-adapt-indentation (org-indent-to-column 2))) (defun org-agenda-insert-diary-make-new-entry (text) - "Make a new entry with TEXT as the first child of the current subtree. + "Make a new entry with TEXT as a child of the current subtree. Position the point in the heading's first body line so that a timestamp can be added there." - (outline-next-heading) - (org-back-over-empty-lines) - (unless (looking-at "[ \t]*$") (save-excursion (insert "\n"))) - (org-insert-heading nil t) - (org-do-demote) + (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))) (let ((col (current-column))) (insert text) (org-end-of-meta-data) -- 2.5.0