From b7c5cf5d446aeef02bf7970fb463ef813c92b509 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 14 Oct 2012 21:47:07 +0200 Subject: [PATCH] org-element: Fix parsing of objects of the same type in a single paragraph * lisp/org-element.el (org-element--get-next-object-candidates): Fix parsing of objects of the same type in a single paragraph. * testing/lisp/test-org-element.el: Add tests. --- lisp/org-element.el | 10 ++++++++-- testing/lisp/test-org-element.el | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 6bcfa855f..b19fc3c3e 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -3886,8 +3886,14 @@ type, as a symbol. OBJECTS is the previous candidates alist." ;; Filter out any object found but not belonging to RESTRICTION. - (setq objects (org-remove-if-not (lambda (obj) (memq (car obj) restriction)) - objects)) + (setq objects + (org-remove-if-not + (lambda (obj) + (let ((type (car obj))) + (memq (or (cdr (assq type org-element-object-successor-alist)) + type) + restriction))) + objects)) (let (next-candidates types-to-search) ;; If no previous result, search every object type in RESTRICTION. ;; Otherwise, keep potential candidates (old objects located after diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index e7cfadabf..55f5eae76 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1523,7 +1523,13 @@ Outside list" (eq 'subscript (org-test-with-temp-text "- _b" (progn (search-forward "_") - (org-element-type (org-element-context))))))) + (org-element-type (org-element-context)))))) + ;; Multiple subscripts in a paragraph. + (should + (= 2 + (org-test-with-temp-text "a_b and c_d" + (length + (org-element-map (org-element-parse-buffer) 'subscript 'identity)))))) ;;;; Superscript @@ -1543,7 +1549,14 @@ Outside list" (eq 'superscript (org-test-with-temp-text "- ^b" (progn (search-forward "^") - (org-element-type (org-element-context))))))) + (org-element-type (org-element-context)))))) + ;; Multiple superscript in a paragraph. + (should + (= 2 + (org-test-with-temp-text "a^b and c^d" + (length + (org-element-map + (org-element-parse-buffer) 'superscript 'identity)))))) ;;;; Table