I tried to make org-refile-copy
do more of the things I'd like to by wrapping it in a function like below, alas without success so far.
(defun paf/refile-ai-targets () "Does an org-refile-copy of an AI, with some linking and side-effects. This does add a link to the original =AI= in the new task, as well as mark the =AI= as done, and change the refiled target to a =TODO=." (interactive) (let* ((orig-marker (save-excursion (org-back-to-heading) (point-marker))) ;; make sure the to-be-filed entry has an ID (orig-id (org-id-get-create))) (progn (let ((org-refile-keep t)) (org-refile nil nil nil "Move AI")) ;; Now we are back at the orig location, so force change the ID ;; (as it has been copied) (org-id-get-create t) ;; t => force change (org-todo 'done) ;; Now take a link with the new forced ID, ;; go to the refiled location, and modify the ;; refiled entry. (let ((orig-link (org-store-link nil))) (org-refile-goto-last-stored) (org-todo "TODO") (org-entry-put (point) "AI" orig-link))) ;; Now move back to where we started to not jar the user (hypb:goto-marker orig-marker)))
However it does not seem to work reliably. When I run it, just after launching Emacs, it fails in the org-refile-goto-last-stored
by claiming the bookmark it needs to create is in a buffer that is not backed by a file. I am not sure how to figure out which buffer that could be.
If I then do M-x bookmark-jump
and select the org-refile-last-stored
it does go to the right place, and after that, the function seems to work. It does not display the window that asks for the refile text though.
Regular org-refile-copy
works flawlessly before and after this.
did I misunderstand something basic in how to use these interactive functions in a programmatic way ? I am not quite sure about the marker and location handling (I played a bit with save-excursion
but it seems to not hold across org-refile-copy
calls) and am quite a noob in elisp...
The code I use is here: https://github.com/pascalfleury/emacs-config#implement-my-own-ai-refiling which is a pointer into my whole config too.