From 79cb160323800d1ee08bd6c77010f586990e81c2 Mon Sep 17 00:00:00 2001 From: Jason Blevins Date: Mon, 22 May 2017 11:58:41 -0400 Subject: [PATCH] Continue GFM task lists after pressing RET Generalizes the behavior for regular unordered and ordered lists. --- markdown-mode.el | 8 +++++++- tests/markdown-test.el | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/markdown-mode.el b/markdown-mode.el index 167d6cb..cbdece3 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -5355,6 +5355,12 @@ increase the indentation by one level." ;; Compute indentation and marker for new list item (setq cur-indent (nth 2 bounds)) (setq marker (nth 4 bounds)) + ;; Is this a GFM checkbox? + (when (save-excursion + (goto-char (cl-first bounds)) + (forward-char (cl-fourth bounds)) + (looking-at "\\(\\[\\)[xX ]\\(\\]\\s-*\\)")) + (setq marker (concat marker (match-string 1) " " (match-string 2)))) (cond ;; Dedent: decrement indentation, find previous marker. ((= arg 4) @@ -5397,7 +5403,7 @@ increase the indentation by one level." (substring (match-string 2) 0 space-adjust) (or old-spacing ". ")))) (insert (concat new-indent new-prefix new-spacing))))) - ;; Unordered list, or ordered list with hash mark + ;; Unordered list, GFM task list, or ordered list with hash mark ((string-match-p "[\\*\\+-]\\|#\\." marker) (insert new-indent marker))))))) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 1508fca..0ad2159 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -3229,6 +3229,13 @@ x: x (should (string-equal (markdown-toggle-gfm-checkbox) "[x]")) (should (string-equal (buffer-string) " - [x] GFM task list item")))) +(ert-deftest test-markdown-lists/toggle-gfm-checkbox () + (markdown-test-string " - [X] item" + (end-of-line) + (call-interactively #'markdown-enter-key) + (should (string-equal (buffer-string) " - [X] item\n - [ ] ")) + (should (= (point) 28)))) + ;;; Outline minor mode tests: (ert-deftest test-markdown-outline/navigation () -- 2.11.4.GIT