I have a single file tasks.org that contains all the tasks for agenda and I have separate projects files with a tasks related to specific project. I try to setup a configuration that will let me refile tasks from project files under the heading * Projects in tasks.org file and from the tasks.org file back to specific project file under heading ** Tasks.

I try to use :regexp to narrow down refilling options to specific heading, but it doesn't work at all, it works only when I use :level parameter - maybe there is a bug in "regexp" parameter implementation or I use it wrong way.

Global org-refile-targets:

(setq org-refile-targets `(
                            (,my/project-1 :level . 1)
                            (,my/project-2 :regexp . "Projects$")))

The example project file:

# -*- mode: org -*-
# Local Variables:
# eval: (setq-local org-refile-targets `((,my/org-tasks-file-path :regexp . "Projects$")))
# End:

* Project 1
** Tasks
*** TODO bar
** Resources

Example tasks.org file:

# -*- mode: org -*-

* Tasks
** TODO foo
* Projects

EDIT: I managed to succesfully refile task from tasks.org to project file. The problem was that there were different heading depths. The tasks.org have 2 levels and project file had 3. I changed project file to match number of heading levels with tasks file and now it works.

The project.org file look like this now:

# -*- mode: org -*-

* Project 1
** Tasks
*** TODO bar
** Resources

The only problem that left is to narrow down local refiling options for project file to just tasks.org * Projects. Local Variables with eval doesn't work. When I eval (setq-local org-refile-targets ((,my/org-tasks-file-path :regexp . "Projects$")))` by hand it works though.

Any idea how can I set org-refile-targets on file level?

  • 1
    The Local Variables: section has to be at the end of the file. That may have been the reason that eval: did not work.
    – NickD
    Jul 30, 2020 at 16:34

1 Answer 1



I created .dir-locals.el file to set local org-refile-targets for all the files in the projects folder.


((nil . (
          (eval . (progn (jarfar/org-projects-set-refile-targets-local)))

I defined jarfar/org-projects-set-refile-targets-local to set local variable, because .dir-locals.el syntax is quite limited, but we can call functions inside of it so we are all good. The function looks like this:

(defun jarfar/org-projects-set-refile-targets-local ()
  "Set local 'org-refile-targets for project org files."
  (setq-local org-refile-targets `((,jarfar/org-tasks-file-path :regexp . "Projects$"))))

Read first post EDIT together with this one for complete solution.

EDIT: I decided to move local folder config from .dir-locals.el to general config:

(setq jarfar/org-projects-folder "~/Documents/emacs/projects)
(dir-locals-set-class-variables 'jarfar/projects-directory
  '((nil . (
     (eval . (progn (jarfar/org-projects-set-refile-targets-local)))
(dir-locals-set-directory-class jarfar/org-projects-folder 'jarfar/projects-directory)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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