org-element-at-point: Throw an error when not in org-mode

* lisp/org-element.el (org-element-at-point): Explicitly throw an
error when not in org-mode buffer.  The parser expects certain
buffer-local constants and may fail otherwise.  It is better to
indicate the problem explicitly instead of dealing with cryptic
generic errors.
(org-element-plain-list-interpreter):
* testing/lisp/test-ox.el (test-org-export/expand-include/links): Make
sure that we never invoke parser in non-Org buffers.
This commit is contained in:
Ihor Radchenko 2023-08-18 11:11:17 +03:00
parent 3ec0933122
commit f1359546ad
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 11 additions and 0 deletions

View File

@ -1780,6 +1780,7 @@ Assume point is at the beginning of the list."
"Interpret plain-list element as Org syntax.
CONTENTS is the contents of the element."
(with-temp-buffer
(org-mode)
(insert contents)
(goto-char (point-min))
(org-list-repair)
@ -8031,6 +8032,9 @@ This function may modify the match data."
(if (org-element-type epom t) epom
(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))
;; Allow re-parsing when the command can benefit from it.
(when (and cached-only
(memq this-command org-element--cache-non-modifying-commands))

View File

@ -1498,6 +1498,7 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-mode)
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
@ -1520,6 +1521,7 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-mode)
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
@ -1542,6 +1544,7 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-mode)
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
@ -1564,6 +1567,7 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-mode)
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
@ -1586,6 +1590,7 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-mode)
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
@ -1608,6 +1613,7 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-mode)
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
@ -1628,6 +1634,7 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-mode)
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)