Refile entries/nodes between org files and org-roam notes

For a variety of reasons, I often need to refile nodes/entries between org-roam files and my other org files (e.g., org-agenda-files). I find the following accomplishes this and I am posting in case others have a similar need :

  (setq myroamfiles (directory-files "~/path/to/my/roam/notes" t "org$"))

  ;; -------- refile settings -----
  (setq org-refile-targets '((org-agenda-files :maxlevel . 5) (myroamfiles :maxlevel . 5)))
  (setq org-refile-use-outline-path 'file)
  (setq org-outline-path-complete-in-steps nil)
  (setq org-refile-allow-creating-parent-nodes 'confirm)

The code is based on Aaron Bieber’s excellent post for setting up org-refile. My addendum is the inclusion of myroamfiles.

EDIT: During a normal session, one creates many org-roam files. (I also cull org-roam files). These changes are not reflected “live” in myroamfiles and therefore org-refile does not provide up-to-date options of target entries for refiling. It seems that a hook(?) could be added to the function that updates the org-roam-db. The hook would do the following: if num-org-roam-files has changed, then redefine/reset myroamfiles and org-refile-targets.

5 Likes