Insert logs after planning info and property drawer

* lisp/org.el (org-add-log-setup): Set `org-log-note-marker' after
  planning info and property drawer.
This commit is contained in:
Nicolas Goaziou 2014-09-22 22:28:22 +02:00
parent 52b63aed04
commit ed825d738b

View file

@ -13520,9 +13520,7 @@ This is done in the same way as adding a state change note."
(interactive) (interactive)
(org-add-log-setup 'note nil nil 'findpos nil)) (org-add-log-setup 'note nil nil 'findpos nil))
(defvar org-property-end-re) (defun org-add-log-setup (&optional purpose state prev-state findpos how extra)
(defun org-add-log-setup (&optional purpose state prev-state
findpos how extra)
"Set up the post command hook to take a note. "Set up the post command hook to take a note.
If this is about to TODO state change, the new state is expected in STATE. If this is about to TODO state change, the new state is expected in STATE.
When FINDPOS is non-nil, find the correct position for the note in When FINDPOS is non-nil, find the correct position for the note in
@ -13530,43 +13528,43 @@ the current entry. If not, assume that it can be inserted at point.
HOW is an indicator what kind of note should be created. HOW is an indicator what kind of note should be created.
EXTRA is additional text that will be inserted into the notes buffer." EXTRA is additional text that will be inserted into the notes buffer."
(let* ((org-log-into-drawer (org-log-into-drawer)) (let* ((org-log-into-drawer (org-log-into-drawer))
(drawer (cond ((stringp org-log-into-drawer) (drawer (cond ((stringp org-log-into-drawer) org-log-into-drawer)
org-log-into-drawer)
(org-log-into-drawer "LOGBOOK")))) (org-log-into-drawer "LOGBOOK"))))
(save-restriction (org-with-wide-buffer
(save-excursion
(when findpos (when findpos
(org-back-to-heading t) (org-back-to-heading t)
(narrow-to-region (point) (save-excursion ;; Skip planning info and property drawer.
(outline-next-heading) (point))) (forward-line)
(looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*" (when (org-looking-at-p org-planning-line-re) (forward-line))
"\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp (when (looking-at org-property-drawer-re)
"[^\r\n]*\\)?"))
(goto-char (match-end 0)) (goto-char (match-end 0))
(forward-line))
(let ((end (if (org-at-heading-p) (point)
(save-excursion (outline-next-heading) (point)))))
(cond (cond
(drawer (drawer
(if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$") (let ((regexp (concat "^[ \t]*:" (regexp-quote drawer) ":[ \t]*$"))
nil t) (case-fold-search t))
(progn (catch 'exit
(goto-char (match-end 0)) ;; Try to find existing drawer.
(or org-log-states-order-reversed (while (re-search-forward regexp end t)
(and (re-search-forward org-property-end-re nil t) (let ((element (org-element-at-point)))
(goto-char (1- (match-beginning 0)))))) (when (eq (org-element-type element) 'drawer)
(insert "\n:" drawer ":\n:END:") (when (and (not org-log-states-order-reversed)
(beginning-of-line 0) (org-element-property :contents-end element))
(org-indent-line) (goto-char (org-element-property :contents-end element)))
(beginning-of-line 2) (throw 'exit nil))))
(org-indent-line) ;; No drawer found. Create one.
(end-of-line 0))) (unless (bolp) (insert "\n"))
((and org-log-state-notes-insert-after-drawers (let ((beg (point)))
(save-excursion (insert ":" drawer ":\n:END:\n")
(forward-line) (looking-at org-drawer-regexp))) (org-indent-region beg (point)))
(forward-line) (end-of-line -1))))
(while (looking-at org-drawer-regexp) (org-log-state-notes-insert-after-drawers
(goto-char (match-end 0)) (while (and (looking-at org-drawer-regexp)
(re-search-forward org-property-end-re (point-max) t) (progn (goto-char (match-end 0))
(forward-line)) (re-search-forward org-property-end-re end t)))
(forward-line -1))) (forward-line)))))
(unless org-log-states-order-reversed (unless org-log-states-order-reversed
(and (= (char-after) ?\n) (forward-char 1)) (and (= (char-after) ?\n) (forward-char 1))
(org-skip-over-state-notes) (org-skip-over-state-notes)
@ -13578,7 +13576,7 @@ EXTRA is additional text that will be inserted into the notes buffer."
org-log-note-how how org-log-note-how how
org-log-note-extra extra org-log-note-extra extra
org-log-note-effective-time (org-current-effective-time)) org-log-note-effective-time (org-current-effective-time))
(add-hook 'post-command-hook 'org-add-log-note 'append))))) (add-hook 'post-command-hook 'org-add-log-note 'append))))
(defun org-skip-over-state-notes () (defun org-skip-over-state-notes ()
"Skip past the list of State notes in an entry." "Skip past the list of State notes in an entry."