Function: imenu--split-menu

imenu--split-menu is a byte-compiled function defined in imenu.el.gz.

Signature

(imenu--split-menu MENULIST TITLE)

Documentation

Split the alist MENULIST into a nested alist, if it is long enough.

In any case, add TITLE to the front of the alist. If IMENU--RESCAN-ITEM is present in MENULIST, it is moved to the beginning of the returned alist. The returned alist DOES NOT share structure with MENULIST.

Source Code

;; Defined in /usr/src/emacs/lisp/imenu.el.gz
(defun imenu--split-menu (menulist title)
  "Split the alist MENULIST into a nested alist, if it is long enough.
In any case, add TITLE to the front of the alist.
If IMENU--RESCAN-ITEM is present in MENULIST, it is moved to the
beginning of the returned alist.
The returned alist DOES NOT share structure with MENULIST."
  (let ((menulist (copy-sequence menulist))
        keep-at-top)
    (if (memq imenu--rescan-item menulist)
	(setq keep-at-top (list imenu--rescan-item)
	      menulist (delq imenu--rescan-item menulist)))
    (dolist (item menulist)
      (when (imenu--subalist-p item)
	(push item keep-at-top)
	(setq menulist (delq item menulist))))
    (if imenu-sort-function
	(setq menulist (sort menulist imenu-sort-function)))
    (if (> (length menulist) imenu-max-items)
	(setq menulist
	      (mapcar
	       (lambda (menu)
		 (cons (format "From: %s" (caar menu)) menu))
	       (imenu--split menulist imenu-max-items))))
    (cons title
	  (nconc (nreverse keep-at-top) menulist))))