org-element: Fix `org-element-insert-before'

* lisp/org-element.el (org-element-insert-before): Do not call
  `reverse' as contents might use `eq' objects.

* testing/lisp/test-ox.el (test-org-export/uninterpreted): Add test

Reported-by: Justin Kirby <justinkirby@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/112065>
This commit is contained in:
Nicolas Goaziou 2017-02-13 16:29:54 +01:00
parent fe97948e89
commit d347d85a15
2 changed files with 15 additions and 7 deletions

View file

@ -593,16 +593,15 @@ Parse tree is modified by side effect."
(specialp (and (not property)
(eq siblings parent)
(eq (car parent) location))))
;; Install ELEMENT at the appropriate POSITION within SIBLINGS.
;; Install ELEMENT at the appropriate LOCATION within SIBLINGS.
(cond (specialp)
((or (null siblings) (eq (car siblings) location))
(push element siblings))
((null location) (nconc siblings (list element)))
(t (let ((previous (cadr (memq location (reverse siblings)))))
(if (not previous)
(error "No location found to insert element")
(let ((next (memq previous siblings)))
(setcdr next (cons element (cdr next))))))))
(t
(let ((index (cl-position location siblings)))
(unless index (error "No location found to insert element"))
(push element (cdr (nthcdr (1- index) siblings))))))
;; Store SIBLINGS at appropriate place in parse tree.
(cond
(specialp (setcdr parent (copy-sequence parent)) (setcar parent element))

View file

@ -747,6 +747,15 @@ Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
(paragraph . (lambda (p c i) c))
(section . (lambda (s c i) c))))
nil nil nil '(:with-emphasize nil)))))
(should
(equal "/simple/ /example/\n"
(org-test-with-temp-text "/simple/ /example/"
(org-export-as
(org-export-create-backend
:transcoders '((bold . (lambda (b c i) "dummy"))
(paragraph . (lambda (p c i) c))
(section . (lambda (s c i) c))))
nil nil nil '(:with-emphasize nil)))))
;; LaTeX environment.
(should
(equal "dummy\n"
@ -839,7 +848,7 @@ Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
:transcoders
'((subscript . (lambda (s c i) "dummy"))
(template . (lambda (c i) (org-export-data
(plist-get i :title) i)))
(plist-get i :title) i)))
(section . (lambda (s c i) c))))
nil nil nil '(:with-sub-superscript nil)))))
;; Handle uninterpreted objects in captions.