瀏覽代碼

org-element: Normalize contents of elements in place

* contrib/lisp/org-element.el (org-element-normalize-contents):
  Normalize contents of elements in place.  This is required to be
  sure that a normalized element still is `eq' to its equivalent in
  the parse tree.
Nicolas Goaziou 12 年之前
父節點
當前提交
69af0913b2
共有 1 個文件被更改,包括 19 次插入19 次删除
  1. 19 19
      contrib/lisp/org-element.el

+ 19 - 19
contrib/lisp/org-element.el

@@ -3941,7 +3941,7 @@ indentation is not done with TAB characters."
     (if (not ind-list) element
       ;; Build ELEMENT back, replacing each string with the same
       ;; string minus common indentation.
-      (let* (build			; for byte compiler
+      (let* (build			; For byte compiler.
 	     (build
 	      (function
 	       (lambda (blob mci first-flag)
@@ -3949,24 +3949,24 @@ indentation is not done with TAB characters."
 		 ;; shortened from MCI white spaces.  FIRST-FLAG is
 		 ;; non-nil when the first string hasn't been seen
 		 ;; yet.
-		 (nconc
-		  (list (org-element-type blob) (nth 1 blob))
-		  (mapcar
-		   (lambda (object)
-		     (when (and first-flag (stringp object))
-		       (setq first-flag nil)
-		       (setq object
-			     (replace-regexp-in-string
-			      (format "\\` \\{%d\\}" mci) "" object)))
-		     (cond
-		      ((stringp object)
-		       (replace-regexp-in-string
-			(format "\n \\{%d\\}" mci) "\n" object))
-		      ((memq (org-element-type object)
-			     org-element-recursive-objects)
-		       (funcall build object mci first-flag))
-		      (t object)))
-		   (org-element-contents blob)))))))
+		 (setcdr (cdr blob)
+			 (mapcar
+			  (lambda (object)
+			    (when (and first-flag (stringp object))
+			      (setq first-flag nil)
+			      (setq object
+				    (replace-regexp-in-string
+				     (format "\\` \\{%d\\}" mci) "" object)))
+			    (cond
+			     ((stringp object)
+			      (replace-regexp-in-string
+			       (format "\n \\{%d\\}" mci) "\n" object))
+			     ((memq (org-element-type object)
+				    org-element-recursive-objects)
+			      (funcall build object mci first-flag))
+			     (t object)))
+			  (org-element-contents blob)))
+		 blob))))
 	(funcall build element (apply 'min ind-list) (not ignore-first))))))