Browse Source

Merge branch 'capture-plain-text-into-nodes'

Carsten Dominik 14 years ago
parent
commit
a54afa7e8e
2 changed files with 40 additions and 5 deletions
  1. 19 5
      lisp/org-capture.el
  2. 21 0
      lisp/org.el

+ 19 - 5
lisp/org-capture.el

@@ -1012,13 +1012,27 @@ it.  When it is a variable, retrieve the value.  Return whatever we get."
     (org-table-align)))
     (org-table-align)))
 
 
 (defun org-capture-place-plain-text ()
 (defun org-capture-place-plain-text ()
-  "Place the template plainly."
+  "Place the template plainly.
+If the target locator points at an Org node, place the template into
+the text of the entry, before the first child.  If not, place the
+template at the beginning or end of the file.
+Of course, if exact position has been required, just put it at point."
   (let* ((txt (org-capture-get :template))
   (let* ((txt (org-capture-get :template))
 	 beg end)
 	 beg end)
-    (goto-char (cond
-		((org-capture-get :exact-position))
-		((org-capture-get :prepend) (point-min))
-		(t (point-max))))
+    (cond
+     ((org-capture-get :exact-position))
+     ((and (org-capture-get :target-entry-p)
+	   (bolp)
+	   (looking-at org-outline-regexp))
+      ;; we should place the text into this entry
+      (if (org-capture-get :prepend)
+	  ;; Skip meta data and drawers
+	  (org-end-of-meta-data-and-drawers)
+	;; go to ent of the entry text, before the next headline
+	(outline-next-heading)))
+     (t
+      ;; beginning or end of file
+      (goto-char (if (org-capture-get :prepend) (point-min) (point-max)))))
     (or (bolp) (newline))
     (or (bolp) (newline))
     (org-capture-empty-lines-before)
     (org-capture-empty-lines-before)
     (setq beg (point))
     (setq beg (point))

+ 21 - 0
lisp/org.el

@@ -19827,6 +19827,27 @@ If there is no such heading, return nil."
 	(unless (eobp) (backward-char 1)))
 	(unless (eobp) (backward-char 1)))
     ad-do-it))
     ad-do-it))
 
 
+(defun org-end-of-meta-data-and-drawers ()
+  "Jump to the first text after meta data and drawers in the current entry.
+This will move over empty lines, lines with planning time stamps,
+clocking lines, and drawers."
+  (org-back-to-heading t)
+  (let ((end (save-excursion (outline-next-heading) (point)))
+	(re (concat "[ \t]*$"
+		    "\\|"
+		    "\\(" org-drawer-regexp "\\)" ; group 1 are drawers
+		    "\\|"
+		    "\\([ \t]*\\(" org-keyword-time-regexp "\\)\\)")))
+    (forward-line 1)
+    (while (looking-at (concat "[ \t]*\\(" org-keyword-time-regexp "\\)"))
+      (if (not (match-end 1))
+	  ;; empty or planning line
+	  (forward-line 1)
+	;; a drawer, find the end
+	(re-search-forward "^[ \t]*:END:" end 'move)
+	(forward-line 1)))
+    (point)))
+
 (defun org-forward-same-level (arg &optional invisible-ok)
 (defun org-forward-same-level (arg &optional invisible-ok)
   "Move forward to the arg'th subheading at same level as this one.
   "Move forward to the arg'th subheading at same level as this one.
 Stop at the first and last subheadings of a superior heading.
 Stop at the first and last subheadings of a superior heading.