1

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 ?

Trevoke
  • 2,375
  • 21
  • 34

1 Answers1

1

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))
Trevoke
  • 2,375
  • 21
  • 34