summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-10-30 01:06:36 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-12-19 12:19:58 +0100
commit45d57bb4db7130e0b8b8995eed7976308e60237b (patch)
treee65dd843a0926e1d151874a3e678b459a5249ee8
parent835b8e05e512bee7370b8d3aee749c222636335c (diff)
downloadorg-mode-45d57bb4db7130e0b8b8995eed7976308e60237b.tar.gz
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.
-rw-r--r--etc/ORG-NEWS7
-rw-r--r--lisp/org-list.el19
-rw-r--r--testing/lisp/test-org-list.el33
3 files changed, 59 insertions, 0 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1d83983..3f5529f 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 abc6c53..c0c9ddc 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 fe9da96..cace245 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