From 2c3157e34e9f9e63afe3f62b423bdbdf4c8859ca Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 21 Jul 2010 11:18:31 +0200 Subject: [PATCH] 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. --- lisp/org-list.el | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lisp/org-list.el b/lisp/org-list.el index 444d8e19e..39f9021b0 100644 --- a/lisp/org-list.el +++ b/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