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
1 changed files with 49 additions and 51 deletions

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,55 +13528,55 @@ 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) ;; Skip planning info and property drawer.
(narrow-to-region (point) (save-excursion (forward-line)
(outline-next-heading) (point))) (when (org-looking-at-p org-planning-line-re) (forward-line))
(looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*" (when (looking-at org-property-drawer-re)
"\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp (goto-char (match-end 0))
"[^\r\n]*\\)?")) (forward-line))
(goto-char (match-end 0)) (let ((end (if (org-at-heading-p) (point)
(cond (save-excursion (outline-next-heading) (point)))))
(drawer (cond
(if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$") (drawer
nil t) (let ((regexp (concat "^[ \t]*:" (regexp-quote drawer) ":[ \t]*$"))
(progn (case-fold-search t))
(goto-char (match-end 0)) (catch 'exit
(or org-log-states-order-reversed ;; Try to find existing drawer.
(and (re-search-forward org-property-end-re nil t) (while (re-search-forward regexp end t)
(goto-char (1- (match-beginning 0)))))) (let ((element (org-element-at-point)))
(insert "\n:" drawer ":\n:END:") (when (eq (org-element-type element) 'drawer)
(beginning-of-line 0) (when (and (not org-log-states-order-reversed)
(org-indent-line) (org-element-property :contents-end element))
(beginning-of-line 2) (goto-char (org-element-property :contents-end element)))
(org-indent-line) (throw 'exit nil))))
(end-of-line 0))) ;; No drawer found. Create one.
((and org-log-state-notes-insert-after-drawers (unless (bolp) (insert "\n"))
(save-excursion (let ((beg (point)))
(forward-line) (looking-at org-drawer-regexp))) (insert ":" drawer ":\n:END:\n")
(forward-line) (org-indent-region beg (point)))
(while (looking-at org-drawer-regexp) (end-of-line -1))))
(goto-char (match-end 0)) (org-log-state-notes-insert-after-drawers
(re-search-forward org-property-end-re (point-max) t) (while (and (looking-at org-drawer-regexp)
(forward-line)) (progn (goto-char (match-end 0))
(forward-line -1))) (re-search-forward org-property-end-re end t)))
(unless org-log-states-order-reversed (forward-line)))))
(and (= (char-after) ?\n) (forward-char 1)) (unless org-log-states-order-reversed
(org-skip-over-state-notes) (and (= (char-after) ?\n) (forward-char 1))
(skip-chars-backward " \t\n\r"))) (org-skip-over-state-notes)
(move-marker org-log-note-marker (point)) (skip-chars-backward " \t\n\r")))
(setq org-log-note-purpose purpose (move-marker org-log-note-marker (point))
org-log-note-state state (setq org-log-note-purpose purpose
org-log-note-previous-state prev-state org-log-note-state state
org-log-note-how how org-log-note-previous-state prev-state
org-log-note-extra extra org-log-note-how how
org-log-note-effective-time (org-current-effective-time)) org-log-note-extra extra
(add-hook 'post-command-hook 'org-add-log-note 'append))))) org-log-note-effective-time (org-current-effective-time))
(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."