alphapapa / org-web-tools

View, capture, and archive Web pages in Org-mode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`org-element-at-point` cannot be used in non-Org buffer

mooseyboots opened this issue · comments

i recently updated my packages, now i receive an error when i try to use org-web-tools-read-url-as-org.

the backtrace i see looks like this (w url and html args substituted):

error("`org-element-at-point' cannot be used in non-Org buffer %S (%s)" #<buffer  *temp*> fundamental-mode)
org-element-at-point(nil cached)
org-before-first-heading-p()
org-back-to-heading-or-point-min(t)
org-get-property-block()
org-at-property-p()
org-web-tools--remove-custom_id_properties()
org-web-tools--clean-pandoc-output()
org-web-tools--html-to-org-with-pandoc(my-urls-html)
org-web-tools--url-as-readable-org(my-url)

i wonder if when updating, org was updated, and the behaviour of org-element-at-point has been changed?

Yes, Org 9.6.something changed a lot of things related to org-element. This is probably a limitation we'll have to deal with now. But it probably won't be hard to fix.

I can't promise to get to this soon, so patches welcome.

Thanks for reporting.

i don't know the library's code, but i just tried adding (org-mode) to org-web-tools--html-to-org-with-pandoc (just before calling the offending functions) and it un-broke it for me:

(defun org-web-tools--html-to-org-with-pandoc (html &optional selector)
  "Return string of HTML converted to Org with Pandoc.
When SELECTOR is non-nil, the HTML is filtered using
`esxml-query' SELECTOR and re-rendered to HTML with
`org-web-tools--dom-to-html', which see."
  (when selector
    (setq html (->> (with-temp-buffer
                      (insert html)
                      (libxml-parse-html-region 1 (point-max)))
                    (esxml-query selector)
                    ;; MAYBE: Should probably use `shr-dom-print' instead.
                    (org-web-tools--dom-to-html))))
  (with-temp-buffer
    (insert html)
    (unless (zerop (call-process-region (point-min) (point-max) "pandoc"
                                        t t nil
                                        (org-web-tools--pandoc-no-wrap-option)
                                        "-f" "html-raw_html-native_divs" "-t" "org"))
      ;; TODO: Add error output, see org-protocol-capture-html
      (error "Pandoc failed"))
    (org-mode)
    (org-web-tools--clean-pandoc-output)
    (buffer-string)))

i'm just not sure if that's all there is to it?