Function: hierarchy-map-tree

hierarchy-map-tree is a byte-compiled function defined in hierarchy.el.gz.

Signature

(hierarchy-map-tree FUNCTION HIERARCHY &optional ITEM INDENT)

Documentation

Apply FUNCTION on each item of HIERARCHY under ITEM.

This function navigates the tree bottom-up: FUNCTION is first called on leafs and the result is passed as parameter when calling FUNCTION on parents.

FUNCTION should take 3 parameters: the current item, its indentation level (a number), and a list representing the result of applying hierarchy-map-tree to each child of the item.

INDENT is 0 by default and is passed as second parameter to FUNCTION. INDENT is incremented by 1 at each level of the tree.

This function returns the result of applying FUNCTION to ITEM (the first root if nil).

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/hierarchy.el.gz
(defun hierarchy-map-tree (function hierarchy &optional item indent)
  "Apply FUNCTION on each item of HIERARCHY under ITEM.

This function navigates the tree bottom-up: FUNCTION is first called on
leafs and the result is passed as parameter when calling FUNCTION on
parents.

FUNCTION should take 3 parameters: the current item, its indentation
level (a number), and a list representing the result of applying
`hierarchy-map-tree' to each child of the item.

INDENT is 0 by default and is passed as second parameter to FUNCTION.
INDENT is incremented by 1 at each level of the tree.

This function returns the result of applying FUNCTION to ITEM (the first
root if nil)."
  (let ((item (or item (car (hierarchy-roots hierarchy))))
        (indent (or indent 0)))
    (funcall function item indent
             (mapcar (lambda (child)
                       (hierarchy-map-tree function hierarchy
                                           child (1+ indent)))
                     (hierarchy-children hierarchy item)))))