Subject: bug#79292: [PATCH] Improve project-compile command prompt

From: Gabriel do Nascimento Ribeiro <[email-masked]>
Date: Wed, 27 Aug 2025 20:43:51 +0000

I thought that temporarily binding an user-option was fine.  Anyway, here is
an updated version of the patch that uses a defvar.  Thanks!

>From 4cabf62e8e6a6b7c8f3a0c4afa177a04b7594d88 Mon Sep 17 00:00:00 2001
From: Gabriel Ribeiro <[email-masked]>
Date: Wed, 27 Aug 2025 17:38:23 -0300
Subject: [PATCH] Include project root in project-compile prompt

* lisp/progmodes/compile.el:
  (compilation-command-prompt): New variable.
  (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                  |  4 ++++
 lisp/progmodes/compile.el | 15 +++++++++++----
 lisp/progmodes/project.el | 18 +++++++++++++++++-
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index bd2ce33b851..0b183df629a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -516,6 +516,10 @@ project should be removed.
 *** 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 'project-compile' command.
+
 *** 'project-remember-project' can now be called interactively.

 ---
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 8cfa793cfc6..5f75fc3abca 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -121,6 +121,10 @@ compilation-hidden-output
                  (repeat regexp))
   :version "29.1")

+(defvar compilation-command-prompt "Compile command: "
+  "String or function to call to compute the `compile' command
+minibuffer prompt.")
+
 (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 +1819,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 05f3a9991be..02382fd5c95 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

________________________________________
From: Eli Zaretskii <[email-masked]>
Sent: Friday, August 22, 2025 2:15 PM
To: Gabriel do Nascimento Ribeiro
Cc: [email-masked]
Subject: Re: bug#79292: [PATCH] Improve project-compile command prompt

> From: Gabriel do Nascimento Ribeiro <[email-masked]>
> Date: Fri, 22 Aug 2025 16:46:58 +0000
> msip_labels:
>
> 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').

Thanks, but IMO making compilation-command-prompt a defcustom is the
wrong way to implement this.  A defcustom is a user option, and thus
should not be overridden by Lisp programs, ever.  Instead, make it a
defvar, then Lisp programs could bind it to whatever values they want.