Subject: bug#77423: Add labels to project-switch-use-entire-map prompt

From: Dmitry Gutov <[email-masked]>
Date: Tue, 1 Apr 2025 03:25:16 +0300

X-Debbugs-CC: [email-masked]
Tags: patch

This makes the return value of project--keymap-prompt include labels 
from the value of project-switch-commands (only those present - the 
other keys are printed without labels).

Seemingly makes it more readable, though longer.

This changes the 't' behavior, but if somebody really prefers the 
abbreviated version, we can make it a third value.

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index d954b78a745..f27958e7c45 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -2205,13 +2205,28 @@ project-key-prompt-style
   :version "30.1")
 
 (defun project--keymap-prompt ()
-  "Return a prompt for the project switching using the prefix map."
-  (let (keys)
-    (map-keymap
-     (lambda (evt _)
-       (when (characterp evt) (push evt keys)))
-     project-prefix-map)
-    (mapconcat (lambda (key) (help-key-description (string key) nil)) keys " ")))
+  "Return a prompt for the project switching using the prefix map.
+It includes labels for commands present in `project-switch-commands'."
+  (let (entries)
+   (pcase-dolist (`(,cmd ,label _) project-switch-commands)
+     (let ((key (where-is-internal cmd (list project-prefix-map) t)))
+       (when key
+         (push
+          (if (not (eq project-key-prompt-style 'brackets))
+              (format "%s %s"
+                      (propertize (key-description key) 'face 'help-key-binding)
+                      label)
+            (format "[%s] %s"
+                    (propertize (key-description key) 'face 'bold)
+                    label))
+          entries))))
+   (map-keymap
+    (lambda (evt def)
+      (when (and (characterp evt)
+                 (not (assq def project-switch-commands)))
+        (push (help-key-description (string evt) nil) entries)))
+    project-prefix-map)
+   (mapconcat #'identity (nreverse entries) " ")))
 
 (defun project--menu-prompt ()
   "Return a prompt for the project switching dispatch menu."