Function: org-capture-place-entry

org-capture-place-entry is a byte-compiled function defined in org-capture.el.gz.

Signature

(org-capture-place-entry)

Documentation

Place the template as a new Org entry.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-capture.el.gz
(defun org-capture-place-entry ()
  "Place the template as a new Org entry."
  (let ((template (org-capture-get :template))
	(reversed? (org-capture-get :prepend))
	(exact-position (org-capture-get :exact-position))
	(insert-here? (org-capture-get :insert-here))
	(level 1))
    (org-capture-verify-tree template)
    (when exact-position (goto-char exact-position))
    (cond
     ;; Force insertion at point.
     (insert-here?
      ;; FIXME: level should probably set directly within (let ...).
      (setq level (org-get-valid-level
                   (if (or (org-at-heading-p)
                           (ignore-errors
			     (save-excursion (org-back-to-heading t))))
                       (org-outline-level)
                     1))))
     ;; Insert as a child of the current entry.
     ((org-capture-get :target-entry-p)
      (setq level (org-get-valid-level
		   (if (org-at-heading-p) (org-outline-level) 1)
		   1))
      (if reversed? (outline-next-heading) (org-end-of-subtree t t)))
     ;; Insert as a top-level entry at the beginning of the file.
     (reversed?
      (goto-char (point-min))
      (unless (org-at-heading-p) (outline-next-heading)))
     ;; Otherwise, insert as a top-level entry at the end of the file.
     (t (goto-char (point-max))
        ;; Make sure that last point is not folded.
        (org-fold-core-cycle-over-indirect-buffers
          (org-fold-region (max 1 (1- (point-max))) (point-max) nil))))
    (let ((origin (point-marker)))
      (unless (bolp) (insert "\n"))
      (org-capture-empty-lines-before)
      (let ((beg (point)))
	(save-restriction
	  (when insert-here? (narrow-to-region beg beg))
	  (org-paste-subtree level template 'for-yank))
	(org-capture-position-for-last-stored beg)
	(org-capture-empty-lines-after)
	(unless (org-at-heading-p) (outline-next-heading))
	(org-capture-mark-kill-region origin (point))
	(org-capture-narrow beg (if (eobp) (point) (1- (point))))
	(org-capture--position-cursor beg (point))))))