all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nikolai Weibull <now@disu.se>
To: Bastien <bzg@altern.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: org-agenda-insert-diary-make-new-entry adds entry as first child?
Date: Fri, 30 May 2014 18:12:50 +0200	[thread overview]
Message-ID: <CADdV=MuGhWqysqiv24S2=u+GE5qxOxJ8rrv-Ye_3uMDXgadsOQ@mail.gmail.com> (raw)
In-Reply-To: <87wqd3s30s.fsf@bzg.ath.cx>

On Fri, May 30, 2014 at 5:24 PM, Bastien <bzg@altern.org> wrote:
> Hi Nikolai,
>
> Nikolai Weibull <now@disu.se> writes:
>
>> When set to 'top-level, the documentation mentions that it adds it to
>> the end of the file and testing confirms this.  It thus seems more
>> consistent to always add entries towards the end of the file.
>
> Okay -- please go ahead with a patch if you have time.

Here’s a suggested solution.  We keep track of whether the parent
entry already has any children, then we call org-insert-heading with
two universal arguments to add an entry at the end of the current
subtree.  Finally, if there weren’t any children already, we demote
the entry we added so that it becomes a child of the parent entry.
Please note that this was written while eating dinner with my kid.

(defun org-agenda-insert-diary-make-new-entry (text)
  "Make new entry as last child of current entry.
Add TEXT as headline, and position the cursor in the second line so that
a timestamp can be added there."
  (let ((org-show-following-heading t)
    (org-show-siblings t)
    (org-show-hierarchy-above t)
    (org-show-entry-below t)
    (has-children (save-excursion (org-goto-first-child)))
    col)
    (org-back-over-empty-lines)
    (or (looking-at "[ \t]*$")
    (progn (insert "\n") (backward-char 1)))
    (org-insert-heading 16 t)
    (unless has-children
      (org-do-demote))
    (setq col (current-column))
    (insert text "\n")
    (if org-adapt-indentation (org-indent-to-column col))
    (let ((org-show-following-heading t)
      (org-show-siblings t)
      (org-show-hierarchy-above t)
      (org-show-entry-below t))
      (org-show-context))))
      (org-show-context))))

  reply	other threads:[~2014-05-30 16:12 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 [this message]
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                             ` [PATCH] " Nikolai Weibull
2015-08-24 20:39                               ` 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

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

  git send-email \
    --in-reply-to='CADdV=MuGhWqysqiv24S2=u+GE5qxOxJ8rrv-Ye_3uMDXgadsOQ@mail.gmail.com' \
    --to=now@disu.se \
    --cc=bzg@altern.org \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.