浏览代码

org-list: never add useless blank lines when inserting an item

* lisp/org-list.el (org-list-insert-item): when insertion point is in
  some white line after the end of the list, remove all unnecessary
  white lines there before proceeding. Also refactor a snippet of
  code.
Nicolas Goaziou 13 年之前
父节点
当前提交
054230b138
共有 1 个文件被更改,包括 10 次插入5 次删除
  1. 10 5
      lisp/org-list.el

+ 10 - 5
lisp/org-list.el

@@ -1245,15 +1245,20 @@ This function modifies STRUCT."
 	    (and (not beforep) split-line-p
 		 (progn
 		   (goto-char pos)
+		   ;; If POS is greater than ITEM-END, then point is
+		   ;; in some white lines after the end of the list.
+		   ;; Those must be removed, or they will be left,
+		   ;; stacking up after the list.
+		   (when (< item-end pos)
+		     (delete-region (1- item-end) (point-at-eol)))
 		   (skip-chars-backward " \r\t\n")
 		   (setq pos (point))
 		   (delete-and-extract-region pos item-end-no-blank))))
 	   (body (concat bullet (when box (concat box " ")) after-bullet
-			 (or (and text-cut
-				  (if (string-match "\\`[ \t]+" text-cut)
-				      (replace-match "" t t text-cut)
-				    text-cut))
-			     "")))
+			 (and text-cut
+			      (if (string-match "\\`[ \t]+" text-cut)
+				  (replace-match "" t t text-cut)
+				text-cut))))
 	   (item-sep (make-string  (1+ blank-nb) ?\n))
 	   (item-size (+ ind-size (length body) (length item-sep)))
 	   (size-offset (- item-size (length text-cut))))