org-element-at-point: Demote error to warning when called from non-Org buffer

* lisp/org-element.el (org-element-at-point): Do not throw an error
when `org-element-at-point' is called from non-Org buffer.  A number
of third-party packages are incorrectly using `org-element-at-point'
this way, relying upon `org-element-at-point' working in certain
scenarios.  Throwing an error (as was done previously) made an urgent
call to fix this problem, even when `org-element-at-point' happened to
work in a particular scenario.  Now, we just display a warning to give
package author more time to address or work around this.

See https://github.com/alphapapa/org-web-tools/issues/61:

    @yantar92 I understand why this change was made, but perhaps it
    was a bit premature, given how much breakage it's causing
    downstream? It would seem appropriate to at least make it a
    warning for a full major version before making it an error, to
    give downstream devs and users a break.
This commit is contained in:
Ihor Radchenko 2023-11-05 14:12:54 +02:00
parent 459a10979d
commit fac55324ac
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 2 additions and 2 deletions

View File

@ -8287,8 +8287,8 @@ This function may modify the match data."
(setq epom (or epom (point)))
(org-with-point-at epom
(unless (derived-mode-p 'org-mode)
(error "`org-element-at-point' cannot be used in non-Org buffer %S (%s)"
(current-buffer) major-mode))
(warn "`org-element-at-point' cannot be used in non-Org buffer %S (%s)"
(current-buffer) major-mode))
;; Allow re-parsing when the command can benefit from it.
(when (and cached-only
(memq this-command org-element--cache-non-modifying-commands))