org-list: Implement `org-list-to-org'

* lisp/org-list.el (org-list-to-org): New function.
* testing/lisp/test-org-list.el (test-org-list/to-org): New test.
This commit is contained in:
Nicolas Goaziou 2016-10-30 01:06:36 +02:00
parent 835b8e05e5
commit 45d57bb4db
3 changed files with 59 additions and 0 deletions

View File

@ -120,6 +120,13 @@ narrowed to current buffer to achieve a similar functionality.
For an equivalent to a ~nil~ value, set
~org-agenda-show-future-repeats~ to nil and
~org-agenda-prefer-last-repeat~ to ~t~.
** New functions
*** ~org-list-to-org~
It is the reciprocal of ~org-list-to-lisp~, which see.
* Version 9.0
** Incompatible changes

View File

@ -3555,6 +3555,25 @@ PARAMS is a property list with overruling parameters for
(require 'ox-texinfo)
(org-list-to-generic list (org-combine-plists '(:backend texinfo) params)))
(defun org-list-to-org (list &optional params)
"Convert LIST into an Org plain list.
LIST is as returned by `org-list-parse-list'. PARAMS is a property list
with overruling parameters for `org-list-to-generic'."
(let* ((make-item
(lambda (type _depth &optional c)
(concat (if (eq type 'ordered) "1. " "- ")
(and c (format "[@%d] " c)))))
(defaults
(list :istart make-item
:icount make-item
:ifmt (lambda (_type contents)
(replace-regexp-in-string "\n" "\n " contents))
:dtend " :: "
:cbon "[X] "
:cboff "[ ] "
:cbtrans "[-] ")))
(org-list-to-generic list (org-combine-plists defaults params))))
(defun org-list-to-subtree (list &optional params)
"Convert LIST into an Org subtree.
LIST is as returned by `org-list-to-lisp'. PARAMS is a property

View File

@ -1326,6 +1326,39 @@
(skip-chars-backward " \r\t\n")
(point)))))))
(ert-deftest test-org-list/to-org ()
"Test `org-list-to-org' specifications."
;; Un-ordered list.
(should
(equal "- a"
(org-test-with-temp-text "- a"
(org-list-to-org (org-list-to-lisp) nil))))
;; Ordered list.
(should
(equal "1. a"
(org-test-with-temp-text "1. a"
(org-list-to-org (org-list-to-lisp) nil))))
;; Descriptive list.
(should
(equal "- a :: b"
(org-test-with-temp-text "- a :: b"
(org-list-to-org (org-list-to-lisp) nil))))
;; Nested list.
(should
(equal "- a\n - b"
(org-test-with-temp-text "- a\n - b"
(org-list-to-org (org-list-to-lisp) nil))))
;; Item spanning over multiple lines.
(should
(equal "- a\n b"
(org-test-with-temp-text "- a\n b"
(org-list-to-org (org-list-to-lisp) nil))))
;; Item with continuation text after a sub-list.
(should
(equal "- a\n - b\n c"
(org-test-with-temp-text "- a\n - b\n c"
(org-list-to-org (org-list-to-lisp) nil)))))
(provide 'test-org-list)
;;; test-org-list.el ends here