From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikolai Weibull Subject: Re: org-agenda-insert-diary-make-new-entry adds entry as first child? Date: Fri, 30 May 2014 18:12:50 +0200 Message-ID: References: <87vbsnmpqo.fsf@bzg.ath.cx> <8761kn8ir9.fsf@bzg.ath.cx> <87wqd3s30s.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqPQK-0004X0-FD for emacs-orgmode@gnu.org; Fri, 30 May 2014 12:12:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WqPQJ-0004CF-1k for emacs-orgmode@gnu.org; Fri, 30 May 2014 12:12:52 -0400 Received: from mail-qg0-x234.google.com ([2607:f8b0:400d:c04::234]:53067) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqPQI-0004C8-U5 for emacs-orgmode@gnu.org; Fri, 30 May 2014 12:12:50 -0400 Received: by mail-qg0-f52.google.com with SMTP id a108so5865937qge.25 for ; Fri, 30 May 2014 09:12:50 -0700 (PDT) In-Reply-To: <87wqd3s30s.fsf@bzg.ath.cx> 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: Bastien Cc: emacs-orgmode@gnu.org On Fri, May 30, 2014 at 5:24 PM, Bastien wrote: > Hi Nikolai, > > Nikolai Weibull 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=E2=80=99s 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=E2=80=99t 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))))