Browse Source

org-element--parse-to: Fix skipping sibling optimisation

* lisp/org-element.el (org-element--parse-to): Fallback to normal
parsing when there are no siblings between POS and ELEM-END.

Reported in
https://github.com/yantar92/org/issues/38#issuecomment-982830497
Ihor Radchenko 3 years ago
parent
commit
328be6df40
1 changed files with 12 additions and 8 deletions
  1. 12 8
      lisp/org-element.el

+ 12 - 8
lisp/org-element.el

@@ -6420,14 +6420,18 @@ If you observe Emacs hangs frequently, please report this to Org mode mailing li
                        ;; may exist though.  Parse starting from the
                        ;; last sibling or from ELEM-END if there are
                        ;; no other siblings.
-                       (goto-char pos)
-                       (re-search-backward
-                        (rx-to-string
-                         `(and bol (repeat ,(let ((level (org-element-property :level element)))
-                                              (if org-odd-levels-only (1- (* level 2)) level))
-                                           "*")
-                               " "))
-                        elem-end t))))
+                       (let ((p (point)))
+                         (goto-char pos)
+                         (unless
+                             (re-search-backward
+                              (rx-to-string
+                               `(and bol (repeat ,(let ((level (org-element-property :level element)))
+                                                    (if org-odd-levels-only (1- (* level 2)) level))
+                                                 "*")
+                                     " "))
+                              elem-end t)
+                           ;; Roll-back to normal parsing.
+                           (goto-char p))))))
 	         (setq mode (org-element--next-mode mode type nil)))
 	        ;; A non-greater element contains point: return it.
 	        ((not (memq type org-element-greater-elements))