1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-01 03:11:09 -08:00

Clean-up partition-columns implementation

This commit is contained in:
justbur 2015-08-03 11:26:56 -04:00
parent 3effbaf080
commit af9e3425ec

View file

@ -921,32 +921,28 @@ Returns a plist that holds the page strings, as well as metadata."
(-partition-all avl-lines keys)))
(page-width 0) (n-pages 0) (n-keys 0)
page-cols pages page-widths keys/page)
(if (> (car (car cols-w-widths)) avl-width)
;; give up if first column doesn't fit
(if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)
;; give up if any columns don't fit
(list :pages nil :page-height 0 :page-widths '(0)
:keys/page '(0) :n-pages 0 :tot-keys 0)
(dolist (col cols-w-widths)
(if (<= (+ (car col) page-width) avl-width)
(progn (push (cdr col) page-cols)
(setq page-width (+ page-width (car col))
n-keys (+ (length (cdr col)) n-keys)))
(when (> (length page-cols) 0)
(push (which-key--join-columns page-cols) pages)
(push n-keys keys/page)
(push page-width page-widths)
(setq n-pages (1+ n-pages)
n-keys (length (cdr col))
page-cols (list (cdr col))
page-width (car col)))))
(when (> (length page-cols) 0)
(while cols-w-widths
(when (not (<= (+ (caar cols-w-widths) page-width) avl-width))
(error "which-key: error in partition-columns"))
(while (and cols-w-widths
(<= (+ (caar cols-w-widths) page-width) avl-width))
(setq col (pop cols-w-widths)
page-width (+ page-width (car col))
n-keys (+ (length (cdr col)) n-keys))
(push (cdr col) page-cols))
(push (which-key--join-columns page-cols) pages)
(push n-keys keys/page)
(push page-width page-widths)
(setq n-pages (1+ n-pages)))
(setq n-pages (1+ n-pages)
n-keys 0 page-cols '() page-width 0))
(list :pages (reverse pages) :page-height avl-lines
:page-widths (reverse page-widths)
:keys/page (reverse keys/page) :n-pages n-pages
:tot-keys (cl-reduce '+ keys/page :initial-value 0)))))
:tot-keys (apply #'+ keys/page)))))
(defun which-key--create-pages (keys sel-win-width)
"Create page strings using `which-key--partition-columns'.