Function: imenu--split

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

Signature

(imenu--split LIST N)

Documentation

Split LIST into sublists of max length N.

Example (imenu--split '(1 2 3 4 5 6 7 8) 3) => ((1 2 3) (4 5 6) (7 8)) The returned list DOES NOT share structure with LIST.

Source Code

;; Defined in /usr/src/emacs/lisp/imenu.el.gz
(defun imenu--split (list n)
  "Split LIST into sublists of max length N.
Example (imenu--split \\='(1 2 3 4 5 6 7 8) 3) => ((1 2 3) (4 5 6) (7 8))
The returned list DOES NOT share structure with LIST."
  (let ((remain list)
	(result '())
	(sublist '())
	(i 0))
    (while remain
      (push (pop remain) sublist)
      (incf i)
      (and (= i n)
	   ;; We have finished a sublist
	   (progn (push (nreverse sublist) result)
		  (setq i 0)
		  (setq sublist '()))))
    ;; There might be a sublist (if the length of LIST mod n is != 0)
    ;; that has to be added to the result list.
    (and sublist
	 (push (nreverse sublist) result))
    (nreverse result)))