diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2020-08-16 11:42:53 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2020-08-16 11:42:53 +0200 |
commit | 567662d5b09718d3225b131ca3d016ee9efcab81 (patch) | |
tree | 7f0a2697b3bc00c63b09ae3ae9c51185d20d79cc | |
parent | 3f04ad8d2ce14074cc786af266984b796d245fc0 (diff) | |
download | org-mode-567662d5b09718d3225b131ca3d016ee9efcab81.tar.gz |
list: Fix item insertion when split point is near blanks
* lisp/org-list.el (org-list-insert-item): Ignore blanks around cut
position.
* testing/lisp/test-org-list.el (test-org-list/insert-item): Add test.
Reported-by: Samuel Wales <samologist@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2020-08/msg00065.html>
-rw-r--r-- | lisp/org-list.el | 22 | ||||
-rw-r--r-- | testing/lisp/test-org-list.el | 8 |
2 files changed, 21 insertions, 9 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el index c43630d..b838328 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -1292,8 +1292,11 @@ This function modifies STRUCT." (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)))) + ;; Cut position is after any blank on the line. + (save-excursion + (skip-chars-forward " \t") + (setq pos (point))) + (delete-and-extract-region (point) item-end-no-blank)))) (body (concat bullet (and box (concat box " ")) @@ -1325,12 +1328,15 @@ This function modifies STRUCT." (setcar e (+ p item-size)) (setcar (nthcdr 6 e) (+ end size-offset))) ;; Items starting after modified item fall into two - ;; categories. If item was split, and current item was - ;; located after split point, it was moved to the new item. - ;; This means that the part between body start of body and - ;; split point was removed. So we compute the offset and - ;; shift item's positions accordingly. In any other case, - ;; the item was simply shifted by SIZE-OFFSET. + ;; categories. + ;; + ;; If modified item was split, and current sub-item was + ;; located after split point, it was moved to the new item: + ;; the part between body start and split point (POS) was + ;; removed. So we compute the length of that part and shift + ;; item's positions accordingly. + ;; + ;; Otherwise, the item was simply shifted by SIZE-OFFSET. ((and split-line-p (not beforep) (>= p pos) (<= p item-end-no-blank)) (let ((offset (- pos item ind (length bullet) (length after-bullet)))) (setcar e (- p offset)) diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el index 7898f05..078e596 100644 --- a/testing/lisp/test-org-list.el +++ b/testing/lisp/test-org-list.el @@ -892,7 +892,13 @@ b. Item 2<point>" (= 0 (org-test-with-temp-text "- item\n - sub-list\n resume item<point>" (org-insert-item) - (current-indentation))))) + (current-indentation)))) + ;; Test splitting with blanks around. + (should + (equal "- A\n B\n- C\n - D\n- [ ] E" + (org-test-with-temp-text "- A\n B <point> C\n - D\n- [ ] E" + (org-insert-item) + (buffer-string))))) (ert-deftest test-org-list/repair () "Test `org-list-repair' specifications." |