diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 1d8398304..3f5529f7a 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -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 diff --git a/lisp/org-list.el b/lisp/org-list.el index abc6c539d..c0c9ddcdf 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -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 diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el index fe9da96d8..cace24531 100644 --- a/testing/lisp/test-org-list.el +++ b/testing/lisp/test-org-list.el @@ -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