1

I'm trying to make a function that will allow me to add properties to all entries in an org file that contain a particular tag ("drill"):

(defun add-to-chinese-anki ()
  (interactive)
  (org-entry-put (point) "ANKI_DECK" "Chinese Org Notes")
  (org-entry-put (point) "ANKI_NOTE_TYPE" "chinese-org-drill")
  (org-entry-put (point) "ANKI_TAGS" "languages")
  )

(defun add-all-to-chinese-anki ()
  (interactive)
  (org-map-entries (lambda () (add-to-chinese-anki) "drill" 'file))
  )

However the above code is adding the tags to every entry in the file, and not filtering by tag. Any help would be appreciated!

1

Your call to org-map-entries is wrong - you have a misplaced paren. It should be

   ...
   (org-map-entries (lambda () (add-to-chinese-anki)) "drill" 'file)
   ...

Note that the lambda is not necessary. The following works just as well:

   ...
   (org-map-entries #'add-to-chinese-anki "drill" 'file)
   ...

For more complicated matching, the Matching tags and properties section of the manual is indispensable: you can read it locally with C-h i g(org) Matching tags RET.

4
  • Thanks for this! – Ishmael7 Mar 20 at 21:28
  • One further question on this: do you know is it possible to skip entries which inherit the tag? Or in other words, to only run the function for the parent entry and not the child entries? – Ishmael7 Mar 20 at 21:59
  • Try let-binding org-use-tag-inheritance to nil around the org-map-entries call. Untested. – NickD Mar 20 at 22:13
  • Thank you - it works :) – Ishmael7 Mar 20 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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