Don't print empty keymaps in `C-h b'

* lisp/help.el (describe-map-tree): Don't print the heading if the
keymap is empty (bug#22334).  Tweak the look to compress it more
vertically.
This commit is contained in:
Lars Ingebrigtsen 2021-11-01 03:18:02 +01:00
parent 686d85c767
commit 1200ecba27
2 changed files with 46 additions and 53 deletions

View file

@ -1275,17 +1275,8 @@ Any inserted text ends in two newlines (used by
result))
amaps))
(maps orig-maps)
(print-title (or maps always-title)))
;; Print title.
(when print-title
(insert (concat (if title
(concat title
(if prefix
(concat " Starting With "
(help--key-description-fontified prefix)))
":\n"))
"key binding\n"
"--- -------\n")))
(print-title (or maps always-title))
(start-point (point)))
;; Describe key bindings.
(setq help--keymaps-seen nil)
(while (consp maps)
@ -1310,8 +1301,24 @@ Any inserted text ends in two newlines (used by
(describe-map (cdr elt) elt-prefix transl partial
sub-shadows no-menu mention-shadow)))
(setq maps (cdr maps)))
(when print-title
(insert "\n"))))
;; Print title...
(when (and print-title
;; ... unless the keymap was empty.
(/= (point) start-point))
(save-excursion
(goto-char start-point)
(when (eolp)
(delete-region (point) (1+ (point))))
(insert
(concat
(if title
(concat title
(if prefix
(concat " Starting With "
(help--key-description-fontified prefix)))
":\n"))
"\nkey binding\n"
(make-separator-line)))))))
(defun help--shadow-lookup (keymap key accept-default remap)
"Like `lookup-key', but with command remapping.