lang/org: fix insert-item tests; refactor +org/insert-item

This commit is contained in:
Henrik Lissner 2018-02-17 22:41:58 -05:00
parent cf4420e903
commit aafa45e271
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 30 additions and 13 deletions

View file

@ -142,7 +142,7 @@ wrong places)."
(- (point) (line-beginning-position)))))
(save-match-data
(pcase direction
('below
(`below
(org-end-of-item)
(backward-char)
(end-of-line)
@ -153,7 +153,7 @@ wrong places)."
(org-next-item)
(org-end-of-line)))
(insert "\n" (make-string pad 32) (or marker ""))))
('above
(`above
(goto-char (line-beginning-position))
(if (and marker (string-match-p "[0-9]+[).]" marker))
(org-insert-item)
@ -174,8 +174,9 @@ wrong places)."
(org-element-property :level context)
1)))
(pcase direction
('below
(let ((at-eol (= (point) (1- (line-end-position)))))
(`below
(let ((at-eol (>= (point) (1- (line-end-position))))
org-insert-heading-respect-content)
(goto-char (line-end-position))
(org-end-of-subtree)
(insert (concat "\n"
@ -185,11 +186,12 @@ wrong places)."
"\n"))
(make-string level ?*)
" "))))
('above
(`above
(org-back-to-heading)
(org-insert-heading)
(when (= level 1)
(save-excursion (insert "\n")))))
(insert (make-string level ?*) " ")
(save-excursion
(insert "\n")
(if (= level 1) (insert "\n")))))
(when (org-element-property :todo-type context)
(org-todo 'todo))))

View file

@ -1,6 +1,8 @@
;; -*- no-byte-compile: t; -*-
;;; lang/org/test/autoload-org.el
(require! :lang org)
(defmacro should-org-buffer!! (source expected &rest body)
`(should-buffer!! ,source ,expected
(org-mode)
@ -40,3 +42,21 @@ newline."
"+ {|}"
"+ Next item")
(+org/insert-item 'below)))
(def-test! insert-item-numbered-list
"Should append/prepend new second-level (and higher) headers without an extra
newline."
(should-org-buffer!! ("1. {0}List item") ("1. List item\n2. {|}")
(+org/insert-item 'below))
(should-org-buffer!! ("1. {0}List item"
"2. Sub item")
("1. List item"
"2. {|}"
"3. Sub item")
(+org/insert-item 'below))
(should-org-buffer!! ("1. {0}List item"
"2. Next item")
("1. {|}"
"2. List item"
"3. Next item")
(+org/insert-item 'above)))

View file

@ -1,5 +0,0 @@
;;; lang/org/test/org.el -*- lexical-binding: t; -*-
(require! :lang org)
;;