Skip to main content
fix type in code
Source Link

I am trying to specify a refile target with a regexp, but can't get it to work. Specifically, I'm trying to use the new :refile-targets property in org-capture-templates, but this question holds for using regexps in org-refile-targets as well.


Since version 9.5, org mode comes with the :refile-targets org-capture-templates property. The description reads:

When exiting capture mode via org-capture-refile, the variable org-refile-targets will be temporarily bound to the value of this property.

In theory, org-refile-targets allows to set targets via regexp:

a cons cell (:regexp . "REGEXP") with a regular expression matching headlines that are refiling targets.


I want to set :refile-targets to the parts of the current file indicated with <---:

* Undesirable heading
** Targets

* Desirable heading
** Targets                 <---- this whole subtree is a desirable target
** Subheading
*** Targets                <---- this whole subtree is a desirable target

This is my capture template:

(("c" "Capture")
("ce" "Capture example")
entry
(file "path/to/file")
"* %^{prompt}"
:refile-targets REFILE_TARGET_DISCUSSED_BELOW)

These are representative examples of regexps that I have tried:

  1. ((nil . :regexp . "Targets")) obviously includes the undesirable Undesirable heading subtree
  2. ((nil . :regexp . "Desirable heading.*Targets")) does not return anything
  3. ((nil . :regexp . "Desirable heading\\.\\*Targets")) does not return anything

Details:

  • In org-refile-targets, the syntax is setq org-refile-targets '((nil . :regexp . "REGEXP")), while in org-capture-templates the syntax is :refile-targets ((nil . :regexp . "REGEXP")) (without the quote)
  • The regexp in 3. was constructed with rx because the only example of complex :regexp in the wild that I have found used rx.

I am trying to specify a refile target with a regexp, but can't get it to work. Specifically, I'm trying to use the new :refile-targets property in org-capture-templates, but this question holds for using regexps in org-refile-targets as well.


Since version 9.5, org mode comes with the :refile-targets org-capture-templates property. The description reads:

When exiting capture mode via org-capture-refile, the variable org-refile-targets will be temporarily bound to the value of this property.

In theory, org-refile-targets allows to set targets via regexp:

a cons cell (:regexp . "REGEXP") with a regular expression matching headlines that are refiling targets.


I want to set :refile-targets to the parts of the current file indicated with <---:

* Undesirable heading
** Targets

* Desirable heading
** Targets                 <---- this whole subtree is a desirable target
** Subheading
*** Targets                <---- this whole subtree is a desirable target

This is my capture template:

(("c" "Capture")
("ce" "Capture example")
entry
(file "path/to/file")
"* %^{prompt}"
:refile-targets REFILE_TARGET_DISCUSSED_BELOW)

These are representative examples of regexps that I have tried:

  1. ((nil . :regexp "Targets")) obviously includes the undesirable Undesirable heading subtree
  2. ((nil . :regexp "Desirable heading.*Targets")) does not return anything
  3. ((nil . :regexp "Desirable heading\\.\\*Targets")) does not return anything

Details:

  • In org-refile-targets, the syntax is setq org-refile-targets '((nil . :regexp "REGEXP")), while in org-capture-templates the syntax is :refile-targets ((nil . :regexp "REGEXP")) (without the quote)
  • The regexp in 3. was constructed with rx because the only example of complex :regexp in the wild that I have found used rx.

I am trying to specify a refile target with a regexp, but can't get it to work. Specifically, I'm trying to use the new :refile-targets property in org-capture-templates, but this question holds for using regexps in org-refile-targets as well.


Since version 9.5, org mode comes with the :refile-targets org-capture-templates property. The description reads:

When exiting capture mode via org-capture-refile, the variable org-refile-targets will be temporarily bound to the value of this property.

In theory, org-refile-targets allows to set targets via regexp:

a cons cell (:regexp . "REGEXP") with a regular expression matching headlines that are refiling targets.


I want to set :refile-targets to the parts of the current file indicated with <---:

* Undesirable heading
** Targets

* Desirable heading
** Targets                 <---- this whole subtree is a desirable target
** Subheading
*** Targets                <---- this whole subtree is a desirable target

This is my capture template:

(("c" "Capture")
("ce" "Capture example")
entry
(file "path/to/file")
"* %^{prompt}"
:refile-targets REFILE_TARGET_DISCUSSED_BELOW)

These are representative examples of regexps that I have tried:

  1. ((nil :regexp . "Targets")) obviously includes the undesirable Undesirable heading subtree
  2. ((nil :regexp . "Desirable heading.*Targets")) does not return anything
  3. ((nil :regexp . "Desirable heading\\.\\*Targets")) does not return anything

Details:

  • In org-refile-targets, the syntax is setq org-refile-targets '((nil :regexp . "REGEXP")), while in org-capture-templates the syntax is :refile-targets ((nil :regexp . "REGEXP")) (without the quote)
  • The regexp in 3. was constructed with rx because the only example of complex :regexp in the wild that I have found used rx.
Source Link

Using regexp in org-refile-targets and the `:refile-targets` property in org-capture-templates

I am trying to specify a refile target with a regexp, but can't get it to work. Specifically, I'm trying to use the new :refile-targets property in org-capture-templates, but this question holds for using regexps in org-refile-targets as well.


Since version 9.5, org mode comes with the :refile-targets org-capture-templates property. The description reads:

When exiting capture mode via org-capture-refile, the variable org-refile-targets will be temporarily bound to the value of this property.

In theory, org-refile-targets allows to set targets via regexp:

a cons cell (:regexp . "REGEXP") with a regular expression matching headlines that are refiling targets.


I want to set :refile-targets to the parts of the current file indicated with <---:

* Undesirable heading
** Targets

* Desirable heading
** Targets                 <---- this whole subtree is a desirable target
** Subheading
*** Targets                <---- this whole subtree is a desirable target

This is my capture template:

(("c" "Capture")
("ce" "Capture example")
entry
(file "path/to/file")
"* %^{prompt}"
:refile-targets REFILE_TARGET_DISCUSSED_BELOW)

These are representative examples of regexps that I have tried:

  1. ((nil . :regexp "Targets")) obviously includes the undesirable Undesirable heading subtree
  2. ((nil . :regexp "Desirable heading.*Targets")) does not return anything
  3. ((nil . :regexp "Desirable heading\\.\\*Targets")) does not return anything

Details:

  • In org-refile-targets, the syntax is setq org-refile-targets '((nil . :regexp "REGEXP")), while in org-capture-templates the syntax is :refile-targets ((nil . :regexp "REGEXP")) (without the quote)
  • The regexp in 3. was constructed with rx because the only example of complex :regexp in the wild that I have found used rx.