Parcourir la source

org-element: Fix small bug

* lisp/org-element.el (org-element-at-point): Return consistent value
  when function is called on a blank line within a plain list.
* testing/lisp/test-org-element.el: Add test.
Nicolas Goaziou il y a 12 ans
Parent
commit
8fc893a036
2 fichiers modifiés avec 19 ajouts et 2 suppressions
  1. 3 2
      lisp/org-element.el
  2. 16 0
      testing/lisp/test-org-element.el

+ 3 - 2
lisp/org-element.el

@@ -4116,8 +4116,9 @@ first element of current section."
 		       ;; return that element instead.
 		       (and (= cend origin)
 			    (memq type
-				  '(center-block drawer dynamic-block inlinetask
-						 quote-block special-block))))
+				  '(center-block
+				    drawer dynamic-block inlinetask item
+				    plain-list quote-block special-block))))
 		   (throw 'exit (if keep-trail trail element))
 		 (setq parent element)
 		 (case type

+ 16 - 0
testing/lisp/test-org-element.el

@@ -2270,6 +2270,22 @@ Paragraph \\alpha."
        (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph\n#+END_CENTER"
 	 (progn (forward-line 2)
 		(org-element-type (org-element-at-point))))))
+  ;; Special case: at a blank line between two items, be sure to
+  ;; return item above instead of the last element of its contents.
+  (should
+   (eq 'item
+       (org-test-with-temp-text "- Para1\n\n- Para2"
+	 (progn (forward-line)
+		(org-element-type
+		 (let ((org-empty-line-terminates-plain-lists nil))
+		   (org-element-at-point)))))))
+  ;; Special case: at the last blank line in a plain list, return it
+  ;; instead of the last item.
+  (should
+   (eq 'plain-list
+       (org-test-with-temp-text "- Para1\n- Para2\n\nPara3"
+	 (progn (forward-line 2)
+		(org-element-type (org-element-at-point))))))
   ;; With an optional argument, return trail.
   (should
    (equal '(paragraph center-block)