Function: org-list-to-lisp
org-list-to-lisp is a byte-compiled function defined in
org-list.el.gz.
Signature
(org-list-to-lisp &optional DELETE)
Documentation
Parse the list at point and maybe DELETE it.
Return a list whose car is a symbol of list type, among
ordered, unordered and descriptive. Then, each item is
a list of strings and other sub-lists.
For example, the following list:
1. first item
+ sub-item one
+ [X] sub-item two
more text in first item
2. [@3] last item
is parsed as
(ordered
("first item"
(unordered
("sub-item one")
("[X] sub-item two"))
"more text in first item")
("[@3] last item"))
Point is left at list's end.
Aliases
org-list-parse-list (obsolete since 9.0)
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-list.el.gz
;;; Send and receive lists
(defun org-list-to-lisp (&optional delete)
"Parse the list at point and maybe DELETE it.
Return a list whose car is a symbol of list type, among
`ordered', `unordered' and `descriptive'. Then, each item is
a list of strings and other sub-lists.
For example, the following list:
1. first item
+ sub-item one
+ [X] sub-item two
more text in first item
2. [@3] last item
is parsed as
(ordered
(\"first item\"
(unordered
(\"sub-item one\")
(\"[X] sub-item two\"))
\"more text in first item\")
(\"[@3] last item\"))
Point is left at list's end."
(letrec ((struct (org-list-struct))
(prevs (org-list-prevs-alist struct))
(parents (org-list-parents-alist struct))
(top (org-list-get-top-point struct))
(bottom (org-list-get-bottom-point struct))
(trim
(lambda (text)
;; Remove indentation and final newline from TEXT.
(org-remove-indentation
(if (string-match-p "\n\\'" text)
(substring text 0 -1)
text))))
(parse-sublist
(lambda (e)
;; Return a list whose car is list type and cdr a list
;; of items' body.
(cons (org-list-get-list-type (car e) struct prevs)
(mapcar parse-item e))))
(parse-item
(lambda (e)
;; Return a list containing counter of item, if any,
;; text and any sublist inside it.
(let* ((end (org-list-get-item-end e struct))
(children (org-list-get-children e struct parents))
(body
(save-excursion
(goto-char e)
(looking-at "[ \t]*\\S-+[ \t]*")
(list
(funcall
trim
(concat
(make-string (string-width (match-string 0)) ?\s)
(buffer-substring-no-properties
(match-end 0) (or (car children) end))))))))
(while children
(let* ((child (car children))
(sub (org-list-get-all-items child struct prevs))
(last-in-sub (car (last sub))))
(push (funcall parse-sublist sub) body)
;; Remove whole sub-list from children.
(setq children (cdr (memq last-in-sub children)))
;; There is a chunk of text belonging to the item
;; if last child doesn't end where next child
;; starts or where item ends.
(let ((sub-end (org-list-get-item-end last-in-sub struct))
(next (or (car children) end)))
(when (/= sub-end next)
(push (funcall
trim
(buffer-substring-no-properties sub-end next))
body)))))
(nreverse body)))))
;; Store output, take care of cursor position and deletion of
;; list, then return output.
(prog1 (funcall parse-sublist (org-list-get-all-items top struct prevs))
(goto-char top)
(when delete
(delete-region top bottom)
(when (and (not (looking-at "[ \t]*$")) (looking-at org-list-end-re))
(replace-match ""))))))