Skip to content

Handle changes to org AST in v9.7#9

Merged
jlumpe merged 11 commits intojlumpe:masterfrom
tcahill:org-9.7-support
Aug 25, 2025
Merged

Handle changes to org AST in v9.7#9
jlumpe merged 11 commits intojlumpe:masterfrom
tcahill:org-9.7-support

Conversation

@tcahill
Copy link
Contributor

@tcahill tcahill commented Feb 25, 2025

I see you're not planning to continue maintaining this package, so it's totally fair if you don't want to integrate these changes - just thought I'd submit this for your consideration or in case anyone else might find it useful!

Currently using this package with org v9.7 causes most nodes to end up with an error object under the standard-properties property like this:

"standard-properties": {
"$$data_type": "error",
"message": "Don't know how to encode value [1 1 24 704 704 0 ... ]"
}

Additionally, some property values are now 'deferred' and look like this in the exported JSON:

"EXPORT_DATE": "[org-element-deferred org-element--substring (50 60) t]"

It turns out that org 9.7 includes changes to the AST that account for both of these issues:

  1. Some properties like begin and end have been moved into a vector under standard-properties. ox-json-encode-auto doesn't handle vectors, thus the error.

  2. Some properties can now be deferred and their value won't be calculated until accessed through an appropriate function like org-element-property.

Both of these changes were introduced in https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=1260f61830bfdee821de9233051a821f4ac4831c. Here, I'm using the function now recommended when enumerating all of the node's properties, org-element-properties-map, which both expands standard-properties and optionally resolves deferred properties.

To ensure I'm not breaking earlier versions, I also extended the test-export test to do a full comparison between the expected and actual JSON output. Because refs aren't stable and some properties don't appear to have consistent values across org-mode/Emacs versions, I removed some properties from the "expected" JSON and modified the JSON comparison helpers to optionally tolerate missing keys and just assert that the keys that two objects have in common have the same values. Tests are passing for all versions except 26.3, and it looks like that version is also broken on master.

Org v9.7 introduced two significant changes to the AST that must be
considered when enumerating a node's properties:

  1. Some properties which were previously present in the property
     list (e.g. :begin and :end) are now stored as elements of a vector
     under the :standard-properties key in the property list.

  2. Property values can now be 'deferred', meaning they are not
     calculated until accessed via a getter function like
     ~org-element-property~.

~org-element-properties-map~ is now the recommended way to traverse a
node's properties and handles both of these changes.
Previously, ~test-export~ just asserted that the exported JSON was valid JSON
and the $$data_type key of the top-level object was "org-document". This commit
introduces a JSON file representing the expected output of the test with some
keys whose values might change from one run to another (e.g. `ref`) omitted. To
compare this file with the actual output of the test, an optional argument was
added to the ~json-compare~ test helper that, when non-nil, causes the
comparison not to fail when keys in one object are missing from the other.
It appears Emacs 30 introduces a new warning:

ox-json.el:1086:26: Error: ‘memql’ called with literal list that may never
match (element 1 of arg 2)
@jlumpe
Copy link
Owner

jlumpe commented Mar 8, 2025

Hi tcahill, thanks for submitting the PR. Apologies for the delay in responding. I currently don't have a development environment set up for this project, but I am planning on getting that working again and reviewing + merging this PR when I have the time. Hopefully sometime this month.

@jlumpe jlumpe force-pushed the master branch 4 times, most recently from 173a064 to 9797c65 Compare August 10, 2025 06:24
@jlumpe
Copy link
Owner

jlumpe commented Aug 10, 2025

Thanks for the great work on this. I finally got a good test environment set up and was able to revisit it.

I actually spent a lot of time updating/improving the tests first and inadvertently duplicated your work there. I've merged the current master back into this PR, which required overwriting all the test improvements. Let me know if it looks alright.

@jlumpe jlumpe merged commit 0f7c63b into jlumpe:master Aug 25, 2025
4 of 5 checks passed
@jlumpe
Copy link
Owner

jlumpe commented Aug 25, 2025

Merged, thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants