Browse Source

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>
Nicolas Goaziou 8 years ago
parent
commit
d347d85a15
2 changed files with 15 additions and 7 deletions
  1. 5 6
      lisp/org-element.el
  2. 10 1
      testing/lisp/test-ox.el

+ 5 - 6
lisp/org-element.el

@@ -593,16 +593,15 @@ Parse tree is modified by side effect."
 	 (specialp (and (not property)
 	 (specialp (and (not property)
 			(eq siblings parent)
 			(eq siblings parent)
 			(eq (car parent) location))))
 			(eq (car parent) location))))
-    ;; Install ELEMENT at the appropriate POSITION within SIBLINGS.
+    ;; Install ELEMENT at the appropriate LOCATION within SIBLINGS.
     (cond (specialp)
     (cond (specialp)
 	  ((or (null siblings) (eq (car siblings) location))
 	  ((or (null siblings) (eq (car siblings) location))
 	   (push element siblings))
 	   (push element siblings))
 	  ((null location) (nconc siblings (list element)))
 	  ((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.
     ;; Store SIBLINGS at appropriate place in parse tree.
     (cond
     (cond
      (specialp (setcdr parent (copy-sequence parent)) (setcar parent element))
      (specialp (setcdr parent (copy-sequence parent)) (setcar parent element))

+ 10 - 1
testing/lisp/test-ox.el

@@ -747,6 +747,15 @@ Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
 			     (paragraph . (lambda (p c i) c))
 			     (paragraph . (lambda (p c i) c))
 			     (section . (lambda (s c i) c))))
 			     (section . (lambda (s c i) c))))
 	     nil nil nil '(:with-emphasize nil)))))
 	     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.
   ;; LaTeX environment.
   (should
   (should
    (equal "dummy\n"
    (equal "dummy\n"
@@ -839,7 +848,7 @@ Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
 	      :transcoders
 	      :transcoders
 	      '((subscript . (lambda (s c i) "dummy"))
 	      '((subscript . (lambda (s c i) "dummy"))
 		(template . (lambda (c i) (org-export-data
 		(template . (lambda (c i) (org-export-data
-				      (plist-get i :title) i)))
+					   (plist-get i :title) i)))
 		(section . (lambda (s c i) c))))
 		(section . (lambda (s c i) c))))
 	     nil nil nil '(:with-sub-superscript nil)))))
 	     nil nil nil '(:with-sub-superscript nil)))))
   ;; Handle uninterpreted objects in captions.
   ;; Handle uninterpreted objects in captions.