Browse Source

org-element: `org-element-parse-secondary-string' accepts nil argument

* lisp/org-element.el (org-element-parse-secondary-string): Accept nil
  argument as a special case.

Reported-by: Rasmus <rasmus@gmx.us>
<http://permalink.gmane.org/gmane.emacs.orgmode/96234>
Nicolas Goaziou 10 years ago
parent
commit
bcf6970369
1 changed files with 19 additions and 14 deletions
  1. 19 14
      lisp/org-element.el

+ 19 - 14
lisp/org-element.el

@@ -3940,20 +3940,25 @@ looked after.
 
 Optional argument PARENT, when non-nil, is the element or object
 containing the secondary string.  It is used to set correctly
-`:parent' property within the string."
-  (let ((local-variables (buffer-local-variables)))
-    (with-temp-buffer
-      (dolist (v local-variables)
-	(ignore-errors
-	  (if (symbolp v) (makunbound v)
-	    (org-set-local (car v) (cdr v)))))
-      (insert string)
-      (restore-buffer-modified-p nil)
-      (let ((secondary (org-element--parse-objects
-			(point-min) (point-max) nil restriction)))
-	(when parent
-	  (dolist (o secondary) (org-element-put-property o :parent parent)))
-	secondary))))
+`:parent' property within the string.
+
+If STRING is the empty string or nil, return nil."
+  (cond
+   ((not string) nil)
+   ((equal string "") nil)
+   (t (let ((local-variables (buffer-local-variables)))
+	(with-temp-buffer
+	  (dolist (v local-variables)
+	    (ignore-errors
+	      (if (symbolp v) (makunbound v)
+		(org-set-local (car v) (cdr v)))))
+	  (insert string)
+	  (restore-buffer-modified-p nil)
+	  (let ((data (org-element--parse-objects
+		       (point-min) (point-max) nil restriction)))
+	    (when parent
+	      (dolist (o data) (org-element-put-property o :parent parent)))
+	    data))))))
 
 (defun org-element-map
     (data types fun &optional info first-match no-recursion with-affiliated)