Преглед на файлове

Better guessing of blank lines when inserting an item.

* org-list.el (org-list-insert-item-generic): When local search
  doesn't help, search the list globally for blank lines. Moreover,
  don't bother with new lists, and add 1 blank line.
Nicolas Goaziou преди 15 години
родител
ревизия
2c3157e34e
променени са 1 файла, в които са добавени 16 реда и са изтрити 3 реда
  1. 16 3
      lisp/org-list.el

+ 16 - 3
lisp/org-list.el

@@ -355,9 +355,17 @@ function ends."
 	  (let ((insert-blank-p
 		 (cdr (assq 'plain-list-item org-blank-before-new-entry))))
 	    (cond
+	     ;; Trivial cases where there should be none.
 	     ((or org-empty-line-terminates-plain-lists
 		  (not insert-blank-p)) 0)
-	     ((eq insert-blank-p t) 1)
+	     ;; When `org-blank-before-new-entry' says so, or item is
+	     ;; alone in the whole list, it is 1.
+	     ((or (eq insert-blank-p t)
+		  (save-excursion
+		    (goto-char (org-list-top-point))
+		    (end-of-line)
+		    (not (org-search-forward-unenclosed
+			  org-item-beginning-re (org-list-bottom-point) t)))) 1)
 	     ;; plain-list-item is 'auto. Count blank lines separating
 	     ;; neighbours items in list.
 	     (t (let ((next-p (org-get-next-item (point) (org-list-bottom-point))))
@@ -367,8 +375,13 @@ function ends."
 			   (org-back-over-empty-lines))
 		   ;; Is there a previous item?
 		   ((not (org-first-list-item-p)) (org-back-over-empty-lines))
-		   ;; no luck: item is alone. Use default value.
-		   (t 1)))))))
+		   ;; Local search failed: search globally.
+		   ((and (goto-char (org-list-bottom-point))
+			 (beginning-of-line 0)
+			 (org-search-backward-unenclosed "^[ \t]*$" (org-list-top-point) t))
+		    (1+ (org-back-over-empty-lines)))
+		   ;; No blank line found in the whole list.
+		   (t 0)))))))
 	 (insert-fun
 	  (lambda (text)
 	    ;; insert bullet above item in order to avoid bothering