Browse Source

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 <konubinix@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/94482>
Nicolas Goaziou 10 years ago
parent
commit
a1116aa54e
1 changed files with 24 additions and 21 deletions
  1. 24 21
      lisp/org-agenda.el

+ 24 - 21
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.