0

My org file structure is as follows:

* JOB Major Project 1
** PROJECT Mini Project p
** PROJECT Mini Project q
* JOB Major Project 2
** PROJECT Mini Project x
** PROJECT Mini Project y

JOB and PROJECT being TODO items

I would like to be able to refile to either a JOB or a PROJECT todo item, that is, first by JOB and then by PROJECT. That is, I want to file by TODO items of any kind, whether they are JOB or PROJECT.

I want a combination of:

 '(org-refile-targets '((nil :todo . "JOB"))))

and

 '(org-refile-targets '((nil :todo . "PROJECT"))))

I thought

 '(org-refile-targets '((nil :regexp . "JOB|PROJECT"))))

or

 '(org-refile-targets '((nil :regexp . "JOB\|PROJECT"))))

would do the trick, but I get 'no refile targets'.

All is within one org file.

1
  • Try '((nil :todo . "PROJECT") (nil :todo . "JOB")). Remember org-refile-targets is a list of conses. Since it is a somewhat complicated variable, I used customize to set it and then looked at its values with C-h v org-refile-targets. Untested, but it looks like a reasonable possibility to me.
    – NickD
    Dec 15, 2022 at 16:15

2 Answers 2

0

What op is asking is how do you set org-refile-targets based multiple conditions like todo, regexp etc... AFIK you can't do this, the solution is to use the org-refile-target-verify-function.

In this example we need both the :regexp key that matches "README" and :maxlevel 1. You can use the function to match anything you want. In this case I use org-get-previous-line-level.

(defun my/org-refile ()
"Call `org-refile' with a specific target."
(interactive)
  (let* ((orfiles org-agenda-files )
        (org-refile-target-verify-function (lambda ()
                                              (when (org-get-previous-line-level)
                                                (= (org-get-previous-line-level) 0))))
        ;; Won't work you will still see other levels, solution: use the org-refile-target-verify-function
        ;;(org-refile-targets `(,(cons orfiles (cons :regexp "README")) ,(cons orfiles (cons :maxlevel 1)))))
        (org-refile-targets `(,(cons orfiles (cons :regexp "README")))))
  (org-refile)))
0

I just posted about a very similar thing with refile: see my question.

I've found that org-refile-targets can be viewed as unioning together targets, and ``org-refile-target-verify-function` filters some out.

You should be able to use multiple entries for a single file: in my own configuration, I have a certain file with a :tag . "refile-here" entry, and also a :regexp entry that matches other headings in the same file that don't have the refile-here tag, but (for my own idiosyncratic reasons) want to have them as a refile target. So those two entries are inclusive -- you get headings matching either one.

Separately, ``org-refile-target-verify-function` is exclusive, and can be used to filter out headings you don't want as a target.

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.