emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nikolai Weibull <now@disu.se>
To: emacs-orgmode@gnu.org
Cc: Nikolai Weibull <now@disu.se>
Subject: [PATCH] Allow inserting diary entries last in date tree
Date: Mon, 24 Aug 2015 10:40:58 +0200	[thread overview]
Message-ID: <1440405658-37048-1-git-send-email-now@disu.se> (raw)
In-Reply-To: <87k2slzqgn.fsf@nicolasgoaziou.fr>

* 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..d97b3a9 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)
+  (cond
+   ((eq org-agenda-insert-diary-strategy 'date-tree-last)
+    (end-of-line)
+    (org-insert-heading '(4) t)
+    (org-do-demote))
+   (t
+    (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 ((col (current-column)))
     (insert text)
     (org-end-of-meta-data)
-- 
2.5.0

  reply	other threads:[~2015-08-24  8:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-30  9:03 org-agenda-insert-diary-make-new-entry adds entry as first child? Nikolai Weibull
2014-05-30 12:10 ` Bastien
2014-05-30 14:02   ` Nikolai Weibull
2014-05-30 14:04     ` Bastien
2014-05-30 14:47       ` Nikolai Weibull
2014-05-30 15:24         ` Bastien
2014-05-30 16:12           ` Nikolai Weibull
2014-07-28 14:20             ` Bastien
2015-03-07 21:49               ` Nikolai Weibull
2015-04-11 19:05                 ` Nicolas Goaziou
2015-08-20 11:51                   ` Nikolai Weibull
2015-08-20 11:51                     ` [PATCH 2/2] Allow inserting diary entries last in date tree Nikolai Weibull
2015-08-23  7:40                       ` Nicolas Goaziou
2015-08-23 17:11                         ` Nikolai Weibull
2015-08-23 20:42                           ` Nicolas Goaziou
2015-08-24  8:40                             ` Nikolai Weibull [this message]
2015-08-24 20:39                               ` [PATCH] " Nicolas Goaziou
2015-08-24 20:55                                 ` Nicolas Goaziou
2015-08-25  5:52                                   ` [PATCH] Add news about org-agenda-insert-diary-strategy Nikolai Weibull
2015-08-25  6:05                                     ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440405658-37048-1-git-send-email-now@disu.se \
    --to=now@disu.se \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).