Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2017-06-02 09:23:03 +02:00
commit ed291a4a91
1 changed files with 30 additions and 40 deletions

View File

@ -1088,48 +1088,38 @@ may have been stored before."
(defun org-capture-place-entry () (defun org-capture-place-entry ()
"Place the template as a new Org entry." "Place the template as a new Org entry."
(let* ((txt (org-capture-get :template)) (let ((reversed? (org-capture-get :prepend))
(reversed (org-capture-get :prepend)) level)
(target-entry-p (org-capture-get :target-entry-p)) (when (org-capture-get :exact-position)
level beg end) (goto-char (org-capture-get :exact-position)))
(and (org-capture-get :exact-position)
(goto-char (org-capture-get :exact-position)))
(cond (cond
((not target-entry-p) ;; Insert as a child of the current entry.
;; Insert as top-level entry, either at beginning or at end of ((org-capture-get :target-entry-p)
;; file. (setq level (org-get-valid-level
(setq level 1) (if (org-at-heading-p) (org-outline-level) 1)
(if reversed 1))
(progn (goto-char (point-min)) (if reversed? (outline-next-heading) (org-end-of-subtree t)))
(or (org-at-heading-p) ;; Insert as a top-level entry at the beginning of the file.
(outline-next-heading))) (reversed?
(goto-char (point-max)) (goto-char (point-min))
(or (bolp) (insert "\n")))) (unless (org-at-heading-p) (outline-next-heading)))
(t ;; Otherwise, insert as a top-level entry at the end of the file.
;; Insert as a child of the current entry (t (goto-char (point-max))))
(and (looking-at "\\*+") (unless (bolp) (insert "\n"))
(setq level (- (match-end 0) (match-beginning 0))))
(setq level (org-get-valid-level (or level 1) 1))
(if reversed
(progn
(outline-next-heading)
(or (bolp) (insert "\n")))
(org-end-of-subtree t nil)
(or (bolp) (insert "\n")))))
(org-capture-empty-lines-before) (org-capture-empty-lines-before)
(setq beg (point)) (let ((beg (point))
(org-capture-verify-tree txt) (template (org-capture-get :template)))
(org-paste-subtree level txt 'for-yank) (org-capture-verify-tree template)
(org-capture-empty-lines-after) (org-paste-subtree level template 'for-yank)
(org-capture-position-for-last-stored beg) (org-capture-empty-lines-after)
(outline-next-heading) (org-capture-position-for-last-stored beg)
(setq end (point)) (unless (org-at-heading-p) (outline-next-heading))
(org-capture-mark-kill-region beg (1- end)) (let ((end (point)))
(org-capture-narrow beg (1- end)) (org-capture-mark-kill-region beg end)
(if (or (re-search-backward "%\\?" beg t) (org-capture-narrow beg end)
(re-search-forward "%\\?" end t)) (when (or (re-search-backward "%\\?" beg t)
(replace-match "")))) (re-search-forward "%\\?" end t))
(replace-match ""))))))
(defun org-capture-place-item () (defun org-capture-place-item ()
"Place the template as a new plain list item." "Place the template as a new plain list item."