branch: externals/org
commit f1359546ad7dee9698b75ca25ad453e6f054bd06
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    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.
---
 lisp/org-element.el     | 4 ++++
 testing/lisp/test-ox.el | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 69a62a2f5c..58693d4e33 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -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))
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 87c6db8af0..4ba0ba0325 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -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)

Reply via email to