diff options
author | Carsten Dominik <carsten.dominik@gmail.com> | 2011-04-07 08:36:31 +0200 |
---|---|---|
committer | Carsten Dominik <carsten.dominik@gmail.com> | 2011-04-07 08:47:13 +0200 |
commit | f1ffed8a6caf041b2c9728e5de03f001fdf2ce9e (patch) | |
tree | bd691f7b89880ebe7d34b8c456733c7a8e026f5a | |
parent | 1df06e0fa9dd7a137f7d0cfc1840264a6c83ccc4 (diff) | |
download | org-mode-f1ffed8a6caf041b2c9728e5de03f001fdf2ce9e.tar.gz |
Allow to capture plain templates into Org nodes
* lisp/org.el (org-end-of-meta-data-and-drawers): New function.
* lisp/org-capture.el (org-capture-place-plain-text): Implement adding
plain text templates to Org nodes.
This is something which came out of a discussion with Philip Rooke, in
the thread
Philip tried to use a capture template with template type plain, but
using a date tree as a target. Plain templates where placed at the
end of the file, not at the end of the entry. I complained first that
mixing headlined entries and plain snippets into the same capture
target is not possible, but I realized that there is a way to make
this work OK. The headlined entries become children, and the plain
text snippets become part of the text before the first child.
-rw-r--r-- | lisp/org-capture.el | 24 | ||||
-rw-r--r-- | lisp/org.el | 21 |
2 files changed, 40 insertions, 5 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 2ae8a74..5512178 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1012,13 +1012,27 @@ it. When it is a variable, retrieve the value. Return whatever we get." (org-table-align))) (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)) 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)) (org-capture-empty-lines-before) (setq beg (point)) diff --git a/lisp/org.el b/lisp/org.el index 0a34a1e..c2b4797 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19826,6 +19826,27 @@ If there is no such heading, return nil." (unless (eobp) (backward-char 1))) 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) "Move forward to the arg'th subheading at same level as this one. Stop at the first and last subheadings of a superior heading. |