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.
This commit is contained in:
Nicolas Goaziou 2012-10-14 21:47:07 +02:00
parent c65abd8577
commit b7c5cf5d44
2 changed files with 23 additions and 4 deletions

View File

@ -3886,8 +3886,14 @@ type, as a symbol.
OBJECTS is the previous candidates alist." OBJECTS is the previous candidates alist."
;; Filter out any object found but not belonging to RESTRICTION. ;; Filter out any object found but not belonging to RESTRICTION.
(setq objects (org-remove-if-not (lambda (obj) (memq (car obj) restriction)) (setq objects
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) (let (next-candidates types-to-search)
;; If no previous result, search every object type in RESTRICTION. ;; If no previous result, search every object type in RESTRICTION.
;; Otherwise, keep potential candidates (old objects located after ;; Otherwise, keep potential candidates (old objects located after

View File

@ -1523,7 +1523,13 @@ Outside list"
(eq 'subscript (eq 'subscript
(org-test-with-temp-text "- _b" (org-test-with-temp-text "- _b"
(progn (search-forward "_") (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 ;;;; Superscript
@ -1543,7 +1549,14 @@ Outside list"
(eq 'superscript (eq 'superscript
(org-test-with-temp-text "- ^b" (org-test-with-temp-text "- ^b"
(progn (search-forward "^") (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 ;;;; Table