Function: org-list-to-generic

org-list-to-generic is a byte-compiled function defined in org-list.el.gz.

Signature

(org-list-to-generic LIST PARAMS)

Documentation

Convert a LIST parsed through org-list-to-lisp to a custom format.

LIST is a list as returned by org-list-to-lisp, which see. PARAMS is a property list of parameters used to tweak the output format.

Valid parameters are:

:backend, :raw

  Export back-end used as a basis to transcode elements of the
  list, when no specific parameter applies to it. It is also
  used to translate its contents. You can prevent this by
  setting :raw property to a non-nil value.

:splice

  When non-nil, only export the contents of the top most plain
  list, effectively ignoring its opening and closing lines.

:ustart, :uend

  Strings to start and end an unordered list. They can also be
  set to a function returning a string or nil, which will be
  called with the depth of the list, counting from 1.

:ostart, :oend

  Strings to start and end an ordered list. They can also be set
  to a function returning a string or nil, which will be called
  with the depth of the list, counting from 1.

:dstart, :dend

  Strings to start and end a descriptive list. They can also be
  set to a function returning a string or nil, which will be
  called with the depth of the list, counting from 1.

:dtstart, :dtend, :ddstart, :ddend

  Strings to start and end a descriptive term.

:istart, :iend

  Strings to start or end a list item, and to start a list item
  with a counter. They can also be set to a function returning
  a string or nil, which will be called with two arguments: the
  type of list and the depth of the item, counting from 1.

:icount

  Strings to start a list item with a counter. It can also be
  set to a function returning a string or nil, which will be
  called with three arguments: the type of list, the depth of the
  item, counting from 1, and the counter. Its value, when
  non-nil, has precedence over :istart.

:isep

  String used to separate items. It can also be set to
  a function returning a string or nil, which will be called with
  two arguments: the type of list and the depth of the item,
  counting from 1. It always start on a new line.

:ifmt

  Function to be applied to the contents of every item. It is
  called with two arguments: the type of list and the contents.

:cbon, :cboff, :cbtrans

  String to insert, respectively, an un-checked check-box,
  a checked check-box and a check-box in transitional state.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-list.el.gz
(defun org-list-to-generic (list params)
  "Convert a LIST parsed through `org-list-to-lisp' to a custom format.

LIST is a list as returned by `org-list-to-lisp', which see.
PARAMS is a property list of parameters used to tweak the output
format.

Valid parameters are:

:backend, :raw

  Export back-end used as a basis to transcode elements of the
  list, when no specific parameter applies to it.  It is also
  used to translate its contents.  You can prevent this by
  setting :raw property to a non-nil value.

:splice

  When non-nil, only export the contents of the top most plain
  list, effectively ignoring its opening and closing lines.

:ustart, :uend

  Strings to start and end an unordered list.  They can also be
  set to a function returning a string or nil, which will be
  called with the depth of the list, counting from 1.

:ostart, :oend

  Strings to start and end an ordered list.  They can also be set
  to a function returning a string or nil, which will be called
  with the depth of the list, counting from 1.

:dstart, :dend

  Strings to start and end a descriptive list.  They can also be
  set to a function returning a string or nil, which will be
  called with the depth of the list, counting from 1.

:dtstart, :dtend, :ddstart, :ddend

  Strings to start and end a descriptive term.

:istart, :iend

  Strings to start or end a list item, and to start a list item
  with a counter.  They can also be set to a function returning
  a string or nil, which will be called with two arguments: the
  type of list and the depth of the item, counting from 1.

:icount

  Strings to start a list item with a counter.  It can also be
  set to a function returning a string or nil, which will be
  called with three arguments: the type of list, the depth of the
  item, counting from 1, and the counter.  Its value, when
  non-nil, has precedence over `:istart'.

:isep

  String used to separate items.  It can also be set to
  a function returning a string or nil, which will be called with
  two arguments: the type of list and the depth of the item,
  counting from 1.  It always start on a new line.

:ifmt

  Function to be applied to the contents of every item.  It is
  called with two arguments: the type of list and the contents.

:cbon, :cboff, :cbtrans

  String to insert, respectively, an un-checked check-box,
  a checked check-box and a check-box in transitional state."
  (require 'ox)
  (let* ((backend (plist-get params :backend))
	 (custom-backend
	  (org-export-create-backend
	   :parent (or backend 'org)
	   :transcoders
	   `((plain-list . ,(org-list--to-generic-plain-list params))
	     (item . ,(org-list--to-generic-item params))
	     (macro . (lambda (m c i) (org-element-macro-interpreter m nil))))))
	 data info)
    ;; Write LIST back into Org syntax and parse it.
    (with-temp-buffer
      (let ((org-inhibit-startup t)) (org-mode))
      (letrec ((insert-list
		(lambda (l)
		  (dolist (i (cdr l))
		    (funcall insert-item i (car l)))))
	       (insert-item
		(lambda (i type)
		  (let ((start (point)))
		    (insert (if (eq type 'ordered) "1. " "- "))
		    (dolist (e i)
		      (if (consp e) (funcall insert-list e)
			(insert e)
			(insert "\n")))
		    (beginning-of-line)
		    (save-excursion
		      (let ((ind (if (eq type 'ordered) 3 2)))
			(while (> (point) start)
			  (unless (looking-at-p "[ \t]*$")
			    (indent-to ind))
			  (forward-line -1))))))))
	(funcall insert-list list))
      (setf data
	    (org-element-map (org-element-parse-buffer) 'plain-list
	      #'identity nil t))
      (setf info (org-export-get-environment backend nil params)))
    (when (and backend (symbolp backend) (not (org-export-get-backend backend)))
      (user-error "Unknown :backend value"))
    (unless backend (require 'ox-org))
    ;; When ':raw' property has a non-nil value, turn all objects back
    ;; into Org syntax.
    (when (and backend (plist-get params :raw))
      (org-element-map data org-element-all-objects
	(lambda (object)
	  (org-element-set-element
	   object (org-element-interpret-data object)))))
    ;; We use a low-level mechanism to export DATA so as to skip all
    ;; usual pre-processing and post-processing, i.e., hooks, filters,
    ;; Babel code evaluation, include keywords and macro expansion,
    ;; and filters.
    (let ((output (org-export-data-with-backend data custom-backend info)))
      ;; Remove final newline.
      (if (org-string-nw-p output) (substring-no-properties output 0 -1) ""))))