Function: which-key--list-to-pages

which-key--list-to-pages is a byte-compiled function defined in which-key.el.gz.

Signature

(which-key--list-to-pages KEYS AVL-LINES AVL-WIDTH)

Documentation

Convert list of KEYS to columns based on dimensions AVL-LINES and AVL-WIDTH.

Return a which-key--pages object that holds the page strings, as well as metadata.

Source Code

;; Defined in /usr/src/emacs/lisp/which-key.el.gz
(defun which-key--list-to-pages (keys avl-lines avl-width)
  "Convert list of KEYS to columns based on dimensions AVL-LINES and AVL-WIDTH.
Return a `which-key--pages' object that holds the page strings,
as well as metadata."
  (let ((cols-w-widths (mapcar (lambda (c) (which-key--pad-column c avl-width))
			       (which-key--partition-list avl-lines keys)))
        (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0)
        page-cols pages page-widths keys/page col)
    (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)
        ;; give up if no columns fit
        nil
      (while cols-w-widths
        ;; start new page
        (cl-incf n-pages)
        (setq col (pop cols-w-widths))
        (setq page-cols (list (cdr col)))
        (setq page-width (car col))
        (setq n-keys (length (cdr col)))
        (setq n-columns 1)
        ;; add additional columns as long as they fit
        (while (and cols-w-widths
                    (or (null which-key-max-display-columns)
                        (< n-columns which-key-max-display-columns))
                    (<= (+ page-width 1 (caar cols-w-widths)) avl-width))
          (setq col (pop cols-w-widths))
          (push (cdr col) page-cols)
          (cl-incf page-width (1+ (car col)))
          (cl-incf n-keys (length (cdr col)))
          (cl-incf n-columns))
        (push (which-key--join-columns page-cols) pages)
        (push n-keys keys/page)
        (push page-width page-widths))
      (make-which-key--pages
       :pages (nreverse pages)
       :height (if (> n-pages 1) avl-lines (min avl-lines n-keys))
       :widths (nreverse page-widths)
       :keys/page (reverse keys/page)
       :page-nums (number-sequence 1 n-pages)
       :num-pages n-pages
       :total-keys (apply #'+ keys/page)))))