浏览代码

org-element: Fix failing "plain-list-parser" test

* lisp/org-element.el (org-element--list-struct): Fix failing
  "plain-list-parser" test.
* testing/lisp/test-org-element.el: Update test.
Nicolas Goaziou 12 年之前
父节点
当前提交
d8b983b85a
共有 2 个文件被更改,包括 21 次插入20 次删除
  1. 8 7
      lisp/org-element.el
  2. 13 13
      testing/lisp/test-org-element.el

+ 8 - 7
lisp/org-element.el

@@ -1147,9 +1147,10 @@ CONTENTS is the contents of the element."
 ;;;; Plain List
 
 (defun org-element--list-struct (limit)
-;; Return structure of list at point.  Internal function.  See
-;; `org-list-struct' for details.
+  ;; Return structure of list at point.  Internal function.  See
+  ;; `org-list-struct' for details.
   (let ((case-fold-search t)
+	(top-ind limit)
 	(item-re (org-item-re))
 	(drawers-re (concat ":\\("
 			    (mapconcat 'regexp-quote org-drawers "\\|")
@@ -1178,6 +1179,7 @@ CONTENTS is the contents of the element."
 	   ((looking-at item-re)
 	    (let ((ind (save-excursion (skip-chars-forward " \t")
 				       (current-column))))
+	      (setq top-ind (min top-ind ind))
 	      (while (and items (<= ind (nth 1 (car items))))
 		(let ((item (pop items)))
 		  (setcar (nthcdr 6 item) (point))
@@ -1209,13 +1211,12 @@ CONTENTS is the contents of the element."
 	   ;; At some text line.  Check if it ends any previous item.
 	   (t
 	    (let ((ind (progn (skip-chars-forward " \t") (current-column))))
+	      (when (<= ind top-ind)
+		(skip-chars-backward " \r\t\n")
+		(forward-line))
 	      (while (<= ind (nth 1 (car items)))
 		(let ((item (pop items)))
-		  (setcar (nthcdr 6 item)
-			  (if items (line-beginning-position)
-			    (skip-chars-backward " \r\t\n")
-			    (forward-line)
-			    (point)))
+		  (setcar (nthcdr 6 item) (line-beginning-position))
 		  (push item struct)
 		  (unless items
 		    (throw 'exit (sort struct 'car-less-than-car))))))

+ 13 - 13
testing/lisp/test-org-element.el

@@ -1494,24 +1494,24 @@ e^{i\\pi}+1=0
 
 (ert-deftest test-org-element/plain-list-parser ()
   "Test `plain-list' parser."
-  (should
-   (org-test-with-temp-text "- item"
-     (org-element-map (org-element-parse-buffer) 'plain-list 'identity)))
+  (org-test-with-temp-text "- item"
+    (should (org-element-map (org-element-parse-buffer) 'plain-list 'identity)))
   ;; Blank lines after the list only belong to outer plain list.
-  (org-test-with-temp-text "
+  (should
+   (equal
+    '(t t)
+    (org-test-with-temp-text "
 - outer
   - inner
 
 Outside list"
-    (let ((endings (org-element-map
-		    (org-element-parse-buffer) 'plain-list
-		    (lambda (pl) (org-element-property :end pl)))))
-      ;; Move to ending of outer list.
-      (goto-char (car endings))
-      (should (looking-at "Outside list"))
-      ;; Move to ending of inner list.
-      (goto-char (nth 1 endings))
-      (should (looking-at "^$")))))
+      (let ((endings (org-element-map (org-element-parse-buffer) 'plain-list
+		       (lambda (pl) (org-element-property :end pl)))))
+	(list
+	 ;; Move to ending of outer list.
+	 (progn (goto-char (car endings)) (looking-at "Outside list"))
+	 ;; Move to ending of inner list.
+	 (progn (goto-char (nth 1 endings)) (looking-at "^$"))))))))
 
 
 ;;;; Planning