lang/org: fix insert-item tests; refactor +org/insert-item
This commit is contained in:
parent
cf4420e903
commit
aafa45e271
3 changed files with 30 additions and 13 deletions
|
@ -142,7 +142,7 @@ wrong places)."
|
||||||
(- (point) (line-beginning-position)))))
|
(- (point) (line-beginning-position)))))
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(pcase direction
|
(pcase direction
|
||||||
('below
|
(`below
|
||||||
(org-end-of-item)
|
(org-end-of-item)
|
||||||
(backward-char)
|
(backward-char)
|
||||||
(end-of-line)
|
(end-of-line)
|
||||||
|
@ -153,7 +153,7 @@ wrong places)."
|
||||||
(org-next-item)
|
(org-next-item)
|
||||||
(org-end-of-line)))
|
(org-end-of-line)))
|
||||||
(insert "\n" (make-string pad 32) (or marker ""))))
|
(insert "\n" (make-string pad 32) (or marker ""))))
|
||||||
('above
|
(`above
|
||||||
(goto-char (line-beginning-position))
|
(goto-char (line-beginning-position))
|
||||||
(if (and marker (string-match-p "[0-9]+[).]" marker))
|
(if (and marker (string-match-p "[0-9]+[).]" marker))
|
||||||
(org-insert-item)
|
(org-insert-item)
|
||||||
|
@ -174,8 +174,9 @@ wrong places)."
|
||||||
(org-element-property :level context)
|
(org-element-property :level context)
|
||||||
1)))
|
1)))
|
||||||
(pcase direction
|
(pcase direction
|
||||||
('below
|
(`below
|
||||||
(let ((at-eol (= (point) (1- (line-end-position)))))
|
(let ((at-eol (>= (point) (1- (line-end-position))))
|
||||||
|
org-insert-heading-respect-content)
|
||||||
(goto-char (line-end-position))
|
(goto-char (line-end-position))
|
||||||
(org-end-of-subtree)
|
(org-end-of-subtree)
|
||||||
(insert (concat "\n"
|
(insert (concat "\n"
|
||||||
|
@ -185,11 +186,12 @@ wrong places)."
|
||||||
"\n"))
|
"\n"))
|
||||||
(make-string level ?*)
|
(make-string level ?*)
|
||||||
" "))))
|
" "))))
|
||||||
('above
|
(`above
|
||||||
(org-back-to-heading)
|
(org-back-to-heading)
|
||||||
(org-insert-heading)
|
(insert (make-string level ?*) " ")
|
||||||
(when (= level 1)
|
(save-excursion
|
||||||
(save-excursion (insert "\n")))))
|
(insert "\n")
|
||||||
|
(if (= level 1) (insert "\n")))))
|
||||||
(when (org-element-property :todo-type context)
|
(when (org-element-property :todo-type context)
|
||||||
(org-todo 'todo))))
|
(org-todo 'todo))))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
;; -*- no-byte-compile: t; -*-
|
;; -*- no-byte-compile: t; -*-
|
||||||
;;; lang/org/test/autoload-org.el
|
;;; lang/org/test/autoload-org.el
|
||||||
|
|
||||||
|
(require! :lang org)
|
||||||
|
|
||||||
(defmacro should-org-buffer!! (source expected &rest body)
|
(defmacro should-org-buffer!! (source expected &rest body)
|
||||||
`(should-buffer!! ,source ,expected
|
`(should-buffer!! ,source ,expected
|
||||||
(org-mode)
|
(org-mode)
|
||||||
|
@ -40,3 +42,21 @@ newline."
|
||||||
"+ {|}"
|
"+ {|}"
|
||||||
"+ Next item")
|
"+ Next item")
|
||||||
(+org/insert-item 'below)))
|
(+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)))
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
;;; lang/org/test/org.el -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
(require! :lang org)
|
|
||||||
|
|
||||||
;;
|
|
Loading…
Add table
Add a link
Reference in a new issue