From 2b2b2c5c99753cf71309ae8a82be915875ad5186 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 17 Apr 2014 21:37:07 +0200 Subject: [PATCH] org-element: Fix infloop at the end of an incomplete table row * lisp/org-element.el (org-element-context): Fix infloop. Be more cautious when point is at the end of buffer. * testing/lisp/test-org-element.el (test-org-element/context): Add test. --- lisp/org-element.el | 11 ++++++++--- testing/lisp/test-org-element.el | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 29a90be41..e9f0b2c58 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5745,8 +5745,11 @@ Providing it allows for quicker computation." (cbeg (org-element-property :contents-begin next)) (cend (org-element-property :contents-end next))) (cond - ;; Skip objects ending before or at POS. - ((<= end pos) + ;; Skip objects ending before point. Also skip + ;; objects ending at point unless it is also the + ;; end of buffer, since we want to return the + ;; innermost object. + ((and (<= end pos) (/= (point-max) end)) (goto-char end) ;; For convenience, when object ends at POS, ;; without any space, store it in LAST, as we @@ -5764,7 +5767,9 @@ Providing it allows for quicker computation." ;; object, for consistency with ;; convenience feature above. (and (= pos cend) - (not (memq (char-before pos) '(?\s ?\t)))))) + (or (= (point-max) pos) + (not (memq (char-before pos) + '(?\s ?\t))))))) (goto-char cbeg) (narrow-to-region (point) cend) (setq parent next diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 1bc2a5363..7b7eda3a6 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -3076,6 +3076,12 @@ Paragraph \\alpha." (eq 'bold (org-test-with-temp-text "* *bold*" (search-forward "bo") + (org-element-type (org-element-context))))) + ;; Special case: incomplete cell at the end of a table row. + (should + (eq 'table-cell + (org-test-with-temp-text "|a|b|c" + (goto-char (point-max)) (org-element-type (org-element-context))))))