Skip to content

Commit

Permalink
Merge branch 'feat-columnsize'
Browse files Browse the repository at this point in the history
  • Loading branch information
justbur committed Jan 2, 2022
2 parents 99a7923 + 0abac5e commit 4c82226
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions which-key.el
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ Also adds \"..\". If nil, disable any truncation."
:group 'which-key
:type '(choice integer (const :tag "Disable truncation" nil)))

(defcustom which-key-min-column-description-width 0
"Every column should at least have this width."
:group 'which-key
:type 'integer)

(defcustom which-key-add-column-padding 0
"Additional padding (number of spaces) to add to the left of
each key column."
Expand Down Expand Up @@ -1843,12 +1848,12 @@ non-nil, then bindings are collected recursively for all prefixes."
(rows (apply #'cl-mapcar #'list padded)))
(mapconcat (lambda (row) (mapconcat #'identity row " ")) rows "\n")))

(defsubst which-key--max-len (keys index)
(defsubst which-key--max-len (keys index &optional initial-value)
"Internal function for finding the max length of the INDEX
element in each list element of KEYS."
(cl-reduce
(lambda (x y) (max x (which-key--string-width (nth index y))))
keys :initial-value 0))
keys :initial-value (if initial-value initial-value 0)))

(defun which-key--pad-column (col-keys)
"Take a column of (key separator description) COL-KEYS,
Expand All @@ -1857,7 +1862,8 @@ that width."
(let* ((col-key-width (+ which-key-add-column-padding
(which-key--max-len col-keys 0)))
(col-sep-width (which-key--max-len col-keys 1))
(col-desc-width (which-key--max-len col-keys 2))
(col-desc-width (which-key--max-len
col-keys 2 which-key-min-column-description-width))
(col-width (+ 1 col-key-width col-sep-width col-desc-width)))
(cons col-width
(mapcar (lambda (k)
Expand Down

0 comments on commit 4c82226

Please sign in to comment.