weblorg icon indicating copy to clipboard operation
weblorg copied to clipboard

fix: undefer org headline nodes for org 9.7

Open nanzhong opened this issue 2 years ago • 3 comments

The unreleased 9.7 version of org-mode introduced a change that breaks the current weblorg-slugify implementation. The change results in some org nodes being deferred and requiring the org buffer to be live when lazily evaluated. (See https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/etc/ORG-NEWS#n148).

This change in behaviour results in errors such as:

Error: wrong-type-argument (stringp [org-element-deferred org-element--headline-raw-value (4 29) nil])
  mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode -0x1dd916894512f81>))
  debug-early-backtrace()
  debug-early(error (wrong-type-argument stringp [org-element-deferred org-element--headline-raw-value (4 29) nil]))
  replace-regexp-in-string("[^[:alnum:]]" "-" [org-element-deferred org-element--headline-raw-value (4 29) nil])
  #f(compiled-function (accum item) #<bytecode -0x14baae06cc0870c3>)([org-element-deferred org-element--headline-raw-value (4 29) nil] ("[^[:alnum:]]" . "-"))
  #f(compiled-function (elt) #<bytecode 0x190baab04a068801>)(("[^[:alnum:]]" . "-"))
  mapc(#f(compiled-function (elt) #<bytecode 0x190baab04a068801>) (("[^[:alnum:]]" . "-") ("--+" . "-") ("^-" . "") ("-$" . "")))
  seq-do(#f(compiled-function (elt) #<bytecode 0x190baab04a068801>) (("[^[:alnum:]]" . "-") ("--+" . "-") ("^-" . "") ("-$" . "")))
  seq-reduce(#f(compiled-function (accum item) #<bytecode -0x14baae06cc0870c3>) (("[^[:alnum:]]" . "-") ("--+" . "-") ("^-" . "") ("-$" . "")) [org-element-deferred org-element--headline-raw-value (4 29) nil])
  weblorg--slugify([org-element-deferred org-element--headline-raw-value (4 29) nil])

This PR makes use of the updated support in org-element-property to forced undeferring. Once 9.7 is released, this would be good to revisit (whether that means bumping the required org version or keeping this conditional).

nanzhong avatar Dec 28 '23 21:12 nanzhong

Mhmm, not quite sure why the version detection is not working in CI. It seems to be working as expected locally.

It looks like the version of emacs being used in CI makes use of org 9.6 even in the snapshot version as it's building from the github emacs mirror. So I would expect both the 26.3 and snapshot tests to be calling the old branch, which it doesn't seem to be doing 🤔.

nanzhong avatar Dec 28 '23 21:12 nanzhong

Ah, I think the reason it's failing is because org-element-property is defined using defsubst in 9.6 and define-inline in 9.7. The inlining that happens during byte compilation seems to be what's tripping this up since in 9.6, org-element-property only allows for 2 arguments.

I'm not that familiar with emacs lisp, so I don't have a clear idea of how to fix this, but I'll dig a little deeper and see.

nanzhong avatar Dec 29 '23 01:12 nanzhong

I've reworked this to make use of org-element-propertise-resolve to conditionally resolve deferred element properties on org 9.7+ sidestepping changing inlined function.

nanzhong avatar Dec 29 '23 04:12 nanzhong