aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Bernoulli2022-08-04 14:05:08 +0200
committerJonas Bernoulli2022-08-04 14:05:08 +0200
commit254d6fdc2b3c993b599fc3ca29cda14bc6c0a5fb (patch)
treefbefafd9ecc03a447698985fe9f45b0dd3aae375
parent16c992f80fa6394b4dc5166e6c14129ec4946e12 (diff)
downloademacs-254d6fdc2b3c993b599fc3ca29cda14bc6c0a5fb.tar.gz
emacs-254d6fdc2b3c993b599fc3ca29cda14bc6c0a5fb.zip
Don't pad beyond maximal width
The old implementation behaved as if the "description" is the only information that is being displayed, however in actuality the available width has to be shared with the key (and the separator between the two). Failing to take that into account meant that every binding whose description isn't *by itself* wider than the width available to display all the information got excessive padding, which later has to be removed during truncation again (resulting in misleading ellipses).
-rw-r--r--which-key.el13
1 files changed, 8 insertions, 5 deletions
diff --git a/which-key.el b/which-key.el
index 89bdbe86457..8162d207f70 100644
--- a/which-key.el
+++ b/which-key.el
@@ -1865,15 +1865,18 @@ element in each list element of KEYS."
1865 (lambda (x y) (max x (which-key--string-width (nth index y)))) 1865 (lambda (x y) (max x (which-key--string-width (nth index y))))
1866 keys :initial-value (if initial-value initial-value 0))) 1866 keys :initial-value (if initial-value initial-value 0)))
1867 1867
1868(defun which-key--pad-column (col-keys) 1868(defun which-key--pad-column (col-keys avl-width)
1869 "Take a column of (key separator description) COL-KEYS, 1869 "Take a column of (key separator description) COL-KEYS,
1870calculate the max width in the column and pad all cells out to 1870calculate the max width in the column and pad all cells out to
1871that width." 1871that width."
1872 (let* ((col-key-width (+ which-key-add-column-padding 1872 (let* ((col-key-width (+ which-key-add-column-padding
1873 (which-key--max-len col-keys 0))) 1873 (which-key--max-len col-keys 0)))
1874 (col-sep-width (which-key--max-len col-keys 1)) 1874 (col-sep-width (which-key--max-len col-keys 1))
1875 (col-desc-width (which-key--max-len 1875 (avl-width (- avl-width col-key-width col-sep-width))
1876 col-keys 2 which-key-min-column-description-width)) 1876 (col-desc-width (min avl-width
1877 (which-key--max-len
1878 col-keys 2
1879 which-key-min-column-description-width)))
1877 (col-width (+ 1 col-key-width col-sep-width col-desc-width)) 1880 (col-width (+ 1 col-key-width col-sep-width col-desc-width))
1878 (col-format (concat "%" (int-to-string col-key-width) 1881 (col-format (concat "%" (int-to-string col-key-width)
1879 "s%s%-" (int-to-string col-desc-width) "s"))) 1882 "s%s%-" (int-to-string col-desc-width) "s")))
@@ -1893,8 +1896,8 @@ that width."
1893 "Convert list of KEYS to columns based on dimensions AVL-LINES and AVL-WIDTH. 1896 "Convert list of KEYS to columns based on dimensions AVL-LINES and AVL-WIDTH.
1894Returns a `which-key--pages' object that holds the page strings, 1897Returns a `which-key--pages' object that holds the page strings,
1895as well as metadata." 1898as well as metadata."
1896 (let ((cols-w-widths (mapcar #'which-key--pad-column 1899 (let ((cols-w-widths (mapcar (lambda (c) (which-key--pad-column c avl-width))
1897 (which-key--partition-list avl-lines keys))) 1900 (which-key--partition-list avl-lines keys)))
1898 (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0) 1901 (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0)
1899 page-cols pages page-widths keys/page col) 1902 page-cols pages page-widths keys/page col)
1900 (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width) 1903 (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)