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

    org-src--edit-buffer: Fix failure when markers point to no buffer
    
    * lisp/org-src.el (org-src--edit-buffer): Fix edge case when the
    markers point to nowhere.  This happens when we consider
    temporary *Org parse* buffer created as a copy of an existing Org
    buffer and that source Org buffer gets killed.
    
    Reported-by: Иван Чижов <ivchiz...@gmail.com>
    Link: 
https://orgmode.org/list/CACKynC_Kmezc6wT8ia=tkemrbO5+6fRyfgyQdOE7zfiidA=d...@mail.gmail.com
---
 lisp/org-src.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 6570b1b2ab..8cdefc02b2 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -339,10 +339,14 @@ Return nil if there is no such buffer."
     (dolist (b (buffer-list))
       (with-current-buffer b
        (and (org-src-edit-buffer-p)
-            (= beg org-src--beg-marker)
             (eq (marker-buffer beg) (marker-buffer org-src--beg-marker))
-            (= end org-src--end-marker)
             (eq (marker-buffer end) (marker-buffer org-src--end-marker))
+             ;; Do it after comparing buffers.  In some scenarios
+             ;; (namely, when Org buffer is generated as a copy and
+             ;; the source buffer gets killed), these markers may
+             ;; point nowhere making `=' throw an error.
+            (= beg org-src--beg-marker)
+            (= end org-src--end-marker)
             (throw 'exit b))))))
 
 (defun org-src--coordinates (pos beg end)

Reply via email to