0

From org-refile to a known fixed location I have learned that the argument RFLOC looks like this:

'(heading file regular-expression position-of-target-heading)

I am trying to programmatically refile a subtree to become the child of a given heading. This is easy, manually, as long as I have (file :maxlevel . 1) as part of the org-refile-targets.

With point on the heading of the subtree, I call (org-refile nil nil ("Projects" "/tmp/projects.org" nil nil)). This does refile to the /tmp/projects.org file but the refiled subtree becomes a sibling of Projects, not a child.

How can I change my code so that the subtree properly moves under Projects ?

0

Turns out org-mode provides a function to retrieve existing refile targets, which means if it's OK to set org-refile-targets, we can just let org-mode do the hard work of creating the RFLOC variable.

This means the code I need is just the following. I go through the generated refile targets and I find the one heading that matches what I am looking for - in this case, a string that ends with Projects :

(find-if
  (lambda (refloc) (string-match ".*Projects"
                                 (car refloc)))
  (org-refile-get-targets))
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.