After renaming the property, so that its name does not contain a dash[1], here is an example file with a code block that you can try out:
* foo
** one
** two
:PROPERTIES:
:someprop: some value
:END:
** three
** four
:PROPERTIES:
:someprop:
:END:
* Code :noexport:
#+begin_src elisp :results drawer
(save-excursion
(goto-char 2)
(org-map-entries (lambda () (nth 4 (org-heading-components))) "someprop<>\"\"" 'tree))
#+end_src
#+RESULTS:
:results:
(two)
:end:
The matcher matches entries with non-empty values for the property someprop
. Note that the scope is set to tree
, so in conjunction with the save-excursion/goto-char
, it applies only to the tree starting with headline foo
: it does not apply to the Code
headline. Try adding another top-level headline (with or without property drawers) after the foo
tree (i.e. just before the Code
headline) and see that it too will be skipped.
Note that the function that org-map-entries
applies to each matching headline should take no arguments - see its doc string with C-h f org-map-entries
. The function is called with point
set to the beginning of the headline, so that's all it knows: in the example, we call org-heading-components
which assumes that point is at a headline and proceeds to parse it to get the individual components as a list; in particular the title is the fifth element of the list (remember nth
counts elements from 0). See the doc string of the function for the other components.
One other important point is that the matcher does not seem to distinguish between headlines with no someprop
property at all and headlines that have a someprop
property with an empty value: change the matcher to "someprop=\"\""
and it will match every headline in the foo
tree except the two
entry.
[1] Although dashes are supposedly legal in property names (see Org syntax), the matcher code seems to be buggy and does not like the dash: with the dash, it found no matches at all.
org-map-entries
, how about this documentation? Using the Mapping APIC-c / m
i.e. a sparse tree search. Either this ororg-map-entries
will get you a list of headlines. The main question is: what do you want to do with those headlines?