reddit / emacs

Updating properties in org-mode headings with values from a different buffer

graduale ยท 2022-08-23 15:41
Suppose you have a list of org-mode headings each with a property drawer. Suppose you have another list of org-mode headings, in a different buffer, say, each with a property drawer too. I'm looking for a way to update the values of properties of the first list of headings using the second list. So, for example, if I have: * Heading 1 :PROPERTIES: :COLOR: blue :AGE: 5 days :END: * Heading 2 :PROPERTIES: :COLOR: red :AGE: 10 days :END: I want to be able to update it with: * Heading 1 :PROPERTIES: :COLOR: green :END: * Heading 2 :PROPERTIES: :COLOR: orange :END: So that the result is this: * Heading 1 :PROPERTIES: :COLOR: green :AGE: 5 days :END: * Heading 2 :PROPERTIES: :COLOR: orange :AGE: 10 days :END: Now my questions: - Is there some ready-made utility for doing this? - If not, can you think of some ready-made utilities that would help with this? I thought I'd check with folks here to see if there's a likely better way than cooking up my own tool. I've been reading through the documentation of the org-element and property APIs and I have a very rough sense how to use it for what I want, but I'm having trouble with one issue: - how do I get the list of properties (with or without their values) in the first list of headings so I get candidate properties to update using the second list? I understand `org-entry-properties` is a place to start, but I only want the properties explicitly listed in the property drawer. (If I call `org-entry-properties` on the first heading in the initial list, I get this: (("CATEGORY" . "???") ("AGE" . "5 days") ("COLOR" . "blue") ("BLOCKED" . "") ("FILE") ("PRIORITY" . "B") ("ITEM" . "Heading 1")) Can I just assume that there is a fixed list of default properties that will always be included in such a list?