[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-agenda-insert-diary-make-new-entry adds entry as first child

From: Nikolai Weibull
Subject: Re: [O] org-agenda-insert-diary-make-new-entry adds entry as first child?
Date: Fri, 30 May 2014 18:12:50 +0200

On Fri, May 30, 2014 at 5:24 PM, Bastien <address@hidden> wrote:
> Hi Nikolai,
> Nikolai Weibull <address@hidden> 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)))
    (or (looking-at "[ \t]*$")
    (progn (insert "\n") (backward-char 1)))
    (org-insert-heading 16 t)
    (unless has-children
    (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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]