Fix `:jump-to-captured' when refiling a capture target
* lisp/org-capture.el (org-capture-refile): Call `org-capture-goto-last-stored' at the appropriate time. * testing/lisp/test-org-capture.el (test-org-capture/refile): Add test. Reported-by: "Raymond Zeitler" <zeitra@yahoo.com> <http://lists.gnu.org/archive/html/emacs-orgmode/2017-08/msg00704.html>
This commit is contained in:
parent
18a48b5861
commit
1654a5a98a
|
@ -818,13 +818,17 @@ for `entry'-type templates"))
|
||||||
(let* ((base (or (buffer-base-buffer) (current-buffer)))
|
(let* ((base (or (buffer-base-buffer) (current-buffer)))
|
||||||
(pos (make-marker))
|
(pos (make-marker))
|
||||||
(org-capture-is-refiling t)
|
(org-capture-is-refiling t)
|
||||||
(kill-buffer (org-capture-get :kill-buffer 'local)))
|
(kill-buffer (org-capture-get :kill-buffer 'local))
|
||||||
|
(jump-to-captured (org-capture-get :jump-to-captured 'local)))
|
||||||
;; Since `org-capture-finalize' may alter buffer contents (e.g.,
|
;; Since `org-capture-finalize' may alter buffer contents (e.g.,
|
||||||
;; empty lines) around entry, use a marker to refer to the
|
;; empty lines) around entry, use a marker to refer to the
|
||||||
;; headline to be refiled. Place the marker in the base buffer,
|
;; headline to be refiled. Place the marker in the base buffer,
|
||||||
;; as the current indirect one is going to be killed.
|
;; as the current indirect one is going to be killed.
|
||||||
(set-marker pos (save-excursion (org-back-to-heading t) (point)) base)
|
(set-marker pos (save-excursion (org-back-to-heading t) (point)) base)
|
||||||
(org-capture-put :kill-buffer nil)
|
;; `org-capture-finalize' calls `org-capture-goto-last-stored' too
|
||||||
|
;; early. We want to wait for the refiling to be over, so we
|
||||||
|
;; control when the latter function is called.
|
||||||
|
(org-capture-put :kill-buffer nil :jump-to-captured nil)
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(progn
|
(progn
|
||||||
(org-capture-finalize)
|
(org-capture-finalize)
|
||||||
|
@ -833,7 +837,8 @@ for `entry'-type templates"))
|
||||||
(org-with-wide-buffer
|
(org-with-wide-buffer
|
||||||
(goto-char pos)
|
(goto-char pos)
|
||||||
(call-interactively 'org-refile))))
|
(call-interactively 'org-refile))))
|
||||||
(when kill-buffer (kill-buffer base)))
|
(when kill-buffer (kill-buffer base))
|
||||||
|
(when jump-to-captured (org-capture-goto-last-stored)))
|
||||||
(set-marker pos nil))))
|
(set-marker pos nil))))
|
||||||
|
|
||||||
(defun org-capture-kill ()
|
(defun org-capture-kill ()
|
||||||
|
|
|
@ -127,7 +127,23 @@
|
||||||
(buffer-substring-no-properties
|
(buffer-substring-no-properties
|
||||||
(line-beginning-position)
|
(line-beginning-position)
|
||||||
(line-end-position))))))
|
(line-end-position))))))
|
||||||
(catch :return (org-capture-refile))))))))
|
(catch :return (org-capture-refile)))))))
|
||||||
|
;; When the entry is refiled, `:jump-to-captured' moves point to the
|
||||||
|
;; refile location, not the initial capture target.
|
||||||
|
(should
|
||||||
|
(org-test-with-temp-text-in-file "* Refile target"
|
||||||
|
(let ((file1 (buffer-file-name)))
|
||||||
|
(org-test-with-temp-text-in-file "* A"
|
||||||
|
(let* ((file2 (buffer-file-name))
|
||||||
|
(org-capture-templates
|
||||||
|
`(("t" "Todo" entry (file+headline ,file2 "A")
|
||||||
|
"** H1 %?" :jump-to-captured t))))
|
||||||
|
(org-capture nil "t")
|
||||||
|
(cl-letf (((symbol-function 'org-refile-get-location)
|
||||||
|
(lambda (&rest args)
|
||||||
|
(list (file-name-nondirectory file1) file1 nil nil))))
|
||||||
|
(org-capture-refile)
|
||||||
|
(list file1 file2 (buffer-file-name)))))))))
|
||||||
|
|
||||||
|
|
||||||
(provide 'test-org-capture)
|
(provide 'test-org-capture)
|
||||||
|
|
Loading…
Reference in New Issue