From 53b84f7fddbcde969f44318ffcdab889c767352c Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 6 Mar 2025 12:41:57 +0100 Subject: [PATCH] Use substitute-command-keys in gnus-score-insert-help * lisp/gnus/gnus-score.el (gnus-score-insert-help): Use substitute-command-keys. Clean up the code a bit. --- lisp/gnus/gnus-score.el | 43 +++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el index 4f6c12a81ba..a4102ef0b51 100644 --- a/lisp/gnus/gnus-score.el +++ b/lisp/gnus/gnus-score.el @@ -789,31 +789,28 @@ current score file." (delete-windows-on (current-buffer)) (erase-buffer) (insert string ":\n\n") - (let ((max -1) - (list alist) - (i 0) - n width pad format) - ;; find the longest string to display - (while list - (setq n (length (nth idx (car list)))) - (unless (> max n) - (setq max n)) - (setq list (cdr list))) - (setq max (+ max 4)) ; %c, `:', SPACE, a SPACE at end - (setq n (/ (1- (window-width)) max)) ; items per line - (setq width (/ (1- (window-width)) n)) ; width of each item - ;; insert `n' items, each in a field of width `width' - (while alist - (if (< i n) - () - (setq i 0) + (let* ((longest-string (+ 4 ; %c, `:', SPACE, a SPACE at end + (seq-reduce #'max + (mapcar (lambda (elem) + (length (nth idx elem))) + alist) + 0))) + (w (1- (window-width))) + (items-per-line (/ w longest-string)) + (item-width (/ w items-per-line)) + (pad (- item-width 3)) + (i 0)) + ;; Insert `items-per-line' items, each in a field of width + ;; `item-width'. + (dolist (elem alist) + (when (>= i items-per-line) + (setq i 0) (delete-char -1) ; the `\n' takes a char (insert "\n")) - (setq pad (- width 3)) - (setq format (concat "%c: %-" (int-to-string pad) "s")) - (insert (format format (caar alist) (nth idx (car alist)))) - (setq alist (cdr alist)) - (setq i (1+ i)))) + (insert (substitute-command-keys + (format (concat "\\`%c': %-" (int-to-string pad) "s") + (car elem) (nth idx elem)))) + (incf i))) (goto-char (point-min)) ;; display ourselves in a small window at the bottom (appt-select-lowest-window)