From 5a550938ce806ee88f62e6df774af47df83312a4 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 23 Mar 2015 23:35:57 +0100 Subject: [PATCH] org-list: Modify M-RET on a description tag * lisp/org-list.el (org-list-insert-item): On a description tag, insert item before current one. However, past the colons, insert it after. * testing/lisp/test-org-list.el (test-org-list/insert-item): Add tests. Reported-by: Leo Ufimtsev --- lisp/org-list.el | 16 ++++++++++------ testing/lisp/test-org-list.el | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/lisp/org-list.el b/lisp/org-list.el index 1525c2c5a..cbd65deae 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -1273,12 +1273,16 @@ This function modifies STRUCT." (beforep (progn (looking-at org-list-full-item-re) - ;; Do not count tag in a non-descriptive list. - (<= pos (if (and (match-beginning 4) - (save-match-data - (string-match "[.)]" (match-string 1)))) - (match-beginning 4) - (match-end 0))))) + (<= pos + (cond + ((not (match-beginning 4)) (match-end 0)) + ;; Ignore tag in a non-descriptive list. + ((save-match-data (string-match "[.)]" (match-string 1))) + (match-beginning 4)) + (t (save-excursion + (goto-char (match-end 4)) + (skip-chars-forward " \t") + (point))))))) (split-line-p (org-get-alist-option org-M-RET-may-split-line 'item)) (blank-nb (org-list-separating-blank-lines-number pos struct prevs)) diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el index 7c5a3fe43..241dafe1c 100644 --- a/testing/lisp/test-org-list.el +++ b/testing/lisp/test-org-list.el @@ -711,7 +711,45 @@ (goto-char (point-max)) (org-insert-item) (forward-line -1) - (looking-at "$"))))) + (looking-at "$")))) + ;; When called before or on the bullet, insert new item before + ;; current one. + (should + (equal "- \n- item" + (org-test-with-temp-text "- item" + (org-insert-item) + (buffer-string)))) + (should + (equal "- \n- item" + (org-test-with-temp-text "- item" + (org-insert-item) + (buffer-string)))) + ;; When called on tag in a descriptive list, insert new item before + ;; current one too. + (should + (equal "- :: \n- tag :: item" + (org-test-with-temp-text "- tag :: item" + (org-insert-item) + (buffer-string)))) + (should + (equal "- :: \n- tag :: item" + (org-test-with-temp-text "- tag :: item" + (org-insert-item) + (buffer-string)))) + ;; Further, it splits the line or add a blank new item after it, + ;; according to `org-M-RET-may-split-line'. + (should + (equal "- it\n- em" + (org-test-with-temp-text "- item" + (let ((org-M-RET-may-split-line '((default . t)))) + (org-insert-item)) + (buffer-string)))) + (should + (equal "- item\n- " + (org-test-with-temp-text "- item" + (let ((org-M-RET-may-split-line '((default . nil)))) + (org-insert-item)) + (buffer-string))))) (ert-deftest test-org-list/repair () "Test `org-list-repair' specifications." -- 2.11.4.GIT