Function: tabulated-list-groups-categorize

tabulated-list-groups-categorize is a byte-compiled function defined in tabulated-list.el.gz.

Signature

(tabulated-list-groups-categorize ENTRIES PATH-FUNCTION)

Documentation

Make a tree of groups from list of ENTRIES.

On each entry from ENTRIES apply PATH-FUNCTION that should return a list of paths that the entry has on the group tree that means that every entry can belong to multiple categories. Every path is a list of strings where every string is an outline heading at increasing level of deepness.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/tabulated-list.el.gz
(defun tabulated-list-groups-categorize (entries path-function)
  "Make a tree of groups from list of ENTRIES.
On each entry from ENTRIES apply PATH-FUNCTION that should return a list of
paths that the entry has on the group tree that means that every entry
can belong to multiple categories.  Every path is a list of strings
where every string is an outline heading at increasing level of deepness."
  (let ((tree nil)
        (hash (make-hash-table :test #'equal)))
    (cl-labels
        ((trie-add (list tree)
           (when list
             (setf (alist-get (car list) tree nil nil #'equal)
                   (trie-add (cdr list)
                             (alist-get (car list) tree nil nil #'equal)))
             tree))
         (trie-get (tree path)
           (mapcar (lambda (elt)
                     (cons (car elt)
                           (if (cdr elt)
                               (trie-get (cdr elt) (cons (car elt) path))
                             (apply #'vector (nreverse
                                              (gethash (reverse
                                                        (cons (car elt) path))
                                                       hash))))))
                   (reverse tree))))
      (dolist (entry entries)
        (dolist (path (funcall path-function entry))
          (unless (gethash path hash)
            (setq tree (trie-add path tree)))
          (cl-pushnew entry (gethash path hash))))
      (trie-get tree nil))))