Subject: [PATCH] Improve project-compile command prompt

From: Gabriel do Nascimento Ribeiro <[email-masked]>
Date: Fri, 22 Aug 2025 16:46:58 +0000

Improve 'project-compile' command prompt, which makes it more consistent with
the new project switch prompt introduced by commit 86e17fbcbddb, and makes it
clear to users which compilation command is being executed (default 'compile' or
'project-compile').

>From 05fd5ea90e3fad1d20fe30f7597aae897cda438a Mon Sep 17 00:00:00 2001
From: Gabriel Ribeiro <[email-masked]>
Date: Fri, 22 Aug 2025 13:40:53 -0300
Subject: [PATCH] Include project root in project-compile prompt

* lisp/progmodes/compile.el:
  (compilation-command-prompt): New user option.
  (compilation-read-command): Use it.
* lisp/progmodes/project.el:
  (project-compilation-command-prompt): New user option.
  (project--compilation-command-prompt): New function to generate the
  default project-compile prompt.
  (project-compile): Use it.
---
 etc/NEWS                  |  8 ++++++++
 lisp/progmodes/compile.el | 18 ++++++++++++++----
 lisp/progmodes/project.el | 18 +++++++++++++++++-
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ebf03b53e12..4df47922bf7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -515,6 +515,10 @@ which removes all non-remote projects.
 *** New command 'project-save-some-buffers' bound to 'C-x p C-x s'.
 This is like 'C-x s', but only for this project's buffers.
 
+*** New user option 'project-compilation-command-prompt'
+This user option controls the computation of the minibuffer prompt for
+the 'projet-compile' command.  See also 'compilation-command-prompt'.
+
 *** 'project-remember-project' can now be called interactively.
 
 ---
@@ -595,6 +599,10 @@ To use the ':foreground' or current text color ensure the 'fill' attribute
 in the SVG is set to 'currentcolor', or set the image spec's ':css'
 value to 'svg {fill: currentcolor;}'.
 
+*** New user option 'compilation-command-prompt'
+This user option controls the computation of the minibuffer prompt for
+the `compile' command.  See also 'project-compilation-command-prompt'.
+
 
 * Editing Changes in Emacs 31.1
 
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 8cfa793cfc6..f192ab11406 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -121,6 +121,13 @@ compilation-hidden-output
                  (repeat regexp))
   :version "29.1")
 
+(defcustom compilation-command-prompt "Compile command: "
+  "String or function to call to compute the `compile' command
+minibuffer prompt."
+  :type '(choice string
+                 function)
+  :version "31.1")
+
 (defvar compilation-first-column 1
   "This is how compilers number the first column, usually 1 or 0.
 If this is buffer-local in the destination buffer, Emacs obeys
@@ -1815,10 +1822,13 @@ compilation-mode-font-lock-keywords
    compilation-mode-font-lock-keywords))
 
 (defun compilation-read-command (command)
-  (read-shell-command "Compile command: " command
-                      (if (equal (car compile-history) command)
-                          '(compile-history . 1)
-                        'compile-history)))
+  (let ((prompt (if (functionp compilation-command-prompt)
+                    (funcall compilation-command-prompt)
+                  compilation-command-prompt))
+        (initial (if (equal (car compile-history) command)
+                     '(compile-history . 1)
+                   'compile-history)))
+  (read-shell-command prompt command initial)))
 
 
 ;;;###autoload
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index efc00ac8733..f2294422b7a 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1605,6 +1605,21 @@ project-compilation-buffer-name-function
                         project-prefixed-buffer-name)
                  (function :tag "Custom function")))
 
+(defcustom project-compilation-command-prompt #'project--compilation-command-prompt
+  "String or function to call to compute the `project-compile' command
+minibuffer prompt."
+  :type '(choice string
+                 function)
+  :version "31.1")
+
+(defun project--compilation-command-prompt ()
+  (let ((project (project-current)))
+    (if project
+        (format-message "Compile command in `%s': "
+                        (propertize (project-root project)
+                                    'face 'font-lock-string-face))
+      "Compile command: ")))
+
 ;;;###autoload
 (defun project-compile ()
   "Run `compile' in the project root."
@@ -1613,7 +1628,8 @@ project-compile
   (let ((default-directory (project-root (project-current t)))
         (compilation-buffer-name-function
          (or project-compilation-buffer-name-function
-             compilation-buffer-name-function)))
+             compilation-buffer-name-function))
+        (compilation-command-prompt project-compilation-command-prompt))
     (call-interactively #'compile)))
 
 ;;;###autoload
-- 
2.34.1

---
Gabriel