From a1116aa54ee4befd8fa52e3f92207db200ebfd59 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 30 Jan 2015 10:23:47 +0100 Subject: [PATCH] Fix `org-agenda-insert-diary-make-new-entry' * lisp/org-agenda.el (org-agenda-insert-diary-make-new-entry): Ensure point is at a real body line and not in front of meta data, so regular contents can be inserted safely after a call to this function. Reported-by: Samuel Loury --- lisp/org-agenda.el | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index ad4018d6e..3476a2504 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -9488,27 +9488,30 @@ a timestamp can be added there." (defun org-agenda-insert-diary-make-new-entry (text) "Make a new entry with TEXT as the first child of the current subtree. -Position the point in the line right after the new heading 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) - col) - (outline-next-heading) - (org-back-over-empty-lines) - (or (looking-at "[ \t]*$") - (progn (insert "\n") (backward-char 1))) - (org-insert-heading nil t) - (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)))) +Position the point in the heading's first body line so that +a timestamp can be added there." + (let (col) + (org-with-wide-buffer + (outline-next-heading) + (org-back-over-empty-lines) + (or (looking-at "[ \t]*$") + (progn (insert "\n") (backward-char 1))) + (org-insert-heading nil t) + (org-do-demote) + (setq col (current-column)) + (insert text) + (forward-line) + (when (org-looking-at-p org-planning-line-re) (forward-line)) + (when (looking-at org-property-drawer-re) + (goto-char (match-end 0)) + (forward-line)) + (unless (bolp) (insert "\n")) + (when 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))))) (defun org-agenda-diary-entry () "Make a diary entry, like the `i' command from the calendar. -- 2.11.4.GIT