Browse Source

Merge branch 'maint'

Nicolas Goaziou 4 years ago
parent
commit
d61631bb19
2 changed files with 15 additions and 3 deletions
  1. 3 3
      lisp/org-list.el
  2. 12 0
      testing/lisp/test-org-list.el

+ 3 - 3
lisp/org-list.el

@@ -1240,15 +1240,15 @@ This function modifies STRUCT."
 	 ;; (SPLIT-LINE-P).
 	 (item
 	  (catch :exit
-	    ;; Do not initialize I as top item as we don't know if the
-	    ;; list is correctly structured.
 	    (let ((i nil))
 	      (pcase-dolist (`(,start ,_ ,_ ,_ ,_ ,_ ,end) struct)
 		(cond
 		 ((> start pos) (throw :exit i))
 		 ((< end pos) nil)	;skip sub-lists before point
 		 (t (setq i start))))
-	      (or i (org-list-get-top-point struct)))))
+	      ;; If no suitable item is found, insert a sibling of the
+	      ;; last item in buffer.
+	      (or i (caar (reverse struct))))))
 	 (item-end (org-list-get-item-end item struct))
 	 (item-end-no-blank (org-list-get-item-end-before-blank item struct))
 	 (beforep

+ 12 - 0
testing/lisp/test-org-list.el

@@ -749,6 +749,18 @@ b. Item 2<point>"
 	  (org-test-with-temp-text "- <point>item"
 	    (org-insert-item)
 	    (buffer-string))))
+  ;; When called at the very end of the list, insert new item as
+  ;; a sibling of the very last one.
+  (should
+   (equal "- A\n\n  - B\n\n  - "
+	  (org-test-with-temp-text "- A\n\n - B\n\n<point>"
+	    (org-insert-item)
+	    (buffer-string))))
+  (should
+   (equal "- A\n\n  - B\n\n  - "
+	  (org-test-with-temp-text "- A\n\n  - B\n\n  <point>"
+	    (org-insert-item)
+	    (buffer-string))))
   ;; When called on tag in a descriptive list, insert new item before
   ;; current one too.
   (should