emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: James TD Smith <ahktenzero@mohorovi.cc>
To: emacs-orgmode@gnu.org
Subject: [PATCH 5/7] Fix note insertion in entries with drawers.
Date: Fri, 25 Jul 2008 00:46:29 +0100	[thread overview]
Message-ID: <20080724234629.23478.41349.stgit@nyarlathotep.internal.mohorovi.cc> (raw)
In-Reply-To: <20080724234608.23478.48564.stgit@nyarlathotep.internal.mohorovi.cc>

The code to find the insertion point after a heading for notes was not skipping
over drawers, resulting in notes being added inbetween the scheduling keywords
and the first drawer. Notes are now inserted after any drawers in an item.
---

 lisp/ChangeLog |    2 ++
 lisp/org.el    |   43 ++++++++++++++++++++++++-------------------
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ea6e60e..d072d40 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -3,6 +3,8 @@
 	* org.el (org-get-refile-targets): Replace links with their
 	descriptions
 	(org-imenu-get-tree): Replace links with their descriptions
+	(org-add-log-setup): Skip over drawers (properties, clocks etc)
+	when adding notes.
 
 	* org-agenda.el (org-agenda-get-closed): show durations of clocked
 	items as well as the start and end times.
diff --git a/lisp/org.el b/lisp/org.el
index cbce370..97e0d03 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8444,10 +8444,10 @@ For calling through lisp, arg is also interpreted in the following way:
 	    ;; It is now done, and it was not done before
 	    (org-add-planning-info 'closed (org-current-time))
 	    (if (and (not dolog) (eq 'note org-log-done))
-		(org-add-log-setup 'done state 'findpos 'note)))
+		(org-add-log-setup 'done state t 'note)))
 	  (when (and state dolog)
 	    ;; This is a non-nil state, and we need to log it
-	    (org-add-log-setup 'state state 'findpos dolog)))
+	    (org-add-log-setup 'state state t dolog)))
 	;; Fixup tag positioning
 	(and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
 	(when org-provide-todo-statistics
@@ -8681,7 +8681,7 @@ This function is run automatically after each state change to a DONE state."
 		(setq org-log-note-how 'note))
 	  ;; Set up for taking a record
 	  (org-add-log-setup 'state (or done-word (car org-done-keywords))
-			     'findpos org-log-repeat)))
+			     t org-log-repeat)))
       (org-back-to-heading t)
       (org-add-planning-info nil nil 'closed)
       (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
@@ -8908,22 +8908,27 @@ This is done in the same way as adding a state change note."
 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
 the current entry.  If not, assume that it can be inserted at point."
-  (save-excursion
-    (when findpos
-      (org-back-to-heading t)
-      (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
-			  "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
-			  "[^\r\n]*\\)?"))
-      (goto-char (match-end 0))
-      (unless org-log-states-order-reversed
-	(and (= (char-after) ?\n) (forward-char 1))
-	(org-skip-over-state-notes)
-	(skip-chars-backward " \t\n\r")))
-    (move-marker org-log-note-marker (point))
-    (setq org-log-note-purpose purpose
-	  org-log-note-state state
-	  org-log-note-how how)
-    (add-hook 'post-command-hook 'org-add-log-note 'append)))
+  (save-restriction
+    (save-excursion
+      (when findpos
+	(org-back-to-heading t)
+	(org-narrow-to-subtree)
+	(looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"
+			    "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
+			    "[^\r\n]*\\)?"))
+	(goto-char (match-end 0))
+	(while (re-search-forward
+		(concat "\\(" org-drawer-regexp "\\|" org-property-end-re "\\)")
+		(point-max) t))
+	(unless org-log-states-order-reversed
+	  (and (= (char-after) ?\n) (forward-char 1))
+	  (org-skip-over-state-notes)
+	  (skip-chars-backward " \t\n\r")))
+      (move-marker org-log-note-marker (point))
+      (setq org-log-note-purpose purpose
+	    org-log-note-state state
+	    org-log-note-how how)
+      (add-hook 'post-command-hook 'org-add-log-note 'append))))
 
 (defun org-skip-over-state-notes ()
   "Skip past the list of State notes in an entry."

  parent reply	other threads:[~2008-07-24 23:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-24 23:46 [PATCH 1/7] Some improvements to the modeline clock display James TD Smith
2008-07-24 23:46 ` [PATCH 2/7] Fix X clipboard handling in emacs21 James TD Smith
2008-07-24 23:46 ` [PATCH 3/7] Show durations of clocked times in timeline James TD Smith
2008-07-24 23:46 ` [PATCH 4/7] Fix link display in imenus and the refile interface James TD Smith
2008-07-24 23:46 ` James TD Smith [this message]
2008-07-24 23:46 ` [PATCH 6/7] Add some functions for handling checklists James TD Smith
2008-07-24 23:46 ` [PATCH 7/7] Add some new interaction between remember and clocked tasks James TD Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080724234629.23478.41349.stgit@nyarlathotep.internal.mohorovi.cc \
    --to=ahktenzero@mohorovi.cc \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).