Function: org-apply-on-list

org-apply-on-list is a byte-compiled function defined in org-list.el.gz.

Signature

(org-apply-on-list FUNCTION INIT-VALUE &rest ARGS)

Documentation

Call FUNCTION on each item of the list at point.

FUNCTION must be called with at least one argument: INIT-VALUE, that will contain the value returned by the function at the previous item, plus ARGS extra arguments.

FUNCTION is applied on items in reverse order.

As an example, (org-apply-on-list (lambda (result) (1+ result)) 0) will return the number of items in the current list.

Sublists of the list are skipped. Cursor is always at the beginning of the item.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-list.el.gz
;;; Misc Tools

(defun org-apply-on-list (function init-value &rest args)
  "Call FUNCTION on each item of the list at point.
FUNCTION must be called with at least one argument: INIT-VALUE,
that will contain the value returned by the function at the
previous item, plus ARGS extra arguments.

FUNCTION is applied on items in reverse order.

As an example, \(org-apply-on-list \(lambda \(result) \(1+ result)) 0)
will return the number of items in the current list.

Sublists of the list are skipped.  Cursor is always at the
beginning of the item."
  (let* ((struct (org-list-struct))
	 (prevs (org-list-prevs-alist struct))
         (item (copy-marker (line-beginning-position)))
	 (all (org-list-get-all-items (marker-position item) struct prevs))
	 (value init-value))
    (dolist (e (nreverse all))
      (goto-char e)
      (setq value (apply function value args)))
    (goto-char item)
    (move-marker item nil)
    value))